Skip to content

Commit

Permalink
Revert "disable zone commands (vesoft-inc#3776)"
Browse files Browse the repository at this point in the history
This reverts commit d650f79.
  • Loading branch information
liwenhui-soul committed Mar 11, 2022
1 parent 6d4f8ee commit fbd5ee0
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/common/meta/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ using RemoteListeners =
std::unordered_map<GraphSpaceID,
std::unordered_map<PartitionID, std::vector<RemoteListenerInfo>>>;


} // namespace meta
} // namespace nebula

Expand Down
21 changes: 9 additions & 12 deletions src/graph/validator/AdminValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ Status CreateSpaceValidator::validateImpl() {
auto status = Status::OK();
spaceDesc_.space_name_ref() = std::move(*(sentence->spaceName()));
if (sentence->zoneNames()) {
return Status::SemanticError("Create space with zone is unsupported");
spaceDesc_.zone_names_ref() = sentence->zoneNames()->zoneNames();
}

StatusOr<std::string> retStatusOr;
std::string result;
auto *charsetInfo = qctx_->getCharsetInfo();
Expand Down Expand Up @@ -332,6 +331,10 @@ Status ShowListenerValidator::toPlan() {

// Register hosts, unregistered host won't be allowed to join cluster.
Status AddHostsValidator::validateImpl() {
return Status::OK();
}

Status AddHostsValidator::toPlan() {
auto sentence = static_cast<AddHostsSentence *>(sentence_);
auto hosts = sentence->hosts()->hosts();
if (hosts.empty()) {
Expand All @@ -342,19 +345,18 @@ Status AddHostsValidator::validateImpl() {
if (it != hosts.end()) {
return Status::SemanticError("Host have duplicated");
}
return Status::OK();
}

Status AddHostsValidator::toPlan() {
auto sentence = static_cast<AddHostsSentence *>(sentence_);
auto hosts = sentence->hosts()->hosts();
auto *addHost = AddHosts::make(qctx_, nullptr, hosts);
root_ = addHost;
tail_ = root_;
return Status::OK();
}

Status DropHostsValidator::validateImpl() {
return Status::OK();
}

Status DropHostsValidator::toPlan() {
auto sentence = static_cast<DropHostsSentence *>(sentence_);
auto hosts = sentence->hosts()->hosts();
if (hosts.empty()) {
Expand All @@ -365,12 +367,7 @@ Status DropHostsValidator::validateImpl() {
if (it != hosts.end()) {
return Status::SemanticError("Host have duplicated");
}
return Status::OK();
}

Status DropHostsValidator::toPlan() {
auto sentence = static_cast<DropHostsSentence *>(sentence_);
auto hosts = sentence->hosts()->hosts();
auto *dropHost = DropHosts::make(qctx_, nullptr, hosts);
root_ = dropHost;
tail_ = root_;
Expand Down
12 changes: 6 additions & 6 deletions src/graph/validator/MaintainValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ Status ShowEdgeIndexStatusValidator::toPlan() {
}

Status MergeZoneValidator::validateImpl() {
return Status::SemanticError("Merge zone is unsupported");
return Status::OK();
}

Status MergeZoneValidator::toPlan() {
Expand All @@ -514,7 +514,7 @@ Status MergeZoneValidator::toPlan() {
}

Status RenameZoneValidator::validateImpl() {
return Status::SemanticError("Rename zone is unsupported");
return Status::OK();
}

Status RenameZoneValidator::toPlan() {
Expand All @@ -539,7 +539,7 @@ Status DropZoneValidator::toPlan() {
}

Status DivideZoneValidator::validateImpl() {
return Status::SemanticError("Divide zone is unsupported");
return Status::OK();
}

Status DivideZoneValidator::toPlan() {
Expand All @@ -563,11 +563,11 @@ Status DescribeZoneValidator::toPlan() {
return Status::OK();
}

Status ShowZonesValidator::validateImpl() {
return Status::SemanticError("Show zones is unsupported");
Status ListZonesValidator::validateImpl() {
return Status::OK();
}

Status ShowZonesValidator::toPlan() {
Status ListZonesValidator::toPlan() {
auto *doNode = ListZones::make(qctx_, nullptr);
root_ = doNode;
tail_ = root_;
Expand Down
4 changes: 2 additions & 2 deletions src/graph/validator/MaintainValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ class DescribeZoneValidator final : public Validator {
Status toPlan() override;
};

class ShowZonesValidator final : public Validator {
class ListZonesValidator final : public Validator {
public:
ShowZonesValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {
ListZonesValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {
setNoSpaceRequired();
}

Expand Down
2 changes: 1 addition & 1 deletion src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryCon
case Sentence::Kind::kDescribeZone:
return std::make_unique<DescribeZoneValidator>(sentence, context);
case Sentence::Kind::kListZones:
return std::make_unique<ShowZonesValidator>(sentence, context);
return std::make_unique<ListZonesValidator>(sentence, context);
case Sentence::Kind::kAddHostsIntoZone:
return std::make_unique<AddHostsIntoZoneValidator>(sentence, context);
case Sentence::Kind::kAddListener:
Expand Down
8 changes: 8 additions & 0 deletions src/parser/AdminSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ std::string ShowCollationSentence::toString() const {
return std::string("SHOW COLLATION");
}

std::string ShowGroupsSentence::toString() const {
return std::string("SHOW GROUPS");
}

std::string ShowZonesSentence::toString() const {
return std::string("SHOW ZONES");
}

std::string SpaceOptItem::toString() const {
switch (optType_) {
case OptionType::PARTITION_NUM:
Expand Down
16 changes: 16 additions & 0 deletions src/parser/AdminSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ class ShowCollationSentence final : public Sentence {
std::string toString() const override;
};

class ShowGroupsSentence final : public Sentence {
public:
ShowGroupsSentence() {
kind_ = Kind::kShowGroups;
}
std::string toString() const override;
};

class ShowZonesSentence final : public Sentence {
public:
ShowZonesSentence() {
kind_ = Kind::kShowZones;
}
std::string toString() const override;
};

class SpaceOptItem final {
public:
using Value = boost::variant<int64_t, std::string, meta::cpp2::ColumnTypeDef>;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/MaintainSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ std::string DescribeZoneSentence::toString() const {
return folly::stringPrintf("DESCRIBE ZONE `%s`", zoneName_.get()->c_str());
}

std::string ShowZonesSentence::toString() const {
std::string ListZonesSentence::toString() const {
return folly::stringPrintf("SHOW ZONES");
}

Expand Down
4 changes: 2 additions & 2 deletions src/parser/MaintainSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,9 @@ class DescribeZoneSentence : public Sentence {
std::unique_ptr<std::string> zoneName_;
};

class ShowZonesSentence : public Sentence {
class ListZonesSentence : public Sentence {
public:
ShowZonesSentence() {
ListZonesSentence() {
kind_ = Kind::kListZones;
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -3403,7 +3403,7 @@ show_sentence
$$ = new ShowCollationSentence();
}
| KW_SHOW KW_ZONES {
$$ = new ShowZonesSentence();
$$ = new ListZonesSentence();
}
| KW_SHOW KW_STATS {
$$ = new ShowStatsSentence();
Expand Down
58 changes: 29 additions & 29 deletions tests/admin/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def test_space(self):
self.check_resp_succeeded(resp)

# check result
# resp = self.client.execute('DESC SPACE space_with_default_options')
# expect_result = [['space_with_default_options', 100, 1, 'utf8', 'utf8_bin',
# 'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
resp = self.client.execute('DESC SPACE space_with_default_options')
expect_result = [['space_with_default_options', 100, 1, 'utf8', 'utf8_bin',
'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# drop space
resp = self.client.execute('DROP SPACE space_with_default_options')
Expand All @@ -42,26 +42,26 @@ def test_space(self):
# desc space
resp = self.client.execute('DESC SPACE default_space')
self.check_resp_succeeded(resp)
# expect_result = [['default_space', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)',
# False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
expect_result = [['default_space', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)',
False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# show create space
# TODO(shylock) need meta cache to permission checking
time.sleep(self.delay)
resp = self.client.execute('SHOW CREATE SPACE default_space')
self.check_resp_succeeded(resp)

# create_space_str_result = 'CREATE SPACE `default_space` (partition_num = 9, '\
# 'replica_factor = 1, '\
# 'charset = utf8, '\
# 'collate = utf8_bin, '\
# 'vid_type = FIXED_STRING(8), '\
# 'atomic_edge = false) '\
# 'ON default_zone'
create_space_str_result = 'CREATE SPACE `default_space` (partition_num = 9, '\
'replica_factor = 1, '\
'charset = utf8, '\
'collate = utf8_bin, '\
'vid_type = FIXED_STRING(8), '\
'atomic_edge = false) '\
'ON default_zone'

# expect_result = [['default_space', create_space_str_result]]
# self.check_result(resp, expect_result)
expect_result = [['default_space', create_space_str_result]]
self.check_result(resp, expect_result)

# check result from show create
resp = self.client.execute('DROP SPACE default_space')
Expand Down Expand Up @@ -92,8 +92,8 @@ def test_charset_collate(self):

resp = self.client.execute('DESC SPACE space_charset_collate')
self.check_resp_succeeded(resp)
# expect_result = [['space_charset_collate', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
expect_result = [['space_charset_collate', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# drop space
resp = self.client.execute('DROP SPACE space_charset_collate')
Expand All @@ -105,8 +105,8 @@ def test_charset_collate(self):

resp = self.client.execute('DESC SPACE space_charset')
self.check_resp_succeeded(resp)
# expect_result = [['space_charset', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
expect_result = [['space_charset', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# drop space
resp = self.client.execute('DROP SPACE space_charset')
Expand All @@ -118,8 +118,8 @@ def test_charset_collate(self):

resp = self.client.execute('DESC SPACE space_collate')
self.check_resp_succeeded(resp)
# expect_result = [['space_collate', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
expect_result = [['space_collate', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)', False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# drop space
resp = self.client.execute('DROP SPACE space_collate')
Expand Down Expand Up @@ -155,9 +155,9 @@ def test_charset_collate(self):

resp = self.client.execute('DESC SPACE space_capital')
self.check_resp_succeeded(resp)
# expect_result = [['space_capital', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)',
# False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
expect_result = [['space_capital', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(8)',
False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# drop space
resp = self.client.execute('DROP SPACE space_capital')
Expand Down Expand Up @@ -208,8 +208,8 @@ def test_create_space_with_string_vid(self):

resp = self.client.execute('DESC SPACE space_string_vid')
self.check_resp_succeeded(resp)
# expect_result = [['space_string_vid', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(30)', False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
expect_result = [['space_string_vid', 9, 1, 'utf8', 'utf8_bin', 'FIXED_STRING(30)', False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# clean up
resp = self.client.execute('DROP SPACE space_string_vid')
Expand All @@ -223,8 +223,8 @@ def test_create_space_with_int_vid(self):

resp = self.client.execute('DESC SPACE space_int_vid')
self.check_resp_succeeded(resp)
# expect_result = [['space_int_vid', 9, 1, 'utf8', 'utf8_bin', 'INT64', False, 'default_zone', T_EMPTY]]
# self.check_result(resp, expect_result, {0})
expect_result = [['space_int_vid', 9, 1, 'utf8', 'utf8_bin', 'INT64', False, 'default_zone', T_EMPTY]]
self.check_result(resp, expect_result, {0})

# clean up
resp = self.client.execute('DROP SPACE space_int_vid')
Expand Down
2 changes: 1 addition & 1 deletion tests/common/nebula_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def start(self):
for storaged in self.storaged_processes
]
)
cmd = "ADD HOSTS {}".format(hosts)
cmd = "ADD HOSTS {} INTO NEW ZONE \"default_zone\"".format(hosts)
print("add hosts cmd is {}".format(cmd))
resp = client.execute(cmd)
assert resp.is_succeeded(), resp.error_msg()
Expand Down
30 changes: 30 additions & 0 deletions tests/maintain/test_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,33 @@
class TestZone(NebulaTestSuite):
def test_zone(self):
pass
# resp = self.client.execute('SHOW HOSTS')
# self.check_resp_succeeded(resp)
# assert not resp.is_empty()
# storage_port = resp.row_values(0)[1].as_int()

# # Get Zone
# resp = self.client.execute('DESC ZONE default_zone_127.0.0.1_' + str(storage_port))
# self.check_resp_succeeded(resp)

# resp = self.client.execute('DESCRIBE ZONE zone_0')
# self.check_resp_succeeded(resp)

# # Get Zone which is not exist
# resp = self.client.execute('DESC ZONE zone_not_exist')
# self.check_resp_failed(resp)

# resp = self.client.execute('DESCRIBE ZONE zone_not_exist')
# self.check_resp_failed(resp)

# # SHOW Zones
# resp = self.client.execute('SHOW ZONES')
# self.check_resp_succeeded(resp)

# # Drop Zone
# resp = self.client.execute('DROP ZONE zone_0')
# self.check_resp_succeeded(resp)

# # Drop Zone which is not exist
# resp = self.client.execute('DROP ZONE zone_0')
# self.check_resp_failed(resp)
4 changes: 2 additions & 2 deletions tests/tck/features/admin/Hosts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ Feature: Admin hosts
"""
CREATE SPACE space_without_vid_type(partition_num=9, replica_factor=3) on default_zone;
"""
Then a SemanticError should be raised at runtime: Create space with zone is unsupported
Then a SemanticError should be raised at runtime: space vid_type must be specified explicitly
When executing query:
"""
CREATE SPACE space_without_vid_type on default_zone;
"""
Then a SemanticError should be raised at runtime: Create space with zone is unsupported
Then a SemanticError should be raised at runtime: space vid_type must be specified explicitly
When executing query:
"""
CREATE SPACE space_specify_vid_type(partition_num=9, replica_factor=1, vid_type=FIXED_STRING(8));
Expand Down
Loading

0 comments on commit fbd5ee0

Please sign in to comment.