Skip to content

Commit

Permalink
fix drop host from a zone
Browse files Browse the repository at this point in the history
  • Loading branch information
darionyaphet committed Sep 18, 2021
1 parent 07b5470 commit 110d36a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 12 deletions.
40 changes: 40 additions & 0 deletions src/meta/processors/zone/UpdateZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,46 @@ 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()) {
spaceIter->next();
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;
}
}
partIter->next();
}
spaceIter->next();
}

auto hosts = MetaServiceUtils::parseZoneHosts(std::move(nebula::value(zoneValueRet)));
auto host = req.get_node();
auto iter = std::find(hosts.begin(), hosts.end(), host);
Expand Down
61 changes: 49 additions & 12 deletions src/meta/test/GroupZoneTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "meta/processors/zone/ListZonesProcessor.h"
#include "meta/processors/zone/UpdateGroupProcessor.h"
#include "meta/processors/zone/UpdateZoneProcessor.h"
#include "meta/processors/parts/CreateSpaceProcessor.h"
#include "meta/processors/parts/DropSpaceProcessor.h"
#include "meta/test/TestUtils.h"

namespace nebula {
Expand Down Expand Up @@ -255,18 +257,6 @@ TEST(GroupAndZoneTest, GroupAndZoneTest) {
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::E_INVALID_PARM, resp.get_code());
}
// Drop host from zone
{
cpp2::DropHostFromZoneReq req;
req.set_zone_name("zone_0");
HostAddr node{"12", 12};
req.set_node(std::move(node));
auto* processor = DropHostFromZoneProcessor::instance(kv.get());
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
}
// Drop host from zone which zone is not exist
{
cpp2::DropHostFromZoneReq req;
Expand Down Expand Up @@ -303,6 +293,53 @@ TEST(GroupAndZoneTest, GroupAndZoneTest) {
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
}
{
cpp2::SpaceDesc properties;
properties.set_space_name("space");
properties.set_partition_num(12);
properties.set_replica_factor(3);
properties.set_group_name("group_0");
cpp2::CreateSpaceReq req;
req.set_properties(std::move(properties));
auto* processor = CreateSpaceProcessor::instance(kv.get());
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
}
// Drop host from zone
{
cpp2::DropHostFromZoneReq req;
req.set_zone_name("zone_0");
HostAddr node{"12", 12};
req.set_node(std::move(node));
auto* processor = DropHostFromZoneProcessor::instance(kv.get());
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::E_CONFLICT, resp.get_code());
}
{
cpp2::DropSpaceReq req;
req.set_space_name("space");
req.set_if_exists(false);
auto* processor = DropSpaceProcessor::instance(kv.get());
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
}
{
cpp2::DropHostFromZoneReq req;
req.set_zone_name("zone_0");
HostAddr node{"12", 12};
req.set_node(std::move(node));
auto* processor = DropHostFromZoneProcessor::instance(kv.get());
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
}
// Add Group which zone not exist
{
LOG(INFO) << "Add Group which zone not exist";
Expand Down

0 comments on commit 110d36a

Please sign in to comment.