Skip to content

Commit

Permalink
Reduce the blocking time of the write lock when deleting space (#5754)
Browse files Browse the repository at this point in the history
* Reduce the blocking time of the write lock when deleting space

When the number of parts of a space is relatively large and the amount of data written is also large, it will block for a long time in the removeSpace function when deleting the space. Affect business read and write

* Resolve compilation issues

Resolve compilation issues
  • Loading branch information
flymysql authored Nov 15, 2023
1 parent 8dfb587 commit 4c6a0a7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/kvstore/NebulaStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,36 +516,43 @@ std::shared_ptr<Part> NebulaStore::newPart(GraphSpaceID spaceId,
}

void NebulaStore::removeSpace(GraphSpaceID spaceId) {
folly::RWSpinLock::WriteHolder wh(&lock_);
if (beforeRemoveSpace_) {
beforeRemoveSpace_(spaceId);
{
folly::RWSpinLock::WriteHolder wh(&lock_);
if (beforeRemoveSpace_) {
beforeRemoveSpace_(spaceId);
}
}

auto spaceIt = this->spaces_.find(spaceId);
if (spaceIt != this->spaces_.end()) {
auto spaceOr = space(spaceId);
if (ok(spaceOr)) {
folly::RWSpinLock::WriteHolder wh(&lock_);
auto spaceIt = this->spaces_.find(spaceId);
for (auto& [partId, part] : spaceIt->second->parts_) {
// before calling removeSpace, meta client would call removePart to remove all parts in
// meta cache, which do not contain learners, so we remove them here
if (part->isLearner()) {
removePart(spaceId, partId, false);
}
}
auto& engines = spaceIt->second->engines_;
this->spaces_.erase(spaceIt);
}
if (ok(spaceOr)) {
auto spaceIt = value(spaceOr);
auto& engines = spaceIt->engines_;
for (auto& engine : engines) {
auto parts = engine->allParts();
for (auto& partId : parts) {
engine->removePart(partId);
}
CHECK_EQ(0, engine->totalPartsNum());
}
CHECK(spaceIt->second->parts_.empty());
CHECK(spaceIt->parts_.empty());
std::vector<std::string> enginePaths;
if (FLAGS_auto_remove_invalid_space) {
for (auto& engine : engines) {
enginePaths.emplace_back(engine->getDataRoot());
}
}
this->spaces_.erase(spaceIt);
if (FLAGS_auto_remove_invalid_space) {
for (const auto& path : enginePaths) {
removeSpaceDir(path);
Expand Down

0 comments on commit 4c6a0a7

Please sign in to comment.