From b77fa599b86252cf2a49dcb09cb803dbc2ba4c04 Mon Sep 17 00:00:00 2001 From: "darion.yaphet" Date: Tue, 7 Dec 2021 17:48:38 +0800 Subject: [PATCH] fix critical27 comment --- src/graph/executor/admin/SpaceExecutor.cpp | 8 ++-- src/meta/ActiveHostsMan.cpp | 5 +-- .../processors/zone/DropHostsProcessor.cpp | 43 +++++++++++++------ src/meta/processors/zone/DropHostsProcessor.h | 5 +-- .../processors/zone/RenameZoneProcessor.cpp | 3 ++ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/graph/executor/admin/SpaceExecutor.cpp b/src/graph/executor/admin/SpaceExecutor.cpp index 801a97d2a7d..f2a452482fc 100644 --- a/src/graph/executor/admin/SpaceExecutor.cpp +++ b/src/graph/executor/admin/SpaceExecutor.cpp @@ -220,14 +220,12 @@ folly::Future ShowCreateSpaceExecutor::execute() { auto fmt = properties.comment_ref().has_value() ? "CREATE SPACE `%s` (partition_num = %d, replica_factor = %d, " "charset = %s, collate = %s, vid_type = %s, atomic_edge = %s" - ")%s" + ") ON %s" " comment = '%s'" : "CREATE SPACE `%s` (partition_num = %d, replica_factor = %d, " "charset = %s, collate = %s, vid_type = %s, atomic_edge = %s" - ")%s"; - auto zoneNames = !properties.get_zone_names().empty() - ? " ON " + folly::join(",", properties.get_zone_names()) - : ""; + ") ON %s"; + auto zoneNames = folly::join(",", properties.get_zone_names()); if (properties.comment_ref().has_value()) { row.values.emplace_back( folly::stringPrintf(fmt, diff --git a/src/meta/ActiveHostsMan.cpp b/src/meta/ActiveHostsMan.cpp index c870c5127b8..5a9b243de3c 100644 --- a/src/meta/ActiveHostsMan.cpp +++ b/src/meta/ActiveHostsMan.cpp @@ -102,11 +102,10 @@ ErrorOr> ActiveHostsMan::getActiv return retCode; } - std::vector machines; + std::unordered_set machines; while (machineIter->valid()) { auto machine = MetaKeyUtils::parseMachineKey(machineIter->key()); - LOG(INFO) << "Machine " << machine; - machines.emplace_back(std::move(machine)); + machines.emplace(std::move(machine)); machineIter->next(); } diff --git a/src/meta/processors/zone/DropHostsProcessor.cpp b/src/meta/processors/zone/DropHostsProcessor.cpp index 12802889906..8fe90aaa37e 100644 --- a/src/meta/processors/zone/DropHostsProcessor.cpp +++ b/src/meta/processors/zone/DropHostsProcessor.cpp @@ -9,6 +9,8 @@ namespace nebula { namespace meta { void DropHostsProcessor::process(const cpp2::DropHostsReq& req) { + folly::SharedMutex::ReadHolder zHolder(LockUtils::zoneLock()); + folly::SharedMutex::ReadHolder mHolder(LockUtils::machineLock()); auto hosts = req.get_hosts(); if (std::unique(hosts.begin(), hosts.end()) != hosts.end()) { LOG(ERROR) << "Hosts have duplicated element"; @@ -25,6 +27,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) { } std::vector data; + std::vector rewriteData; // Check that partition is not held on the host const auto& spacePrefix = MetaKeyUtils::spacePrefix(); auto spaceIterRet = doPrefix(spacePrefix); @@ -77,17 +80,35 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) { auto iter = nebula::value(iterRet).get(); while (iter->valid()) { + auto zoneKey = iter->key().data(); auto hs = MetaKeyUtils::parseZoneHosts(iter->val()); + // Delete all hosts in the zone if (std::all_of(hs.begin(), hs.end(), [&hosts](auto& h) { return std::find(hosts.begin(), hosts.end(), h) != hosts.end(); })) { auto zoneName = MetaKeyUtils::parseZoneName(iter->key()); LOG(INFO) << "Drop zone " << zoneName; - code = checkRelatedSpace(zoneName); - if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { + auto result = checkRelatedSpaceAndCollect(zoneName); + if (!nebula::ok(result)) { + LOG(ERROR) << "Check related space failed"; + code = nebula::error(result); break; } + + const auto& rewrites = nebula::value(result); + rewriteData.insert(rewriteData.end(), rewrites.begin(), rewrites.end()); data.emplace_back(iter->key()); + } else { + // Delete some hosts in the zone + for (auto& h : hosts) { + auto it = std::find(hs.begin(), hs.end(), h); + if (it != hs.end()) { + hs.erase(it); + } + } + + auto zoneValue = MetaKeyUtils::zoneVal(hs); + rewriteData.emplace_back(std::move(zoneKey), std::move(zoneValue)); } iter->next(); } @@ -114,7 +135,9 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) { doMultiRemove(std::move(data)); } -nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpace(const std::string& zoneName) { +ErrorOr> +DropHostsProcessor::checkRelatedSpaceAndCollect(const std::string& zoneName) { + std::vector data; const auto& prefix = MetaKeyUtils::spacePrefix(); auto ret = doPrefix(prefix); if (!nebula::ok(ret)) { @@ -137,19 +160,15 @@ nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpace(const std::string& } else { zones.erase(it); properties.set_zone_names(zones); - rewriteSpaceProperties(iter->key().data(), properties); + + auto spaceKey = iter->key().data(); + auto spaceVal = MetaKeyUtils::spaceVal(properties); + data.emplace_back(std::move(spaceKey), std::move(spaceVal)); } } iter->next(); } - return nebula::cpp2::ErrorCode::SUCCEEDED; -} - -void DropHostsProcessor::rewriteSpaceProperties(const std::string& spaceKey, - const meta::cpp2::SpaceDesc& properties) { - auto spaceVal = MetaKeyUtils::spaceVal(properties); - std::vector data = {{spaceKey, spaceVal}}; - doSyncPutAndUpdate(std::move(data)); + return data; } } // namespace meta diff --git a/src/meta/processors/zone/DropHostsProcessor.h b/src/meta/processors/zone/DropHostsProcessor.h index 41057636c02..8469eb79a45 100644 --- a/src/meta/processors/zone/DropHostsProcessor.h +++ b/src/meta/processors/zone/DropHostsProcessor.h @@ -22,9 +22,8 @@ class DropHostsProcessor : public BaseProcessor { private: explicit DropHostsProcessor(kvstore::KVStore* kvstore) : BaseProcessor(kvstore) {} - nebula::cpp2::ErrorCode checkRelatedSpace(const std::string& zoneName); - - void rewriteSpaceProperties(const std::string& spaceKey, const meta::cpp2::SpaceDesc& properties); + ErrorOr> checkRelatedSpaceAndCollect( + const std::string& zoneName); }; } // namespace meta diff --git a/src/meta/processors/zone/RenameZoneProcessor.cpp b/src/meta/processors/zone/RenameZoneProcessor.cpp index 4dcbf8fe5b5..d3bb2e750b9 100644 --- a/src/meta/processors/zone/RenameZoneProcessor.cpp +++ b/src/meta/processors/zone/RenameZoneProcessor.cpp @@ -9,6 +9,9 @@ namespace nebula { namespace meta { void RenameZoneProcessor::process(const cpp2::RenameZoneReq& req) { + folly::SharedMutex::ReadHolder zHolder(LockUtils::zoneLock()); + folly::SharedMutex::ReadHolder mHolder(LockUtils::machineLock()); + auto originalZoneName = req.get_original_zone_name(); auto originalZoneKey = MetaKeyUtils::zoneKey(originalZoneName); auto originalZoneValueRet = doGet(std::move(originalZoneKey));