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 9, 2021
1 parent cb8a1a2 commit aa997e6
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 54 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
68 changes: 53 additions & 15 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,21 +80,49 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {

auto iter = nebula::value(iterRet).get();
while (iter->valid()) {
auto zoneKey = iter->key();
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());
auto zoneName = MetaKeyUtils::parseZoneName(zoneKey);
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;
}
data.emplace_back(iter->key());

const auto& rewrites = nebula::value(result);
rewriteData.insert(rewriteData.end(), rewrites.begin(), rewrites.end());
data.emplace_back(zoneKey);
} 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);
LOG(INFO) << "Zone Value: " << zoneValue;
rewriteData.emplace_back(std::move(zoneKey), std::move(zoneValue));
}
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
break;
}
iter->next();
}

if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
handleErrorCode(code);
onFinished();
return;
}

// Detach the machine from cluster
for (auto& host : hosts) {
auto machineKey = MetaKeyUtils::machineKey(host.host, host.port);
Expand All @@ -111,10 +142,21 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
}

resp_.set_code(nebula::cpp2::ErrorCode::SUCCEEDED);
doMultiRemove(std::move(data));
folly::Baton<true, std::atomic> baton;
kvstore_->asyncMultiRemove(kDefaultSpaceId,
kDefaultPartId,
std::move(data),
[this, &baton](nebula::cpp2::ErrorCode result) {
this->handleErrorCode(result);
baton.post();
});
baton.wait();
doSyncPutAndUpdate(std::move(rewriteData));
}

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 +179,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
2 changes: 2 additions & 0 deletions src/meta/processors/zone/RenameZoneProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace nebula {
namespace meta {

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

auto originalZoneName = req.get_original_zone_name();
auto originalZoneKey = MetaKeyUtils::zoneKey(originalZoneName);
auto originalZoneValueRet = doGet(std::move(originalZoneKey));
Expand Down
10 changes: 10 additions & 0 deletions src/meta/test/ProcessorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3303,11 +3303,17 @@ TEST(ProcessorTest, DropHostsTest) {
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
ASSERT_EQ(6, resp.get_zones().size());
ASSERT_EQ("default_zone_127.0.0.1_8987", resp.get_zones()[0].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[0].get_nodes().size());
ASSERT_EQ("default_zone_127.0.0.1_8988", resp.get_zones()[1].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[1].get_nodes().size());
ASSERT_EQ("default_zone_127.0.0.1_8989", resp.get_zones()[2].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[2].get_nodes().size());
ASSERT_EQ("zone_0", resp.get_zones()[3].get_zone_name());
ASSERT_EQ(2, resp.get_zones()[3].get_nodes().size());
ASSERT_EQ("zone_1", resp.get_zones()[4].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[4].get_nodes().size());
ASSERT_EQ("zone_2", resp.get_zones()[5].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[5].get_nodes().size());
}
{
// Create Space on cluster, the replica number same with the zone size
Expand Down Expand Up @@ -3466,9 +3472,13 @@ TEST(ProcessorTest, DropHostsTest) {
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
ASSERT_EQ(4, resp.get_zones().size());
ASSERT_EQ("default_zone_127.0.0.1_8988", resp.get_zones()[0].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[0].get_nodes().size());
ASSERT_EQ("default_zone_127.0.0.1_8989", resp.get_zones()[1].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[1].get_nodes().size());
ASSERT_EQ("zone_0", resp.get_zones()[2].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[2].get_nodes().size());
ASSERT_EQ("zone_2", resp.get_zones()[3].get_zone_name());
ASSERT_EQ(1, resp.get_zones()[3].get_nodes().size());
}
}

Expand Down
22 changes: 13 additions & 9 deletions src/parser/MaintainSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,37 +379,40 @@ std::string MergeZoneSentence::toString() const {
buf.reserve(128);
buf += "MERGE ZONE ";
buf += zoneNames_->toString();
buf += " INTO ";
buf += " INTO \"";
buf += *zoneName_;
buf += "\"";
return buf;
}

std::string DropZoneSentence::toString() const {
return folly::stringPrintf("DROP ZONE %s", zoneName_.get()->c_str());
return folly::stringPrintf("DROP ZONE \"%s\"", zoneName_.get()->c_str());
}

std::string SplitZoneSentence::toString() const {
std::string buf;
buf.reserve(128);
buf += "SPLIT ZONE ";
buf += "SPLIT ZONE \"";
buf += *zoneName_;
buf += " INTO ";
buf += "\" INTO \"";
buf += zoneNames_->toString();
buf += "\"";
return buf;
}

std::string RenameZoneSentence::toString() const {
std::string buf;
buf.reserve(128);
buf += "RENAME ZONE ";
buf += "RENAME ZONE \"";
buf += *originalZoneName_;
buf += " TO ";
buf += "\" TO \"";
buf += *zoneName_;
buf += "\"";
return buf;
}

std::string DescribeZoneSentence::toString() const {
return folly::stringPrintf("DESCRIBE ZONE %s", zoneName_.get()->c_str());
return folly::stringPrintf("DESCRIBE ZONE \"%s\"", zoneName_.get()->c_str());
}

std::string ListZonesSentence::toString() const { return folly::stringPrintf("SHOW ZONES"); }
Expand All @@ -420,11 +423,12 @@ std::string AddHostsIntoZoneSentence::toString() const {
buf += "ADD HOSTS ";
buf += address_->toString();
if (isNew_) {
buf += " INTO NEW ZONE ";
buf += " INTO NEW ZONE \"";
} else {
buf += " INTO ZONE ";
buf += " INTO ZONE \"";
}
buf += *zoneName_;
buf += "\"";
return buf;
}

Expand Down
2 changes: 2 additions & 0 deletions src/parser/Sentence.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ class ZoneNameList final {
std::string toString() const {
std::string buf;
for (const auto &zone : zones_) {
buf += "\"";
buf += *zone;
buf += "\"";
buf += ",";
}
if (!zones_.empty()) {
Expand Down
18 changes: 9 additions & 9 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -2686,10 +2686,10 @@ add_hosts_sentence
: KW_ADD KW_HOSTS host_list {
$$ = new AddHostsSentence($3);
}
| KW_ADD KW_HOSTS host_list KW_INTO KW_ZONE name_label {
| KW_ADD KW_HOSTS host_list KW_INTO KW_ZONE STRING {
$$ = new AddHostsIntoZoneSentence($3, $6, false);
}
| KW_ADD KW_HOSTS host_list KW_INTO KW_NEW KW_ZONE name_label {
| KW_ADD KW_HOSTS host_list KW_INTO KW_NEW KW_ZONE STRING {
$$ = new AddHostsIntoZoneSentence($3, $7, true);
}
;
Expand All @@ -2702,13 +2702,13 @@ drop_hosts_sentence


merge_zone_sentence
: KW_MERGE KW_ZONE zone_name_list KW_INTO name_label {
: KW_MERGE KW_ZONE zone_name_list KW_INTO STRING {
$$ = new MergeZoneSentence($3, $5);
}
;

drop_zone_sentence
: KW_DROP KW_ZONE name_label {
: KW_DROP KW_ZONE STRING {
$$ = new DropZoneSentence($3);
}
;
Expand All @@ -2720,16 +2720,16 @@ drop_zone_sentence
// ;

rename_zone_sentence
: KW_RENAME KW_ZONE name_label KW_TO name_label {
: KW_RENAME KW_ZONE STRING KW_TO STRING {
$$ = new RenameZoneSentence($3, $5);
}
;

desc_zone_sentence
: KW_DESCRIBE KW_ZONE name_label {
: KW_DESCRIBE KW_ZONE STRING {
$$ = new DescribeZoneSentence($3);
}
| KW_DESC KW_ZONE name_label {
| KW_DESC KW_ZONE STRING {
$$ = new DescribeZoneSentence($3);
}
;
Expand Down Expand Up @@ -3307,11 +3307,11 @@ show_config_item
;

zone_name_list
: name_label {
: STRING {
$$ = new ZoneNameList();
$$->addZone($1);
}
| zone_name_list COMMA name_label {
| zone_name_list COMMA STRING {
$$ = $1;
$$->addZone($3);
}
Expand Down
Loading

0 comments on commit aa997e6

Please sign in to comment.