Skip to content

Commit

Permalink
fix issue 3675
Browse files Browse the repository at this point in the history
  • Loading branch information
darionyaphet committed Jan 11, 2022
1 parent a9a603b commit 9434b39
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/interface/common.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ enum ErrorCode {
E_CONFLICT = -2008,
E_INVALID_PARM = -2009,
E_WRONGCLUSTER = -2010,
E_ZONE_NOT_ENOUGH = -2011,

E_STORE_FAILURE = -2021,
E_STORE_SEGMENT_ILLEGAL = -2022,
Expand Down
19 changes: 8 additions & 11 deletions src/meta/processors/parts/CreateSpaceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) {
int32_t zoneNum = zones.size();
if (replicaFactor > zoneNum) {
LOG(ERROR) << "Replication number should less than or equal to zone number.";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
handleErrorCode(nebula::cpp2::ErrorCode::E_ZONE_NOT_ENOUGH);
onFinished();
return;
}
Expand Down Expand Up @@ -234,16 +234,16 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) {

auto pickedZones = std::move(pickedZonesRet).value();
auto partHostsRet = pickHostsWithZone(pickedZones, zoneHosts);
if (!partHostsRet.ok()) {
if (!nebula::ok(partHostsRet)) {
LOG(ERROR) << "Pick hosts with zone failed.";
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
code = nebula::error(partHostsRet);
break;
}

auto partHosts = std::move(partHostsRet).value();
auto partHosts = nebula::value(partHostsRet);
if (partHosts.empty()) {
LOG(ERROR) << "Pick hosts is empty.";
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
code = nebula::cpp2::ErrorCode::E_NO_HOSTS;
break;
}

Expand All @@ -268,16 +268,12 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) {
LOG(INFO) << "Create space " << spaceName;
}

StatusOr<Hosts> CreateSpaceProcessor::pickHostsWithZone(
ErrorOr<nebula::cpp2::ErrorCode, Hosts> CreateSpaceProcessor::pickHostsWithZone(
const std::vector<std::string>& zones,
const std::unordered_map<std::string, Hosts>& zoneHosts) {
Hosts pickedHosts;
nebula::cpp2::ErrorCode code = nebula::cpp2::ErrorCode::SUCCEEDED;
for (auto iter = zoneHosts.begin(); iter != zoneHosts.end(); iter++) {
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
break;
}

if (iter->second.empty()) {
LOG(ERROR) << "Zone " << iter->first << " is empty";
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
Expand Down Expand Up @@ -305,12 +301,13 @@ StatusOr<Hosts> CreateSpaceProcessor::pickHostsWithZone(
}
}

CHECK_CODE_AND_BREAK();
hostLoading_[picked] += 1;
pickedHosts.emplace_back(toThriftHost(std::move(picked)));
}

if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
return Status::Error("Host not found");
return code;
}
return pickedHosts;
}
Expand Down
5 changes: 3 additions & 2 deletions src/meta/processors/parts/CreateSpaceProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class CreateSpaceProcessor : public BaseProcessor<cpp2::ExecResp> {
: BaseProcessor<cpp2::ExecResp>(kvstore) {}

// Get the host with the least load in the zone
StatusOr<Hosts> pickHostsWithZone(const std::vector<std::string>& zones,
const std::unordered_map<std::string, Hosts>& zoneHosts);
ErrorOr<nebula::cpp2::ErrorCode, Hosts> pickHostsWithZone(
const std::vector<std::string>& zones,
const std::unordered_map<std::string, Hosts>& zoneHosts);

// Get the zones with the least load
StatusOr<std::vector<std::string>> pickLightLoadZones(int32_t replicaFactor);
Expand Down
4 changes: 2 additions & 2 deletions src/meta/test/ProcessorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3295,7 +3295,7 @@ TEST(ProcessorTest, DropHostsTest) {
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::E_INVALID_PARM, resp.get_code());
ASSERT_EQ(nebula::cpp2::ErrorCode::E_ZONE_NOT_ENOUGH, resp.get_code());
}
{
cpp2::AddHostsIntoZoneReq req;
Expand Down Expand Up @@ -3432,7 +3432,7 @@ TEST(ProcessorTest, DropHostsTest) {
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(nebula::cpp2::ErrorCode::E_INVALID_PARM, resp.get_code());
ASSERT_EQ(nebula::cpp2::ErrorCode::E_ZONE_NOT_ENOUGH, resp.get_code());
}
{
// Drop hosts which hold partition.
Expand Down

0 comments on commit 9434b39

Please sign in to comment.