diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 8449612cfa9..8fd04d8ecab 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -1204,6 +1204,25 @@ folly::Future>> MetaClient::listHosts(cpp2: return future; } +folly::Future> MetaClient::alterSpace(const std::string& spaceName, + meta::cpp2::AlterSpaceOp op, + const std::vector& paras) { + cpp2::AlterSpaceReq req; + req.set_op(op); + req.set_space_name(spaceName); + req.set_paras(paras); + folly::Promise> promise; + auto future = promise.getFuture(); + getResponse( + std::move(req), + [](auto client, auto request) { return client->future_alterSpace(request); }, + [](cpp2::ExecResp&& resp) -> bool { + return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED; + }, + std::move(promise)); + return future; +} + folly::Future>> MetaClient::listParts( GraphSpaceID spaceId, std::vector partIds) { cpp2::ListPartsReq req; diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 80f975e0181..abaa817cb85 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -260,6 +260,10 @@ class MetaClient { folly::Future>> listHosts( cpp2::ListHostType type = cpp2::ListHostType::ALLOC); + folly::Future> alterSpace(const std::string& spaceName, + meta::cpp2::AlterSpaceOp op, + const std::vector& paras); + folly::Future>> listParts(GraphSpaceID spaceId, std::vector partIds); diff --git a/src/graph/executor/Executor.cpp b/src/graph/executor/Executor.cpp index b44ef027e33..691d30249a1 100644 --- a/src/graph/executor/Executor.cpp +++ b/src/graph/executor/Executor.cpp @@ -511,6 +511,9 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { case PlanNode::Kind::kAppendVertices: { return pool->add(new AppendVerticesExecutor(node, qctx)); } + case PlanNode::Kind::kAlterSpace: { + return pool->add(new AlterSpaceExecutor(node, qctx)); + } case PlanNode::Kind::kUnknown: { LOG(FATAL) << "Unknown plan node kind " << static_cast(node->kind()); break; diff --git a/src/graph/executor/admin/SpaceExecutor.cpp b/src/graph/executor/admin/SpaceExecutor.cpp index f2a452482fc..0a4cf763830 100644 --- a/src/graph/executor/admin/SpaceExecutor.cpp +++ b/src/graph/executor/admin/SpaceExecutor.cpp @@ -257,5 +257,22 @@ folly::Future ShowCreateSpaceExecutor::execute() { .build()); }); } + +folly::Future AlterSpaceExecutor::execute() { + SCOPED_TIMER(&execTime_); + auto *asnode = asNode(node()); + return qctx() + ->getMetaClient() + ->alterSpace(asnode->getSpaceName(), asnode->getAlterSpaceOp(), asnode->getParas()) + .via(runner()) + .thenValue([this](StatusOr &&resp) { + SCOPED_TIMER(&execTime_); + if (!resp.ok()) { + LOG(ERROR) << resp.status().toString(); + return std::move(resp).status(); + } + return Status::OK(); + }); +} } // namespace graph } // namespace nebula diff --git a/src/graph/executor/admin/SpaceExecutor.h b/src/graph/executor/admin/SpaceExecutor.h index e0c917d93f0..d3b338af1dd 100644 --- a/src/graph/executor/admin/SpaceExecutor.h +++ b/src/graph/executor/admin/SpaceExecutor.h @@ -58,6 +58,14 @@ class ShowCreateSpaceExecutor final : public Executor { folly::Future execute() override; }; + +class AlterSpaceExecutor final : public Executor { + public: + AlterSpaceExecutor(const PlanNode *node, QueryContext *qctx) + : Executor("AlterSpaceExecutor", node, qctx) {} + + folly::Future execute() override; +}; } // namespace graph } // namespace nebula diff --git a/src/graph/planner/plan/Admin.h b/src/graph/planner/plan/Admin.h index c95ecfadf2f..74cac7b0a7b 100644 --- a/src/graph/planner/plan/Admin.h +++ b/src/graph/planner/plan/Admin.h @@ -194,6 +194,38 @@ class DropSpace final : public SingleDependencyNode { bool ifExists_; }; +class AlterSpace final : public SingleDependencyNode { + public: + static AlterSpace* make(QueryContext* qctx, + PlanNode* input, + const std::string& spaceName, + meta::cpp2::AlterSpaceOp op, + const std::vector& paras) { + return qctx->objPool()->add(new AlterSpace(qctx, input, spaceName, op, paras)); + } + const std::string& getSpaceName() const { return spaceName_; } + + meta::cpp2::AlterSpaceOp getAlterSpaceOp() const { return op_; } + + const std::vector& getParas() const { return paras_; } + + private: + AlterSpace(QueryContext* qctx, + PlanNode* input, + const std::string& spaceName, + meta::cpp2::AlterSpaceOp op, + const std::vector& paras) + : SingleDependencyNode(qctx, Kind::kAlterSpace, input), + spaceName_(spaceName), + op_(op), + paras_(paras) {} + + private: + std::string spaceName_; + meta::cpp2::AlterSpaceOp op_; + std::vector paras_; +}; + class DescSpace final : public SingleDependencyNode { public: static DescSpace* make(QueryContext* qctx, PlanNode* input, std::string spaceName) { diff --git a/src/graph/planner/plan/PlanNode.cpp b/src/graph/planner/plan/PlanNode.cpp index b69e401610d..e18c72cc023 100644 --- a/src/graph/planner/plan/PlanNode.cpp +++ b/src/graph/planner/plan/PlanNode.cpp @@ -170,6 +170,8 @@ const char* PlanNode::toString(PlanNode::Kind kind) { return "DropEdge"; case Kind::kShowSpaces: return "ShowSpaces"; + case Kind::kAlterSpace: + return "AlterSpaces"; case Kind::kShowTags: return "ShowTags"; case Kind::kShowEdges: diff --git a/src/graph/planner/plan/PlanNode.h b/src/graph/planner/plan/PlanNode.h index 910a69e88b9..be7b281dc81 100644 --- a/src/graph/planner/plan/PlanNode.h +++ b/src/graph/planner/plan/PlanNode.h @@ -90,6 +90,7 @@ class PlanNode { kDropSpace, kDropTag, kDropEdge, + kAlterSpace, // index related kCreateTagIndex, diff --git a/src/graph/service/PermissionCheck.cpp b/src/graph/service/PermissionCheck.cpp index 13b5859fbc7..517e6373790 100644 --- a/src/graph/service/PermissionCheck.cpp +++ b/src/graph/service/PermissionCheck.cpp @@ -51,6 +51,7 @@ Status PermissionCheck::permissionCheck(ClientSession *session, return Status::OK(); } case Sentence::Kind::kCreateSpace: + case Sentence::Kind::kAlterSpace: case Sentence::Kind::kCreateSpaceAs: case Sentence::Kind::kDropSpace: case Sentence::Kind::kCreateSnapshot: diff --git a/src/graph/validator/AdminValidator.cpp b/src/graph/validator/AdminValidator.cpp index fb32c5d21ad..fe6d72073a6 100644 --- a/src/graph/validator/AdminValidator.cpp +++ b/src/graph/validator/AdminValidator.cpp @@ -163,6 +163,17 @@ Status CreateSpaceAsValidator::toPlan() { return Status::OK(); } +Status AlterSpaceValidator::validateImpl() { return Status::OK(); } + +Status AlterSpaceValidator::toPlan() { + auto sentence = static_cast(sentence_); + auto *doNode = AlterSpace::make( + qctx_, nullptr, sentence->spaceName(), sentence->alterSpaceOp(), sentence->paras()); + root_ = doNode; + tail_ = root_; + return Status::OK(); +} + Status DescSpaceValidator::validateImpl() { return Status::OK(); } Status DescSpaceValidator::toPlan() { diff --git a/src/graph/validator/AdminValidator.h b/src/graph/validator/AdminValidator.h index 0ae1864b9f3..6107afc583c 100644 --- a/src/graph/validator/AdminValidator.h +++ b/src/graph/validator/AdminValidator.h @@ -48,6 +48,16 @@ class CreateSpaceAsValidator final : public Validator { std::string newSpaceName_; }; +class AlterSpaceValidator final : public Validator { + public: + AlterSpaceValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {} + + private: + Status validateImpl() override; + + Status toPlan() override; +}; + class DescSpaceValidator final : public Validator { public: DescSpaceValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) { diff --git a/src/graph/validator/Validator.cpp b/src/graph/validator/Validator.cpp index 022e60a023c..355f6217dcd 100644 --- a/src/graph/validator/Validator.cpp +++ b/src/graph/validator/Validator.cpp @@ -252,6 +252,8 @@ std::unique_ptr Validator::makeValidator(Sentence* sentence, QueryCon return std::make_unique(sentence, context); case Sentence::Kind::kKillQuery: return std::make_unique(sentence, context); + case Sentence::Kind::kAlterSpace: + return std::make_unique(sentence, context); case Sentence::Kind::kUnknown: case Sentence::Kind::kReturn: { // nothing diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift index dc3513d00cd..ccc4c76357b 100644 --- a/src/interface/meta.thrift +++ b/src/interface/meta.thrift @@ -203,6 +203,16 @@ struct ExecResp { 3: common.HostAddr leader, } +enum AlterSpaceOp { + ADD_ZONE = 0x01, +} (cpp.enum_strict) + +struct AlterSpaceReq { + 1: binary space_name, + 2: AlterSpaceOp op, + 3: list paras, +} + // Job related data structures enum AdminJobOp { ADD = 0x01, @@ -1134,6 +1144,7 @@ service MetaService { ExecResp dropSpace(1: DropSpaceReq req); GetSpaceResp getSpace(1: GetSpaceReq req); ListSpacesResp listSpaces(1: ListSpacesReq req); + ExecResp alterSpace(1: AlterSpaceReq req); ExecResp createSpaceAs(1: CreateSpaceAsReq req); diff --git a/src/meta/CMakeLists.txt b/src/meta/CMakeLists.txt index 837e101f9a4..ff38046f168 100644 --- a/src/meta/CMakeLists.txt +++ b/src/meta/CMakeLists.txt @@ -15,6 +15,7 @@ nebula_add_library( processors/parts/ListSpacesProcessor.cpp processors/parts/DropSpaceProcessor.cpp processors/parts/GetPartsAllocProcessor.cpp + processors/parts/AlterSpaceProcessor.cpp processors/schema/CreateTagProcessor.cpp processors/schema/AlterTagProcessor.cpp processors/schema/GetTagProcessor.cpp diff --git a/src/meta/MetaServiceHandler.cpp b/src/meta/MetaServiceHandler.cpp index cc78fcbf2c6..729d9dedf51 100644 --- a/src/meta/MetaServiceHandler.cpp +++ b/src/meta/MetaServiceHandler.cpp @@ -41,6 +41,7 @@ #include "meta/processors/kv/RemoveRangeProcessor.h" #include "meta/processors/kv/ScanProcessor.h" #include "meta/processors/listener/ListenerProcessor.h" +#include "meta/processors/parts/AlterSpaceProcessor.h" #include "meta/processors/parts/CreateSpaceAsProcessor.h" #include "meta/processors/parts/CreateSpaceProcessor.h" #include "meta/processors/parts/DropSpaceProcessor.h" @@ -85,6 +86,12 @@ folly::Future MetaServiceHandler::future_createSpace( RETURN_FUTURE(processor); } +folly::Future MetaServiceHandler::future_alterSpace( + const cpp2::AlterSpaceReq& req) { + auto* processor = AlterSpaceProcessor::instance(kvstore_); + RETURN_FUTURE(processor); +} + folly::Future MetaServiceHandler::future_createSpaceAs( const cpp2::CreateSpaceAsReq& req) { auto* processor = CreateSpaceAsProcessor::instance(kvstore_); diff --git a/src/meta/MetaServiceHandler.h b/src/meta/MetaServiceHandler.h index a1d7332fbf8..1bc7bf34f3f 100644 --- a/src/meta/MetaServiceHandler.h +++ b/src/meta/MetaServiceHandler.h @@ -30,6 +30,8 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf { * */ folly::Future future_createSpace(const cpp2::CreateSpaceReq& req) override; + folly::Future future_alterSpace(const cpp2::AlterSpaceReq& req) override; + folly::Future future_createSpaceAs(const cpp2::CreateSpaceAsReq& req) override; folly::Future future_dropSpace(const cpp2::DropSpaceReq& req) override; diff --git a/src/meta/processors/parts/AlterSpaceProcessor.cpp b/src/meta/processors/parts/AlterSpaceProcessor.cpp new file mode 100644 index 00000000000..eba785c0058 --- /dev/null +++ b/src/meta/processors/parts/AlterSpaceProcessor.cpp @@ -0,0 +1,13 @@ +/* Copyright (c) 2018 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "meta/processors/parts/AlterSpaceProcessor.h" + +namespace nebula { +namespace meta { +void AlterSpaceProcessor::process(const cpp2::AlterSpaceReq& req) { UNUSED(req); } + +} // namespace meta +} // namespace nebula diff --git a/src/meta/processors/parts/AlterSpaceProcessor.h b/src/meta/processors/parts/AlterSpaceProcessor.h new file mode 100644 index 00000000000..d9cb08417d0 --- /dev/null +++ b/src/meta/processors/parts/AlterSpaceProcessor.h @@ -0,0 +1,29 @@ +/* Copyright (c) 2018 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#ifndef NEBULA_GRAPH_ALTERSPACEPROCESSOR_H +#define NEBULA_GRAPH_ALTERSPACEPROCESSOR_H + +#include "meta/processors/BaseProcessor.h" + +namespace nebula { +namespace meta { +class AlterSpaceProcessor : public BaseProcessor { + public: + static AlterSpaceProcessor* instance(kvstore::KVStore* kvstore) { + return new AlterSpaceProcessor(kvstore); + } + + void process(const cpp2::AlterSpaceReq& req); + + private: + explicit AlterSpaceProcessor(kvstore::KVStore* kvstore) + : BaseProcessor(kvstore) {} +}; + +} // namespace meta +} // namespace nebula + +#endif // NEBULA_GRAPH_ALTERSPACEPROCESSOR_H diff --git a/src/parser/AdminSentences.cpp b/src/parser/AdminSentences.cpp index cd774e27894..2d9b0319847 100644 --- a/src/parser/AdminSentences.cpp +++ b/src/parser/AdminSentences.cpp @@ -112,6 +112,15 @@ std::string DropSpaceSentence::toString() const { return folly::stringPrintf("DROP SPACE %s", spaceName_.get()->c_str()); } +std::string AlterSpaceSentence::toString() const { + std::string zones = paras_.front(); + for (size_t i = 1; i < paras_.size(); i++) { + zones += "," + paras_[i]; + } + return folly::stringPrintf( + "ALTER SPACE %s ADD ZONE %s", spaceName_.get()->c_str(), zones.c_str()); +} + std::string DescribeSpaceSentence::toString() const { return folly::stringPrintf("DESCRIBE SPACE %s", spaceName_.get()->c_str()); } diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index b654700066c..93638e89de7 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -369,6 +369,28 @@ class DropSpaceSentence final : public DropSentence { std::unique_ptr clusterName_; }; +class AlterSpaceSentence final : public Sentence { + public: + AlterSpaceSentence(std::string* spaceName, meta::cpp2::AlterSpaceOp op) + : op_(op), spaceName_(spaceName) { + kind_ = Kind::kAlterSpace; + } + void addPara(const std::string& para) { paras_.push_back(para); } + + std::string spaceName() const { return *spaceName_; } + + const std::vector& paras() const { return paras_; } + + meta::cpp2::AlterSpaceOp alterSpaceOp() const { return op_; } + + std::string toString() const override; + + private: + meta::cpp2::AlterSpaceOp op_; + std::unique_ptr spaceName_; + std::vector paras_; +}; + class DescribeSpaceSentence final : public Sentence { public: explicit DescribeSpaceSentence(std::string* spaceName) { diff --git a/src/parser/Sentence.h b/src/parser/Sentence.h index 4e27150d368..b007149bc07 100644 --- a/src/parser/Sentence.h +++ b/src/parser/Sentence.h @@ -132,6 +132,7 @@ class Sentence { kShowQueries, kKillQuery, kShowMetaLeader, + kAlterSpace, }; Kind kind() const { return kind_; } diff --git a/src/parser/parser.yy b/src/parser/parser.yy index dc88138e53a..4f8911052e1 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -347,7 +347,7 @@ static constexpr size_t kCommentLengthLimit = 256; %type query_unique_identifier %type maintain_sentence -%type create_space_sentence describe_space_sentence drop_space_sentence +%type create_space_sentence describe_space_sentence drop_space_sentence alter_space_sentence %type create_tag_sentence create_edge_sentence %type alter_tag_sentence alter_edge_sentence %type drop_tag_sentence drop_edge_sentence @@ -3319,6 +3319,18 @@ zone_name_list } ; +alter_space_sentence + : KW_ALTER KW_SPACE name_label KW_ADD KW_ZONE name_label_list { + auto sentence = new AlterSpaceSentence($3, meta::cpp2::AlterSpaceOp::ADD_ZONE); + NameLabelList* nl = $6; + std::vector vec = nl->labels(); + for(const std::string *para:vec) { + sentence->addPara(*para); + } + delete nl; + $$ = sentence; + } + create_space_sentence : KW_CREATE KW_SPACE opt_if_not_exists name_label { auto sentence = new CreateSpaceSentence($4, $3); @@ -3657,6 +3669,7 @@ mutate_sentence maintain_sentence : create_space_sentence { $$ = $1; } | describe_space_sentence { $$ = $1; } + | alter_space_sentence { $$ = $1; } | drop_space_sentence { $$ = $1; } | create_tag_sentence { $$ = $1; } | create_edge_sentence { $$ = $1; }