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 28, 2022
1 parent 6abad9f commit 5faf45f
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 58 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
4 changes: 4 additions & 0 deletions src/meta/processors/zone/AddHostsIntoZoneProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
namespace nebula {
namespace meta {

/**
* @brief Add hosts into a given zone which is existing or a new one
* The hosts should be unregistered hosts
*/
class AddHostsIntoZoneProcessor : public BaseProcessor<cpp2::ExecResp> {
public:
static AddHostsIntoZoneProcessor* instance(kvstore::KVStore* kvstore) {
Expand Down
3 changes: 3 additions & 0 deletions src/meta/processors/zone/AddHostsProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
namespace nebula {
namespace meta {

/**
* @brief For each host, make a default zone and add it into the zone.
*/
class AddHostsProcessor : public BaseProcessor<cpp2::ExecResp> {
public:
static AddHostsProcessor* instance(kvstore::KVStore* kvstore) {
Expand Down
21 changes: 11 additions & 10 deletions src/meta/processors/zone/DivideZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
auto zoneValueRet = doGet(zoneKey);
// Check the source zone exist or not
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 @@ -43,7 +43,7 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
}

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 @@ -61,13 +61,14 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
auto hosts = iter->second;
auto valueRet = doGet(MetaKeyUtils::zoneKey(zone));
if (nebula::ok(valueRet) && zone != zoneName) {
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(INFO) << "Zone have duplicated name";
zoneNames.emplace_back(zone);
} else {
LOG(ERROR) << "Zone have duplicated name " << zone;
Expand All @@ -76,12 +77,12 @@ void DivideZoneProcessor::process(const cpp2::DivideZoneReq& req) {
}

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 @@ -101,14 +102,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 @@ -117,7 +118,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 @@ -148,7 +149,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
11 changes: 11 additions & 0 deletions src/meta/processors/zone/DivideZoneProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
namespace nebula {
namespace meta {

/**
* @brief Divide an existing zone to several zones
*/
class DivideZoneProcessor : public BaseProcessor<cpp2::ExecResp> {
public:
static DivideZoneProcessor* instance(kvstore::KVStore* kvstore) {
Expand All @@ -24,6 +27,14 @@ 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!";
} else {
holder->remove(std::move(hostKey));
}
Expand All @@ -159,7 +159,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 @@ -172,7 +172,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
13 changes: 13 additions & 0 deletions src/meta/processors/zone/DropHostsProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
namespace nebula {
namespace meta {

/**
* @brief Drop hosts from this cluster
* The hosts should not hold any parts
* It will remove the hosts from zones they belong to,
* and detach the machine from cluster
*/
class DropHostsProcessor : public BaseProcessor<cpp2::ExecResp> {
public:
static DropHostsProcessor* instance(kvstore::KVStore* kvstore) {
Expand All @@ -23,6 +29,13 @@ 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
17 changes: 16 additions & 1 deletion src/meta/processors/zone/DropZoneProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
namespace nebula {
namespace meta {

/**
* @brief Drop zone from the cluster
* The hosts that belong to the zone should not contain any parts
* It will drop the hosts too
*/
class DropZoneProcessor : public BaseProcessor<cpp2::ExecResp> {
public:
static DropZoneProcessor* instance(kvstore::KVStore* kvstore) {
Expand All @@ -22,9 +27,19 @@ 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
Loading

0 comments on commit 5faf45f

Please sign in to comment.