Skip to content

Commit

Permalink
Merge pull request #1 from flymysql/develop
Browse files Browse the repository at this point in the history
Reduce the blocking time of the write lock when deleting space
  • Loading branch information
flymysql authored Nov 6, 2023
2 parents 38b3e9d + 1647ab5 commit b72df14
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 b72df14

Please sign in to comment.