Skip to content

Commit

Permalink
Refactor schemaManager to support ServerBasedSchemaManager (vesoft-in…
Browse files Browse the repository at this point in the history
…c#241)

* Refactor schemaManager to support ServerBasedSchemaManager

* Rebase on master
  • Loading branch information
dangleptr authored and dutor committed Apr 12, 2019
1 parent a104fb6 commit e7e6afd
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/executor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ add_library(
UseExecutor.cpp
GoExecutor.cpp
PipeExecutor.cpp
DefineEdgeExecutor.cpp
DefineTagExecutor.cpp
# DefineEdgeExecutor.cpp
# DefineTagExecutor.cpp
AlterEdgeExecutor.cpp
AlterTagExecutor.cpp
DescribeTagExecutor.cpp
DescribeEdgeExecutor.cpp
# DescribeTagExecutor.cpp
# DescribeEdgeExecutor.cpp
InsertVertexExecutor.cpp
InsertEdgeExecutor.cpp
AssignmentExecutor.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/executor/DescribeEdgeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Status DescribeEdgeExecutor::prepare() {
void DescribeEdgeExecutor::execute() {
auto *name = sentence_->name();
auto space = ectx()->rctx()->session()->space();
auto edgeType = meta::SchemaManager::toEdgeType(*name);
auto schema = meta::SchemaManager::getEdgeSchema(space, edgeType);
auto edgeType = ectx()->schemaManager()->toEdgeType(*name);
auto schema = ectx()->schemaManager()->getEdgeSchema(space, *name);
resp_ = std::make_unique<cpp2::ExecutionResponse>();

do {
Expand Down
4 changes: 2 additions & 2 deletions src/executor/DescribeTagExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Status DescribeTagExecutor::prepare() {
void DescribeTagExecutor::execute() {
auto *name = sentence_->name();
auto space = ectx()->rctx()->session()->space();
auto tagId = meta::SchemaManager::toTagID(*name);
auto schema = meta::SchemaManager::getTagSchema(space, tagId);
auto tagId = ectx()->schemaManager()->toTagID(*name);
auto schema = ectx()->schemaManager()->getTagSchema(space, *name);

resp_ = std::make_unique<cpp2::ExecutionResponse>();

Expand Down
10 changes: 6 additions & 4 deletions src/executor/ExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "cpp/helpers.h"
#include "graph/RequestContext.h"
#include "parser/SequentialSentences.h"
#include "graph/mock/SchemaManager.h"
#include "meta/SchemaManager.h"
#include "graph/VariableHolder.h"

/**
Expand All @@ -27,7 +27,9 @@ namespace graph {
class ExecutionContext final : public cpp::NonCopyable, public cpp::NonMovable {
public:
using RequestContextPtr = std::unique_ptr<RequestContext<cpp2::ExecutionResponse>>;
ExecutionContext(RequestContextPtr rctx, SchemaManager *sm, storage::StorageClient *storage) {
ExecutionContext(RequestContextPtr rctx,
meta::SchemaManager *sm,
storage::StorageClient *storage) {
rctx_ = std::move(rctx);
sm_ = sm;
storage_ = storage;
Expand All @@ -40,7 +42,7 @@ class ExecutionContext final : public cpp::NonCopyable, public cpp::NonMovable {
return rctx_.get();
}

SchemaManager* schemaManager() const {
meta::SchemaManager* schemaManager() const {
return sm_;
}

Expand All @@ -54,7 +56,7 @@ class ExecutionContext final : public cpp::NonCopyable, public cpp::NonMovable {

private:
RequestContextPtr rctx_;
SchemaManager *sm_{nullptr};
meta::SchemaManager *sm_{nullptr};
storage::StorageClient *storage_{nullptr};
std::unique_ptr<VariableHolder> variableHolder_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/executor/ExecutionEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace nebula {
namespace graph {

ExecutionEngine::ExecutionEngine(std::unique_ptr<storage::StorageClient> storage) {
schemaManager_ = std::make_unique<SchemaManager>();
schemaManager_ = meta::SchemaManager::create();
storage_ = std::move(storage);
}

Expand Down
4 changes: 2 additions & 2 deletions src/executor/ExecutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "cpp/helpers.h"
#include "graph/RequestContext.h"
#include "gen-cpp2/GraphService.h"
#include "graph/mock/SchemaManager.h"
#include "meta/SchemaManager.h"

/**
* ExecutinoEngine is responsible to create and manage ExecutionPlan.
Expand All @@ -35,7 +35,7 @@ class ExecutionEngine final : public cpp::NonCopyable, public cpp::NonMovable {
void execute(RequestContextPtr rctx);

private:
std::unique_ptr<SchemaManager> schemaManager_;
std::unique_ptr<meta::SchemaManager> schemaManager_;
std::unique_ptr<storage::StorageClient> storage_;
};

Expand Down
12 changes: 8 additions & 4 deletions src/executor/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include "graph/GoExecutor.h"
#include "graph/UseExecutor.h"
#include "graph/PipeExecutor.h"
#include "graph/DefineTagExecutor.h"
#include "graph/DefineEdgeExecutor.h"
// #include "graph/DefineTagExecutor.h"
// #include "graph/DefineEdgeExecutor.h"
#include "graph/AlterTagExecutor.h"
#include "graph/AlterEdgeExecutor.h"
#include "graph/DescribeTagExecutor.h"
#include "graph/DescribeEdgeExecutor.h"
// #include "graph/DescribeTagExecutor.h"
// #include "graph/DescribeEdgeExecutor.h"
#include "graph/InsertVertexExecutor.h"
#include "graph/InsertEdgeExecutor.h"
#include "graph/ShowExecutor.h"
Expand All @@ -40,24 +40,28 @@ std::unique_ptr<Executor> Executor::makeExecutor(Sentence *sentence) {
case Sentence::Kind::kPipe:
executor = std::make_unique<PipeExecutor>(sentence, ectx());
break;
/*
case Sentence::Kind::kDefineTag:
executor = std::make_unique<DefineTagExecutor>(sentence, ectx());
break;
case Sentence::Kind::kDefineEdge:
executor = std::make_unique<DefineEdgeExecutor>(sentence, ectx());
break;
*/
case Sentence::Kind::kAlterTag:
executor = std::make_unique<AlterTagExecutor>(sentence, ectx());
break;
case Sentence::Kind::kAlterEdge:
executor = std::make_unique<AlterEdgeExecutor>(sentence, ectx());
break;
/*
case Sentence::Kind::kDescribeTag:
executor = std::make_unique<DescribeTagExecutor>(sentence, ectx());
break;
case Sentence::Kind::kDescribeEdge:
executor = std::make_unique<DescribeEdgeExecutor>(sentence, ectx());
break;
*/
case Sentence::Kind::kInsertVertex:
executor = std::make_unique<InsertVertexExecutor>(sentence, ectx());
break;
Expand Down
6 changes: 3 additions & 3 deletions src/executor/GoExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Status GoExecutor::prepareOver() {
if (clause == nullptr) {
LOG(FATAL) << "Over clause shall never be null";
}
edge_ = meta::SchemaManager::toEdgeType(*clause->edge());
edge_ = ectx()->schemaManager()->toEdgeType(*clause->edge());
reversely_ = clause->isReversely();
if (clause->alias() != nullptr) {
expCtx_->addAlias(*clause->alias(), AliasKind::Edge, *clause->edge());
Expand Down Expand Up @@ -352,7 +352,7 @@ std::vector<storage::cpp2::PropDef> GoExecutor::getStepOutProps() const {
storage::cpp2::PropDef pd;
pd.owner = storage::cpp2::PropOwner::SOURCE;
pd.name = tagProp.second;
auto tagId = meta::SchemaManager::toTagID(tagProp.first);
auto tagId = ectx()->schemaManager()->toTagID(tagProp.first);
pd.set_tag_id(tagId);
props.emplace_back(std::move(pd));
}
Expand All @@ -373,7 +373,7 @@ std::vector<storage::cpp2::PropDef> GoExecutor::getDstProps() const {
storage::cpp2::PropDef pd;
pd.owner = storage::cpp2::PropOwner::DEST;
pd.name = tagProp.second;
auto tagId = meta::SchemaManager::toTagID(tagProp.first);
auto tagId = ectx()->schemaManager()->toTagID(tagProp.first);
pd.set_tag_id(tagId);
props.emplace_back(std::move(pd));
}
Expand Down
4 changes: 2 additions & 2 deletions src/executor/InsertEdgeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Status InsertEdgeExecutor::prepare() {
}

overwritable_ = sentence_->overwritable();
edge_ = meta::SchemaManager::toEdgeType(*sentence_->edge());
edge_ = ectx()->schemaManager()->toEdgeType(*sentence_->edge());
properties_ = sentence_->properties();
rows_ = sentence_->rows();
auto space = ectx()->rctx()->session()->space();
schema_ = meta::SchemaManager::getEdgeSchema(space, edge_);
schema_ = ectx()->schemaManager()->getEdgeSchema(space, edge_);
if (schema_ == nullptr) {
return Status::Error("No schema found for `%s'", sentence_->edge()->c_str());
}
Expand Down
4 changes: 2 additions & 2 deletions src/executor/InsertVertexExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ Status InsertVertexExecutor::prepare() {

overwritable_ = sentence_->overwritable();
vertex_ = sentence_->vertex();
tagId_ = meta::SchemaManager::toTagID(*vertex_);
tagId_ = ectx()->schemaManager()->toTagID(*vertex_);
properties_ = sentence_->properties();
rows_ = sentence_->rows();
// TODO(dutor) check on property names and types
if (rows_.empty()) {
return Status::Error("VALUES cannot be empty");
}
auto space = ectx()->rctx()->session()->space();
schema_ = meta::SchemaManager::getTagSchema(space, tagId_);
schema_ = ectx()->schemaManager()->getTagSchema(space, tagId_);
if (schema_ == nullptr) {
return Status::Error("No schema found for `%s'", vertex_->c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion src/executor/UseExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void UseExecutor::execute() {
auto *session = ectx()->rctx()->session();

// TODO(dutor) Check space's validness and map to type of integer
auto space = meta::SchemaManager::toGraphSpaceID(*sentence_->space());
auto space = ectx()->schemaManager()->toGraphSpaceID(*sentence_->space());
session->setSpace(*sentence_->space(), space);
FLOG_INFO("Graph space switched to `%s', space id: %d", sentence_->space()->c_str(), space);

Expand Down

0 comments on commit e7e6afd

Please sign in to comment.