Skip to content

Commit

Permalink
alter space add zone
Browse files Browse the repository at this point in the history
  • Loading branch information
liwenhui-soul committed Dec 8, 2021
1 parent 8ce59b2 commit 8ef5d52
Showing 22 changed files with 219 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
@@ -1204,6 +1204,25 @@ folly::Future<StatusOr<std::vector<cpp2::HostItem>>> MetaClient::listHosts(cpp2:
return future;
}

folly::Future<StatusOr<bool>> MetaClient::alterSpace(const std::string& spaceName,
meta::cpp2::AlterSpaceOp op,
const std::vector<std::string>& paras) {
cpp2::AlterSpaceReq req;
req.set_op(op);
req.set_space_name(spaceName);
req.set_paras(paras);
folly::Promise<StatusOr<bool>> 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<StatusOr<std::vector<cpp2::PartItem>>> MetaClient::listParts(
GraphSpaceID spaceId, std::vector<PartitionID> partIds) {
cpp2::ListPartsReq req;
4 changes: 4 additions & 0 deletions src/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
@@ -260,6 +260,10 @@ class MetaClient {
folly::Future<StatusOr<std::vector<cpp2::HostItem>>> listHosts(
cpp2::ListHostType type = cpp2::ListHostType::ALLOC);

folly::Future<StatusOr<bool>> alterSpace(const std::string& spaceName,
meta::cpp2::AlterSpaceOp op,
const std::vector<std::string>& paras);

folly::Future<StatusOr<std::vector<cpp2::PartItem>>> listParts(GraphSpaceID spaceId,
std::vector<PartitionID> partIds);

3 changes: 3 additions & 0 deletions src/graph/executor/Executor.cpp
Original file line number Diff line number Diff line change
@@ -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<int32_t>(node->kind());
break;
17 changes: 17 additions & 0 deletions src/graph/executor/admin/SpaceExecutor.cpp
Original file line number Diff line number Diff line change
@@ -257,5 +257,22 @@ folly::Future<Status> ShowCreateSpaceExecutor::execute() {
.build());
});
}

folly::Future<Status> AlterSpaceExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto *asnode = asNode<AlterSpace>(node());
return qctx()
->getMetaClient()
->alterSpace(asnode->getSpaceName(), asnode->getAlterSpaceOp(), asnode->getParas())
.via(runner())
.thenValue([this](StatusOr<bool> &&resp) {
SCOPED_TIMER(&execTime_);
if (!resp.ok()) {
LOG(ERROR) << resp.status().toString();
return std::move(resp).status();
}
return Status::OK();
});
}
} // namespace graph
} // namespace nebula
8 changes: 8 additions & 0 deletions src/graph/executor/admin/SpaceExecutor.h
Original file line number Diff line number Diff line change
@@ -58,6 +58,14 @@ class ShowCreateSpaceExecutor final : public Executor {

folly::Future<Status> execute() override;
};

class AlterSpaceExecutor final : public Executor {
public:
AlterSpaceExecutor(const PlanNode *node, QueryContext *qctx)
: Executor("AlterSpaceExecutor", node, qctx) {}

folly::Future<Status> execute() override;
};
} // namespace graph
} // namespace nebula

32 changes: 32 additions & 0 deletions src/graph/planner/plan/Admin.h
Original file line number Diff line number Diff line change
@@ -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<std::string>& 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<std::string>& getParas() const { return paras_; }

private:
AlterSpace(QueryContext* qctx,
PlanNode* input,
const std::string& spaceName,
meta::cpp2::AlterSpaceOp op,
const std::vector<std::string>& paras)
: SingleDependencyNode(qctx, Kind::kAlterSpace, input),
spaceName_(spaceName),
op_(op),
paras_(paras) {}

private:
std::string spaceName_;
meta::cpp2::AlterSpaceOp op_;
std::vector<std::string> paras_;
};

