Skip to content

Commit

Permalink
remove rebuild index guard when job finished (#4722)
Browse files Browse the repository at this point in the history
* remove rebuild index guard when job finished

* fix reenter problem

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
SuperYoko and Sophie-Xie committed Oct 17, 2022
1 parent 8002213 commit edb8fff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/storage/admin/RebuildIndexTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -71,6 +82,7 @@ ErrorOr<nebula::cpp2::ErrorCode, std::vector<AdminSubTask>> 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;
Expand Down
5 changes: 5 additions & 0 deletions src/storage/admin/RebuildIndexTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ using IndexItems = std::vector<std::shared_ptr<meta::cpp2::IndexItem>>;
*/
class RebuildIndexTask : public AdminTask {
public:
using AdminTask::finish;

RebuildIndexTask(StorageEnv* env, TaskContext&& ctx);

~RebuildIndexTask() {
Expand All @@ -31,6 +33,8 @@ class RebuildIndexTask : public AdminTask {

bool check() override;

void finish(nebula::cpp2::ErrorCode rc) override;

/**
* @brief Generate subtasks for rebuilding index.
*
Expand Down Expand Up @@ -71,6 +75,7 @@ class RebuildIndexTask : public AdminTask {

protected:
GraphSpaceID space_;
bool changedSpaceGuard_{false};
};

} // namespace storage
Expand Down

0 comments on commit edb8fff

Please sign in to comment.