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

Support more validation when create space on an empty zone #3065

Merged
merged 3 commits into from
Oct 18, 2021
Merged
Changes from 1 commit
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
52 changes: 35 additions & 17 deletions src/meta/processors/parts/CreateSpaceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) {
std::string(reinterpret_cast<const char*>(&spaceId), sizeof(spaceId)));
data.emplace_back(MetaServiceUtils::spaceKey(spaceId), MetaServiceUtils::spaceVal(properties));

nebula::cpp2::ErrorCode code = nebula::cpp2::ErrorCode::SUCCEEDED;
if (properties.group_name_ref().has_value()) {
auto& groupName = *properties.group_name_ref();
LOG(INFO) << "Create Space on group: " << groupName;
Expand Down Expand Up @@ -154,14 +155,12 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) {
auto zoneKey = MetaServiceUtils::zoneKey(zone);
auto zoneValueRet = doGet(std::move(zoneKey));
if (!nebula::ok(zoneValueRet)) {
auto retCode = nebula::error(zoneValueRet);
if (retCode == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) {
retCode = nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND;
code = nebula::error(zoneValueRet);
if (code == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) {
code = nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND;
}
LOG(ERROR) << "Get zone " << zone << " failed.";
handleErrorCode(retCode);
onFinished();
return;
break;
}

auto hosts = MetaServiceUtils::parseZoneHosts(std::move(nebula::value(zoneValueRet)));
Expand All @@ -177,30 +176,34 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) {
zoneHosts[zone] = std::move(hosts);
}

if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "Create space failed";
handleErrorCode(code);
onFinished();
return;
}

for (auto partId = 1; partId <= partitionNum; partId++) {
auto pickedZonesRet = pickLightLoadZones(replicaFactor);
if (!pickedZonesRet.ok()) {
LOG(ERROR) << "Pick zone failed.";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
darionyaphet marked this conversation as resolved.
Show resolved Hide resolved
break;
}

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

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

std::stringstream ss;
Expand Down Expand Up @@ -245,6 +248,13 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) {
}
}

if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "Create space failed";
handleErrorCode(code);
onFinished();
return;
}

resp_.set_id(to(spaceId, EntryType::SPACE));
doSyncPutAndUpdate(std::move(data));
LOG(INFO) << "Create space " << spaceName;
Expand Down Expand Up @@ -289,6 +299,16 @@ StatusOr<Hosts> CreateSpaceProcessor::pickHostsWithZone(
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;
break;
}

auto zoneIter = std::find(std::begin(zones), std::end(zones), iter->first);
if (zoneIter == std::end(zones)) {
continue;
Expand All @@ -315,8 +335,6 @@ StatusOr<Hosts> CreateSpaceProcessor::pickHostsWithZone(
}

if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
handleErrorCode(code);
onFinished();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to delete these error handle codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved outside to unified processing

return Status::Error("Host not found");
}
return pickedHosts;
Expand Down