diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 1847e30017..e2bad26deb 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) { - std::cout << "get to index file" << std::endl; - status = BuildIndex(file); - if (!status.ok()) { + 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(); } - - 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 83d112918c..2645a46df6 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 667db2cbae..2794c1b45d 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 cd751270a0..770295a042 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;