class DescSpace final : public SingleDependencyNode {
public:
static DescSpace* make(QueryContext* qctx, PlanNode* input, std::string spaceName) {
2 changes: 2 additions & 0 deletions src/graph/planner/plan/PlanNode.cpp
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions src/graph/planner/plan/PlanNode.h
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@ class PlanNode {
kDropSpace,
kDropTag,
kDropEdge,
kAlterSpace,

// index related
kCreateTagIndex,
1 change: 1 addition & 0 deletions src/graph/service/PermissionCheck.cpp
Original file line number Diff line number Diff line change
@@ -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:
11 changes: 11 additions & 0 deletions src/graph/validator/AdminValidator.cpp
Original file line number Diff line number Diff line change
@@ -163,6 +163,17 @@ Status CreateSpaceAsValidator::toPlan() {
return Status::OK();
}

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

Status AlterSpaceValidator::toPlan() {
auto sentence = static_cast<AlterSpaceSentence *>(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() {
10 changes: 10 additions & 0 deletions src/graph/validator/AdminValidator.h
Original file line number Diff line number Diff line change
@@ -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) {
2 changes: 2 additions & 0 deletions src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
@@ -252,6 +252,8 @@ std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryCon
return std::make_unique<ShowQueriesValidator>(sentence, context);
case Sentence::Kind::kKillQuery:
return std::make_unique<KillQueryValidator>(sentence, context);
case Sentence::Kind::kAlterSpace:
return std::make_unique<AlterSpaceValidator>(sentence, context);
case Sentence::Kind::kUnknown:
case Sentence::Kind::kReturn: {
// nothing
11 changes: 11 additions & 0 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
@@ -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<binary> 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);

1 change: 1 addition & 0 deletions src/meta/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/meta/MetaServiceHandler.cpp
Original file line number Diff line number Diff line change
@@ -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<cpp2::ExecResp> MetaServiceHandler::future_createSpace(
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp> MetaServiceHandler::future_alterSpace(
const cpp2::AlterSpaceReq& req) {
auto* processor = AlterSpaceProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp> MetaServiceHandler::future_createSpaceAs(
const cpp2::CreateSpaceAsReq& req) {
auto* processor = CreateSpaceAsProcessor::instance(kvstore_);
2 changes: 2 additions & 0 deletions src/meta/MetaServiceHandler.h
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf {
* */
folly::Future<cpp2::ExecResp> future_createSpace(const cpp2::CreateSpaceReq& req) override;

folly::Future<cpp2::ExecResp> future_alterSpace(const cpp2::AlterSpaceReq& req) override;

folly::Future<cpp2::ExecResp> future_createSpaceAs(const cpp2::CreateSpaceAsReq& req) override;

folly::Future<cpp2::ExecResp> future_dropSpace(const cpp2::DropSpaceReq& req) override;
13 changes: 13 additions & 0 deletions src/meta/processors/parts/AlterSpaceProcessor.cpp
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions src/meta/processors/parts/AlterSpaceProcessor.h
Original file line number Diff line number Diff line change
@@ -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<cpp2::ExecResp> {
public:
static AlterSpaceProcessor* instance(kvstore::KVStore* kvstore) {
return new AlterSpaceProcessor(kvstore);
}

void process(const cpp2::AlterSpaceReq& req);

private:
explicit AlterSpaceProcessor(kvstore::KVStore* kvstore)
: BaseProcessor<cpp2::ExecResp>(kvstore) {}
};

} // namespace meta
} // namespace nebula

#endif // NEBULA_GRAPH_ALTERSPACEPROCESSOR_H
9 changes: 9 additions & 0 deletions src/parser/AdminSentences.cpp
Original file line number Diff line number Diff line change
@@ -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());
}
22 changes: 22 additions & 0 deletions src/parser/AdminSentences.h
Original file line number Diff line number Diff line change
@@ -369,6 +369,28 @@ class DropSpaceSentence final : public DropSentence {
std::unique_ptr<std::string> 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<std::string>& paras() const { return paras_; }

meta::cpp2::AlterSpaceOp alterSpaceOp() const { return op_; }

std::string toString() const override;

private:
meta::cpp2::AlterSpaceOp op_;
std::unique_ptr<std::string> spaceName_;
std::vector<std::string> paras_;
};

class DescribeSpaceSentence final : public Sentence {
public:
explicit DescribeSpaceSentence(std::string* spaceName) {
1 change: 1 addition & 0 deletions src/parser/Sentence.h
Original file line number Diff line number Diff line change
@@ -132,6 +132,7 @@ class Sentence {
kShowQueries,
kKillQuery,
kShowMetaLeader,
kAlterSpace,
};

Kind kind() const { return kind_; }
15 changes: 14 additions & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
@@ -347,7 +347,7 @@ static constexpr size_t kCommentLengthLimit = 256;
%type <query_unique_identifier> query_unique_identifier

%type <sentence> maintain_sentence
%type <sentence> create_space_sentence describe_space_sentence drop_space_sentence
%type <sentence> create_space_sentence describe_space_sentence drop_space_sentence alter_space_sentence
%type <sentence> create_tag_sentence create_edge_sentence
%type <sentence> alter_tag_sentence alter_edge_sentence
%type <sentence> 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<const std::string *> 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; }

0 comments on commit 8ef5d52

Please sign in to comment.