From a7d5c29f45422af982da7dc4a6671cb7b91736e3 Mon Sep 17 00:00:00 2001 From: nebula-bots <88429921+nebula-bots@users.noreply.github.com> Date: Thu, 13 Jan 2022 16:24:43 +0800 Subject: [PATCH] Support more check about merge zone arguments (#500) Co-authored-by: yaphet <4414314+darionyaphet@users.noreply.github.com> --- src/meta/processors/zone/MergeZoneProcessor.cpp | 11 +++++++++++ src/meta/test/MetaClientTest.cpp | 7 +++++++ src/meta/test/ProcessorTest.cpp | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/meta/processors/zone/MergeZoneProcessor.cpp b/src/meta/processors/zone/MergeZoneProcessor.cpp index fe8f1f227bd..98c6b4b4379 100644 --- a/src/meta/processors/zone/MergeZoneProcessor.cpp +++ b/src/meta/processors/zone/MergeZoneProcessor.cpp @@ -169,6 +169,17 @@ void MergeZoneProcessor::process(const cpp2::MergeZoneReq& req) { // Write the merged zone into meta service auto key = MetaKeyUtils::zoneKey(zoneName); std::vector zoneHosts; + auto valueRet = doGet(key); + if (nebula::ok(valueRet)) { + auto it = std::find(zones.begin(), zones.end(), zoneName); + if (it == zones.end()) { + LOG(ERROR) << "The target zone should exist in merge zone list"; + handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM); + onFinished(); + return; + } + } + for (auto& zone : zones) { auto zoneKey = MetaKeyUtils::zoneKey(zone); auto zoneValueRet = doGet(std::move(zoneKey)); diff --git a/src/meta/test/MetaClientTest.cpp b/src/meta/test/MetaClientTest.cpp index 28b8231e74d..7461f714cb6 100644 --- a/src/meta/test/MetaClientTest.cpp +++ b/src/meta/test/MetaClientTest.cpp @@ -2278,6 +2278,13 @@ TEST(MetaClientTest, MergeZoneTest) { ASSERT_EQ("default_zone_127.0.0.1_8988", zones[2].get_zone_name()); ASSERT_EQ("default_zone_127.0.0.1_8989", zones[3].get_zone_name()); } + { + auto result = client + ->mergeZone({"default_zone_127.0.0.1_8986", "default_zone_127.0.0.1_8987"}, + "default_zone_127.0.0.1_8988") + .get(); + EXPECT_FALSE(result.ok()); + } { // Merge zones is empty auto result = client->mergeZone({}, "new_zone").get(); diff --git a/src/meta/test/ProcessorTest.cpp b/src/meta/test/ProcessorTest.cpp index 6eba572f768..58bce373c42 100644 --- a/src/meta/test/ProcessorTest.cpp +++ b/src/meta/test/ProcessorTest.cpp @@ -3762,6 +3762,16 @@ TEST(ProcessorTest, MergeZoneTest) { ASSERT_EQ("default_zone_127.0.0.1_8988", zones[2].get_zone_name()); ASSERT_EQ("default_zone_127.0.0.1_8989", zones[3].get_zone_name()); } + { + cpp2::MergeZoneReq req; + req.zones_ref() = {"default_zone_127.0.0.1_8986", "default_zone_127.0.0.1_8987"}; + req.zone_name_ref() = "default_zone_127.0.0.1_8988"; + auto* processor = MergeZoneProcessor::instance(kv.get()); + auto f = processor->getFuture(); + processor->process(req); + auto resp = std::move(f).get(); + ASSERT_EQ(nebula::cpp2::ErrorCode::E_INVALID_PARM, resp.get_code()); + } { // Merge an empty zone list cpp2::MergeZoneReq req;