Skip to content

Commit

Permalink
refactor LOG and add comment for meta/processors/zone
Browse files Browse the repository at this point in the history
  • Loading branch information
liwenhui-soul committed Jan 13, 2022
1 parent a01f37f commit 51ec801
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 59 deletions.
12 changes: 6 additions & 6 deletions src/meta/processors/zone/AddHostsIntoZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ void AddHostsIntoZoneProcessor::process(const cpp2::AddHostsIntoZoneReq& req) {

// Confirm that there are no duplicates in the parameters.
if (std::unique(hosts.begin(), hosts.end()) != hosts.end()) {
LOG(ERROR) << "Hosts have duplicated element";
LOG(INFO) << "Hosts have duplicated element";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
}

// Confirm that the parameter is not empty.
if (hosts.empty()) {
LOG(ERROR) << "Hosts is empty";
LOG(INFO) << "Hosts is empty";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
Expand All @@ -37,7 +37,7 @@ void AddHostsIntoZoneProcessor::process(const cpp2::AddHostsIntoZoneReq& req) {
// Ensure that the node is not registered.
auto machineKey = MetaKeyUtils::machineKey(host.host, host.port);
if (machineExist(machineKey) == nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "The host " << host << " have existed!";
LOG(INFO) << "The host " << host << " have existed!";
code = nebula::cpp2::ErrorCode::E_EXISTED;
break;
}
Expand All @@ -56,7 +56,7 @@ void AddHostsIntoZoneProcessor::process(const cpp2::AddHostsIntoZoneReq& req) {
if (isNew) {
// If you are creating a new zone, should make sure the zone not existed.
if (nebula::ok(zoneValueRet)) {
LOG(ERROR) << "Zone " << zoneName << " have existed";
LOG(INFO) << "Zone " << zoneName << " have existed";
handleErrorCode(nebula::cpp2::ErrorCode::E_EXISTED);
onFinished();
return;
Expand All @@ -68,8 +68,8 @@ void AddHostsIntoZoneProcessor::process(const cpp2::AddHostsIntoZoneReq& req) {
if (code == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) {
code = nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND;
}
LOG(ERROR) << "Get zone " << zoneName << " failed, error "
<< apache::thrift::util::enumNameSafe(code);
LOG(INFO) << "Get zone " << zoneName << " failed, error "
<< apache::thrift::util::enumNameSafe(code);
handleErrorCode(code);
onFinished();
return;
Expand Down
22 changes: 11 additions & 11 deletions src/meta/processors/zone/DivideZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
auto zoneKey = MetaKeyUtils::zoneKey(zoneName);
auto zoneValueRet = doGet(zoneKey);
if (!nebula::ok(zoneValueRet)) {
LOG(ERROR) << "Zone " << zoneName << " not existed error: "
<< apache::thrift::util::enumNameSafe(nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND);
LOG(INFO) << "Zone " << zoneName << " not existed error: "
<< apache::thrift::util::enumNameSafe(nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND);
handleErrorCode(nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND);
onFinished();
return;
Expand All @@ -25,7 +25,7 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
auto& zoneItems = req.get_zone_items();
auto zoneHosts = MetaKeyUtils::parseZoneHosts(std::move(nebula::value(zoneValueRet)));
if (zoneItems.size() > zoneHosts.size()) {
LOG(ERROR) << "Zone Item should not greater than hosts size";
LOG(INFO) << "Zone Item should not greater than hosts size";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
Expand All @@ -41,27 +41,27 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
auto hosts = iter->second;
auto valueRet = doGet(MetaKeyUtils::zoneKey(zone));
if (nebula::ok(valueRet)) {
LOG(ERROR) << "Zone " << zone << " have existed";
LOG(INFO) << "Zone " << zone << " have existed";
code = nebula::cpp2::ErrorCode::E_EXISTED;
break;
}

auto it = std::find(zoneNames.begin(), zoneNames.end(), zone);
if (it == zoneNames.end()) {
LOG(ERROR) << "Zone have duplicated name";
LOG(INFO) << "Zone have duplicated name";
zoneNames.emplace_back(zone);
} else {
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
break;
}

if (hosts.empty()) {
LOG(ERROR) << "Hosts should not be empty";
LOG(INFO) << "Hosts should not be empty";
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
}

if (std::unique(hosts.begin(), hosts.end()) != hosts.end()) {
LOG(ERROR) << "Zone have duplicated host";
LOG(INFO) << "Zone have duplicated host";
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
break;
}
Expand All @@ -81,14 +81,14 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
}

if (totalHosts.size() != zoneHosts.size()) {
LOG(ERROR) << "The total host is not all hosts";
LOG(INFO) << "The total host is not all hosts";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
}

if (totalHostsSize != totalHosts.size()) {
LOG(ERROR) << "The host in zone list have duplicate element";
LOG(INFO) << "The host in zone list have duplicate element";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
Expand All @@ -97,7 +97,7 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
for (auto& host : totalHosts) {
auto iter = std::find(zoneHosts.begin(), zoneHosts.end(), host);
if (iter == zoneHosts.end()) {
LOG(ERROR) << "Host " << host << " not exist in original zone";
LOG(INFO) << "Host " << host << " not exist in original zone";
code = nebula::cpp2::ErrorCode::E_INVALID_PARM;
break;
}
Expand Down Expand Up @@ -130,7 +130,7 @@ nebula::cpp2::ErrorCode DivideZoneProcessor::updateSpacesZone(
auto ret = doPrefix(prefix);

if (!nebula::ok(ret)) {
LOG(ERROR) << "List spaces failed";
LOG(INFO) << "List spaces failed";
return nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND;
}

Expand Down
7 changes: 7 additions & 0 deletions src/meta/processors/zone/DivideZoneProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class DivideZoneProcessor : public BaseProcessor<cpp2::ExecResp> {
explicit DivideZoneProcessor(kvstore::KVStore* kvstore)
: BaseProcessor<cpp2::ExecResp>(kvstore) {}

/**
* @brief remove the originalZoneName and add the zoneNames in batchHolder
* @param batchHolder
* @param originalZoneName
* @param zoneNames
* @return
*/
nebula::cpp2::ErrorCode updateSpacesZone(kvstore::BatchHolder* batchHolder,
const std::string& originalZoneName,
const std::vector<std::string>& zoneNames);
Expand Down
22 changes: 11 additions & 11 deletions src/meta/processors/zone/DropHostsProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
folly::SharedMutex::WriteHolder mHolder(LockUtils::machineLock());
auto hosts = req.get_hosts();
if (std::unique(hosts.begin(), hosts.end()) != hosts.end()) {
LOG(ERROR) << "Hosts have duplicated element";
LOG(INFO) << "Hosts have duplicated element";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
}

if (hosts.empty()) {
LOG(ERROR) << "Hosts is empty";
LOG(INFO) << "Hosts is empty";
handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM);
onFinished();
return;
Expand All @@ -43,8 +43,8 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
auto ret = doGet(spaceKey);
if (!nebula::ok(ret)) {
code = nebula::error(ret);
LOG(ERROR) << "Get Space " << spaceId
<< " error: " << apache::thrift::util::enumNameSafe(code);
LOG(INFO) << "Get Space " << spaceId
<< " error: " << apache::thrift::util::enumNameSafe(code);
break;
}

Expand All @@ -55,7 +55,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
auto partHosts = MetaKeyUtils::parsePartVal(partIter->val());
for (auto& h : partHosts) {
if (std::find(hosts.begin(), hosts.end(), h) != hosts.end()) {
LOG(ERROR) << h << " is related with partition";
LOG(INFO) << h << " is related with partition";
code = nebula::cpp2::ErrorCode::E_CONFLICT;
break;
}
Expand All @@ -76,7 +76,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
auto iterRet = doPrefix(prefix);
if (!nebula::ok(iterRet)) {
auto retCode = nebula::error(iterRet);
LOG(ERROR) << "List zones failed, error: " << apache::thrift::util::enumNameSafe(retCode);
LOG(INFO) << "List zones failed, error: " << apache::thrift::util::enumNameSafe(retCode);
handleErrorCode(retCode);
onFinished();
return;
Expand All @@ -94,7 +94,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
LOG(INFO) << "Drop zone " << zoneName;
code = checkRelatedSpaceAndCollect(zoneName, holder.get());
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "Check related space failed";
LOG(INFO) << "Check related space failed";
break;
}

Expand Down Expand Up @@ -127,7 +127,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
auto machineKey = MetaKeyUtils::machineKey(host.host, host.port);
auto ret = machineExist(machineKey);
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "The machine " << host << " not existed!";
LOG(INFO) << "The machine " << host << " not existed!";
code = nebula::cpp2::ErrorCode::E_NO_HOSTS;
break;
}
Expand All @@ -136,7 +136,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
auto hostKey = MetaKeyUtils::hostKey(host.host, host.port);
ret = hostExist(hostKey);
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "The host " << host << " not existed!";
LOG(INFO) << "The host " << host << " not existed!";
code = nebula::cpp2::ErrorCode::E_NO_HOSTS;
break;
}
Expand All @@ -160,7 +160,7 @@ nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpaceAndCollect(
auto ret = doPrefix(prefix);
if (!nebula::ok(ret)) {
auto retCode = nebula::error(ret);
LOG(ERROR) << "List spaces failed, error " << apache::thrift::util::enumNameSafe(retCode);
LOG(INFO) << "List spaces failed, error " << apache::thrift::util::enumNameSafe(retCode);
return nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND;
}

Expand All @@ -173,7 +173,7 @@ nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpaceAndCollect(
auto it = std::find(zones.begin(), zones.end(), zoneName);
if (it != zones.end()) {
if (zones.size() == replicaFactor) {
LOG(ERROR) << "Zone size is same with replica factor";
LOG(INFO) << "Zone size is same with replica factor";
return nebula::cpp2::ErrorCode::E_CONFLICT;
} else {
zones.erase(it);
Expand Down
6 changes: 6 additions & 0 deletions src/meta/processors/zone/DropHostsProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class DropHostsProcessor : public BaseProcessor<cpp2::ExecResp> {
private:
explicit DropHostsProcessor(kvstore::KVStore* kvstore) : BaseProcessor<cpp2::ExecResp>(kvstore) {}

/**
* @brief check all spaces to find the zone, and remove it from the space
* @param zoneName
* @param holder
* @return
*/
nebula::cpp2::ErrorCode checkRelatedSpaceAndCollect(const std::string& zoneName,
kvstore::BatchHolder* holder);
};
Expand Down
16 changes: 8 additions & 8 deletions src/meta/processors/zone/DropZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void DropZoneProcessor::process(const cpp2::DropZoneReq& req) {
auto zoneValueRet = doGet(std::move(zoneKey));
if (!nebula::ok(zoneValueRet)) {
auto code = nebula::error(zoneValueRet);
LOG(ERROR) << "Drop Zone Failed, error: " << apache::thrift::util::enumNameSafe(code);
LOG(INFO) << "Drop Zone Failed, error: " << apache::thrift::util::enumNameSafe(code);
handleErrorCode(nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND);
onFinished();
return;
Expand Down Expand Up @@ -51,7 +51,7 @@ void DropZoneProcessor::process(const cpp2::DropZoneReq& req) {
auto machineKey = MetaKeyUtils::machineKey(host.host, host.port);
auto ret = machineExist(machineKey);
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "The host " << host << " not existed!";
LOG(INFO) << "The host " << host << " not existed!";
code = nebula::cpp2::ErrorCode::E_NO_HOSTS;
break;
}
Expand All @@ -66,7 +66,7 @@ nebula::cpp2::ErrorCode DropZoneProcessor::checkSpaceReplicaZone() {
nebula::cpp2::ErrorCode code = nebula::cpp2::ErrorCode::SUCCEEDED;
if (!nebula::ok(ret)) {
code = nebula::error(ret);
LOG(ERROR) << "List spaces failed, error " << apache::thrift::util::enumNameSafe(code);
LOG(INFO) << "List spaces failed, error " << apache::thrift::util::enumNameSafe(code);
return code;
}

Expand All @@ -78,7 +78,7 @@ nebula::cpp2::ErrorCode DropZoneProcessor::checkSpaceReplicaZone() {
auto spaceZones = properties.get_zone_names();
size_t replicaFactor = properties.get_replica_factor();
if (replicaFactor == spaceZones.size()) {
LOG(ERROR) << "Space " << spaceId << " replica factor and zone size are the same";
LOG(INFO) << "Space " << spaceId << " replica factor and zone size are the same";
code = nebula::cpp2::ErrorCode::E_CONFLICT;
break;
}
Expand All @@ -92,7 +92,7 @@ nebula::cpp2::ErrorCode DropZoneProcessor::checkHostPartition(const HostAddr& ad
auto spaceIterRet = doPrefix(spacePrefix);
if (!nebula::ok(spaceIterRet)) {
auto result = nebula::error(spaceIterRet);
LOG(ERROR) << "Get Spaces Failed, error " << apache::thrift::util::enumNameSafe(result);
LOG(INFO) << "Get Spaces Failed, error " << apache::thrift::util::enumNameSafe(result);
return result;
}

Expand All @@ -104,16 +104,16 @@ nebula::cpp2::ErrorCode DropZoneProcessor::checkHostPartition(const HostAddr& ad
auto partIterRet = doPrefix(partPrefix);
if (!nebula::ok(partIterRet)) {
code = nebula::error(partIterRet);
LOG(ERROR) << "List part failed in list hosts, error: "
<< apache::thrift::util::enumNameSafe(code);
LOG(INFO) << "List part failed in list hosts, error: "
<< apache::thrift::util::enumNameSafe(code);
return code;
}
auto& partIter = nebula::value(partIterRet);
while (partIter->valid()) {
auto hosts = MetaKeyUtils::parsePartVal(partIter->val());
for (auto& host : hosts) {
if (host == address) {
LOG(ERROR) << "Host " << address << " have partition on it";
LOG(INFO) << "Host " << address << " have partition on it";
code = nebula::cpp2::ErrorCode::E_CONFLICT;
break;
}
Expand Down
10 changes: 9 additions & 1 deletion src/meta/processors/zone/DropZoneProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ class DropZoneProcessor : public BaseProcessor<cpp2::ExecResp> {
private:
explicit DropZoneProcessor(kvstore::KVStore* kvstore) : BaseProcessor<cpp2::ExecResp>(kvstore) {}

/**
* @brief check all spaces if they have enough zones to hold replica when dropping one zone
* @return
*/
nebula::cpp2::ErrorCode checkSpaceReplicaZone();

// Check whether the node holds zones on each space
/**
* @brief Check whether the node holds zones on each space
* @param address
* @return
*/
nebula::cpp2::ErrorCode checkHostPartition(const HostAddr& address);
};

Expand Down
4 changes: 2 additions & 2 deletions src/meta/processors/zone/GetZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void GetZoneProcessor::process(const cpp2::GetZoneReq& req) {
if (retCode == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) {
retCode = nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND;
}
LOG(ERROR) << "Get zone " << zoneName
<< " failed, error: " << apache::thrift::util::enumNameSafe(retCode);
LOG(INFO) << "Get zone " << zoneName
<< " failed, error: " << apache::thrift::util::enumNameSafe(retCode);
handleErrorCode(retCode);
onFinished();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/meta/processors/zone/ListZonesProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void ListZonesProcessor::process(const cpp2::ListZonesReq&) {
auto iterRet = doPrefix(prefix);
if (!nebula::ok(iterRet)) {
auto retCode = nebula::error(iterRet);
LOG(ERROR) << "List zones failed, error: " << apache::thrift::util::enumNameSafe(retCode);
LOG(INFO) << "List zones failed, error: " << apache::thrift::util::enumNameSafe(retCode);
handleErrorCode(retCode);
onFinished();
return;
Expand Down
Loading

0 comments on commit 51ec801

Please sign in to comment.