Skip to content

Commit

Permalink
Merge branch 'master' into feature/sample-go
Browse files Browse the repository at this point in the history
  • Loading branch information
Shylock-Hg authored Sep 27, 2021
2 parents ff66206 + e18809b commit 69d0277
Show file tree
Hide file tree
Showing 39 changed files with 854 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ cmake-build*/
core.*
workspace.*
.metals/
.cproject

#py
*.egg-info
Expand Down
15 changes: 15 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,21 @@ folly::Future<StatusOr<GraphSpaceID>> MetaClient::createSpace(meta::cpp2::SpaceD
return future;
}

folly::Future<StatusOr<GraphSpaceID>> MetaClient::createSpaceAs(const std::string& oldSpaceName,
const std::string& newSpaceName) {
cpp2::CreateSpaceAsReq req;
req.set_old_space_name(oldSpaceName);
req.set_new_space_name(newSpaceName);
folly::Promise<StatusOr<GraphSpaceID>> promise;
auto future = promise.getFuture();
getResponse(
std::move(req),
[](auto client, auto request) { return client->future_createSpaceAs(request); },
[](cpp2::ExecResp&& resp) -> GraphSpaceID { return resp.get_id().get_space_id(); },
std::move(promise));
return future;
}

folly::Future<StatusOr<std::vector<SpaceIdName>>> MetaClient::listSpaces() {
cpp2::ListSpacesReq req;
folly::Promise<StatusOr<std::vector<SpaceIdName>>> promise;
Expand Down
3 changes: 3 additions & 0 deletions src/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ class MetaClient {
folly::Future<StatusOr<GraphSpaceID>> createSpace(meta::cpp2::SpaceDesc spaceDesc,
bool ifNotExists = false);

folly::Future<StatusOr<GraphSpaceID>> createSpaceAs(const std::string& oldSpaceName,
const std::string& newSpaceName);

folly::Future<StatusOr<std::vector<SpaceIdName>>> listSpaces();

folly::Future<StatusOr<cpp2::SpaceItem>> getSpace(std::string name);
Expand Down
9 changes: 9 additions & 0 deletions src/common/utils/NebulaKeyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,13 @@ std::string NebulaKeyUtils::toEdgeKey(const folly::StringPiece& lockKey) {
return ret;
}

std::string NebulaKeyUtils::adminTaskKey(int32_t seqId, JobID jobId, TaskID taskId) {
std::string key;
key.reserve(sizeof(int32_t) + sizeof(JobID) + sizeof(TaskID));
key.append(reinterpret_cast<char*>(&seqId), sizeof(int32_t));
key.append(reinterpret_cast<char*>(&jobId), sizeof(JobID));
key.append(reinterpret_cast<char*>(&taskId), sizeof(TaskID));
return key;
}

} // namespace nebula
2 changes: 2 additions & 0 deletions src/common/utils/NebulaKeyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class NebulaKeyUtils final {
LOG(FATAL) << msg.str();
}

static std::string adminTaskKey(int32_t seqId, JobID jobId, TaskID taskId);

static_assert(sizeof(NebulaKeyType) == sizeof(PartitionID));

private:
Expand Down
3 changes: 3 additions & 0 deletions src/graph/executor/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) {
case PlanNode::Kind::kCreateSpace: {
return pool->add(new CreateSpaceExecutor(node, qctx));
}
case PlanNode::Kind::kCreateSpaceAs: {
return pool->add(new CreateSpaceAsExecutor(node, qctx));
}
case PlanNode::Kind::kDescSpace: {
return pool->add(new DescSpaceExecutor(node, qctx));
}
Expand Down
19 changes: 19 additions & 0 deletions src/graph/executor/admin/SpaceExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ folly::Future<Status> CreateSpaceExecutor::execute() {
});
}

folly::Future<Status> CreateSpaceAsExecutor::execute() {
SCOPED_TIMER(&execTime_);

auto *csaNode = asNode<CreateSpaceAsNode>(node());
auto oldSpace = csaNode->getOldSpaceName();
auto newSpace = csaNode->getNewSpaceName();
return qctx()
->getMetaClient()
->createSpaceAs(oldSpace, newSpace)
.via(runner())
.thenValue([](StatusOr<bool> resp) {
if (!resp.ok()) {
LOG(ERROR) << resp.status();
return resp.status();
}
return Status::OK();
});
}

