Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix drop host from a zone #2877

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,6 +8,8 @@

#include "common/base/Base.h"
#include "common/fs/TempDir.h"
#include "meta/processors/parts/CreateSpaceProcessor.h"
#include "meta/processors/parts/DropSpaceProcessor.h"
#include "meta/processors/zone/AddGroupProcessor.h"
#include "meta/processors/zone/AddZoneProcessor.h"
#include "meta/processors/zone/DropGroupProcessor.h"
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