Skip to content

Commit

Permalink
Support more check about merge zone arguments (vesoft-inc#500)
Browse files Browse the repository at this point in the history
Co-authored-by: yaphet <[email protected]>
  • Loading branch information
nebula-bots and darionyaphet authored Jan 13, 2022
1 parent 96f763b commit a7d5c29
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/meta/processors/zone/MergeZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostAddr> 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));
Expand Down
7 changes: 7 additions & 0 deletions src/meta/test/MetaClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions src/meta/test/ProcessorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a7d5c29

Please sign in to comment.