From 0064080657f883b12a3041fb02a8cf2f360b4609 Mon Sep 17 00:00:00 2001 From: "darion.yaphet" Date: Thu, 16 Sep 2021 20:04:49 +0800 Subject: [PATCH] fix drop host from a zone --- .../processors/zone/UpdateZoneProcessor.cpp | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/meta/processors/zone/UpdateZoneProcessor.cpp b/src/meta/processors/zone/UpdateZoneProcessor.cpp index f76f30f15c7..89a11f35479 100644 --- a/src/meta/processors/zone/UpdateZoneProcessor.cpp +++ b/src/meta/processors/zone/UpdateZoneProcessor.cpp @@ -117,6 +117,43 @@ void DropHostFromZoneProcessor::process(const cpp2::DropHostFromZoneReq& req) { return; } + const auto& spacePrefix = MetaServiceUtils::spacePrefix(); + auto spaceIterRet = doPrefix(spacePrefix); + auto spaceIter = nebula::value(spaceIterRet).get(); + while (spaceIter->valid()) { + auto spaceId = MetaServiceUtils::spaceId(spaceIter->key()); + auto spaceKey = MetaServiceUtils::spaceKey(spaceId); + auto ret = doGet(spaceKey); + if (!nebula::ok(ret)) { + auto retCode = nebula::error(ret); + LOG(ERROR) << "Get Space " << spaceId + << " error: " << apache::thrift::util::enumNameSafe(retCode); + handleErrorCode(retCode); + onFinished(); + return; + } + + auto properties = MetaServiceUtils::parseSpace(nebula::value(ret)); + if (!properties.group_name_ref().has_value()) { + continue; + } + + const auto& partPrefix = MetaServiceUtils::partPrefix(spaceId); + auto partIterRet = doPrefix(partPrefix); + auto partIter = nebula::value(partIterRet).get(); + while (partIter->valid()) { + auto partHosts = MetaServiceUtils::parsePartVal(partIter->val()); + for (auto& h : partHosts) { + if (h == req.get_node()) { + LOG(ERROR) << h << " is related with partition"; + handleErrorCode(nebula::cpp2::ErrorCode::E_CONFLICT); + onFinished(); + return; + } + } + } + } + auto hosts = MetaServiceUtils::parseZoneHosts(std::move(nebula::value(zoneValueRet))); auto host = req.get_node(); auto iter = std::find(hosts.begin(), hosts.end(), host);