Skip to content

Commit aa997e6

Browse files
committed
fix critical27 comment
1 parent cb8a1a2 commit aa997e6

10 files changed

+156
-54
lines changed

src/graph/executor/admin/SpaceExecutor.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,12 @@ folly::Future<Status> ShowCreateSpaceExecutor::execute() {
220220
auto fmt = properties.comment_ref().has_value()
221221
? "CREATE SPACE `%s` (partition_num = %d, replica_factor = %d, "
222222
"charset = %s, collate = %s, vid_type = %s, atomic_edge = %s"
223-
")%s"
223+
") ON %s"
224224
" comment = '%s'"
225225
: "CREATE SPACE `%s` (partition_num = %d, replica_factor = %d, "
226226
"charset = %s, collate = %s, vid_type = %s, atomic_edge = %s"
227-
")%s";
228-
auto zoneNames = !properties.get_zone_names().empty()
229-
? " ON " + folly::join(",", properties.get_zone_names())
230-
: "";
227+
") ON %s";
228+
auto zoneNames = folly::join(",", properties.get_zone_names());
231229
if (properties.comment_ref().has_value()) {
232230
row.values.emplace_back(
233231
folly::stringPrintf(fmt,

src/meta/ActiveHostsMan.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ ErrorOr<nebula::cpp2::ErrorCode, std::vector<HostAddr>> ActiveHostsMan::getActiv
102102
return retCode;
103103
}
104104

105-
std::vector<HostAddr> machines;
105+
std::unordered_set<HostAddr> machines;
106106
while (machineIter->valid()) {
107107
auto machine = MetaKeyUtils::parseMachineKey(machineIter->key());
108-
LOG(INFO) << "Machine " << machine;
109-
machines.emplace_back(std::move(machine));
108+
machines.emplace(std::move(machine));
110109
machineIter->next();
111110
}
112111

src/meta/processors/zone/DropHostsProcessor.cpp

+53-15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace nebula {
99
namespace meta {
1010

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

2729
std::vector<std::string> data;
30+
std::vector<kvstore::KV> rewriteData;
2831
// Check that partition is not held on the host
2932
const auto& spacePrefix = MetaKeyUtils::spacePrefix();
3033
auto spaceIterRet = doPrefix(spacePrefix);
@@ -77,21 +80,49 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
7780

7881
auto iter = nebula::value(iterRet).get();
7982
while (iter->valid()) {
83+
auto zoneKey = iter->key();
8084
auto hs = MetaKeyUtils::parseZoneHosts(iter->val());
85+
// Delete all hosts in the zone
8186
if (std::all_of(hs.begin(), hs.end(), [&hosts](auto& h) {
8287
return std::find(hosts.begin(), hosts.end(), h) != hosts.end();
8388
})) {
84-
auto zoneName = MetaKeyUtils::parseZoneName(iter->key());
89+
auto zoneName = MetaKeyUtils::parseZoneName(zoneKey);
8590
LOG(INFO) << "Drop zone " << zoneName;
86-
code = checkRelatedSpace(zoneName);
87-
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
91+
auto result = checkRelatedSpaceAndCollect(zoneName);
92+
if (!nebula::ok(result)) {
93+
LOG(ERROR) << "Check related space failed";
94+
code = nebula::error(result);
8895
break;
8996
}
90-
data.emplace_back(iter->key());
97+
98+
const auto& rewrites = nebula::value(result);
99+
rewriteData.insert(rewriteData.end(), rewrites.begin(), rewrites.end());
100+
data.emplace_back(zoneKey);
101+
} else {
102+
// Delete some hosts in the zone
103+
for (auto& h : hosts) {
104+
auto it = std::find(hs.begin(), hs.end(), h);
105+
if (it != hs.end()) {
106+
hs.erase(it);
107+
}
108+
}
109+
110+
auto zoneValue = MetaKeyUtils::zoneVal(hs);
111+
LOG(INFO) << "Zone Value: " << zoneValue;
112+
rewriteData.emplace_back(std::move(zoneKey), std::move(zoneValue));
113+
}
114+
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
115+
break;
91116
}
92117
iter->next();
93118
}
94119

120+
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
121+
handleErrorCode(code);
122+
onFinished();
123+
return;
124+
}
125+
95126
// Detach the machine from cluster
96127
for (auto& host : hosts) {
97128
auto machineKey = MetaKeyUtils::machineKey(host.host, host.port);
@@ -111,10 +142,21 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) {
111142
}
112143

113144
resp_.set_code(nebula::cpp2::ErrorCode::SUCCEEDED);
114-
doMultiRemove(std::move(data));
145+
folly::Baton<true, std::atomic> baton;
146+
kvstore_->asyncMultiRemove(kDefaultSpaceId,
147+
kDefaultPartId,
148+
std::move(data),
149+
[this, &baton](nebula::cpp2::ErrorCode result) {
150+
this->handleErrorCode(result);
151+
baton.post();
152+
});
153+
baton.wait();
154+
doSyncPutAndUpdate(std::move(rewriteData));
115155
}
116156

117-
nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpace(const std::string& zoneName) {
157+
ErrorOr<nebula::cpp2::ErrorCode, std::vector<kvstore::KV>>
158+
DropHostsProcessor::checkRelatedSpaceAndCollect(const std::string& zoneName) {
159+
std::vector<kvstore::KV> data;
118160
const auto& prefix = MetaKeyUtils::spacePrefix();
119161
auto ret = doPrefix(prefix);
120162
if (!nebula::ok(ret)) {
@@ -137,19 +179,15 @@ nebula::cpp2::ErrorCode DropHostsProcessor::checkRelatedSpace(const std::string&
137179
} else {
138180
zones.erase(it);
139181
properties.set_zone_names(zones);
140-
rewriteSpaceProperties(iter->key().data(), properties);
182+
183+
auto spaceKey = iter->key().data();
184+
auto spaceVal = MetaKeyUtils::spaceVal(properties);
185+
data.emplace_back(std::move(spaceKey), std::move(spaceVal));
141186
}
142187
}
143188
iter->next();
144189
}
145-
return nebula::cpp2::ErrorCode::SUCCEEDED;
146-
}
147-
148-
void DropHostsProcessor::rewriteSpaceProperties(const std::string& spaceKey,
149-
const meta::cpp2::SpaceDesc& properties) {
150-
auto spaceVal = MetaKeyUtils::spaceVal(properties);
151-
std::vector<kvstore::KV> data = {{spaceKey, spaceVal}};
152-
doSyncPutAndUpdate(std::move(data));
190+
return data;
153191
}
154192

155193
} // namespace meta

src/meta/processors/zone/DropHostsProcessor.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ class DropHostsProcessor : public BaseProcessor<cpp2::ExecResp> {
2222
private:
2323
explicit DropHostsProcessor(kvstore::KVStore* kvstore) : BaseProcessor<cpp2::ExecResp>(kvstore) {}
2424

25-
nebula::cpp2::ErrorCode checkRelatedSpace(const std::string& zoneName);
26-
27-
void rewriteSpaceProperties(const std::string& spaceKey, const meta::cpp2::SpaceDesc& properties);
25+
ErrorOr<nebula::cpp2::ErrorCode, std::vector<kvstore::KV>> checkRelatedSpaceAndCollect(
26+
const std::string& zoneName);
2827
};
2928

3029
} // namespace meta

