From 1647ab5ed48ed627857fda5955a37dcbee02b706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B0=E5=B7=9E=E5=B0=8F=E7=BA=A2=E9=B8=A1?= Date: Mon, 6 Nov 2023 17:48:32 +0800 Subject: [PATCH] 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 --- src/kvstore/NebulaStore.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/kvstore/NebulaStore.cpp b/src/kvstore/NebulaStore.cpp index 218062413e3..91621a1be68 100644 --- a/src/kvstore/NebulaStore.cpp +++ b/src/kvstore/NebulaStore.cpp @@ -516,13 +516,17 @@ std::shared_ptr 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 @@ -530,6 +534,10 @@ void NebulaStore::removeSpace(GraphSpaceID spaceId) { 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(); @@ -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 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);