DeleteJob.cpp 1.8 KB
Newer Older
W
wxyu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
W
wxyu 已提交
17

G
groot 已提交
18
#include "scheduler/job/DeleteJob.h"
W
wxyu 已提交
19

G
groot 已提交
20
#include <utility>
W
wxyu 已提交
21 22 23 24

namespace milvus {
namespace scheduler {

W
wxyu 已提交
25 26
DeleteJob::DeleteJob(std::string table_id, engine::meta::MetaPtr meta_ptr, uint64_t num_resource)
    : Job(JobType::DELETE),
W
wxyu 已提交
27 28
      table_id_(std::move(table_id)),
      meta_ptr_(std::move(meta_ptr)),
G
groot 已提交
29 30
      num_resource_(num_resource) {
}
W
wxyu 已提交
31

G
groot 已提交
32 33
void
DeleteJob::WaitAndDelete() {
W
wxyu 已提交
34
    std::unique_lock<std::mutex> lock(mutex_);
G
groot 已提交
35
    cv_.wait(lock, [&] { return done_resource == num_resource_; });
W
wxyu 已提交
36 37 38
    meta_ptr_->DeleteTableFiles(table_id_);
}

G
groot 已提交
39 40
void
DeleteJob::ResourceDone() {
W
wxyu 已提交
41 42 43 44 45 46 47
    {
        std::lock_guard<std::mutex> lock(mutex_);
        ++done_resource;
    }
    cv_.notify_one();
}

W
wxyu 已提交
48 49 50 51 52 53 54
json
DeleteJob::Dump() const {
    json ret{
        {"table_id", table_id_},
        {"number_of_resource", num_resource_},
        {"number_of_done", done_resource},
    };
W
wxyu 已提交
55 56
    auto base = Job::Dump();
    ret.insert(base.begin(), base.end());
W
wxyu 已提交
57 58 59
    return ret;
}

G
groot 已提交
60 61
}  // namespace scheduler
}  // namespace milvus