Skip to content

Commit

Permalink
fix critical27 comment
Browse files Browse the repository at this point in the history
  • Loading branch information
darionyaphet committed Dec 7, 2021
1 parent 53aa7c3 commit b77fa59
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
8 changes: 3 additions & 5 deletions src/graph/executor/admin/SpaceExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,12 @@ folly::Future<Status> ShowCreateSpaceExecutor::execute() {
auto fmt = properties.comment_ref().has_value()
? "CREATE SPACE `%s` (partition_num = %d, replica_factor = %d, "
"charset = %s, collate = %s, vid_type = %s, atomic_edge = %s"
")%s"
") ON %s"
" comment = '%s'"
: "CREATE SPACE `%s` (partition_num = %d, replica_factor = %d, "
"charset = %s, collate = %s, vid_type = %s, atomic_edge = %s"
")%s";
auto zoneNames = !properties.get_zone_names().empty()
? " ON " + folly::join(",", properties.get_zone_names())
: "";
") ON %s";
auto zoneNames = folly::join(",", properties.get_zone_names());
if (properties.comment_ref().has_value()) {
row.values.emplace_back(
folly::stringPrintf(fmt,
Expand Down
5 changes: 2 additions & 3 deletions src/meta/ActiveHostsMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ ErrorOr<nebula::cpp2::ErrorCode, std::vector<HostAddr>> ActiveHostsMan::getActiv
return retCode;
}

std::vector<HostAddr> machines;
std::unordered_set<HostAddr> machines;
while (machineIter->valid()) {
auto machine = MetaKeyUtils::parseMachineKey(machineIter->key());
LOG(INFO) << "Machine " << machine;
machines.emplace_back(std::move(machine));
machines.emplace(std::move(machine));
machineIter->next();
}

Expand Down
43 changes: 31 additions & 12 deletions src/meta/processors/zone/DropHostsProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace nebula {
namespace meta {

void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
folly::SharedMutex::ReadHolder zHolder(LockUtils::zoneLock());
folly::SharedMutex::ReadHolder mHolder(LockUtils::machineLock());
auto hosts = req.get_hosts();
if (std::unique(hosts.begin(), hosts.end()) != hosts.end()) {
LOG(ERROR) << "Hosts have duplicated element";
Expand All @@ -25,6 +27,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
}

std::vector<std::string> data;
std::vector<kvstore::KV> rewriteData;
// Check that partition is not held on the host
const auto& spacePrefix = MetaKeyUtils::spacePrefix();
auto spaceIterRet = doPrefix(spacePrefix);
Expand Down Expand Up @@ -77,17 +80,35 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {

auto iter = nebula::value(iterRet).get();
while (iter->valid()) {
auto zoneKey = iter->key().data();
auto hs = MetaKeyUtils::parseZoneHosts(iter->val());
// Delete all hosts in the zone
if (std::all_of(hs.begin(), hs.end(), [&hosts](auto& h) {
return std::find(hosts.begin(), hosts.end(), h) != hosts.end();
})) {
auto zoneName = MetaKeyUtils::parseZoneName(iter->key());
LOG(INFO) << "Drop zone " << zoneName;
code = checkRelatedSpace(zoneName);
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
auto result = checkRelatedSpaceAndCollect(zoneName);
if (!nebula::ok(result)) {
LOG(ERROR) << "Check related space failed";
code = nebula::error(result);
break;
}

const auto& rewrites = nebula::value(result);
rewriteData.insert(rewriteData.end(), rewrites.begin(), rewrites.end());
data.emplace_back(iter->key());
} else {
// Delete some hosts in the zone
for (auto& h : hosts) {
auto it = std::find(hs.begin(), hs.end(), h);
if (it != hs.end()) {
hs.erase(it);
}
}

auto zoneValue = MetaKeyUtils::zoneVal(hs);
rewriteData.emplace_back(std::move(zoneKey), std::move(zoneValue));
}
iter->next();
}
Expand All @@ -114,7 +135,9 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
doMultiRemove(std::move(data));
}

nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpace(const std::string& zoneName) {
ErrorOr<nebula::cpp2::ErrorCode, std::vector<kvstore::KV>>
DropHostsProcessor::checkRelatedSpaceAndCollect(const std::string& zoneName) {
std::vector<kvstore::KV> data;
const auto& prefix = MetaKeyUtils::spacePrefix();
auto ret = doPrefix(prefix);
if (!nebula::ok(ret)) {
Expand All @@ -137,19 +160,15 @@ nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpace(const std::string&
} else {
zones.erase(it);
properties.set_zone_names(zones);
rewriteSpaceProperties(iter->key().data(), properties);

auto spaceKey = iter->key().data();
auto spaceVal = MetaKeyUtils::spaceVal(properties);
data.emplace_back(std::move(spaceKey), std::move(spaceVal));
}
}
iter->next();
}
return nebula::cpp2::ErrorCode::SUCCEEDED;
}

void DropHostsProcessor::rewriteSpaceProperties(const std::string& spaceKey,
const meta::cpp2::SpaceDesc& properties) {
auto spaceVal = MetaKeyUtils::spaceVal(properties);
std::vector<kvstore::KV> data = {{spaceKey, spaceVal}};
doSyncPutAndUpdate(std::move(data));
return data;
}

} // namespace meta
Expand Down
5 changes: 2 additions & 3 deletions src/meta/processors/zone/DropHostsProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class DropHostsProcessor : public BaseProcessor<cpp2::ExecResp> {
private:
explicit DropHostsProcessor(kvstore::KVStore* kvstore) : BaseProcessor<cpp2::ExecResp>(kvstore) {}

nebula::cpp2::ErrorCode checkRelatedSpace(const std::string& zoneName);

void rewriteSpaceProperties(const std::string& spaceKey, const meta::cpp2::SpaceDesc& properties);
ErrorOr<nebula::cpp2::ErrorCode, std::vector<kvstore::KV>> checkRelatedSpaceAndCollect(
const std::string& zoneName);
};

} // namespace meta
Expand Down
3 changes: 3 additions & 0 deletions src/meta/processors/zone/RenameZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace nebula {
namespace meta {

void RenameZoneProcessor::process(const cpp2::RenameZoneReq& req) {
folly::SharedMutex::ReadHolder zHolder(LockUtils::zoneLock());
folly::SharedMutex::ReadHolder mHolder(LockUtils::machineLock());

auto originalZoneName = req.get_original_zone_name();
auto originalZoneKey = MetaKeyUtils::zoneKey(originalZoneName);
auto originalZoneValueRet = doGet(std::move(originalZoneKey));
Expand Down

0 comments on commit b77fa59

Please sign in to comment.