From 8205248ff260944a6a2d67c0f7e905c1c8133393 Mon Sep 17 00:00:00 2001 From: liwenhui-soul <38217397+liwenhui-soul@users.noreply.github.com> Date: Mon, 21 Feb 2022 11:07:13 +0800 Subject: [PATCH] Revert "disable zone commands (#3776)" This reverts commit d650f79f18a157d52ed48804ca1c70324b323f9f. --- src/common/meta/Common.h | 1 + src/graph/validator/AdminValidator.cpp | 21 ++++---- src/graph/validator/MaintainValidator.cpp | 12 ++--- src/graph/validator/MaintainValidator.h | 4 +- src/graph/validator/Validator.cpp | 2 +- src/parser/AdminSentences.cpp | 8 ++++ src/parser/AdminSentences.h | 16 +++++++ src/parser/MaintainSentences.cpp | 2 +- src/parser/MaintainSentences.h | 4 +- src/parser/parser.yy | 2 +- tests/admin/test_space.py | 58 +++++++++++------------ tests/common/nebula_service.py | 2 +- tests/maintain/test_zone.py | 30 ++++++++++++ tests/tck/features/admin/Hosts.feature | 4 +- tests/tck/features/schema/Comment.feature | 24 +++++----- 15 files changed, 121 insertions(+), 69 deletions(-) diff --git a/src/common/meta/Common.h b/src/common/meta/Common.h index 3841ada4a2a..5b6f9c44e7d 100644 --- a/src/common/meta/Common.h +++ b/src/common/meta/Common.h @@ -62,6 +62,7 @@ using RemoteListeners = std::unordered_map>>; + } // namespace meta } // namespace nebula diff --git a/src/graph/validator/AdminValidator.cpp b/src/graph/validator/AdminValidator.cpp index f95b90c8490..c2d7667d0a1 100644 --- a/src/graph/validator/AdminValidator.cpp +++ b/src/graph/validator/AdminValidator.cpp @@ -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 retStatusOr; std::string result; auto *charsetInfo = qctx_->getCharsetInfo(); @@ -344,6 +343,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(sentence_); auto hosts = sentence->hosts()->hosts(); if (hosts.empty()) { @@ -354,12 +357,7 @@ Status AddHostsValidator::validateImpl() { if (it != hosts.end()) { return Status::SemanticError("Host have duplicated"); } - return Status::OK(); -} -Status AddHostsValidator::toPlan() { - auto sentence = static_cast(sentence_); - auto hosts = sentence->hosts()->hosts(); auto *addHost = AddHosts::make(qctx_, nullptr, hosts); root_ = addHost; tail_ = root_; @@ -367,6 +365,10 @@ Status AddHostsValidator::toPlan() { } Status DropHostsValidator::validateImpl() { + return Status::OK(); +} + +Status DropHostsValidator::toPlan() { auto sentence = static_cast(sentence_); auto hosts = sentence->hosts()->hosts(); if (hosts.empty()) { @@ -377,12 +379,7 @@ Status DropHostsValidator::validateImpl() { if (it != hosts.end()) { return Status::SemanticError("Host have duplicated"); } - return Status::OK(); -} -Status DropHostsValidator::toPlan() { - auto sentence = static_cast(sentence_); - auto hosts = sentence->hosts()->hosts(); auto *dropHost = DropHosts::make(qctx_, nullptr, hosts); root_ = dropHost; tail_ = root_; diff --git a/src/graph/validator/MaintainValidator.cpp b/src/graph/validator/MaintainValidator.cpp index d5287972101..b24c53e5b6a 100644 --- a/src/graph/validator/MaintainValidator.cpp +++ b/src/graph/validator/MaintainValidator.cpp @@ -501,7 +501,7 @@ Status ShowEdgeIndexStatusValidator::toPlan() { } Status MergeZoneValidator::validateImpl() { - return Status::SemanticError("Merge zone is unsupported"); + return Status::OK(); } Status MergeZoneValidator::toPlan() { @@ -514,7 +514,7 @@ Status MergeZoneValidator::toPlan() { } Status RenameZoneValidator::validateImpl() { - return Status::SemanticError("Rename zone is unsupported"); + return Status::OK(); } Status RenameZoneValidator::toPlan() { @@ -539,7 +539,7 @@ Status DropZoneValidator::toPlan() { } Status DivideZoneValidator::validateImpl() { - return Status::SemanticError("Divide zone is unsupported"); + return Status::OK(); } Status DivideZoneValidator::toPlan() { @@ -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_; diff --git a/src/graph/validator/MaintainValidator.h b/src/graph/validator/MaintainValidator.h index a835da62777..86062ab7067 100644 --- a/src/graph/validator/MaintainValidator.h +++ b/src/graph/validator/MaintainValidator.h @@ -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(); } diff --git a/src/graph/validator/Validator.cpp b/src/graph/validator/Validator.cpp index d87ea35bec7..b978e36c997 100644 --- a/src/graph/validator/Validator.cpp +++ b/src/graph/validator/Validator.cpp @@ -219,7 +219,7 @@ std::unique_ptr Validator::makeValidator(Sentence* sentence, QueryCon case Sentence::Kind::kDescribeZone: return std::make_unique(sentence, context); case Sentence::Kind::kListZones: - return std::make_unique(sentence, context); + return std::make_unique(sentence, context); case Sentence::Kind::kAddHostsIntoZone: return std::make_unique(sentence, context); case Sentence::Kind::kAddListener: diff --git a/src/parser/AdminSentences.cpp b/src/parser/AdminSentences.cpp index c9a1e2ff13c..408c892fce2 100644 --- a/src/parser/AdminSentences.cpp +++ b/src/parser/AdminSentences.cpp @@ -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: diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index 2ece4c54405..2dbbe756ca0 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -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 = std::variant; diff --git a/src/parser/MaintainSentences.cpp b/src/parser/MaintainSentences.cpp index d882e5b7873..bb51b521dc0 100644 --- a/src/parser/MaintainSentences.cpp +++ b/src/parser/MaintainSentences.cpp @@ -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"); } diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h index cc56f3cdc43..26fa0c82748 100644 --- a/src/parser/MaintainSentences.h +++ b/src/parser/MaintainSentences.h @@ -1081,9 +1081,9 @@ class DescribeZoneSentence : public Sentence { std::unique_ptr zoneName_; }; -class ShowZonesSentence : public Sentence { +class ListZonesSentence : public Sentence { public: - ShowZonesSentence() { + ListZonesSentence() { kind_ = Kind::kListZones; } diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 6aaa82523f6..6096d178653 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -3403,7 +3403,7 @@ show_sentence $$ = new ShowCollationSentence(); } | KW_SHOW KW_ZONES { - $$ = new ShowZonesSentence(); + $$ = new ListZonesSentence(); } | KW_SHOW KW_STATS { $$ = new ShowStatsSentence(); diff --git a/tests/admin/test_space.py b/tests/admin/test_space.py index 8d2f2fee510..917bdff2566 100644 --- a/tests/admin/test_space.py +++ b/tests/admin/test_space.py @@ -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') @@ -42,9 +42,9 @@ 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 @@ -52,16 +52,16 @@ def test_space(self): 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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') diff --git a/tests/common/nebula_service.py b/tests/common/nebula_service.py index f8e4729ac7f..e587ca35aa6 100644 --- a/tests/common/nebula_service.py +++ b/tests/common/nebula_service.py @@ -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() diff --git a/tests/maintain/test_zone.py b/tests/maintain/test_zone.py index 465fb77653b..74128fe3110 100644 --- a/tests/maintain/test_zone.py +++ b/tests/maintain/test_zone.py @@ -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) diff --git a/tests/tck/features/admin/Hosts.feature b/tests/tck/features/admin/Hosts.feature index 8a067cfb43e..cf76703ebac 100644 --- a/tests/tck/features/admin/Hosts.feature +++ b/tests/tck/features/admin/Hosts.feature @@ -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)); diff --git a/tests/tck/features/schema/Comment.feature b/tests/tck/features/schema/Comment.feature index deb866a161e..94c4ecc8911 100644 --- a/tests/tck/features/schema/Comment.feature +++ b/tests/tck/features/schema/Comment.feature @@ -15,15 +15,15 @@ Feature: Schema Comment SHOW CREATE SPACE ; """ Then the result should be, in any order: - | Space | Create Space | - | "" | /[CREATE SPACE `` \(partition_num = 100, replica_factor = 1, charset = utf8, collate = utf8_bin, vid_type = FIXED_STRING\(8\), atomic_edge = false\) ON]+\s(\w*)\s[comment = ``]+/ | + | Space | Create Space | + | "" | "CREATE SPACE `` (partition_num = 100, replica_factor = 1, charset = utf8, collate = utf8_bin, vid_type = FIXED_STRING(8), atomic_edge = false) ON default_zone comment = ''" | When executing query: """ DESC SPACE ; """ Then the result should be, in any order: - | ID | Name | Partition Number | Replica Factor | Charset | Collate | Vid Type | Atomic Edge | Zones | Comment | - | /\d+/ | "" | 100 | 1 | "utf8" | "utf8_bin" | "FIXED_STRING(8)" | false | /^.+?\d$/ | "" | + | ID | Name | Partition Number | Replica Factor | Charset | Collate | Vid Type | Atomic Edge | Zones | Comment | + | /\d+/ | "" | 100 | 1 | "utf8" | "utf8_bin" | "FIXED_STRING(8)" | false | "default_zone" | "" | When executing query: """ DROP SPACE ; @@ -47,15 +47,15 @@ Feature: Schema Comment SHOW CREATE SPACE test_comment_not_set; """ Then the result should be, in any order: - | Space | Create Space | - | "test_comment_not_set" | /[CREATE SPACE `test_comment_not_set` \(partition_num = 100, replica_factor = 1, charset = utf8, collate = utf8_bin, vid_type = FIXED_STRING\(8\), atomic_edge = false\) ON]+\s(\w*)/ | + | Space | Create Space | + | "test_comment_not_set" | "CREATE SPACE `test_comment_not_set` (partition_num = 100, replica_factor = 1, charset = utf8, collate = utf8_bin, vid_type = FIXED_STRING(8), atomic_edge = false) ON default_zone" | When executing query: """ DESC SPACE test_comment_not_set; """ Then the result should be, in any order: - | ID | Name | Partition Number | Replica Factor | Charset | Collate | Vid Type | Atomic Edge | Zones | Comment | - | /\d+/ | "test_comment_not_set" | 100 | 1 | "utf8" | "utf8_bin" | "FIXED_STRING(8)" | false | /^.+?\d$/ | EMPTY | + | ID | Name | Partition Number | Replica Factor | Charset | Collate | Vid Type | Atomic Edge | Zones | Comment | + | /\d+/ | "test_comment_not_set" | 100 | 1 | "utf8" | "utf8_bin" | "FIXED_STRING(8)" | false | "default_zone" | EMPTY | When executing query: """ DROP SPACE test_comment_not_set; @@ -74,15 +74,15 @@ Feature: Schema Comment SHOW CREATE SPACE test_comment_empty; """ Then the result should be, in any order: - | Space | Create Space | - | "test_comment_empty" | /[CREATE SPACE `test_comment_empty` \(partition_num = 100, replica_factor = 1, charset = utf8, collate = utf8_bin, vid_type = FIXED_STRING\(8\), atomic_edge = false\) ON]+\s(\w*)\s[comment = '']+/ | + | Space | Create Space | + | "test_comment_empty" | "CREATE SPACE `test_comment_empty` (partition_num = 100, replica_factor = 1, charset = utf8, collate = utf8_bin, vid_type = FIXED_STRING(8), atomic_edge = false) ON default_zone comment = ''" | When executing query: """ DESC SPACE test_comment_empty; """ Then the result should be, in any order: - | ID | Name | Partition Number | Replica Factor | Charset | Collate | Vid Type | Atomic Edge | Zones | Comment | - | /\d+/ | "test_comment_empty" | 100 | 1 | "utf8" | "utf8_bin" | "FIXED_STRING(8)" | false | /^.+?\d$/ | "" | + | ID | Name | Partition Number | Replica Factor | Charset | Collate | Vid Type | Atomic Edge | Zones | Comment | + | /\d+/ | "test_comment_empty" | 100 | 1 | "utf8" | "utf8_bin" | "FIXED_STRING(8)" | false | "default_zone" | "" | When executing query: """ DROP SPACE test_comment_empty;