folly::Future<Status> DescSpaceExecutor::execute() {
SCOPED_TIMER(&execTime_);

Expand Down
8 changes: 8 additions & 0 deletions src/graph/executor/admin/SpaceExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class CreateSpaceExecutor final : public Executor {
folly::Future<Status> execute() override;
};

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

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

class DescSpaceExecutor final : public Executor {
public:
DescSpaceExecutor(const PlanNode *node, QueryContext *qctx)
Expand Down
7 changes: 7 additions & 0 deletions src/graph/planner/plan/Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ std::unique_ptr<PlanNodeDescription> CreateSpace::explain() const {
return desc;
}

std::unique_ptr<PlanNodeDescription> CreateSpaceAsNode::explain() const {
auto desc = SingleDependencyNode::explain();
addDescription("oldSpaceName", oldSpaceName_, desc.get());
addDescription("newSpaceName", newSpaceName_, desc.get());
return desc;
}

std::unique_ptr<PlanNodeDescription> DropSpace::explain() const {
auto desc = SingleDependencyNode::explain();
addDescription("spaceName", spaceName_, desc.get());
Expand Down
27 changes: 27 additions & 0 deletions src/graph/planner/plan/Admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,33 @@ class CreateSpace final : public SingleDependencyNode {
bool ifNotExists_{false};
};

class CreateSpaceAsNode final : public SingleDependencyNode {
public:
static CreateSpaceAsNode* make(QueryContext* qctx,
PlanNode* input,
const std::string& oldSpaceName,
const std::string& newSpaceName) {
return qctx->objPool()->add(new CreateSpaceAsNode(qctx, input, oldSpaceName, newSpaceName));
}

std::unique_ptr<PlanNodeDescription> explain() const override;

public:
std::string getOldSpaceName() const { return oldSpaceName_; }

std::string getNewSpaceName() const { return newSpaceName_; }

private:
CreateSpaceAsNode(QueryContext* qctx, PlanNode* input, std::string oldName, std::string newName)
: SingleDependencyNode(qctx, Kind::kCreateSpaceAs, input),
oldSpaceName_(std::move(oldName)),
newSpaceName_(std::move(newName)) {}

private:
std::string oldSpaceName_;
std::string newSpaceName_;
};

class DropSpace final : public SingleDependencyNode {
public:
static DropSpace* make(QueryContext* qctx,
Expand Down
2 changes: 2 additions & 0 deletions src/graph/planner/plan/PlanNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const char* PlanNode::toString(PlanNode::Kind kind) {
return "RegisterSpaceToSession";
case Kind::kCreateSpace:
return "CreateSpace";
case Kind::kCreateSpaceAs:
return "CreateSpaceAs";
case Kind::kCreateTag:
return "CreateTag";
case Kind::kCreateEdge:
Expand Down
1 change: 1 addition & 0 deletions src/graph/planner/plan/PlanNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PlanNode {

// schema related
kCreateSpace,
kCreateSpaceAs,
kCreateTag,
kCreateEdge,
kDescSpace,
Expand Down
1 change: 1 addition & 0 deletions src/graph/service/PermissionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Status PermissionCheck::permissionCheck(ClientSession *session,
return Status::OK();
}
case Sentence::Kind::kCreateSpace:
case Sentence::Kind::kCreateSpaceAs:
case Sentence::Kind::kDropSpace:
case Sentence::Kind::kCreateSnapshot:
case Sentence::Kind::kDropSnapshot:
Expand Down
14 changes: 14 additions & 0 deletions src/graph/validator/AdminValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ Status CreateSpaceValidator::toPlan() {
return Status::OK();
}

Status CreateSpaceAsValidator::validateImpl() {
auto sentence = static_cast<CreateSpaceAsSentence *>(sentence_);
oldSpaceName_ = sentence->getOldSpaceName();
newSpaceName_ = sentence->getNewSpaceName();
return Status::OK();
}

Status CreateSpaceAsValidator::toPlan() {
auto *doNode = CreateSpaceAsNode::make(qctx_, nullptr, oldSpaceName_, newSpaceName_);
root_ = doNode;
tail_ = root_;
return Status::OK();
}

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

Status DescSpaceValidator::toPlan() {
Expand Down
16 changes: 16 additions & 0 deletions src/graph/validator/AdminValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ class CreateSpaceValidator final : public Validator {
bool ifNotExist_;
};

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

private:
Status validateImpl() override;

Status toPlan() override;

private:
std::string oldSpaceName_;
std::string newSpaceName_;
};

class DescSpaceValidator final : public Validator {
public:
DescSpaceValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryCon
return std::make_unique<GroupByValidator>(sentence, context);
case Sentence::Kind::kCreateSpace:
return std::make_unique<CreateSpaceValidator>(sentence, context);
case Sentence::Kind::kCreateSpaceAs:
return std::make_unique<CreateSpaceAsValidator>(sentence, context);
case Sentence::Kind::kCreateTag:
return std::make_unique<CreateTagValidator>(sentence, context);
case Sentence::Kind::kCreateEdge:
Expand Down
7 changes: 7 additions & 0 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ struct CreateSpaceReq {
2: bool if_not_exists,
}

struct CreateSpaceAsReq {
1: binary old_space_name,
2: binary new_space_name,
}

struct DropSpaceReq {
1: binary space_name
2: bool if_exists,
Expand Down Expand Up @@ -1171,6 +1176,8 @@ service MetaService {
GetSpaceResp getSpace(1: GetSpaceReq req);
ListSpacesResp listSpaces(1: ListSpacesReq req);

ExecResp createSpaceAs(1: CreateSpaceAsReq req);

ExecResp createTag(1: CreateTagReq req);
ExecResp alterTag(1: AlterTagReq req);
ExecResp dropTag(1: DropTagReq req);
Expand Down
2 changes: 2 additions & 0 deletions src/kvstore/KVEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class KVEngine {
const std::string& prefix,
std::unique_ptr<KVIterator>* iter) = 0;

virtual nebula::cpp2::ErrorCode scan(std::unique_ptr<KVIterator>* storageIter) = 0;

// Write a single record
virtual nebula::cpp2::ErrorCode put(std::string key, std::string value) = 0;

Expand Down
9 changes: 9 additions & 0 deletions src/kvstore/RocksEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ nebula::cpp2::ErrorCode RocksEngine::rangeWithPrefix(const std::string& start,
return nebula::cpp2::ErrorCode::SUCCEEDED;
}

nebula::cpp2::ErrorCode RocksEngine::scan(std::unique_ptr<KVIterator>* storageIter) {
rocksdb::ReadOptions options;
options.total_order_seek = true;
rocksdb::Iterator* iter = db_->NewIterator(options);
iter->SeekToFirst();
storageIter->reset(new RocksCommonIter(iter));
return nebula::cpp2::ErrorCode::SUCCEEDED;
}

nebula::cpp2::ErrorCode RocksEngine::put(std::string key, std::string value) {
rocksdb::WriteOptions options;
options.disableWAL = FLAGS_rocksdb_disable_wal;
Expand Down
25 changes: 25 additions & 0 deletions src/kvstore/RocksEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ class RocksPrefixIter : public KVIterator {
rocksdb::Slice prefix_;
};

class RocksCommonIter : public KVIterator {
public:
explicit RocksCommonIter(rocksdb::Iterator* iter) : iter_(iter) {}

~RocksCommonIter() = default;

bool valid() const override { return !!iter_ && iter_->Valid(); }

void next() override { iter_->Next(); }

void prev() override { iter_->Prev(); }

folly::StringPiece key() const override {
return folly::StringPiece(iter_->key().data(), iter_->key().size());
}

folly::StringPiece val() const override {
return folly::StringPiece(iter_->value().data(), iter_->value().size());
}

protected:
std::unique_ptr<rocksdb::Iterator> iter_;
};

/**************************************************************************
*
* An implementation of KVEngine based on Rocksdb
Expand Down Expand Up @@ -135,6 +159,7 @@ class RocksEngine : public KVEngine {
nebula::cpp2::ErrorCode prefixWithoutExtractor(const std::string& prefix,
std::unique_ptr<KVIterator>* storageIter);

nebula::cpp2::ErrorCode scan(std::unique_ptr<KVIterator>* storageIter) override;
/*********************
* Data modification
********************/
Expand Down
1 change: 1 addition & 0 deletions src/meta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nebula_add_library(
processors/parts/ListHostsProcessor.cpp
processors/parts/ListPartsProcessor.cpp
processors/parts/CreateSpaceProcessor.cpp
processors/parts/CreateSpaceAsProcessor.cpp
processors/parts/GetSpaceProcessor.cpp
processors/parts/ListSpacesProcessor.cpp
processors/parts/DropSpaceProcessor.cpp
Expand Down
7 changes: 7 additions & 0 deletions src/meta/MetaServiceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "meta/processors/kv/RemoveRangeProcessor.h"
#include "meta/processors/kv/ScanProcessor.h"
#include "meta/processors/listener/ListenerProcessor.h"
#include "meta/processors/parts/CreateSpaceAsProcessor.h"
#include "meta/processors/parts/CreateSpaceProcessor.h"
#include "meta/processors/parts/DropSpaceProcessor.h"
#include "meta/processors/parts/GetPartsAllocProcessor.h"
Expand Down Expand Up @@ -87,6 +88,12 @@ folly::Future<cpp2::ExecResp> MetaServiceHandler::future_createSpace(
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp> MetaServiceHandler::future_createSpaceAs(
const cpp2::CreateSpaceAsReq& req) {
auto* processor = CreateSpaceAsProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

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

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

folly::Future<cpp2::ExecResp> future_dropSpace(const cpp2::DropSpaceReq& req) override;

folly::Future<cpp2::ListSpacesResp> future_listSpaces(const cpp2::ListSpacesReq& req) override;
Expand Down
Loading

0 comments on commit 69d0277

Please sign in to comment.