Skip to content

Commit

Permalink
Reduce the blocking time of the write lock when deleting space
Browse files Browse the repository at this point in the history
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
  • Loading branch information
flymysql authored Nov 6, 2023
1 parent 38b3e9d commit 1647ab5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/kvstore/NebulaStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,20 +516,28 @@ 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);
}
}
this->spaces_.erase(spaceIt);
}
if (ok(spaceOr)) {
auto spaceIt = value(spaceOr);
auto& engines = spaceIt->second->engines_;
for (auto& engine : engines) {
auto parts = engine->allParts();
Expand All @@ -538,14 +546,13 @@ void NebulaStore::removeSpace(GraphSpaceID spaceId) {
}
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 1647ab5

Please sign in to comment.