Skip to content

Commit

Permalink
fix issue 3675 (#3678)
Browse files Browse the repository at this point in the history
  • Loading branch information
darionyaphet authored and Sophie-Xie committed Jan 15, 2022
1 parent 4cf260b commit 2754983
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ Status MetaClient::handleResponse(const RESP& resp) {
return Status::Error("Invalid param!");
case nebula::cpp2::ErrorCode::E_WRONGCLUSTER:
return Status::Error("Wrong cluster!");
case nebula::cpp2::ErrorCode::E_ZONE_NOT_ENOUGH:
return Status::Error("Zone not enough!");
case nebula::cpp2::ErrorCode::E_ZONE_IS_EMPTY:
return Status::Error("Zone is empty!");
case nebula::cpp2::ErrorCode::E_STORE_FAILURE:
return Status::Error("Store failure!");
case nebula::cpp2::ErrorCode::E_STORE_SEGMENT_ILLEGAL:
Expand Down
2 changes: 2 additions & 0 deletions src/common/graph/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
X(E_CONFLICT, -2008) \
X(E_INVALID_PARM, -2009) \
X(E_WRONGCLUSTER, -2010) \
X(E_ZONE_NOT_ENOUGH, -2011) \
X(E_ZONE_IS_EMPTY, -2012) \
\
X(E_STORE_FAILURE, -2021) \
X(E_STORE_SEGMENT_ILLEGAL, -2022) \
Expand Down
2 changes: 2 additions & 0 deletions src/interface/common.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ enum ErrorCode {
E_CONFLICT = -2008,
E_INVALID_PARM = -2009,
E_WRONGCLUSTER = -2010,
E_ZONE_NOT_ENOUGH = -2011,
E_ZONE_IS_EMPTY = -2012,

E_STORE_FAILURE = -2021,
E_STORE_SEGMENT_ILLEGAL = -2022,
Expand Down
21 changes: 9 additions & 12 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,19 +268,15 @@ 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;
code = nebula::cpp2::ErrorCode::E_ZONE_IS_EMPTY;
break;
}

Expand All @@ -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 2754983

Please sign in to comment.