diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 1847e30017b674903f00ea9c427282b9bcf257d5..e2bad26deb2d4207e26b739f477722ebeeb9f7d5 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -899,35 +899,35 @@ DBImpl::BackgroundBuildIndex() { Status status; // step 2: put build index task to scheduler -// for (auto &file : to_index_files) { -// scheduler::BuildIndexJobPtr -// job = std::make_shared(0, meta_ptr_, options_); -// -// scheduler::TableFileSchemaPtr file_ptr = std::make_shared(file); -// -// job->AddToIndexFiles(file_ptr); -// scheduler::JobMgrInst::GetInstance()->Put(job); -// job->WaitBuildIndexFinish(); -// if (!job->GetStatus().ok()) { -// Status status = job->GetStatus(); -// ENGINE_LOG_ERROR << "Building index for " << file.id_ << " failed: " << status.ToString(); -// } -// } + for (auto &file : to_index_files) { + scheduler::BuildIndexJobPtr + job = std::make_shared(0, meta_ptr_, options_); + scheduler::TableFileSchemaPtr file_ptr = std::make_shared(file); - for (auto &file : to_index_files) { - std::cout << "get to index file" << std::endl; - status = BuildIndex(file); - if (!status.ok()) { + job->AddToIndexFiles(file_ptr); + scheduler::JobMgrInst::GetInstance()->Put(job); + job->WaitBuildIndexFinish(); + if (!job->GetStatus().ok()) { + Status status = job->GetStatus(); ENGINE_LOG_ERROR << "Building index for " << file.id_ << " failed: " << status.ToString(); } - - if (shutting_down_.load(std::memory_order_acquire)) { - ENGINE_LOG_DEBUG << "Server will shutdown, skip build index action"; - break; - } } + +// for (auto &file : to_index_files) { +// std::cout << "get to index file" << std::endl; +// status = BuildIndex(file); +// if (!status.ok()) { +// ENGINE_LOG_ERROR << "Building index for " << file.id_ << " failed: " << status.ToString(); +// } +// +// if (shutting_down_.load(std::memory_order_acquire)) { +// ENGINE_LOG_DEBUG << "Server will shutdown, skip build index action"; +// break; +// } +// } + ENGINE_LOG_TRACE << "Background build index thread exit"; } diff --git a/cpp/src/scheduler/TaskCreator.cpp b/cpp/src/scheduler/TaskCreator.cpp index 83d112918c7fa1d3257e4d41dede2d3f28874394..2645a46df6a080333d8a18127f08fb54f9837240 100644 --- a/cpp/src/scheduler/TaskCreator.cpp +++ b/cpp/src/scheduler/TaskCreator.cpp @@ -75,8 +75,8 @@ TaskCreator::Create(const BuildIndexJobPtr &job) { ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource("disk"); for (auto &to_index_file : job->to_index_files()) { - auto task = std::make_shared(to_index_file.second); - task->label() = std::make_shared(std::weak_ptr(res_ptr)); + auto label = std::make_shared(std::weak_ptr(res_ptr)); + auto task = std::make_shared(to_index_file.second, label); task->job_ = job; tasks.emplace_back(task); } diff --git a/cpp/src/scheduler/task/BuildIndexTask.cpp b/cpp/src/scheduler/task/BuildIndexTask.cpp index 667db2cbae821813d118df80506a9efacc49c6f4..2794c1b45d8255edc7dc3564e4471699ca0c3707 100644 --- a/cpp/src/scheduler/task/BuildIndexTask.cpp +++ b/cpp/src/scheduler/task/BuildIndexTask.cpp @@ -29,8 +29,8 @@ namespace milvus { namespace scheduler { -XBuildIndexTask::XBuildIndexTask(TableFileSchemaPtr file) - : Task(TaskType::BuildIndexTask), file_(file) { +XBuildIndexTask::XBuildIndexTask(TableFileSchemaPtr file, TaskLabelPtr label) + : Task(TaskType::BuildIndexTask, std::move(label)), file_(file) { if (file_) { to_index_engine_ = EngineFactory::Build(file_->dimension_, file_->location_, (EngineType) file_->engine_type_, (MetricType) file_->metric_type_, file_->nlist_); diff --git a/cpp/src/scheduler/task/BuildIndexTask.h b/cpp/src/scheduler/task/BuildIndexTask.h index cd751270a07ee50bace19f339b5b4f38074180b4..770295a042971753d33be121ee2dbc60555e2fe7 100644 --- a/cpp/src/scheduler/task/BuildIndexTask.h +++ b/cpp/src/scheduler/task/BuildIndexTask.h @@ -27,7 +27,7 @@ namespace scheduler { class XBuildIndexTask : public Task { public: - explicit XBuildIndexTask(TableFileSchemaPtr file); + explicit XBuildIndexTask(TableFileSchemaPtr file, TaskLabelPtr label); void Load(LoadType type, uint8_t device_id) override;