From d1cdf84e996052e000198e261c9d877f1d8a0203 Mon Sep 17 00:00:00 2001 From: yaphet Date: Mon, 13 May 2019 17:46:38 +0800 Subject: [PATCH] Support edge in meta service (#355) * support edge in meta service * support leader --- src/graph/AlterTagExecutor.cpp | 2 - src/graph/AlterTagExecutor.h | 1 + src/interface/meta.thrift | 35 +++++++++-------- src/meta/MetaServiceHandler.cpp | 20 ++++++++-- src/meta/MetaServiceHandler.h | 10 ++++- src/meta/MetaServiceUtils.cpp | 2 +- src/meta/client/MetaClient.cpp | 43 ++++++++++++++++++++- src/meta/client/MetaClient.h | 9 +++++ src/meta/processors/AlterEdgeProcessor.cpp | 6 +-- src/meta/processors/AlterTagProcessor.cpp | 6 +-- src/meta/processors/BaseProcessor.h | 9 +++++ src/meta/processors/BaseProcessor.inl | 21 +++++++--- src/meta/processors/CreateEdgeProcessor.cpp | 6 +-- src/meta/processors/CreateTagProcessor.cpp | 7 +--- src/meta/processors/GetEdgeProcessor.cpp | 1 + src/meta/processors/GetEdgeProcessor.h | 1 + src/meta/processors/GetProcessor.cpp | 2 +- src/meta/processors/GetTagProcessor.cpp | 1 + src/meta/processors/ListEdgesProcessor.cpp | 6 +-- src/meta/processors/ListHostsProcessor.cpp | 1 - src/meta/processors/ListTagsProcessor.cpp | 6 +-- src/meta/processors/RemoveEdgeProcessor.cpp | 6 +-- src/meta/processors/RemoveEdgeProcessor.h | 7 ++-- src/meta/processors/RemoveTagProcessor.cpp | 7 +--- src/meta/test/ProcessorTest.cpp | 22 ++++------- 25 files changed, 147 insertions(+), 90 deletions(-) diff --git a/src/graph/AlterTagExecutor.cpp b/src/graph/AlterTagExecutor.cpp index 76cf4de7aad..9bfd09bfd50 100644 --- a/src/graph/AlterTagExecutor.cpp +++ b/src/graph/AlterTagExecutor.cpp @@ -15,12 +15,10 @@ AlterTagExecutor::AlterTagExecutor(Sentence *sentence, sentence_ = static_cast(sentence); } - Status AlterTagExecutor::prepare() { return checkIfGraphSpaceChosen(); } - void AlterTagExecutor::execute() { auto *mc = ectx()->getMetaClient(); auto *name = sentence_->name(); diff --git a/src/graph/AlterTagExecutor.h b/src/graph/AlterTagExecutor.h index f7b019ca0c5..6799a62fef0 100644 --- a/src/graph/AlterTagExecutor.h +++ b/src/graph/AlterTagExecutor.h @@ -27,6 +27,7 @@ class AlterTagExecutor final : public Executor { private: AlterTagSentence *sentence_{nullptr}; + nebula::meta::cpp2::AlterSchemaOp getTagOpType(const AlterTagOptItem::OptionType type); }; diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift index b9b454bec5f..1e8b87e79cd 100644 --- a/src/interface/meta.thrift +++ b/src/interface/meta.thrift @@ -29,16 +29,15 @@ enum ErrorCode { // KV Failure E_STORE_FAILURE = -31, E_STORE_SEGMENT_ILLEGAL = -32, - E_KEY_NOT_FOUND = -33, E_UNKNOWN = -99, } (cpp.enum_strict) enum AlterSchemaOp { - ADD = 0x01, + ADD = 0x01, CHANGE = 0x02, - DROP = 0x03, + DROP = 0x03, UNKNOWN = 0x04, } (cpp.enum_strict) @@ -159,28 +158,29 @@ struct GetTagResp { 3: common.Schema schema, } -struct GetEdgeReq { +// Edge related operations. +struct CreateEdgeReq { 1: common.GraphSpaceID space_id, - 2: common.EdgeType edge_type, - 3: common.SchemaVer version, + 2: string edge_name, + 3: common.Schema schema, } struct AlterEdgeReq { - 1: common.GraphSpaceID space_id, - 2: string edge_name, - 3: list edge_items, + 1: common.GraphSpaceID space_id, + 2: string edge_name, + 3: list edge_items, } -struct GetEdgeResp { - 1: ErrorCode code, - 2: common.Schema schema, +struct GetEdgeReq { + 1: common.GraphSpaceID space_id, + 2: common.EdgeType edge_type, + 3: common.SchemaVer version, } -// Edge related operations. -struct CreateEdgeReq { - 1: common.GraphSpaceID space_id, - 2: string edge_name, - 3: common.Schema schema, +struct GetEdgeResp { + 1: ErrorCode code, + 2: common.HostAddr leader, + 3: common.Schema schema, } struct RemoveEdgeReq { @@ -304,6 +304,7 @@ service MetaService { ListTagsResp listTags(1: ListTagsReq req); ExecResp createEdge(1: CreateEdgeReq req); + ExecResp alterEdge(1: AlterEdgeReq req); ExecResp removeEdge(1: RemoveEdgeReq req); GetEdgeResp getEdge(1: GetEdgeReq req); ListEdgesResp listEdges(1: ListEdgesReq req); diff --git a/src/meta/MetaServiceHandler.cpp b/src/meta/MetaServiceHandler.cpp index 701322e4203..0894d9b955e 100644 --- a/src/meta/MetaServiceHandler.cpp +++ b/src/meta/MetaServiceHandler.cpp @@ -17,8 +17,10 @@ #include "meta/processors/AlterTagProcessor.h" #include "meta/processors/CreateEdgeProcessor.h" #include "meta/processors/GetTagProcessor.h" +#include "meta/processors/GetEdgeProcessor.h" #include "meta/processors/ListTagsProcessor.h" #include "meta/processors/ListEdgesProcessor.h" +#include "meta/processors/RemoveEdgeProcessor.h" #include "meta/processors/MultiPutProcessor.h" #include "meta/processors/GetProcessor.h" #include "meta/processors/MultiGetProcessor.h" @@ -144,9 +146,9 @@ MetaServiceHandler::future_listTags(const cpp2::ListTagsReq& req) { RETURN_FUTURE(processor); } -folly::Future -MetaServiceHandler::future_createEdge(const cpp2::CreateEdgeReq& req) { - auto* processor = CreateEdgeProcessor::instance(kvstore_); +folly::Future +MetaServiceHandler::future_getEdge(const cpp2::GetEdgeReq& req) { + auto* processor = GetEdgeProcessor::instance(kvstore_); RETURN_FUTURE(processor); } @@ -156,6 +158,18 @@ MetaServiceHandler::future_listEdges(const cpp2::ListEdgesReq& req) { RETURN_FUTURE(processor); } +folly::Future +MetaServiceHandler::future_createEdge(const cpp2::CreateEdgeReq& req) { + auto* processor = CreateEdgeProcessor::instance(kvstore_); + RETURN_FUTURE(processor); +} + +folly::Future +MetaServiceHandler::future_removeEdge(const cpp2::RemoveEdgeReq& req) { + auto* processor = RemoveEdgeProcessor::instance(kvstore_); + RETURN_FUTURE(processor); +} + folly::Future MetaServiceHandler::future_heartBeat(const cpp2::HBReq& req) { auto* processor = HBProcessor::instance(kvstore_); diff --git a/src/meta/MetaServiceHandler.h b/src/meta/MetaServiceHandler.h index e982a5e275d..cf8c5984670 100644 --- a/src/meta/MetaServiceHandler.h +++ b/src/meta/MetaServiceHandler.h @@ -83,12 +83,18 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf { folly::Future future_listTags(const cpp2::ListTagsReq& req) override; - folly::Future - future_createEdge(const cpp2::CreateEdgeReq& req) override; + folly::Future + future_getEdge(const cpp2::GetEdgeReq& req) override; folly::Future future_listEdges(const cpp2::ListEdgesReq& req) override; + folly::Future + future_createEdge(const cpp2::CreateEdgeReq& req) override; + + folly::Future + future_removeEdge(const cpp2::RemoveEdgeReq& req) override; + /** * HeartBeat * */ diff --git a/src/meta/MetaServiceUtils.cpp b/src/meta/MetaServiceUtils.cpp index 90087a3b5ca..9355d989d7e 100644 --- a/src/meta/MetaServiceUtils.cpp +++ b/src/meta/MetaServiceUtils.cpp @@ -20,7 +20,7 @@ const std::string kIndexTable = "__index__"; // NOLINT std::string MetaServiceUtils::spaceKey(GraphSpaceID spaceId) { std::string key; - key.reserve(256); + key.reserve(128); key.append(kSpacesTable.data(), kSpacesTable.size()); key.append(reinterpret_cast(&spaceId), sizeof(spaceId)); return key; diff --git a/src/meta/client/MetaClient.cpp b/src/meta/client/MetaClient.cpp index aaf8a3b4c48..c93157ca6df 100644 --- a/src/meta/client/MetaClient.cpp +++ b/src/meta/client/MetaClient.cpp @@ -656,11 +656,11 @@ MetaClient::createTagSchema(GraphSpaceID spaceId, std::string name, nebula::cpp2 folly::Future> MetaClient::alterTagSchema(GraphSpaceID spaceId, std::string name, - std::vector tagItems) { + std::vector items) { cpp2::AlterTagReq req; req.set_space_id(std::move(spaceId)); req.set_tag_name(std::move(name)); - req.set_tag_items(std::move(tagItems)); + req.set_tag_items(std::move(items)); return getResponse(std::move(req), [] (auto client, auto request) { return client->future_alterTag(request); @@ -718,6 +718,20 @@ MetaClient::createEdgeSchema(GraphSpaceID spaceId, std::string name, nebula::cpp }, true); } +folly::Future> +MetaClient::alterEdge(GraphSpaceID spaceId, std::string name, + std::vector items) { + cpp2::AlterEdgeReq req; + req.set_space_id(std::move(spaceId)); + req.set_edge_name(std::move(name)); + req.set_edge_items(std::move(items)); + return getResponse(std::move(req), [] (auto client, auto request) { + return client->future_alterEdge(request); + }, [] (cpp2::ExecResp&& resp) -> bool { + return resp.code == cpp2::ErrorCode::SUCCEEDED; + }, true); +} + folly::Future>> MetaClient::listEdgeSchemas(GraphSpaceID spaceId) { cpp2::ListEdgesReq req; @@ -729,6 +743,31 @@ MetaClient::listEdgeSchemas(GraphSpaceID spaceId) { }); } +folly::Future> +MetaClient::getEdgeSchema(GraphSpaceID spaceId, int32_t edgeType, SchemaVer version) { + cpp2::GetEdgeReq req; + req.set_space_id(std::move(spaceId)); + req.set_edge_type(edgeType); + req.set_version(version); + return getResponse(std::move(req), [] (auto client, auto request) { + return client->future_getEdge(request); + }, [] (cpp2::GetEdgeResp&& resp) -> nebula::cpp2::Schema { + return std::move(resp).get_schema(); + }); +} + +folly::Future> +MetaClient::removeEdgeSchema(GraphSpaceID spaceId, std::string name) { + cpp2::RemoveEdgeReq req; + req.set_space_id(std::move(spaceId)); + req.set_edge_name(std::move(name)); + return getResponse(std::move(req), [] (auto client, auto request) { + return client->future_removeEdge(request); + }, [] (cpp2::ExecResp&& resp) -> bool { + return resp.code == cpp2::ErrorCode::SUCCEEDED; + }, true); +} + StatusOr> MetaClient::getTagSchemaFromCache(GraphSpaceID spaceId, TagID tagID, SchemaVer ver) { folly::RWSpinLock::ReadHolder holder(localCacheLock_); diff --git a/src/meta/client/MetaClient.h b/src/meta/client/MetaClient.h index 30ce7d14922..2def323720f 100644 --- a/src/meta/client/MetaClient.h +++ b/src/meta/client/MetaClient.h @@ -116,9 +116,18 @@ class MetaClient { folly::Future> createEdgeSchema(GraphSpaceID spaceId, std::string name, nebula::cpp2::Schema schema); + folly::Future> + alterEdge(GraphSpaceID spaceId, std::string name, std::vector items); + folly::Future>> listEdgeSchemas(GraphSpaceID spaceId); + folly::Future> + getEdgeSchema(GraphSpaceID spaceId, int32_t edgeType, SchemaVer version); + + folly::Future> + removeEdgeSchema(GraphSpaceID spaceId, std::string name); + // Operations for custom kv folly::Future> multiPut(std::string segment, diff --git a/src/meta/processors/AlterEdgeProcessor.cpp b/src/meta/processors/AlterEdgeProcessor.cpp index fba3554e1be..ef45995ba8b 100644 --- a/src/meta/processors/AlterEdgeProcessor.cpp +++ b/src/meta/processors/AlterEdgeProcessor.cpp @@ -11,11 +11,7 @@ namespace nebula { namespace meta { void AlterEdgeProcessor::process(const cpp2::AlterEdgeReq& req) { - if (spaceExist(req.get_space_id()) == Status::SpaceNotFound()) { - resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); - onFinished(); - return; - } + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::WriteHolder wHolder(LockUtils::edgeLock()); auto ret = getEdgeType(req.get_space_id(), req.get_edge_name()); if (!ret.ok()) { diff --git a/src/meta/processors/AlterTagProcessor.cpp b/src/meta/processors/AlterTagProcessor.cpp index dd9dbdd9605..49707adc0d2 100644 --- a/src/meta/processors/AlterTagProcessor.cpp +++ b/src/meta/processors/AlterTagProcessor.cpp @@ -11,11 +11,7 @@ namespace nebula { namespace meta { void AlterTagProcessor::process(const cpp2::AlterTagReq& req) { - if (spaceExist(req.get_space_id()) == Status::SpaceNotFound()) { - resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); - onFinished(); - return; - } + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::WriteHolder wHolder(LockUtils::tagLock()); auto ret = getTagId(req.get_space_id(), req.get_tag_name()); if (!ret.ok()) { diff --git a/src/meta/processors/BaseProcessor.h b/src/meta/processors/BaseProcessor.h index e7b51e6ea97..5470fdc6f2e 100644 --- a/src/meta/processors/BaseProcessor.h +++ b/src/meta/processors/BaseProcessor.h @@ -40,6 +40,13 @@ GENERATE_LOCK(edge); #undef GENERATE_LOCK }; +#define CHECK_SPACE_ID_AND_RETURN(spaceID) \ + if (spaceExist(spaceID) == Status::SpaceNotFound()) { \ + resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); \ + onFinished(); \ + return; \ + } + /** * Check segemnt is consist of numbers and letters and should not empty. * */ @@ -118,6 +125,8 @@ class BaseProcessor { * */ void doPut(std::vector data); + StatusOr> doPrefix(const std::string& key); + /** * General get function. * */ diff --git a/src/meta/processors/BaseProcessor.inl b/src/meta/processors/BaseProcessor.inl index 1593a1652a2..9eba4cd8ef4 100644 --- a/src/meta/processors/BaseProcessor.inl +++ b/src/meta/processors/BaseProcessor.inl @@ -20,6 +20,17 @@ void BaseProcessor::doPut(std::vector data) { }); } +template +StatusOr> +BaseProcessor::doPrefix(const std::string& key) { + std::unique_ptr iter; + auto code = kvstore_->prefix(kDefaultSpaceId_, kDefaultPartId_, key, &iter); + if (code != kvstore::ResultCode::SUCCEEDED) { + return Status::Error("Prefix Failed"); + } + return iter; +} + template StatusOr BaseProcessor::doGet(const std::string& key) { std::string value; @@ -123,7 +134,7 @@ int32_t BaseProcessor::autoIncrementId() { std::string val; auto ret = kvstore_->get(kDefaultSpaceId_, kDefaultPartId_, kIdKey, &val); if (ret != kvstore::ResultCode::SUCCEEDED) { - CHECK_EQ(ret, kvstore::ResultCode::ERR_KEY_NOT_FOUND); + CHECK_EQ(kvstore::ResultCode::ERR_KEY_NOT_FOUND, ret); id = 1; } else { id = *reinterpret_cast(val.c_str()) + 1; @@ -186,12 +197,12 @@ StatusOr BaseProcessor::getTagId(GraphSpaceID spaceId, const std::s template StatusOr BaseProcessor::getEdgeType(GraphSpaceID spaceId, const std::string& name) { auto indexKey = MetaServiceUtils::indexEdgeKey(spaceId, name); - std::string val; - auto ret = kvstore_->get(kDefaultSpaceId_, kDefaultPartId_, indexKey, &val); - if (ret == kvstore::ResultCode::SUCCEEDED) { - return *reinterpret_cast(val.c_str()); + auto ret = doGet(indexKey); + if (ret.ok()) { + return *reinterpret_cast(ret.value().c_str()); } return Status::EdgeNotFound(folly::stringPrintf("Edge %s not found", name.c_str())); } + } // namespace meta } // namespace nebula diff --git a/src/meta/processors/CreateEdgeProcessor.cpp b/src/meta/processors/CreateEdgeProcessor.cpp index bb7d93377c0..1f13fed9e9f 100644 --- a/src/meta/processors/CreateEdgeProcessor.cpp +++ b/src/meta/processors/CreateEdgeProcessor.cpp @@ -11,11 +11,7 @@ namespace nebula { namespace meta { void CreateEdgeProcessor::process(const cpp2::CreateEdgeReq& req) { - if (spaceExist(req.get_space_id()) == Status::SpaceNotFound()) { - resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); - onFinished(); - return; - } + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::WriteHolder wHolder(LockUtils::edgeLock()); auto ret = getEdgeType(req.get_space_id(), req.get_edge_name()); if (ret.ok()) { diff --git a/src/meta/processors/CreateTagProcessor.cpp b/src/meta/processors/CreateTagProcessor.cpp index 077f07039da..fb5225cf594 100644 --- a/src/meta/processors/CreateTagProcessor.cpp +++ b/src/meta/processors/CreateTagProcessor.cpp @@ -11,12 +11,7 @@ namespace nebula { namespace meta { void CreateTagProcessor::process(const cpp2::CreateTagReq& req) { - if (spaceExist(req.get_space_id()) == Status::SpaceNotFound()) { - LOG(ERROR) << "Create Tag Failed : Space " << req.get_space_id() << " not found"; - resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); - onFinished(); - return; - } + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::WriteHolder wHolder(LockUtils::tagLock()); auto ret = getTagId(req.get_space_id(), req.get_tag_name()); std::vector data; diff --git a/src/meta/processors/GetEdgeProcessor.cpp b/src/meta/processors/GetEdgeProcessor.cpp index 64593eacdca..7593302ae76 100644 --- a/src/meta/processors/GetEdgeProcessor.cpp +++ b/src/meta/processors/GetEdgeProcessor.cpp @@ -10,6 +10,7 @@ namespace nebula { namespace meta { void GetEdgeProcessor::process(const cpp2::GetEdgeReq& req) { + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::ReadHolder rHolder(LockUtils::edgeLock()); std::string val; std::string edgeKey = MetaServiceUtils::schemaEdgeKey(req.get_space_id(), diff --git a/src/meta/processors/GetEdgeProcessor.h b/src/meta/processors/GetEdgeProcessor.h index 6793bacf383..c5dc80e7c87 100644 --- a/src/meta/processors/GetEdgeProcessor.h +++ b/src/meta/processors/GetEdgeProcessor.h @@ -27,4 +27,5 @@ class GetEdgeProcessor : public BaseProcessor { } // namespace meta } // namespace nebula + #endif // META_GETEDGEPROCESSOR_H_ diff --git a/src/meta/processors/GetProcessor.cpp b/src/meta/processors/GetProcessor.cpp index 55006e44c8b..d4a3b80a411 100644 --- a/src/meta/processors/GetProcessor.cpp +++ b/src/meta/processors/GetProcessor.cpp @@ -16,7 +16,7 @@ void GetProcessor::process(const cpp2::GetReq& req) { auto result = doGet(key); if (!result.ok()) { LOG(ERROR) << "Get Failed :" << key << " not found!"; - resp_.set_code(cpp2::ErrorCode::E_KEY_NOT_FOUND); + resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); onFinished(); return; } diff --git a/src/meta/processors/GetTagProcessor.cpp b/src/meta/processors/GetTagProcessor.cpp index 82084407f98..a8a6060619d 100644 --- a/src/meta/processors/GetTagProcessor.cpp +++ b/src/meta/processors/GetTagProcessor.cpp @@ -10,6 +10,7 @@ namespace nebula { namespace meta { void GetTagProcessor::process(const cpp2::GetTagReq& req) { + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::ReadHolder rHolder(LockUtils::tagLock()); std::string tagKey = MetaServiceUtils::schemaTagKey(req.get_space_id(), req.get_tag_id(), diff --git a/src/meta/processors/ListEdgesProcessor.cpp b/src/meta/processors/ListEdgesProcessor.cpp index 2868f389fa1..8bf5197539a 100644 --- a/src/meta/processors/ListEdgesProcessor.cpp +++ b/src/meta/processors/ListEdgesProcessor.cpp @@ -10,6 +10,7 @@ namespace nebula { namespace meta { void ListEdgesProcessor::process(const cpp2::ListEdgesReq& req) { + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::ReadHolder rHolder(LockUtils::edgeLock()); auto spaceId = req.get_space_id(); auto prefix = MetaServiceUtils::schemaEdgesPrefix(spaceId); @@ -30,9 +31,8 @@ void ListEdgesProcessor::process(const cpp2::ListEdgesReq& req) { auto nameLen = *reinterpret_cast(val.data()); auto edgeName = val.subpiece(sizeof(int32_t), nameLen).str(); auto schema = MetaServiceUtils::parseSchema(val); - cpp2::EdgeItem edgeItem(apache::thrift::FragileConstructor::FRAGILE, - edgeType, edgeName, vers, schema); - edges.emplace_back(std::move(edgeItem)); + edges.emplace_back(apache::thrift::FragileConstructor::FRAGILE, + edgeType, edgeName, vers, schema); iter->next(); } resp_.set_edges(std::move(edges)); diff --git a/src/meta/processors/ListHostsProcessor.cpp b/src/meta/processors/ListHostsProcessor.cpp index 9aeae8195e7..920638bdf2c 100644 --- a/src/meta/processors/ListHostsProcessor.cpp +++ b/src/meta/processors/ListHostsProcessor.cpp @@ -19,7 +19,6 @@ void ListHostsProcessor::process(const cpp2::ListHostsReq& req) { onFinished(); return; } - resp_.set_code(cpp2::ErrorCode::SUCCEEDED); resp_.set_hosts(std::move(ret.value())); onFinished(); } diff --git a/src/meta/processors/ListTagsProcessor.cpp b/src/meta/processors/ListTagsProcessor.cpp index 00edbbe418f..a21a7489f7e 100644 --- a/src/meta/processors/ListTagsProcessor.cpp +++ b/src/meta/processors/ListTagsProcessor.cpp @@ -10,6 +10,7 @@ namespace nebula { namespace meta { void ListTagsProcessor::process(const cpp2::ListTagsReq& req) { + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::ReadHolder rHolder(LockUtils::tagLock()); auto spaceId = req.get_space_id(); auto prefix = MetaServiceUtils::schemaTagsPrefix(spaceId); @@ -30,9 +31,8 @@ void ListTagsProcessor::process(const cpp2::ListTagsReq& req) { auto nameLen = *reinterpret_cast(val.data()); auto tagName = val.subpiece(sizeof(int32_t), nameLen).str(); auto schema = MetaServiceUtils::parseSchema(val); - cpp2::TagItem tagItem(apache::thrift::FragileConstructor::FRAGILE, - tagID, tagName, vers, schema); - tags.emplace_back(std::move(tagItem)); + tags.emplace_back(apache::thrift::FragileConstructor::FRAGILE, + tagID, tagName, vers, schema); iter->next(); } resp_.set_tags(std::move(tags)); diff --git a/src/meta/processors/RemoveEdgeProcessor.cpp b/src/meta/processors/RemoveEdgeProcessor.cpp index 803f0a9530e..0a4fa4b84d9 100644 --- a/src/meta/processors/RemoveEdgeProcessor.cpp +++ b/src/meta/processors/RemoveEdgeProcessor.cpp @@ -10,11 +10,7 @@ namespace nebula { namespace meta { void RemoveEdgeProcessor::process(const cpp2::RemoveEdgeReq& req) { - if (spaceExist(req.get_space_id()) == Status::SpaceNotFound()) { - resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); - onFinished(); - return; - } + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::WriteHolder wHolder(LockUtils::edgeLock()); auto ret = getEdgeKeys(req.get_space_id(), req.get_edge_name()); if (!ret.ok()) { diff --git a/src/meta/processors/RemoveEdgeProcessor.h b/src/meta/processors/RemoveEdgeProcessor.h index 8163ea71a00..78b69d07b73 100644 --- a/src/meta/processors/RemoveEdgeProcessor.h +++ b/src/meta/processors/RemoveEdgeProcessor.h @@ -4,8 +4,8 @@ * (found in the LICENSE.Apache file in the root directory) */ -#ifndef NEBULA_GRAPH_REMOVEEDGEPROCESSOR_H -#define NEBULA_GRAPH_REMOVEEDGEPROCESSOR_H +#ifndef META_REMOVEEDGEPROCESSOR_H_ +#define META_REMOVEEDGEPROCESSOR_H_ #include "meta/processors/BaseProcessor.h" @@ -29,4 +29,5 @@ class RemoveEdgeProcessor : public BaseProcessor { } // namespace meta } // namespace nebula -#endif // NEBULA_GRAPH_REMOVEEDGEPROCESSOR_H + +#endif // META_REMOVEEDGEPROCESSOR_H_ diff --git a/src/meta/processors/RemoveTagProcessor.cpp b/src/meta/processors/RemoveTagProcessor.cpp index 60b816553f9..2d21095b0ff 100644 --- a/src/meta/processors/RemoveTagProcessor.cpp +++ b/src/meta/processors/RemoveTagProcessor.cpp @@ -10,12 +10,7 @@ namespace nebula { namespace meta { void RemoveTagProcessor::process(const cpp2::RemoveTagReq& req) { - if (spaceExist(req.get_space_id()) == Status::SpaceNotFound()) { - LOG(ERROR) << "Remove Tag Failed : Space " << req.get_space_id() << " not found"; - resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); - onFinished(); - return; - } + CHECK_SPACE_ID_AND_RETURN(req.get_space_id()); folly::SharedMutex::WriteHolder wHolder(LockUtils::tagLock()); auto ret = getTagKeys(req.get_space_id(), req.get_tag_name()); if (!ret.ok()) { diff --git a/src/meta/test/ProcessorTest.cpp b/src/meta/test/ProcessorTest.cpp index 1032e5dcbc2..2b9809258c5 100644 --- a/src/meta/test/ProcessorTest.cpp +++ b/src/meta/test/ProcessorTest.cpp @@ -376,7 +376,7 @@ TEST(ProcessorTest, KVOperationTest) { auto missedFuture = missedProcessor->getFuture(); missedProcessor->process(missedReq); auto missedResp = std::move(missedFuture).get(); - ASSERT_EQ(cpp2::ErrorCode::E_KEY_NOT_FOUND, missedResp.code); + ASSERT_EQ(cpp2::ErrorCode::E_NOT_FOUND, missedResp.code); } { // Multi Get Test @@ -457,6 +457,7 @@ TEST(ProcessorTest, KVOperationTest) { TEST(ProcessorTest, ListOrGetTagsTest) { fs::TempDir rootPath("/tmp/ListTagsTest.XXXXXX"); std::unique_ptr kv(TestUtils::initKV(rootPath.path())); + ASSERT_TRUE(TestUtils::assembleSpace(kv.get(), 1)); TestUtils::mockTag(kv.get(), 10); // test ListTagsProcessor @@ -507,6 +508,7 @@ TEST(ProcessorTest, ListOrGetTagsTest) { TEST(ProcessorTest, ListOrGetEdgesTest) { fs::TempDir rootPath("/tmp/ListEdgesTest.XXXXXX"); std::unique_ptr kv(TestUtils::initKV(rootPath.path())); + ASSERT_TRUE(TestUtils::assembleSpace(kv.get(), 1)); TestUtils::mockEdge(kv.get(), 10); // test ListEdgesProcessor @@ -670,18 +672,9 @@ TEST(ProcessorTest, AlterTagTest) { column.name = folly::stringPrintf("tag_%d_col_%d", 0, 0); dropSch.columns.emplace_back(std::move(column)); - auto addItem = cpp2::AlterSchemaItem(FRAGILE, - cpp2::AlterSchemaOp::ADD, - std::move(addSch)); - auto setItem = cpp2::AlterSchemaItem(FRAGILE, - cpp2::AlterSchemaOp::CHANGE, - std::move(setSch)); - auto dropItem = cpp2::AlterSchemaItem(FRAGILE, - cpp2::AlterSchemaOp::DROP, - std::move(dropSch)); - items.emplace_back(std::move(addItem)); - items.emplace_back(std::move(setItem)); - items.emplace_back(std::move(dropItem)); + items.emplace_back(FRAGILE, cpp2::AlterSchemaOp::ADD, std::move(addSch)); + items.emplace_back(FRAGILE, cpp2::AlterSchemaOp::CHANGE, std::move(setSch)); + items.emplace_back(FRAGILE, cpp2::AlterSchemaOp::DROP, std::move(dropSch)); req.set_space_id(1); req.set_tag_name("tag_0"); req.set_tag_items(items); @@ -779,8 +772,7 @@ TEST(ProcessorTest, AlterTagTest) { column.name = "tag_0_col_2"; column.type.type = SupportedType::INT; addSch.columns.emplace_back(std::move(column)); - auto addItem = cpp2::AlterSchemaItem(FRAGILE, cpp2::AlterSchemaOp::DROP, std::move(addSch)); - items.push_back(addItem); + items.emplace_back(FRAGILE, cpp2::AlterSchemaOp::DROP, std::move(addSch)); req.set_space_id(1); req.set_tag_name("tag_0"); req.set_tag_items(items);