From edb8fffce8648b874a75e5201ba13dbe08f9c8de Mon Sep 17 00:00:00 2001 From: Alex Xing <90179377+SuperYoko@users.noreply.github.com> Date: Fri, 14 Oct 2022 21:09:23 +0800 Subject: [PATCH] remove rebuild index guard when job finished (#4722) * remove rebuild index guard when job finished * fix reenter problem Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> --- src/storage/admin/RebuildIndexTask.cpp | 12 ++++++++++++ src/storage/admin/RebuildIndexTask.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/storage/admin/RebuildIndexTask.cpp b/src/storage/admin/RebuildIndexTask.cpp index 98e0545cb7b..e4cbad43fdf 100644 --- a/src/storage/admin/RebuildIndexTask.cpp +++ b/src/storage/admin/RebuildIndexTask.cpp @@ -17,6 +17,17 @@ const int32_t kReserveNum = 1024 * 4; bool RebuildIndexTask::check() { return env_->kvstore_ != nullptr; } +void RebuildIndexTask::finish(nebula::cpp2::ErrorCode rc) { + if (changedSpaceGuard_) { + auto space = *ctx_.parameters_.space_id_ref(); + for (auto it = env_->rebuildIndexGuard_->begin(); it != env_->rebuildIndexGuard_->end(); ++it) { + if (std::get<0>(it->first) == space) { + env_->rebuildIndexGuard_->insert_or_assign(it->first, IndexState::FINISHED); + } + } + } + AdminTask::finish(rc); +} RebuildIndexTask::RebuildIndexTask(StorageEnv* env, TaskContext&& ctx) : AdminTask(env, std::move(ctx)) { @@ -71,6 +82,7 @@ ErrorOr> RebuildIndexTask::ge for (const auto& part : parts) { env_->rebuildIndexGuard_->insert_or_assign(std::make_tuple(space_, part), IndexState::STARTING); TaskFunction task = std::bind(&RebuildIndexTask::invoke, this, space_, part, items); + changedSpaceGuard_ = true; tasks.emplace_back(std::move(task)); } return tasks; diff --git a/src/storage/admin/RebuildIndexTask.h b/src/storage/admin/RebuildIndexTask.h index 2f3eac072b9..7e8b0fd1a58 100644 --- a/src/storage/admin/RebuildIndexTask.h +++ b/src/storage/admin/RebuildIndexTask.h @@ -23,6 +23,8 @@ using IndexItems = std::vector>; */ class RebuildIndexTask : public AdminTask { public: + using AdminTask::finish; + RebuildIndexTask(StorageEnv* env, TaskContext&& ctx); ~RebuildIndexTask() { @@ -31,6 +33,8 @@ class RebuildIndexTask : public AdminTask { bool check() override; + void finish(nebula::cpp2::ErrorCode rc) override; + /** * @brief Generate subtasks for rebuilding index. * @@ -71,6 +75,7 @@ class RebuildIndexTask : public AdminTask { protected: GraphSpaceID space_; + bool changedSpaceGuard_{false}; }; } // namespace storage