src/meta/processors/zone/RenameZoneProcessor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace nebula {
99
namespace meta {
1010

1111
void RenameZoneProcessor::process(const cpp2::RenameZoneReq& req) {
12+
folly::SharedMutex::ReadHolder zHolder(LockUtils::zoneLock());
13+
1214
auto originalZoneName = req.get_original_zone_name();
1315
auto originalZoneKey = MetaKeyUtils::zoneKey(originalZoneName);
1416
auto originalZoneValueRet = doGet(std::move(originalZoneKey));

src/meta/test/ProcessorTest.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -3303,11 +3303,17 @@ TEST(ProcessorTest, DropHostsTest) {
33033303
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
33043304
ASSERT_EQ(6, resp.get_zones().size());
33053305
ASSERT_EQ("default_zone_127.0.0.1_8987", resp.get_zones()[0].get_zone_name());
3306+
ASSERT_EQ(1, resp.get_zones()[0].get_nodes().size());
33063307
ASSERT_EQ("default_zone_127.0.0.1_8988", resp.get_zones()[1].get_zone_name());
3308+
ASSERT_EQ(1, resp.get_zones()[1].get_nodes().size());
33073309
ASSERT_EQ("default_zone_127.0.0.1_8989", resp.get_zones()[2].get_zone_name());
3310+
ASSERT_EQ(1, resp.get_zones()[2].get_nodes().size());
33083311
ASSERT_EQ("zone_0", resp.get_zones()[3].get_zone_name());
3312+
ASSERT_EQ(2, resp.get_zones()[3].get_nodes().size());
33093313
ASSERT_EQ("zone_1", resp.get_zones()[4].get_zone_name());
3314+
ASSERT_EQ(1, resp.get_zones()[4].get_nodes().size());
33103315
ASSERT_EQ("zone_2", resp.get_zones()[5].get_zone_name());
3316+
ASSERT_EQ(1, resp.get_zones()[5].get_nodes().size());
33113317
}
33123318
{
33133319
// Create Space on cluster, the replica number same with the zone size
@@ -3466,9 +3472,13 @@ TEST(ProcessorTest, DropHostsTest) {
34663472
ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code());
34673473
ASSERT_EQ(4, resp.get_zones().size());
34683474
ASSERT_EQ("default_zone_127.0.0.1_8988", resp.get_zones()[0].get_zone_name());
3475+
ASSERT_EQ(1, resp.get_zones()[0].get_nodes().size());
34693476
ASSERT_EQ("default_zone_127.0.0.1_8989", resp.get_zones()[1].get_zone_name());
3477+
ASSERT_EQ(1, resp.get_zones()[1].get_nodes().size());
34703478
ASSERT_EQ("zone_0", resp.get_zones()[2].get_zone_name());
3479+
ASSERT_EQ(1, resp.get_zones()[2].get_nodes().size());
34713480
ASSERT_EQ("zone_2", resp.get_zones()[3].get_zone_name());
3481+
ASSERT_EQ(1, resp.get_zones()[3].get_nodes().size());
34723482
}
34733483
}
34743484

src/parser/MaintainSentences.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -379,37 +379,40 @@ std::string MergeZoneSentence::toString() const {
379379
buf.reserve(128);
380380
buf += "MERGE ZONE ";
381381
buf += zoneNames_->toString();
382-
buf += " INTO ";
382+
buf += " INTO \"";
383383
buf += *zoneName_;
384+
buf += "\"";
384385
return buf;
385386
}
386387

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

391392
std::string SplitZoneSentence::toString() const {
392393
std::string buf;
393394
buf.reserve(128);
394-
buf += "SPLIT ZONE ";
395+
buf += "SPLIT ZONE \"";
395396
buf += *zoneName_;
396-
buf += " INTO ";
397+
buf += "\" INTO \"";
397398
buf += zoneNames_->toString();
399+
buf += "\"";
398400
return buf;
399401
}
400402

401403
std::string RenameZoneSentence::toString() const {
402404
std::string buf;
403405
buf.reserve(128);
404-
buf += "RENAME ZONE ";
406+
buf += "RENAME ZONE \"";
405407
buf += *originalZoneName_;
406-
buf += " TO ";
408+
buf += "\" TO \"";
407409
buf += *zoneName_;
410+
buf += "\"";
408411
return buf;
409412
}
410413

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

415418
std::string ListZonesSentence::toString() const { return folly::stringPrintf("SHOW ZONES"); }
@@ -420,11 +423,12 @@ std::string AddHostsIntoZoneSentence::toString() const {
420423
buf += "ADD HOSTS ";
421424
buf += address_->toString();
422425
if (isNew_) {
423-
buf += " INTO NEW ZONE ";
426+
buf += " INTO NEW ZONE \"";
424427
} else {
425-
buf += " INTO ZONE ";
428+
buf += " INTO ZONE \"";
426429
}
427430
buf += *zoneName_;
431+
buf += "\"";
428432
return buf;
429433
}
430434

src/parser/Sentence.h

+2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ class ZoneNameList final {
205205
std::string toString() const {
206206
std::string buf;
207207
for (const auto &zone : zones_) {
208+
buf += "\"";
208209
buf += *zone;
210+
buf += "\"";
209211
buf += ",";
210212
}
211213
if (!zones_.empty()) {

src/parser/parser.yy

+9-9
Original file line numberDiff line numberDiff line change
@@ -2686,10 +2686,10 @@ add_hosts_sentence
26862686
: KW_ADD KW_HOSTS host_list {
26872687
$$ = new AddHostsSentence($3);
26882688
}
2689-
| KW_ADD KW_HOSTS host_list KW_INTO KW_ZONE name_label {
2689+
| KW_ADD KW_HOSTS host_list KW_INTO KW_ZONE STRING {
26902690
$$ = new AddHostsIntoZoneSentence($3, $6, false);
26912691
}
2692-
| KW_ADD KW_HOSTS host_list KW_INTO KW_NEW KW_ZONE name_label {
2692+
| KW_ADD KW_HOSTS host_list KW_INTO KW_NEW KW_ZONE STRING {
26932693
$$ = new AddHostsIntoZoneSentence($3, $7, true);
26942694
}
26952695
;
@@ -2702,13 +2702,13 @@ drop_hosts_sentence
27022702

27032703

27042704
merge_zone_sentence
2705-
: KW_MERGE KW_ZONE zone_name_list KW_INTO name_label {
2705+
: KW_MERGE KW_ZONE zone_name_list KW_INTO STRING {
27062706
$$ = new MergeZoneSentence($3, $5);
27072707
}
27082708
;
27092709

27102710
drop_zone_sentence
2711-
: KW_DROP KW_ZONE name_label {
2711+
: KW_DROP KW_ZONE STRING {
27122712
$$ = new DropZoneSentence($3);
27132713
}
27142714
;
@@ -2720,16 +2720,16 @@ drop_zone_sentence
27202720
// ;
27212721

27222722
rename_zone_sentence
2723-
: KW_RENAME KW_ZONE name_label KW_TO name_label {
2723+
: KW_RENAME KW_ZONE STRING KW_TO STRING {
27242724
$$ = new RenameZoneSentence($3, $5);
27252725
}
27262726
;
27272727

27282728
desc_zone_sentence
2729-
: KW_DESCRIBE KW_ZONE name_label {
2729+
: KW_DESCRIBE KW_ZONE STRING {
27302730
$$ = new DescribeZoneSentence($3);
27312731
}
2732-
| KW_DESC KW_ZONE name_label {
2732+
| KW_DESC KW_ZONE STRING {
27332733
$$ = new DescribeZoneSentence($3);
27342734
}
27352735
;
@@ -3307,11 +3307,11 @@ show_config_item
33073307
;
33083308

33093309
zone_name_list
3310-
: name_label {
3310+
: STRING {
33113311
$$ = new ZoneNameList();
33123312
$$->addZone($1);
33133313
}
3314-
| zone_name_list COMMA name_label {
3314+
| zone_name_list COMMA STRING {
33153315
$$ = $1;
33163316
$$->addZone($3);
33173317
}

0 commit comments

Comments
 (0)