diff --git a/.clang-format b/.clang-format index 1f43cf47158..01ad18cec9d 100644 --- a/.clang-format +++ b/.clang-format @@ -22,7 +22,7 @@ AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All +AllowShortFunctionsOnASingleLine: Empty AllowShortLambdasOnASingleLine: All AllowShortIfStatementsOnASingleLine: WithoutElse AllowShortLoopsOnASingleLine: true diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 08bfd000fbc..fb614a7b022 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -59,7 +59,7 @@ jobs: - centos7 - ubuntu2004 compiler: - - gcc-9.2 + - gcc-9.3 - clang-10 exclude: - os: centos7 @@ -91,21 +91,23 @@ jobs: centos7) # build with Release type cmake \ - -DCMAKE_CXX_COMPILER=$TOOLSET_CLANG_DIR/bin/g++ \ - -DCMAKE_C_COMPILER=$TOOLSET_CLANG_DIR/bin/gcc \ + -DCMAKE_CXX_COMPILER=$TOOLSET_GCC_DIR/bin/g++ \ + -DCMAKE_C_COMPILER=$TOOLSET_GCC_DIR/bin/gcc \ -DCMAKE_BUILD_TYPE=Release \ -DENABLE_TESTING=on \ + -GNinja \ -B build echo "::set-output name=j::10" ;; ubuntu2004) # build with Debug type cmake \ - -DCMAKE_CXX_COMPILER=$TOOLSET_CLANG_DIR/bin/g++ \ - -DCMAKE_C_COMPILER=$TOOLSET_CLANG_DIR/bin/gcc \ + -DCMAKE_CXX_COMPILER=$TOOLSET_GCC_DIR/bin/g++ \ + -DCMAKE_C_COMPILER=$TOOLSET_GCC_DIR/bin/gcc \ -DCMAKE_BUILD_TYPE=Debug \ -DENABLE_TESTING=on \ -DENABLE_COVERAGE=on \ + -GNinja \ -B build echo "::set-output name=j::10" ;; @@ -119,6 +121,7 @@ jobs: -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DENABLE_ASAN=on \ -DENABLE_TESTING=on \ + -GNinja \ -B build echo "::set-output name=j::6" ;; @@ -126,8 +129,9 @@ jobs: - name: Make run: | ccache -z - cmake --build build/ -j $(nproc) + ninja -j $(nproc) ccache -s + working-directory: build/ - name: CTest env: ASAN_OPTIONS: fast_unwind_on_malloc=1 diff --git a/cmake/nebula/ThirdPartyConfig.cmake b/cmake/nebula/ThirdPartyConfig.cmake index 838876fff33..e8a93a58cdd 100644 --- a/cmake/nebula/ThirdPartyConfig.cmake +++ b/cmake/nebula/ThirdPartyConfig.cmake @@ -6,7 +6,7 @@ message(">>>> Configuring third party for '${PROJECT_NAME}' <<<<") # 4. /opt/vesoft/third-party, if exists # 5. At last, one copy will be downloaded and installed to ${CMAKE_BINARY_DIR}/third-party/install -set(NEBULA_THIRDPARTY_VERSION "2.0") +set(NEBULA_THIRDPARTY_VERSION "3.0") if(${DISABLE_CXX11_ABI}) SET(NEBULA_THIRDPARTY_ROOT ${CMAKE_BINARY_DIR}/third-party-98/install) @@ -116,7 +116,6 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L ${NEBULA_THIRDPARTY_ROO # All thrift libraries set(THRIFT_LIBRARIES thriftcpp2 - rocketupgrade async thriftprotocol transport diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default index 69eee083941..da2efa27c98 100644 --- a/conf/nebula-graphd.conf.default +++ b/conf/nebula-graphd.conf.default @@ -86,3 +86,5 @@ ########## experimental feature ########## # if use experimental features --enable_experimental_feature=false + +--enable_space_level_metrics=false diff --git a/conf/nebula-graphd.conf.production b/conf/nebula-graphd.conf.production index 3c1518f90cd..67798fa6942 100644 --- a/conf/nebula-graphd.conf.production +++ b/conf/nebula-graphd.conf.production @@ -84,3 +84,5 @@ ########## experimental feature ########## # if use experimental features --enable_experimental_feature=false + +--enable_space_level_metrics=false diff --git a/src/clients/meta/CMakeLists.txt b/src/clients/meta/CMakeLists.txt index 113b88245c6..c5175f58ff6 100644 --- a/src/clients/meta/CMakeLists.txt +++ b/src/clients/meta/CMakeLists.txt @@ -12,4 +12,5 @@ nebula_add_library( FileBasedClusterIdMan.cpp ) +nebula_add_subdirectory(stats) nebula_add_subdirectory(test) diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 851791b0f67..0e7c6ae3568 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -11,7 +11,10 @@ #include #include +#include + #include "clients/meta/FileBasedClusterIdMan.h" +#include "clients/meta/stats/MetaClientStats.h" #include "common/base/Base.h" #include "common/base/MurmurHash2.h" #include "common/conf/Configuration.h" @@ -55,6 +58,8 @@ MetaClient::MetaClient(std::shared_ptr ioThreadPool updateLeader(); bgThread_ = std::make_unique(); LOG(INFO) << "Create meta client to " << active_; + LOG(INFO) << folly::sformat( + "root path: {}, data path size: {}", options_.rootPath_, options_.dataPaths_.size()); } MetaClient::~MetaClient() { @@ -626,6 +631,7 @@ void MetaClient::getResponse(Request req, bool toLeader, int32_t retry, int32_t retryLimit) { + stats::StatsManager::addValue(kNumRpcSentToMetad); auto* evb = ioThreadPool_->getEventBase(); HostAddr host; { @@ -660,6 +666,7 @@ void MetaClient::getResponse(Request req, this](folly::Try&& t) mutable { // exception occurred during RPC if (t.hasException()) { + stats::StatsManager::addValue(kNumRpcSentToMetadFailed); if (toLeader) { updateLeader(); } else { @@ -1106,9 +1113,9 @@ PartitionID MetaClient::partId(int32_t numParts, const VertexID id) const { folly::Future> MetaClient::submitJob( cpp2::AdminJobOp op, cpp2::AdminCmd cmd, std::vector paras) { cpp2::AdminJobReq req; - req.set_op(op); - req.set_cmd(cmd); - req.set_paras(std::move(paras)); + req.op_ref() = op; + req.cmd_ref() = cmd; + req.paras_ref() = std::move(paras); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1122,8 +1129,8 @@ folly::Future> MetaClient::submitJob( folly::Future> MetaClient::createSpace(meta::cpp2::SpaceDesc spaceDesc, bool ifNotExists) { cpp2::CreateSpaceReq req; - req.set_properties(std::move(spaceDesc)); - req.set_if_not_exists(ifNotExists); + req.properties_ref() = std::move(spaceDesc); + req.if_not_exists_ref() = ifNotExists; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1137,8 +1144,8 @@ folly::Future> MetaClient::createSpace(meta::cpp2::SpaceD folly::Future> 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); + req.old_space_name_ref() = oldSpaceName; + req.new_space_name_ref() = newSpaceName; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1165,7 +1172,7 @@ folly::Future>> MetaClient::listSpaces() { folly::Future> MetaClient::getSpace(std::string name) { cpp2::GetSpaceReq req; - req.set_space_name(std::move(name)); + req.space_name_ref() = std::move(name); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1178,8 +1185,8 @@ folly::Future> MetaClient::getSpace(std::string name) folly::Future> MetaClient::dropSpace(std::string name, const bool ifExists) { cpp2::DropSpaceReq req; - req.set_space_name(std::move(name)); - req.set_if_exists(ifExists); + req.space_name_ref() = std::move(name); + req.if_exists_ref() = ifExists; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1194,7 +1201,7 @@ folly::Future> MetaClient::dropSpace(std::string name, const bool folly::Future>> MetaClient::listHosts(cpp2::ListHostType tp) { cpp2::ListHostsReq req; - req.set_type(tp); + req.type_ref() = tp; folly::Promise>> promise; auto future = promise.getFuture(); @@ -1209,8 +1216,8 @@ folly::Future>> MetaClient::listHosts(cpp2: folly::Future>> MetaClient::listParts( GraphSpaceID spaceId, std::vector partIds) { cpp2::ListPartsReq req; - req.set_space_id(spaceId); - req.set_part_ids(std::move(partIds)); + req.space_id_ref() = spaceId; + req.part_ids_ref() = std::move(partIds); folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -1224,7 +1231,7 @@ folly::Future>> MetaClient::listParts( folly::Future>>> MetaClient::getPartsAlloc(GraphSpaceID spaceId, PartTerms* partTerms) { cpp2::GetPartsAllocReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; folly::Promise>>> promise; auto future = promise.getFuture(); getResponse( @@ -1346,8 +1353,8 @@ folly::Future> MetaClient::multiPut( for (auto& element : pairs) { data.emplace_back(std::move(element)); } - req.set_segment(std::move(segment)); - req.set_pairs(std::move(data)); + req.segment_ref() = std::move(segment); + req.pairs_ref() = std::move(data); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1366,8 +1373,8 @@ folly::Future> MetaClient::get(std::string segment, std::s } cpp2::GetReq req; - req.set_segment(std::move(segment)); - req.set_key(std::move(key)); + req.segment_ref() = std::move(segment); + req.key_ref() = std::move(key); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1385,8 +1392,8 @@ folly::Future>> MetaClient::multiGet( } cpp2::MultiGetReq req; - req.set_segment(std::move(segment)); - req.set_keys(std::move(keys)); + req.segment_ref() = std::move(segment); + req.keys_ref() = std::move(keys); folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -1405,9 +1412,9 @@ folly::Future>> MetaClient::scan(std::string s } cpp2::ScanReq req; - req.set_segment(std::move(segment)); - req.set_start(std::move(start)); - req.set_end(std::move(end)); + req.segment_ref() = std::move(segment); + req.start_ref() = std::move(start); + req.end_ref() = std::move(end); folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -1424,8 +1431,8 @@ folly::Future> MetaClient::remove(std::string segment, std::strin } cpp2::RemoveReq req; - req.set_segment(std::move(segment)); - req.set_key(std::move(key)); + req.segment_ref() = std::move(segment); + req.key_ref() = std::move(key); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1446,9 +1453,9 @@ folly::Future> MetaClient::removeRange(std::string segment, } cpp2::RemoveRangeReq req; - req.set_segment(std::move(segment)); - req.set_start(std::move(start)); - req.set_end(std::move(end)); + req.segment_ref() = std::move(segment); + req.start_ref() = std::move(start); + req.end_ref() = std::move(end); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1533,10 +1540,10 @@ folly::Future> MetaClient::createTagSchema(GraphSpaceID spaceId, cpp2::Schema schema, bool ifNotExists) { cpp2::CreateTagReq req; - req.set_space_id(spaceId); - req.set_tag_name(std::move(name)); - req.set_schema(std::move(schema)); - req.set_if_not_exists(ifNotExists); + req.space_id_ref() = spaceId; + req.tag_name_ref() = std::move(name); + req.schema_ref() = std::move(schema); + req.if_not_exists_ref() = ifNotExists; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1552,10 +1559,10 @@ folly::Future> MetaClient::alterTagSchema(GraphSpaceID spaceId, std::vector items, cpp2::SchemaProp schemaProp) { cpp2::AlterTagReq req; - req.set_space_id(spaceId); - req.set_tag_name(std::move(name)); - req.set_tag_items(std::move(items)); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = spaceId; + req.tag_name_ref() = std::move(name); + req.tag_items_ref() = std::move(items); + req.schema_prop_ref() = std::move(schemaProp); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1571,7 +1578,7 @@ folly::Future> MetaClient::alterTagSchema(GraphSpaceID spaceId, folly::Future>> MetaClient::listTagSchemas( GraphSpaceID spaceId) { cpp2::ListTagsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -1586,9 +1593,9 @@ folly::Future> MetaClient::dropTagSchema(GraphSpaceID spaceId, std::string tagName, const bool ifExists) { cpp2::DropTagReq req; - req.set_space_id(spaceId); - req.set_tag_name(std::move(tagName)); - req.set_if_exists(ifExists); + req.space_id_ref() = spaceId; + req.tag_name_ref() = std::move(tagName); + req.if_exists_ref() = ifExists; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1605,9 +1612,9 @@ folly::Future> MetaClient::getTagSchema(GraphSpaceID spac std::string name, int64_t version) { cpp2::GetTagReq req; - req.set_space_id(spaceId); - req.set_tag_name(std::move(name)); - req.set_version(version); + req.space_id_ref() = spaceId; + req.tag_name_ref() = std::move(name); + req.version_ref() = version; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1623,10 +1630,10 @@ folly::Future> MetaClient::createEdgeSchema(GraphSpaceID spac cpp2::Schema schema, bool ifNotExists) { cpp2::CreateEdgeReq req; - req.set_space_id(spaceId); - req.set_edge_name(std::move(name)); - req.set_schema(schema); - req.set_if_not_exists(ifNotExists); + req.space_id_ref() = spaceId; + req.edge_name_ref() = std::move(name); + req.schema_ref() = schema; + req.if_not_exists_ref() = ifNotExists; folly::Promise> promise; auto future = promise.getFuture(); @@ -1643,10 +1650,10 @@ folly::Future> MetaClient::alterEdgeSchema(GraphSpaceID spaceId, std::vector items, cpp2::SchemaProp schemaProp) { cpp2::AlterEdgeReq req; - req.set_space_id(spaceId); - req.set_edge_name(std::move(name)); - req.set_edge_items(std::move(items)); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = spaceId; + req.edge_name_ref() = std::move(name); + req.edge_items_ref() = std::move(items); + req.schema_prop_ref() = std::move(schemaProp); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1662,7 +1669,7 @@ folly::Future> MetaClient::alterEdgeSchema(GraphSpaceID spaceId, folly::Future>> MetaClient::listEdgeSchemas( GraphSpaceID spaceId) { cpp2::ListEdgesReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -1677,9 +1684,9 @@ folly::Future> MetaClient::getEdgeSchema(GraphSpaceID spa std::string name, SchemaVer version) { cpp2::GetEdgeReq req; - req.set_space_id(spaceId); - req.set_edge_name(std::move(name)); - req.set_version(version); + req.space_id_ref() = spaceId; + req.edge_name_ref() = std::move(name); + req.version_ref() = version; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1694,9 +1701,9 @@ folly::Future> MetaClient::dropEdgeSchema(GraphSpaceID spaceId, std::string name, const bool ifExists) { cpp2::DropEdgeReq req; - req.set_space_id(spaceId); - req.set_edge_name(std::move(name)); - req.set_if_exists(ifExists); + req.space_id_ref() = spaceId; + req.edge_name_ref() = std::move(name); + req.if_exists_ref() = ifExists; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -1717,16 +1724,16 @@ folly::Future> MetaClient::createTagIndex(GraphSpaceID spaceID const cpp2::IndexParams* indexParams, const std::string* comment) { cpp2::CreateTagIndexReq req; - req.set_space_id(spaceID); - req.set_index_name(std::move(indexName)); - req.set_tag_name(std::move(tagName)); - req.set_fields(std::move(fields)); - req.set_if_not_exists(ifNotExists); + req.space_id_ref() = spaceID; + req.index_name_ref() = std::move(indexName); + req.tag_name_ref() = std::move(tagName); + req.fields_ref() = std::move(fields); + req.if_not_exists_ref() = ifNotExists; if (indexParams != nullptr) { - req.set_index_params(*indexParams); + req.index_params_ref() = *indexParams; } if (comment != nullptr) { - req.set_comment(*comment); + req.comment_ref() = *comment; } folly::Promise> promise; @@ -1743,9 +1750,9 @@ folly::Future> MetaClient::dropTagIndex(GraphSpaceID spaceID, std::string name, bool ifExists) { cpp2::DropTagIndexReq req; - req.set_space_id(spaceID); - req.set_index_name(std::move(name)); - req.set_if_exists(ifExists); + req.space_id_ref() = (spaceID); + req.index_name_ref() = (std::move(name)); + req.if_exists_ref() = (ifExists); folly::Promise> promise; auto future = promise.getFuture(); @@ -1762,8 +1769,8 @@ folly::Future> MetaClient::dropTagIndex(GraphSpaceID spaceID, folly::Future> MetaClient::getTagIndex(GraphSpaceID spaceID, std::string name) { cpp2::GetTagIndexReq req; - req.set_space_id(spaceID); - req.set_index_name(std::move(name)); + req.space_id_ref() = spaceID; + req.index_name_ref() = std::move(name); folly::Promise> promise; auto future = promise.getFuture(); @@ -1778,7 +1785,7 @@ folly::Future> MetaClient::getTagIndex(GraphSpaceID sp folly::Future>> MetaClient::listTagIndexes( GraphSpaceID spaceId) { cpp2::ListTagIndexesReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; folly::Promise>> promise; auto future = promise.getFuture(); @@ -1792,8 +1799,8 @@ folly::Future>> MetaClient::listTagIndexes folly::Future> MetaClient::rebuildTagIndex(GraphSpaceID spaceID, std::string name) { cpp2::RebuildIndexReq req; - req.set_space_id(spaceID); - req.set_index_name(std::move(name)); + req.space_id_ref() = spaceID; + req.index_name_ref() = std::move(name); folly::Promise> promise; auto future = promise.getFuture(); @@ -1810,7 +1817,7 @@ folly::Future> MetaClient::rebuildTagIndex(GraphSpaceID spaceID, folly::Future>> MetaClient::listTagIndexStatus( GraphSpaceID spaceID) { cpp2::ListIndexStatusReq req; - req.set_space_id(spaceID); + req.space_id_ref() = spaceID; folly::Promise>> promise; auto future = promise.getFuture(); @@ -1833,16 +1840,16 @@ folly::Future> MetaClient::createEdgeIndex( const cpp2::IndexParams* indexParams, const std::string* comment) { cpp2::CreateEdgeIndexReq req; - req.set_space_id(spaceID); - req.set_index_name(std::move(indexName)); - req.set_edge_name(std::move(edgeName)); - req.set_fields(std::move(fields)); - req.set_if_not_exists(ifNotExists); + req.space_id_ref() = spaceID; + req.index_name_ref() = std::move(indexName); + req.edge_name_ref() = std::move(edgeName); + req.fields_ref() = std::move(fields); + req.if_not_exists_ref() = ifNotExists; if (indexParams != nullptr) { - req.set_index_params(*indexParams); + req.index_params_ref() = *indexParams; } if (comment != nullptr) { - req.set_comment(*comment); + req.comment_ref() = *comment; } folly::Promise> promise; @@ -1860,9 +1867,9 @@ folly::Future> MetaClient::dropEdgeIndex(GraphSpaceID spaceId, std::string name, bool ifExists) { cpp2::DropEdgeIndexReq req; - req.set_space_id(spaceId); - req.set_index_name(std::move(name)); - req.set_if_exists(ifExists); + req.space_id_ref() = spaceId; + req.index_name_ref() = std::move(name); + req.if_exists_ref() = ifExists; folly::Promise> promise; auto future = promise.getFuture(); @@ -1879,8 +1886,8 @@ folly::Future> MetaClient::dropEdgeIndex(GraphSpaceID spaceId, folly::Future> MetaClient::getEdgeIndex(GraphSpaceID spaceId, std::string name) { cpp2::GetEdgeIndexReq req; - req.set_space_id(spaceId); - req.set_index_name(std::move(name)); + req.space_id_ref() = spaceId; + req.index_name_ref() = std::move(name); folly::Promise> promise; auto future = promise.getFuture(); @@ -1895,7 +1902,7 @@ folly::Future> MetaClient::getEdgeIndex(GraphSpaceID s folly::Future>> MetaClient::listEdgeIndexes( GraphSpaceID spaceId) { cpp2::ListEdgeIndexesReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; folly::Promise>> promise; auto future = promise.getFuture(); @@ -2072,8 +2079,8 @@ StatusOr MetaClient::getAllLatestVerEdgeSchemaFromCache(const GraphS folly::Future> MetaClient::rebuildEdgeIndex(GraphSpaceID spaceID, std::string name) { cpp2::RebuildIndexReq req; - req.set_space_id(spaceID); - req.set_index_name(std::move(name)); + req.space_id_ref() = spaceID; + req.index_name_ref() = std::move(name); folly::Promise> promise; auto future = promise.getFuture(); @@ -2090,7 +2097,7 @@ folly::Future> MetaClient::rebuildEdgeIndex(GraphSpaceID spaceID, folly::Future>> MetaClient::listEdgeIndexStatus( GraphSpaceID spaceID) { cpp2::ListIndexStatusReq req; - req.set_space_id(spaceID); + req.space_id_ref() = spaceID; folly::Promise>> promise; auto future = promise.getFuture(); @@ -2311,7 +2318,9 @@ StatusOr MetaClient::getLeaderInfo() { return leadersInfo_; } -const std::vector& MetaClient::getAddresses() { return addrs_; } +const std::vector& MetaClient::getAddresses() { + return addrs_; +} std::vector MetaClient::getRolesByUserFromCache(const std::string& user) { if (!ready_) { @@ -2401,14 +2410,14 @@ StatusOr MetaClient::getLatestEdgeVersionFromCache(const GraphSpaceID folly::Future> MetaClient::heartbeat() { cpp2::HBReq req; - req.set_host(options_.localHost_); - req.set_role(options_.role_); - req.set_git_info_sha(options_.gitInfoSHA_); + req.host_ref() = options_.localHost_; + req.role_ref() = options_.role_; + req.git_info_sha_ref() = options_.gitInfoSHA_; if (options_.role_ == cpp2::HostRole::STORAGE) { if (options_.clusterId_.load() == 0) { options_.clusterId_ = FileBasedClusterIdMan::getClusterIdFromFile(FLAGS_cluster_id_path); } - req.set_cluster_id(options_.clusterId_.load()); + req.cluster_id_ref() = options_.clusterId_.load(); std::unordered_map> leaderIds; if (listener_ != nullptr) { listener_->fetchLeaderInfo(leaderIds); @@ -2419,9 +2428,9 @@ folly::Future> MetaClient::heartbeat() { leaderIds_ = leaderIds; } } - req.set_leader_partIds(std::move(leaderIds)); + req.leader_partIds_ref() = std::move(leaderIds); } else { - req.set_leader_partIds(std::move(leaderIds)); + req.leader_partIds_ref() = std::move(leaderIds); } kvstore::SpaceDiskPartsMap diskParts; @@ -2433,11 +2442,25 @@ folly::Future> MetaClient::heartbeat() { diskParts_.clear(); diskParts_ = diskParts; } - req.set_disk_parts(diskParts); + req.disk_parts_ref() = diskParts; } } else { - req.set_disk_parts(diskParts); + req.disk_parts_ref() = diskParts; + } + } + + // info used in the agent, only set once + // TOOD(spw): if we could add data path(disk) dynamicly in the future, it should be + // reported every time it changes + if (!dirInfoReported_) { + nebula::cpp2::DirInfo dirInfo; + if (options_.role_ == cpp2::HostRole::GRAPH) { + dirInfo.root_ref() = options_.rootPath_; + } else if (options_.role_ == cpp2::HostRole::STORAGE) { + dirInfo.root_ref() = options_.rootPath_; + dirInfo.data_ref() = options_.dataPaths_; } + req.dir_ref() = dirInfo; } folly::Promise> promise; @@ -2459,7 +2482,12 @@ folly::Future> MetaClient::heartbeat() { metadLastUpdateTime_ = resp.get_last_update_time_in_ms(); VLOG(1) << "Metad last update time: " << metadLastUpdateTime_; metaServerVersion_ = resp.get_meta_version(); - return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED; + + bool succeeded = resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED; + if (succeeded) { + dirInfoReported_ = true; + } + return succeeded; }, std::move(promise), true); @@ -2470,9 +2498,9 @@ folly::Future> MetaClient::createUser(std::string account, std::string password, bool ifNotExists) { cpp2::CreateUserReq req; - req.set_account(std::move(account)); - req.set_encoded_pwd(std::move(password)); - req.set_if_not_exists(ifNotExists); + req.account_ref() = std::move(account); + req.encoded_pwd_ref() = std::move(password); + req.if_not_exists_ref() = ifNotExists; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2487,8 +2515,8 @@ folly::Future> MetaClient::createUser(std::string account, folly::Future> MetaClient::dropUser(std::string account, bool ifExists) { cpp2::DropUserReq req; - req.set_account(std::move(account)); - req.set_if_exists(ifExists); + req.account_ref() = std::move(account); + req.if_exists_ref() = ifExists; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2503,8 +2531,8 @@ folly::Future> MetaClient::dropUser(std::string account, bool ifE folly::Future> MetaClient::alterUser(std::string account, std::string password) { cpp2::AlterUserReq req; - req.set_account(std::move(account)); - req.set_encoded_pwd(std::move(password)); + req.account_ref() = std::move(account); + req.encoded_pwd_ref() = std::move(password); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2519,7 +2547,7 @@ folly::Future> MetaClient::alterUser(std::string account, std::st folly::Future> MetaClient::grantToUser(cpp2::RoleItem roleItem) { cpp2::GrantRoleReq req; - req.set_role_item(std::move(roleItem)); + req.role_item_ref() = std::move(roleItem); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2534,7 +2562,7 @@ folly::Future> MetaClient::grantToUser(cpp2::RoleItem roleItem) { folly::Future> MetaClient::revokeFromUser(cpp2::RoleItem roleItem) { cpp2::RevokeRoleReq req; - req.set_role_item(std::move(roleItem)); + req.role_item_ref() = std::move(roleItem); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2561,7 +2589,7 @@ folly::Future>> MetaClient folly::Future>> MetaClient::listRoles(GraphSpaceID space) { cpp2::ListRolesReq req; - req.set_space_id(std::move(space)); + req.space_id_ref() = std::move(space); folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -2576,9 +2604,9 @@ folly::Future> MetaClient::changePassword(std::string account, std::string newPwd, std::string oldPwd) { cpp2::ChangePasswordReq req; - req.set_account(std::move(account)); - req.set_new_encoded_pwd(std::move(newPwd)); - req.set_old_encoded_pwd(std::move(oldPwd)); + req.account_ref() = std::move(account); + req.new_encoded_pwd_ref() = std::move(newPwd); + req.old_encoded_pwd_ref() = std::move(oldPwd); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2593,7 +2621,7 @@ folly::Future> MetaClient::changePassword(std::string account, folly::Future>> MetaClient::getUserRoles(std::string account) { cpp2::GetUserRolesReq req; - req.set_account(std::move(account)); + req.account_ref() = std::move(account); folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -2609,13 +2637,13 @@ folly::Future> MetaClient::getTagDefaultValue(GraphSpaceID const std::string& field) { cpp2::GetReq req; static std::string defaultKey = "__default__"; - req.set_segment(defaultKey); + req.segment_ref() = defaultKey; std::string key; key.reserve(64); key.append(reinterpret_cast(&spaceId), sizeof(GraphSpaceID)); key.append(reinterpret_cast(&tagId), sizeof(TagID)); key.append(field); - req.set_key(std::move(key)); + req.key_ref() = std::move(key); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2631,13 +2659,13 @@ folly::Future> MetaClient::getEdgeDefaultValue(GraphSpaceI const std::string& field) { cpp2::GetReq req; static std::string defaultKey = "__default__"; - req.set_segment(defaultKey); + req.segment_ref() = defaultKey; std::string key; key.reserve(64); key.append(reinterpret_cast(&spaceId), sizeof(GraphSpaceID)); key.append(reinterpret_cast(&edgeType), sizeof(EdgeType)); key.append(field); - req.set_key(std::move(key)); + req.key_ref() = std::move(key); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2650,7 +2678,7 @@ folly::Future> MetaClient::getEdgeDefaultValue(GraphSpaceI folly::Future> MetaClient::regConfig(const std::vector& items) { cpp2::RegConfigReq req; - req.set_items(items); + req.items_ref() = items; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2669,10 +2697,10 @@ folly::Future>> MetaClient::getConfig( return Status::Error("Not ready!"); } cpp2::ConfigItem item; - item.set_module(module); - item.set_name(name); + item.module_ref() = module; + item.name_ref() = name; cpp2::GetConfigReq req; - req.set_item(item); + req.item_ref() = item; folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -2687,12 +2715,12 @@ folly::Future> MetaClient::setConfig(const cpp2::ConfigModule& mo const std::string& name, const Value& value) { cpp2::ConfigItem item; - item.set_module(module); - item.set_name(name); - item.set_value(value); + item.module_ref() = module; + item.name_ref() = name; + item.value_ref() = value; cpp2::SetConfigReq req; - req.set_item(item); + req.item_ref() = item; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2708,7 +2736,7 @@ folly::Future> MetaClient::setConfig(const cpp2::ConfigModule& mo folly::Future>> MetaClient::listConfigs( const cpp2::ConfigModule& module) { cpp2::ListConfigsReq req; - req.set_module(module); + req.module_ref() = module; folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -2735,7 +2763,7 @@ folly::Future> MetaClient::createSnapshot() { folly::Future> MetaClient::dropSnapshot(const std::string& name) { cpp2::DropSnapshotReq req; - req.set_name(name); + req.name_ref() = name; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2766,9 +2794,9 @@ folly::Future> MetaClient::addListener(GraphSpaceID spaceId, cpp2::ListenerType type, std::vector hosts) { cpp2::AddListenerReq req; - req.set_space_id(spaceId); - req.set_type(type); - req.set_hosts(std::move(hosts)); + req.space_id_ref() = spaceId; + req.type_ref() = type; + req.hosts_ref() = std::move(hosts); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2784,8 +2812,8 @@ folly::Future> MetaClient::addListener(GraphSpaceID spaceId, folly::Future> MetaClient::removeListener(GraphSpaceID spaceId, cpp2::ListenerType type) { cpp2::RemoveListenerReq req; - req.set_space_id(spaceId); - req.set_type(type); + req.space_id_ref() = spaceId; + req.type_ref() = type; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -2801,7 +2829,7 @@ folly::Future> MetaClient::removeListener(GraphSpaceID spaceId, folly::Future>> MetaClient::listListener( GraphSpaceID spaceId) { cpp2::ListListenerReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; folly::Promise>> promise; auto future = promise.getFuture(); getResponse( @@ -3049,7 +3077,7 @@ void MetaClient::loadLeader(const std::vector& hostItems, folly::Future> MetaClient::addHosts(std::vector hosts) { cpp2::AddHostsReq req; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); folly::Promise> promise; auto future = promise.getFuture(); @@ -3065,7 +3093,7 @@ folly::Future> MetaClient::addHosts(std::vector hosts) folly::Future> MetaClient::dropHosts(std::vector hosts) { cpp2::DropHostsReq req; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); folly::Promise> promise; auto future = promise.getFuture(); @@ -3082,8 +3110,8 @@ folly::Future> MetaClient::dropHosts(std::vector hosts) folly::Future> MetaClient::mergeZone(std::vector zones, std::string zoneName) { cpp2::MergeZoneReq req; - req.set_zone_name(zoneName); - req.set_zones(zones); + req.zone_name_ref() = zoneName; + req.zones_ref() = zones; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3099,8 +3127,8 @@ folly::Future> MetaClient::mergeZone(std::vector zon folly::Future> MetaClient::renameZone(std::string originalZoneName, std::string zoneName) { cpp2::RenameZoneReq req; - req.set_original_zone_name(originalZoneName); - req.set_zone_name(zoneName); + req.original_zone_name_ref() = originalZoneName; + req.zone_name_ref() = zoneName; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3115,7 +3143,7 @@ folly::Future> MetaClient::renameZone(std::string originalZoneNam folly::Future> MetaClient::dropZone(std::string zoneName) { cpp2::DropZoneReq req; - req.set_zone_name(std::move(zoneName)); + req.zone_name_ref() = std::move(zoneName); folly::Promise> promise; auto future = promise.getFuture(); @@ -3132,7 +3160,7 @@ folly::Future> MetaClient::dropZone(std::string zoneName) { folly::Future> MetaClient::splitZone( std::string zoneName, std::unordered_map>) { cpp2::SplitZoneReq req; - req.set_zone_name(zoneName); + req.zone_name_ref() = zoneName; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3149,9 +3177,9 @@ folly::Future> MetaClient::addHostsIntoZone(std::vector std::string zoneName, bool isNew) { cpp2::AddHostsIntoZoneReq req; - req.set_hosts(hosts); - req.set_zone_name(zoneName); - req.set_is_new(isNew); + req.hosts_ref() = hosts; + req.zone_name_ref() = zoneName; + req.is_new_ref() = isNew; folly::Promise> promise; auto future = promise.getFuture(); @@ -3167,7 +3195,7 @@ folly::Future> MetaClient::addHostsIntoZone(std::vector folly::Future>> MetaClient::getZone(std::string zoneName) { cpp2::GetZoneReq req; - req.set_zone_name(std::move(zoneName)); + req.zone_name_ref() = std::move(zoneName); folly::Promise>> promise; auto future = promise.getFuture(); @@ -3193,7 +3221,7 @@ folly::Future>> MetaClient::listZones() { folly::Future> MetaClient::getStats(GraphSpaceID spaceId) { cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3211,11 +3239,11 @@ folly::Future> MetaClient::reportTaskFinish( nebula::cpp2::ErrorCode taskErrCode, cpp2::StatsItem* statisticItem) { cpp2::ReportTaskReq req; - req.set_code(taskErrCode); - req.set_job_id(jobId); - req.set_task_id(taskId); + req.code_ref() = taskErrCode; + req.job_id_ref() = jobId; + req.task_id_ref() = taskId; if (statisticItem) { - req.set_stats(*statisticItem); + req.stats_ref() = *statisticItem; } folly::Promise> pro; auto fut = pro.getFuture(); @@ -3231,8 +3259,8 @@ folly::Future> MetaClient::reportTaskFinish( folly::Future> MetaClient::signInFTService( cpp2::FTServiceType type, const std::vector& clients) { cpp2::SignInFTServiceReq req; - req.set_type(type); - req.set_clients(clients); + req.type_ref() = type; + req.clients_ref() = clients; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3285,8 +3313,8 @@ StatusOr> MetaClient::getFTClientsFromCache() { folly::Future> MetaClient::createFTIndex(const std::string& name, const cpp2::FTIndex& index) { cpp2::CreateFTIndexReq req; - req.set_fulltext_index_name(name); - req.set_index(index); + req.fulltext_index_name_ref() = name; + req.index_ref() = index; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3303,8 +3331,8 @@ folly::Future> MetaClient::createFTIndex(const std::string& name, folly::Future> MetaClient::dropFTIndex(GraphSpaceID spaceId, const std::string& name) { cpp2::DropFTIndexReq req; - req.set_fulltext_index_name(name); - req.set_space_id(spaceId); + req.fulltext_index_name_ref() = name; + req.space_id_ref() = spaceId; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3389,9 +3417,9 @@ StatusOr MetaClient::getFTIndexByNameFromCache(GraphSpaceID space folly::Future> MetaClient::createSession( const std::string& userName, const HostAddr& graphAddr, const std::string& clientIp) { cpp2::CreateSessionReq req; - req.set_user(userName); - req.set_graph_addr(graphAddr); - req.set_client_ip(clientIp); + req.user_ref() = userName; + req.graph_addr_ref() = graphAddr; + req.client_ip_ref() = clientIp; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3406,7 +3434,7 @@ folly::Future> MetaClient::createSession( folly::Future> MetaClient::updateSessions( const std::vector& sessions) { cpp2::UpdateSessionsReq req; - req.set_sessions(sessions); + req.sessions_ref() = sessions; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3432,7 +3460,7 @@ folly::Future> MetaClient::listSessions() { folly::Future> MetaClient::getSession(SessionID sessionId) { cpp2::GetSessionReq req; - req.set_session_id(sessionId); + req.session_id_ref() = sessionId; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3445,7 +3473,7 @@ folly::Future> MetaClient::getSession(SessionID s folly::Future> MetaClient::removeSession(SessionID sessionId) { cpp2::RemoveSessionReq req; - req.set_session_id(sessionId); + req.session_id_ref() = sessionId; folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3460,7 +3488,7 @@ folly::Future> MetaClient::removeSession(SessionID sess folly::Future> MetaClient::killQuery( std::unordered_map> killQueries) { cpp2::KillQueryReq req; - req.set_kill_queries(std::move(killQueries)); + req.kill_queries_ref() = std::move(killQueries); folly::Promise> promise; auto future = promise.getFuture(); getResponse( @@ -3565,8 +3593,8 @@ bool MetaClient::checkIsPlanKilled(SessionID sessionId, ExecutionPlanID planId) Status MetaClient::verifyVersion() { auto req = cpp2::VerifyClientVersionReq(); - req.set_build_version(getOriginVersion()); - req.set_host(options_.localHost_); + req.build_version_ref() = getOriginVersion(); + req.host_ref() = options_.localHost_; folly::Promise> promise; auto future = promise.getFuture(); getResponse( diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 5edefa2a000..b76790e21aa 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -184,7 +184,9 @@ struct MetaClientOptions { serviceName_(opt.serviceName_), skipConfig_(opt.skipConfig_), role_(opt.role_), - gitInfoSHA_(opt.gitInfoSHA_) {} + gitInfoSHA_(opt.gitInfoSHA_), + dataPaths_(opt.dataPaths_), + rootPath_(opt.rootPath_) {} // Current host address HostAddr localHost_{"", 0}; @@ -200,6 +202,10 @@ struct MetaClientOptions { cpp2::HostRole role_ = cpp2::HostRole::UNKNOWN; // gitInfoSHA of Host using this client std::string gitInfoSHA_{""}; + // data path list, used in storaged + std::vector dataPaths_; + // install path, used in metad/graphd/storaged + std::string rootPath_; }; class MetaClient { @@ -638,9 +644,13 @@ class MetaClient { folly::Future> ingest(GraphSpaceID spaceId); - HostAddr getMetaLeader() { return leader_; } + HostAddr getMetaLeader() { + return leader_; + } - int64_t HeartbeatTime() { return heartbeatTime_; } + int64_t HeartbeatTime() { + return heartbeatTime_; + } protected: // Return true if load succeeded. @@ -759,6 +769,8 @@ class MetaClient { HostAddr leader_; HostAddr localHost_; + // Only report dir info once when started + bool dirInfoReported_ = false; struct ThreadLocalInfo { int64_t localLastUpdateTime_{-2}; LocalCache localCache_; diff --git a/src/clients/meta/stats/CMakeLists.txt b/src/clients/meta/stats/CMakeLists.txt new file mode 100644 index 00000000000..68a18484869 --- /dev/null +++ b/src/clients/meta/stats/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2021 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. + +nebula_add_library( + meta_client_stats_obj + OBJECT + MetaClientStats.cpp + ) diff --git a/src/clients/meta/stats/MetaClientStats.cpp b/src/clients/meta/stats/MetaClientStats.cpp new file mode 100644 index 00000000000..3f73f4f76fe --- /dev/null +++ b/src/clients/meta/stats/MetaClientStats.cpp @@ -0,0 +1,19 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "clients/meta/stats/MetaClientStats.h" + +namespace nebula { + +stats::CounterId kNumRpcSentToMetad; +stats::CounterId kNumRpcSentToMetadFailed; + +void initMetaClientStats() { + kNumRpcSentToMetad = stats::StatsManager::registerStats("num_rpc_sent_to_metad", "rate, sum"); + kNumRpcSentToMetadFailed = + stats::StatsManager::registerStats("num_rpc_sent_to_metad_failed", "rate, sum"); +} + +} // namespace nebula diff --git a/src/clients/meta/stats/MetaClientStats.h b/src/clients/meta/stats/MetaClientStats.h new file mode 100644 index 00000000000..46fa1497931 --- /dev/null +++ b/src/clients/meta/stats/MetaClientStats.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include "common/stats/StatsManager.h" + +namespace nebula { + +extern stats::CounterId kNumRpcSentToMetad; +extern stats::CounterId kNumRpcSentToMetadFailed; + +void initMetaClientStats(); + +} // namespace nebula diff --git a/src/clients/storage/CMakeLists.txt b/src/clients/storage/CMakeLists.txt index c6df1f8dda6..34293727a3a 100644 --- a/src/clients/storage/CMakeLists.txt +++ b/src/clients/storage/CMakeLists.txt @@ -19,3 +19,5 @@ nebula_add_library( InternalStorageClient.cpp ) +nebula_add_subdirectory(stats) + diff --git a/src/clients/storage/InternalStorageClient.cpp b/src/clients/storage/InternalStorageClient.cpp index c3bfb15fe2b..c51bd6dd4aa 100644 --- a/src/clients/storage/InternalStorageClient.cpp +++ b/src/clients/storage/InternalStorageClient.cpp @@ -55,10 +55,10 @@ void InternalStorageClient::chainUpdateEdge(cpp2::UpdateEdgeRequest& reversedReq VLOG(1) << "leader host: " << leader; cpp2::ChainUpdateEdgeRequest chainReq; - chainReq.set_update_edge_request(reversedRequest); - chainReq.set_term(termOfSrc); + chainReq.update_edge_request_ref() = reversedRequest; + chainReq.term_ref() = termOfSrc; if (optVersion) { - chainReq.set_edge_version(optVersion.value()); + chainReq.edge_version_ref() = optVersion.value(); } auto resp = getResponse( evb, @@ -120,13 +120,13 @@ cpp2::ChainAddEdgesRequest InternalStorageClient::makeChainAddReq(const cpp2::Ad TermID termId, folly::Optional ver) { cpp2::ChainAddEdgesRequest ret; - ret.set_space_id(req.get_space_id()); - ret.set_parts(req.get_parts()); - ret.set_prop_names(req.get_prop_names()); - ret.set_if_not_exists(req.get_if_not_exists()); - ret.set_term(termId); + ret.space_id_ref() = req.get_space_id(); + ret.parts_ref() = req.get_parts(); + ret.prop_names_ref() = req.get_prop_names(); + ret.if_not_exists_ref() = req.get_if_not_exists(); + ret.term_ref() = termId; if (ver) { - ret.set_edge_version(ver.value()); + ret.edge_version_ref() = ver.value(); } return ret; } diff --git a/src/clients/storage/StorageClient.cpp b/src/clients/storage/StorageClient.cpp index eca714f6977..41cb0928715 100644 --- a/src/clients/storage/StorageClient.cpp +++ b/src/clients/storage/StorageClient.cpp @@ -30,9 +30,9 @@ StorageClient::CommonRequestParam::CommonRequestParam(GraphSpaceID space_, cpp2::RequestCommon StorageClient::CommonRequestParam::toReqCommon() const { cpp2::RequestCommon common; - common.set_session_id(session); - common.set_plan_id(plan); - common.set_profile_detail(profile); + common.session_id_ref() = session; + common.plan_id_ref() = plan; + common.profile_detail_ref() = profile; return common; } @@ -69,35 +69,35 @@ StorageRpcRespFuture StorageClient::getNeighbors( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_column_names(colNames); - req.set_parts(std::move(c.second)); - req.set_common(common); + req.space_id_ref() = param.space; + req.column_names_ref() = colNames; + req.parts_ref() = std::move(c.second); + req.common_ref() = common; cpp2::TraverseSpec spec; - spec.set_edge_types(edgeTypes); - spec.set_edge_direction(edgeDirection); - spec.set_dedup(dedup); - spec.set_random(random); + spec.edge_types_ref() = edgeTypes; + spec.edge_direction_ref() = edgeDirection; + spec.dedup_ref() = dedup; + spec.random_ref() = random; if (statProps != nullptr) { - spec.set_stat_props(*statProps); + spec.stat_props_ref() = *statProps; } if (vertexProps != nullptr) { - spec.set_vertex_props(*vertexProps); + spec.vertex_props_ref() = *vertexProps; } if (edgeProps != nullptr) { - spec.set_edge_props(*edgeProps); + spec.edge_props_ref() = *edgeProps; } if (expressions != nullptr) { - spec.set_expressions(*expressions); + spec.expressions_ref() = *expressions; } if (!orderBy.empty()) { - spec.set_order_by(orderBy); + spec.order_by_ref() = orderBy; } - spec.set_limit(limit); + spec.limit_ref() = limit; if (filter != nullptr) { - spec.set_filter(filter->encode()); + spec.filter_ref() = filter->encode(); } - req.set_traverse_spec(std::move(spec)); + req.traverse_spec_ref() = std::move(spec); } return collectResponse( @@ -132,12 +132,12 @@ StorageRpcRespFuture StorageClient::addVertices( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_if_not_exists(ifNotExists); - req.set_ignore_existed_index(ignoreExistedIndex); - req.set_parts(std::move(c.second)); - req.set_prop_names(propNames); - req.set_common(common); + req.space_id_ref() = param.space; + req.if_not_exists_ref() = ifNotExists; + req.ignore_existed_index_ref() = ignoreExistedIndex; + req.parts_ref() = std::move(c.second); + req.prop_names_ref() = propNames; + req.common_ref() = common; } return collectResponse( @@ -171,12 +171,12 @@ StorageRpcRespFuture StorageClient::addEdges(const CommonReq for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_if_not_exists(ifNotExists); - req.set_ignore_existed_index(ignoreExistedIndex); - req.set_parts(std::move(c.second)); - req.set_prop_names(propNames); - req.set_common(common); + req.space_id_ref() = param.space; + req.if_not_exists_ref() = ifNotExists; + req.ignore_existed_index_ref() = ignoreExistedIndex; + req.parts_ref() = std::move(c.second); + req.prop_names_ref() = propNames; + req.common_ref() = common; } return collectResponse( param.evb, @@ -215,26 +215,26 @@ StorageRpcRespFuture StorageClient::getProps( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_parts(std::move(c.second)); - req.set_dedup(dedup); + req.space_id_ref() = param.space; + req.parts_ref() = std::move(c.second); + req.dedup_ref() = dedup; if (vertexProps != nullptr) { - req.set_vertex_props(*vertexProps); + req.vertex_props_ref() = *vertexProps; } if (edgeProps != nullptr) { - req.set_edge_props(*edgeProps); + req.edge_props_ref() = *edgeProps; } if (expressions != nullptr) { - req.set_expressions(*expressions); + req.expressions_ref() = *expressions; } if (!orderBy.empty()) { - req.set_order_by(orderBy); + req.order_by_ref() = orderBy; } - req.set_limit(limit); + req.limit_ref() = limit; if (filter != nullptr) { - req.set_filter(filter->encode()); + req.filter_ref() = filter->encode(); } - req.set_common(common); + req.common_ref() = common; } return collectResponse(param.evb, @@ -263,9 +263,9 @@ StorageRpcRespFuture StorageClient::deleteEdges( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_parts(std::move(c.second)); - req.set_common(common); + req.space_id_ref() = param.space; + req.parts_ref() = std::move(c.second); + req.common_ref() = common; } return collectResponse( @@ -296,9 +296,9 @@ StorageRpcRespFuture StorageClient::deleteVertices( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_parts(std::move(c.second)); - req.set_common(common); + req.space_id_ref() = param.space; + req.parts_ref() = std::move(c.second); + req.common_ref() = common; } return collectResponse( @@ -329,9 +329,9 @@ StorageRpcRespFuture StorageClient::deleteTags( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_parts(std::move(c.second)); - req.set_common(common); + req.space_id_ref() = param.space; + req.parts_ref() = std::move(c.second); + req.common_ref() = common; } return collectResponse( @@ -375,16 +375,16 @@ folly::Future> StorageClient::updateVert } request.first = std::move(host).value(); cpp2::UpdateVertexRequest req; - req.set_space_id(param.space); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); - req.set_part_id(part); - req.set_updated_props(std::move(updatedProps)); - req.set_return_props(std::move(returnProps)); - req.set_insertable(insertable); - req.set_common(param.toReqCommon()); + req.space_id_ref() = param.space; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; + req.part_id_ref() = part; + req.updated_props_ref() = std::move(updatedProps); + req.return_props_ref() = std::move(returnProps); + req.insertable_ref() = insertable; + req.common_ref() = param.toReqCommon(); if (condition.size() > 0) { - req.set_condition(std::move(condition)); + req.condition_ref() = std::move(condition); } request.second = std::move(req); @@ -429,15 +429,15 @@ folly::Future> StorageClient::updateEdge } request.first = std::move(host).value(); cpp2::UpdateEdgeRequest req; - req.set_space_id(space); - req.set_edge_key(edgeKey); - req.set_part_id(part); - req.set_updated_props(std::move(updatedProps)); - req.set_return_props(std::move(returnProps)); - req.set_insertable(insertable); - req.set_common(param.toReqCommon()); + req.space_id_ref() = space; + req.edge_key_ref() = edgeKey; + req.part_id_ref() = part; + req.updated_props_ref() = std::move(updatedProps); + req.return_props_ref() = std::move(returnProps); + req.insertable_ref() = insertable; + req.common_ref() = param.toReqCommon(); if (condition.size() > 0) { - req.set_condition(std::move(condition)); + req.condition_ref() = std::move(condition); } request.second = std::move(req); @@ -473,9 +473,9 @@ folly::Future> StorageClient::getUUID(GraphSpaceID s } request.first = std::move(host).value(); cpp2::GetUUIDReq req; - req.set_space_id(space); - req.set_part_id(part); - req.set_name(name); + req.space_id_ref() = space; + req.part_id_ref() = part; + req.name_ref() = name; request.second = std::move(req); return getResponse(evb, @@ -501,9 +501,9 @@ StorageRpcRespFuture StorageClient::lookupIndex( } nebula::cpp2::SchemaID schemaId; if (isEdge) { - schemaId.set_edge_type(tagOrEdge); + schemaId.edge_type_ref() = tagOrEdge; } else { - schemaId.set_tag_id(tagOrEdge); + schemaId.tag_id_ref() = tagOrEdge; } auto& clusters = status.value(); @@ -512,16 +512,16 @@ StorageRpcRespFuture StorageClient::lookupIndex( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(space); - req.set_parts(std::move(c.second)); - req.set_return_columns(returnCols); + req.space_id_ref() = space; + req.parts_ref() = std::move(c.second); + req.return_columns_ref() = returnCols; cpp2::IndexSpec spec; - spec.set_contexts(contexts); - spec.set_schema_id(schemaId); - req.set_indices(spec); - req.set_common(common); - req.set_limit(limit); + spec.contexts_ref() = contexts; + spec.schema_id_ref() = schemaId; + req.indices_ref() = spec; + req.common_ref() = common; + req.limit_ref() = limit; } return collectResponse( @@ -547,11 +547,11 @@ StorageRpcRespFuture StorageClient::lookupAndTravers for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(space); - req.set_parts(std::move(c.second)); - req.set_indices(indexSpec); - req.set_traverse_spec(traverseSpec); - req.set_common(common); + req.space_id_ref() = space; + req.parts_ref() = std::move(c.second); + req.indices_ref() = indexSpec; + req.traverse_spec_ref() = traverseSpec; + req.common_ref() = common; } return collectResponse( @@ -577,14 +577,14 @@ StorageRpcRespFuture StorageClient::scanEdge( for (const auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_parts(std::move(c.second)); - req.set_return_columns(edgeProp); - req.set_limit(limit); + req.space_id_ref() = param.space; + req.parts_ref() = std::move(c.second); + req.return_columns_ref() = edgeProp; + req.limit_ref() = limit; if (filter != nullptr) { - req.set_filter(filter->encode()); + req.filter_ref() = filter->encode(); } - req.set_common(param.toReqCommon()); + req.common_ref() = param.toReqCommon(); } return collectResponse(param.evb, @@ -608,14 +608,14 @@ StorageRpcRespFuture StorageClient::scanVertex( for (const auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(param.space); - req.set_parts(std::move(c.second)); - req.set_return_columns(vertexProp); - req.set_limit(limit); + req.space_id_ref() = param.space; + req.parts_ref() = std::move(c.second); + req.return_columns_ref() = vertexProp; + req.limit_ref() = limit; if (filter != nullptr) { - req.set_filter(filter->encode()); + req.filter_ref() = filter->encode(); } - req.set_common(param.toReqCommon()); + req.common_ref() = param.toReqCommon(); } return collectResponse( @@ -641,9 +641,9 @@ folly::SemiFuture> StorageClient::get( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(space); - req.set_parts(std::move(c.second)); - req.set_return_partly(returnPartly); + req.space_id_ref() = space; + req.parts_ref() = std::move(c.second); + req.return_partly_ref() = returnPartly; } return collectResponse(evb, @@ -667,8 +667,8 @@ folly::SemiFuture> StorageClient::put( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(space); - req.set_parts(std::move(c.second)); + req.space_id_ref() = space; + req.parts_ref() = std::move(c.second); } return collectResponse(evb, @@ -692,8 +692,8 @@ folly::SemiFuture> StorageClient::remove( for (auto& c : clusters) { auto& host = c.first; auto& req = requests[host]; - req.set_space_id(space); - req.set_parts(std::move(c.second)); + req.space_id_ref() = space; + req.parts_ref() = std::move(c.second); } return collectResponse(evb, @@ -761,7 +761,8 @@ StatusOr> StorageClient:: cb = [](const cpp2::NewVertex& v) -> const VertexID& { DCHECK_EQ(Value::Type::INT, v.get_id().type()); auto& mutableV = const_cast(v); - mutableV.set_id(Value(std::string(reinterpret_cast(&v.get_id().getInt()), 8))); + mutableV.id_ref() = + Value(std::string(reinterpret_cast(&v.get_id().getInt()), 8)); return mutableV.get_id().getStr(); }; } else if (vidType == PropertyType::FIXED_STRING) { @@ -825,10 +826,10 @@ StatusOr> StorageClient::ge DCHECK_EQ(Value::Type::INT, eKey.get_src().type()); DCHECK_EQ(Value::Type::INT, eKey.get_dst().type()); auto& mutableEK = const_cast(eKey); - mutableEK.set_src( - Value(std::string(reinterpret_cast(&eKey.get_src().getInt()), 8))); - mutableEK.set_dst( - Value(std::string(reinterpret_cast(&eKey.get_dst().getInt()), 8))); + mutableEK.src_ref() = + Value(std::string(reinterpret_cast(&eKey.get_src().getInt()), 8)); + mutableEK.dst_ref() = + Value(std::string(reinterpret_cast(&eKey.get_dst().getInt()), 8)); return mutableEK.get_src().getStr(); }; } else if (vidType == PropertyType::FIXED_STRING) { diff --git a/src/clients/storage/StorageClientBase-inl.h b/src/clients/storage/StorageClientBase-inl.h index a402bc71a88..abeb3ed130c 100644 --- a/src/clients/storage/StorageClientBase-inl.h +++ b/src/clients/storage/StorageClientBase-inl.h @@ -7,7 +7,9 @@ #include +#include "clients/storage/stats/StorageClientStats.h" #include "common/ssl/SSLConfig.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" namespace nebula { @@ -230,6 +232,7 @@ void StorageClientBase::getResponseImpl( std::pair request, RemoteFunc remoteFunc, std::shared_ptr>> pro) { + stats::StatsManager::addValue(kNumRpcSentToStoraged); using TransportException = apache::thrift::transport::TTransportException; if (evb == nullptr) { DCHECK(!!ioThreadPool_); @@ -266,6 +269,7 @@ void StorageClientBase::getResponseImpl( .thenError(folly::tag_t{}, [spaceId, partsId = std::move(partsId), host, pro, this]( TransportException&& ex) mutable { + stats::StatsManager::addValue(kNumRpcSentToStoragedFailed); if (ex.getType() == TransportException::TIMED_OUT) { LOG(ERROR) << "Request to " << host << " time out: " << ex.what(); } else { @@ -278,6 +282,7 @@ void StorageClientBase::getResponseImpl( .thenError(folly::tag_t{}, [spaceId, partsId = std::move(partsId), host, pro, this]( std::exception&& ex) mutable { + stats::StatsManager::addValue(kNumRpcSentToStoragedFailed); // exception occurred during RPC pro->setValue(Status::Error( folly::stringPrintf("RPC failure in StorageClient: %s", ex.what()))); diff --git a/src/clients/storage/StorageClientBase.h b/src/clients/storage/StorageClientBase.h index 8ee65d321ae..3ad810d4802 100644 --- a/src/clients/storage/StorageClientBase.h +++ b/src/clients/storage/StorageClientBase.h @@ -92,7 +92,9 @@ class StorageRpcResponse final { } // Not thread-safe. - std::vector& responses() { return responses_; } + std::vector& responses() { + return responses_; + } // Not thread-safe. const std::vector>& hostLatency() const { diff --git a/src/clients/storage/stats/CMakeLists.txt b/src/clients/storage/stats/CMakeLists.txt new file mode 100644 index 00000000000..a1acb23dcea --- /dev/null +++ b/src/clients/storage/stats/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2021 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. + +nebula_add_library( + storage_client_stats_obj + OBJECT + StorageClientStats.cpp + ) diff --git a/src/clients/storage/stats/StorageClientStats.cpp b/src/clients/storage/stats/StorageClientStats.cpp new file mode 100644 index 00000000000..097f4cf3e8c --- /dev/null +++ b/src/clients/storage/stats/StorageClientStats.cpp @@ -0,0 +1,20 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "clients/meta/stats/MetaClientStats.h" + +namespace nebula { + +stats::CounterId kNumRpcSentToStoraged; +stats::CounterId kNumRpcSentToStoragedFailed; + +void initStorageClientStats() { + kNumRpcSentToStoraged = + stats::StatsManager::registerStats("num_rpc_sent_to_storaged", "rate, sum"); + kNumRpcSentToStoragedFailed = + stats::StatsManager::registerStats("num_rpc_sent_to_storaged_failed", "rate, sum"); +} + +} // namespace nebula diff --git a/src/clients/storage/stats/StorageClientStats.h b/src/clients/storage/stats/StorageClientStats.h new file mode 100644 index 00000000000..9c2e3567e4d --- /dev/null +++ b/src/clients/storage/stats/StorageClientStats.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include "common/stats/StatsManager.h" + +namespace nebula { + +extern stats::CounterId kNumRpcSentToStoraged; +extern stats::CounterId kNumRpcSentToStoragedFailed; + +void initStorageClientStats(); + +} // namespace nebula diff --git a/src/codec/RowReader.cpp b/src/codec/RowReader.cpp index 3a892038ba5..fa5c190dcbf 100644 --- a/src/codec/RowReader.cpp +++ b/src/codec/RowReader.cpp @@ -29,9 +29,13 @@ bool RowReader::Iterator::operator==(const Iterator& rhs) const noexcept { return reader_ == rhs.reader_ && index_ == rhs.index_; } -const RowReader::Cell& RowReader::Iterator::operator*() const noexcept { return cell_; } +const RowReader::Cell& RowReader::Iterator::operator*() const noexcept { + return cell_; +} -const RowReader::Cell* RowReader::Iterator::operator->() const noexcept { return &cell_; } +const RowReader::Cell* RowReader::Iterator::operator->() const noexcept { + return &cell_; +} RowReader::Iterator& RowReader::Iterator::operator++() { if (index_ < reader_->numFields()) { diff --git a/src/codec/RowReader.h b/src/codec/RowReader.h index 1a3ff180bcd..7ba61ff7633 100644 --- a/src/codec/RowReader.h +++ b/src/codec/RowReader.h @@ -44,7 +44,9 @@ class RowReader { Iterator& operator++(); bool operator==(const Iterator& rhs) const noexcept; - bool operator!=(const Iterator& rhs) const noexcept { return !operator==(rhs); } + bool operator!=(const Iterator& rhs) const noexcept { + return !operator==(rhs); + } private: const RowReader* reader_; @@ -55,7 +57,9 @@ class RowReader { Iterator(const RowReader* reader, size_t index) : reader_(reader), cell_(this), index_(index) {} - void reset(size_t index = 0) { index_ = index; } + void reset(size_t index = 0) { + index_ = index; + } }; public: @@ -70,17 +74,29 @@ class RowReader { // Return the number of bytes used for the header info virtual size_t headerLen() const noexcept = 0; - virtual Iterator begin() const noexcept { return Iterator(this, 0); } + virtual Iterator begin() const noexcept { + return Iterator(this, 0); + } - virtual const Iterator& end() const noexcept { return endIter_; } + virtual const Iterator& end() const noexcept { + return endIter_; + } - virtual SchemaVer schemaVer() const noexcept { return schema_->getVersion(); } + virtual SchemaVer schemaVer() const noexcept { + return schema_->getVersion(); + } - virtual size_t numFields() const noexcept { return schema_->getNumFields(); } + virtual size_t numFields() const noexcept { + return schema_->getNumFields(); + } - virtual const meta::SchemaProviderIf* getSchema() const { return schema_; } + virtual const meta::SchemaProviderIf* getSchema() const { + return schema_; + } - virtual const std::string getData() const { return data_.toString(); } + virtual const std::string getData() const { + return data_.toString(); + } protected: meta::SchemaProviderIf const* schema_; diff --git a/src/codec/RowReaderV1.cpp b/src/codec/RowReaderV1.cpp index 84085845b2e..5e7a28404bc 100644 --- a/src/codec/RowReaderV1.cpp +++ b/src/codec/RowReaderV1.cpp @@ -224,7 +224,9 @@ Value RowReaderV1::getValueByIndex(const int64_t index) const noexcept { } } -int64_t RowReaderV1::getTimestamp() const noexcept { return std::numeric_limits::max(); } +int64_t RowReaderV1::getTimestamp() const noexcept { + return std::numeric_limits::max(); +} /************************************************************ * diff --git a/src/codec/RowReaderV1.h b/src/codec/RowReaderV1.h index 22760da1982..473e338fdbe 100644 --- a/src/codec/RowReaderV1.h +++ b/src/codec/RowReaderV1.h @@ -31,9 +31,13 @@ class RowReaderV1 : public RowReader { Value getValueByIndex(const int64_t index) const noexcept override; int64_t getTimestamp() const noexcept override; - int32_t readerVer() const noexcept override { return 1; } + int32_t readerVer() const noexcept override { + return 1; + } - size_t headerLen() const noexcept override { return headerLen_; } + size_t headerLen() const noexcept override { + return headerLen_; + } protected: bool resetImpl(meta::SchemaProviderIf const* schema, folly::StringPiece row) noexcept override; diff --git a/src/codec/RowReaderV2.h b/src/codec/RowReaderV2.h index 0ecc440854f..1785ad8dab9 100644 --- a/src/codec/RowReaderV2.h +++ b/src/codec/RowReaderV2.h @@ -32,9 +32,13 @@ class RowReaderV2 : public RowReader { Value getValueByIndex(const int64_t index) const noexcept override; int64_t getTimestamp() const noexcept override; - int32_t readerVer() const noexcept override { return 2; } + int32_t readerVer() const noexcept override { + return 2; + } - size_t headerLen() const noexcept override { return headerLen_; } + size_t headerLen() const noexcept override { + return headerLen_; + } protected: bool resetImpl(meta::SchemaProviderIf const* schema, folly::StringPiece row) noexcept override; diff --git a/src/codec/RowReaderWrapper.h b/src/codec/RowReaderWrapper.h index a4b70e7ae2c..acd3a11ad80 100644 --- a/src/codec/RowReaderWrapper.h +++ b/src/codec/RowReaderWrapper.h @@ -143,21 +143,37 @@ class RowReaderWrapper : public RowReader { static void getVersions(const folly::StringPiece& row, SchemaVer& schemaVer, int32_t& readerVer); - operator bool() const noexcept { return operator!=(nullptr); } + operator bool() const noexcept { + return operator!=(nullptr); + } - bool operator==(std::nullptr_t) const noexcept { return !operator!=(nullptr); } + bool operator==(std::nullptr_t) const noexcept { + return !operator!=(nullptr); + } - bool operator!=(std::nullptr_t) const noexcept { return currReader_ != nullptr; } + bool operator!=(std::nullptr_t) const noexcept { + return currReader_ != nullptr; + } - RowReaderWrapper* operator->() const noexcept { return get(); } + RowReaderWrapper* operator->() const noexcept { + return get(); + } - RowReaderWrapper* get() const noexcept { return const_cast(this); } + RowReaderWrapper* get() const noexcept { + return const_cast(this); + } - RowReaderWrapper* get() noexcept { return this; } + RowReaderWrapper* get() noexcept { + return this; + } - RowReaderWrapper& operator*() const noexcept { return *get(); } + RowReaderWrapper& operator*() const noexcept { + return *get(); + } - void reset() noexcept { currReader_ = nullptr; } + void reset() noexcept { + currReader_ = nullptr; + } private: RowReaderV1 readerV1_; diff --git a/src/codec/RowWriterV2.h b/src/codec/RowWriterV2.h index 30138e89c65..acb0069c4ef 100644 --- a/src/codec/RowWriterV2.h +++ b/src/codec/RowWriterV2.h @@ -96,9 +96,13 @@ class RowWriterV2 { ~RowWriterV2() = default; // Return the exact length of the encoded binary array - int64_t size() const noexcept { return buf_.size(); } + int64_t size() const noexcept { + return buf_.size(); + } - const meta::SchemaProviderIf* schema() const { return schema_; } + const meta::SchemaProviderIf* schema() const { + return schema_; + } const std::string& getEncodedStr() const noexcept { CHECK(finished_) << "You need to call finish() first"; diff --git a/src/codec/test/CMakeLists.txt b/src/codec/test/CMakeLists.txt index f529f16431e..1bf4e06fe07 100644 --- a/src/codec/test/CMakeLists.txt +++ b/src/codec/test/CMakeLists.txt @@ -22,6 +22,9 @@ set(CODEC_TEST_LIBS $ $ $ + $ + $ + $ $ $ $ diff --git a/src/codec/test/ResultSchemaProvider.cpp b/src/codec/test/ResultSchemaProvider.cpp index 2ff95c1c782..7d1037dca1b 100644 --- a/src/codec/test/ResultSchemaProvider.cpp +++ b/src/codec/test/ResultSchemaProvider.cpp @@ -33,34 +33,54 @@ ResultSchemaProvider::ResultSchemaField::ResultSchemaField(std::string name, defaultValue_(defaultValue), geoShape_(geoShape) {} -const char* ResultSchemaProvider::ResultSchemaField::name() const { return name_.c_str(); } +const char* ResultSchemaProvider::ResultSchemaField::name() const { + return name_.c_str(); +} -PropertyType ResultSchemaProvider::ResultSchemaField::type() const { return type_; } +PropertyType ResultSchemaProvider::ResultSchemaField::type() const { + return type_; +} bool ResultSchemaProvider::ResultSchemaField::hasDefault() const { return defaultValue_ != nullptr; } -bool ResultSchemaProvider::ResultSchemaField::nullable() const { return nullable_; } +bool ResultSchemaProvider::ResultSchemaField::nullable() const { + return nullable_; +} -Expression* ResultSchemaProvider::ResultSchemaField::defaultValue() const { return defaultValue_; } +Expression* ResultSchemaProvider::ResultSchemaField::defaultValue() const { + return defaultValue_; +} -size_t ResultSchemaProvider::ResultSchemaField::size() const { return size_; } +size_t ResultSchemaProvider::ResultSchemaField::size() const { + return size_; +} -size_t ResultSchemaProvider::ResultSchemaField::offset() const { return offset_; } +size_t ResultSchemaProvider::ResultSchemaField::offset() const { + return offset_; +} -size_t ResultSchemaProvider::ResultSchemaField::nullFlagPos() const { return nullFlagPos_; } +size_t ResultSchemaProvider::ResultSchemaField::nullFlagPos() const { + return nullFlagPos_; +} -meta::cpp2::GeoShape ResultSchemaProvider::ResultSchemaField::geoShape() const { return geoShape_; } +meta::cpp2::GeoShape ResultSchemaProvider::ResultSchemaField::geoShape() const { + return geoShape_; +} /*********************************** * * ResultSchemaProvider * **********************************/ -size_t ResultSchemaProvider::getNumFields() const noexcept { return columns_.size(); } +size_t ResultSchemaProvider::getNumFields() const noexcept { + return columns_.size(); +} -size_t ResultSchemaProvider::getNumNullableFields() const noexcept { return numNullableFields_; } +size_t ResultSchemaProvider::getNumNullableFields() const noexcept { + return numNullableFields_; +} size_t ResultSchemaProvider::size() const noexcept { if (columns_.size() > 0) { diff --git a/src/codec/test/ResultSchemaProvider.h b/src/codec/test/ResultSchemaProvider.h index 87327b13c97..abb4961c522 100644 --- a/src/codec/test/ResultSchemaProvider.h +++ b/src/codec/test/ResultSchemaProvider.h @@ -48,7 +48,9 @@ class ResultSchemaProvider : public meta::SchemaProviderIf { public: virtual ~ResultSchemaProvider() = default; - SchemaVer getVersion() const noexcept override { return schemaVer_; } + SchemaVer getVersion() const noexcept override { + return schemaVer_; + } size_t getNumFields() const noexcept override; diff --git a/src/codec/test/RowReaderBenchmark.cpp b/src/codec/test/RowReaderBenchmark.cpp index 54eaa6d889b..f1c22c35e77 100644 --- a/src/codec/test/RowReaderBenchmark.cpp +++ b/src/codec/test/RowReaderBenchmark.cpp @@ -154,13 +154,21 @@ void randomTest(SchemaWriter* schema, /************************* * Beginning of Tests ************************/ -TEST(RowReader, SequentialShort) { sequentialTest(&schemaShort, dataShortV1, dataShortV2); } +TEST(RowReader, SequentialShort) { + sequentialTest(&schemaShort, dataShortV1, dataShortV2); +} -TEST(RowReader, SequentialLong) { sequentialTest(&schemaLong, dataLongV1, dataLongV2); } +TEST(RowReader, SequentialLong) { + sequentialTest(&schemaLong, dataLongV1, dataLongV2); +} -TEST(RowReader, RandomShort) { randomTest(&schemaShort, dataShortV1, dataShortV2, shortRandom); } +TEST(RowReader, RandomShort) { + randomTest(&schemaShort, dataShortV1, dataShortV2, shortRandom); +} -TEST(RowReader, RandomLong) { randomTest(&schemaLong, dataLongV1, dataLongV2, longRandom); } +TEST(RowReader, RandomLong) { + randomTest(&schemaLong, dataLongV1, dataLongV2, longRandom); +} /************************* * End of Tests ************************/ @@ -168,13 +176,21 @@ TEST(RowReader, RandomLong) { randomTest(&schemaLong, dataLongV1, dataLongV2, lo /************************* * Beginning of benchmarks ************************/ -BENCHMARK(seq_read_short_v1, iters) { sequentialRead(&schemaShort, dataShortV1, iters); } -BENCHMARK_RELATIVE(seq_read_short_v2, iters) { sequentialRead(&schemaShort, dataShortV2, iters); } +BENCHMARK(seq_read_short_v1, iters) { + sequentialRead(&schemaShort, dataShortV1, iters); +} +BENCHMARK_RELATIVE(seq_read_short_v2, iters) { + sequentialRead(&schemaShort, dataShortV2, iters); +} BENCHMARK_DRAW_LINE(); -BENCHMARK(seq_read_long_v1, iters) { sequentialRead(&schemaLong, dataLongV1, iters); } -BENCHMARK_RELATIVE(seq_read_long_v2, iters) { sequentialRead(&schemaLong, dataLongV2, iters); } +BENCHMARK(seq_read_long_v1, iters) { + sequentialRead(&schemaLong, dataLongV1, iters); +} +BENCHMARK_RELATIVE(seq_read_long_v2, iters) { + sequentialRead(&schemaLong, dataLongV2, iters); +} BENCHMARK_DRAW_LINE(); @@ -187,7 +203,9 @@ BENCHMARK_RELATIVE(random_read_short_v2, iters) { BENCHMARK_DRAW_LINE(); -BENCHMARK(random_read_long_v1, iters) { randomRead(&schemaLong, dataLongV1, longRandom, iters); } +BENCHMARK(random_read_long_v1, iters) { + randomRead(&schemaLong, dataLongV1, longRandom, iters); +} BENCHMARK_RELATIVE(random_read_long_v2, iters) { randomRead(&schemaLong, dataLongV2, longRandom, iters); } diff --git a/src/codec/test/RowWriterBenchmark.cpp b/src/codec/test/RowWriterBenchmark.cpp index ae35c6156ec..9e687ff7e66 100644 --- a/src/codec/test/RowWriterBenchmark.cpp +++ b/src/codec/test/RowWriterBenchmark.cpp @@ -66,15 +66,23 @@ void writeDataV2(SchemaWriter* schema, int32_t iters) { /************************* * Beginning of benchmarks ************************/ -BENCHMARK(WriteShortRowV1, iters) { writeDataV1(&schemaShort, iters); } +BENCHMARK(WriteShortRowV1, iters) { + writeDataV1(&schemaShort, iters); +} -BENCHMARK_RELATIVE(WriteShortRowV2, iters) { writeDataV2(&schemaShort, iters); } +BENCHMARK_RELATIVE(WriteShortRowV2, iters) { + writeDataV2(&schemaShort, iters); +} BENCHMARK_DRAW_LINE(); -BENCHMARK(WriteLongRowV1, iters) { writeDataV1(&schemaLong, iters); } +BENCHMARK(WriteLongRowV1, iters) { + writeDataV1(&schemaLong, iters); +} -BENCHMARK_RELATIVE(WriteLongRowV2, iters) { writeDataV2(&schemaLong, iters); } +BENCHMARK_RELATIVE(WriteLongRowV2, iters) { + writeDataV2(&schemaLong, iters); +} /************************* * End of benchmarks ************************/ diff --git a/src/codec/test/RowWriterV1.cpp b/src/codec/test/RowWriterV1.cpp index 3e9f10801a2..7448e827798 100644 --- a/src/codec/test/RowWriterV1.cpp +++ b/src/codec/test/RowWriterV1.cpp @@ -11,7 +11,9 @@ using meta::SchemaProviderIf; using meta::cpp2::Schema; using nebula::cpp2::PropertyType; -RowWriterV1::RowWriterV1(const SchemaProviderIf* schema) : schema_(schema) { CHECK(!!schema_); } +RowWriterV1::RowWriterV1(const SchemaProviderIf* schema) : schema_(schema) { + CHECK(!!schema_); +} int64_t RowWriterV1::size() const noexcept { auto offsetBytes = calcOccupiedBytes(cord_.size()); diff --git a/src/codec/test/RowWriterV1.h b/src/codec/test/RowWriterV1.h index fcb82131a51..62cc782e6cb 100644 --- a/src/codec/test/RowWriterV1.h +++ b/src/codec/test/RowWriterV1.h @@ -48,7 +48,9 @@ class RowWriterV1 { // Calculate the exact length of the encoded binary array int64_t size() const noexcept; - const meta::SchemaProviderIf* schema() const { return schema_; } + const meta::SchemaProviderIf* schema() const { + return schema_; + } // Data stream RowWriterV1& operator<<(bool v) noexcept; diff --git a/src/common/base/ConcurrentLRUCache.h b/src/common/base/ConcurrentLRUCache.h index 7893039319e..41a12e90ab6 100644 --- a/src/common/base/ConcurrentLRUCache.h +++ b/src/common/base/ConcurrentLRUCache.h @@ -58,7 +58,9 @@ class ConcurrentLRUCache final { return buckets_[bucketIndex(key, hint)].putIfAbsent(std::move(key), std::move(val)); } - void evict(const K& key, int32_t hint = -1) { buckets_[bucketIndex(key, hint)].evict(key); } + void evict(const K& key, int32_t hint = -1) { + buckets_[bucketIndex(key, hint)].evict(key); + } void clear() { for (uint32_t i = 0; i < bucketsNum_; i++) { @@ -179,13 +181,21 @@ class LRU { ~LRU() = default; - size_t size() const { return map_.size(); } + size_t size() const { + return map_.size(); + } - size_t capacity() const { return capacity_; } + size_t capacity() const { + return capacity_; + } - bool empty() const { return map_.empty(); } + bool empty() const { + return map_.empty(); + } - bool contains(const key_type& key) { return map_.find(key) != map_.end(); } + bool contains(const key_type& key) { + return map_.find(key) != map_.end(); + } void insert(key_type&& key, value_type&& value) { typename map_type::iterator it = map_.find(key); @@ -250,11 +260,17 @@ class LRU { evicts_ = 0; } - uint64_t total() { return total_; } + uint64_t total() { + return total_; + } - uint64_t hits() { return hits_; } + uint64_t hits() { + return hits_; + } - uint64_t evicts() { return evicts_; } + uint64_t evicts() { + return evicts_; + } private: void evict() { diff --git a/src/common/base/Cord.cpp b/src/common/base/Cord.cpp index c07e470fbe6..4ecf1549576 100644 --- a/src/common/base/Cord.cpp +++ b/src/common/base/Cord.cpp @@ -14,7 +14,9 @@ Cord::Cord(int32_t blockSize) blockContentSize_(blockSize_ - sizeof(char*)), blockPt_(blockContentSize_) {} -Cord::~Cord() { clear(); } +Cord::~Cord() { + clear(); +} void Cord::allocateBlock() { DCHECK_EQ(blockPt_, blockContentSize_); @@ -33,9 +35,13 @@ void Cord::allocateBlock() { } } -size_t Cord::size() const noexcept { return len_; } +size_t Cord::size() const noexcept { + return len_; +} -bool Cord::empty() const noexcept { return len_ == 0; } +bool Cord::empty() const noexcept { + return len_ == 0; +} void Cord::clear() { if (head_) { @@ -163,9 +169,13 @@ Cord& Cord::operator<<(uint64_t value) { return write(reinterpret_cast(&value), sizeof(uint64_t)); } -Cord& Cord::operator<<(char value) { return write(&value, sizeof(char)); } +Cord& Cord::operator<<(char value) { + return write(&value, sizeof(char)); +} -Cord& Cord::operator<<(bool value) { return write(reinterpret_cast(&value), sizeof(bool)); } +Cord& Cord::operator<<(bool value) { + return write(reinterpret_cast(&value), sizeof(bool)); +} Cord& Cord::operator<<(float value) { return write(reinterpret_cast(&value), sizeof(float)); @@ -175,9 +185,13 @@ Cord& Cord::operator<<(double value) { return write(reinterpret_cast(&value), sizeof(double)); } -Cord& Cord::operator<<(const std::string& value) { return write(value.data(), value.size()); } +Cord& Cord::operator<<(const std::string& value) { + return write(value.data(), value.size()); +} -Cord& Cord::operator<<(const char* value) { return write(value, strlen(value)); } +Cord& Cord::operator<<(const char* value) { + return write(value, strlen(value)); +} Cord& Cord::operator<<(const Cord& rhs) { char* next = rhs.head_; diff --git a/src/common/base/EitherOr.h b/src/common/base/EitherOr.h index 8dcb0a1c053..d832196b31a 100644 --- a/src/common/base/EitherOr.h +++ b/src/common/base/EitherOr.h @@ -116,7 +116,9 @@ class EitherOr { static constexpr State convert_to_s = TypeConverter::state; public: - virtual ~EitherOr() { destruct(); } + virtual ~EitherOr() { + destruct(); + } /*********************************************** * @@ -380,11 +382,17 @@ class EitherOr { * State check * **********************************************/ - bool isVoid() const { return state_ == State::VOID; } + bool isVoid() const { + return state_ == State::VOID; + } - bool isLeftType() const { return state_ == State::LEFT_TYPE; } + bool isLeftType() const { + return state_ == State::LEFT_TYPE; + } - bool isRightType() const { return state_ == State::RIGHT_TYPE; } + bool isRightType() const { + return state_ == State::RIGHT_TYPE; + } /*********************************************** * diff --git a/src/common/base/ICord.h b/src/common/base/ICord.h index 9a850f94191..dee5d18498f 100644 --- a/src/common/base/ICord.h +++ b/src/common/base/ICord.h @@ -16,11 +16,17 @@ class ICord { "kBlockContentSize must be power of 2"); ICord() : head_(inlineBlock_), tail_(head_) {} - virtual ~ICord() { clear(); } + virtual ~ICord() { + clear(); + } - size_t size() const noexcept { return len_; } + size_t size() const noexcept { + return len_; + } - bool empty() const noexcept { return len_ == 0; } + bool empty() const noexcept { + return len_ == 0; + } void clear() { auto alloc = next(head_); @@ -148,7 +154,9 @@ class ICord { return write(reinterpret_cast(&value), sizeof(uint64_t)); } - ICord& operator<<(char value) { return write(&value, sizeof(char)); } + ICord& operator<<(char value) { + return write(&value, sizeof(char)); + } ICord& operator<<(bool value) { return write(reinterpret_cast(&value), sizeof(bool)); @@ -166,7 +174,9 @@ class ICord { return write(value.data(), value.size()); } - ICord& operator<<(const char* value) { return write(value, strlen(value)); } + ICord& operator<<(const char* value) { + return write(value, strlen(value)); + } ICord& operator<<(const ICord& rhs) { char* n = rhs.head_; @@ -187,13 +197,19 @@ class ICord { void* operator new(std::size_t) = delete; // Is the capacity full filled - bool isFull() const { return len_ != 0 && lengthMod() == 0; } + bool isFull() const { + return len_ != 0 && lengthMod() == 0; + } // Used size in last block - std::size_t lengthMod() const { return len_ & (kBlockContentSize - 1); } + std::size_t lengthMod() const { + return len_ & (kBlockContentSize - 1); + } // Is there only inline allocation - bool isInline() const { return len_ < kBlockContentSize; } + bool isInline() const { + return len_ < kBlockContentSize; + } // return next block pointer char* next(char* p) const { diff --git a/src/common/base/MurmurHash2.h b/src/common/base/MurmurHash2.h index 8a855624b43..f9e6c6ef797 100644 --- a/src/common/base/MurmurHash2.h +++ b/src/common/base/MurmurHash2.h @@ -85,7 +85,9 @@ class MurmurHash2 { } // std::thread::id - size_t operator()(std::thread::id id) const noexcept { return std::hash()(id); } + size_t operator()(std::thread::id id) const noexcept { + return std::hash()(id); + } // literal string(without decay) template >> diff --git a/src/common/base/ObjectPool.h b/src/common/base/ObjectPool.h index 990d5f1310c..7f73e5a2c60 100644 --- a/src/common/base/ObjectPool.h +++ b/src/common/base/ObjectPool.h @@ -19,6 +19,8 @@ namespace nebula { class Expression; +typedef std::lock_guard SLGuard; + class ObjectPool final : private cpp::NonCopyable, private cpp::NonMovable { public: ObjectPool() {} @@ -26,16 +28,16 @@ class ObjectPool final : private cpp::NonCopyable, private cpp::NonMovable { ~ObjectPool() = default; void clear() { - folly::SpinLockGuard g(lock_); + SLGuard g(lock_); objects_.clear(); } template T *add(T *obj) { - if constexpr (std::is_same_v) { + if constexpr (std::is_base_of::value) { VLOG(3) << "New expression added into pool: " << obj->toString(); } - folly::SpinLockGuard g(lock_); + SLGuard g(lock_); objects_.emplace_back(obj); return obj; } @@ -45,7 +47,9 @@ class ObjectPool final : private cpp::NonCopyable, private cpp::NonMovable { return add(new T(std::forward(args)...)); } - bool empty() const { return objects_.empty(); } + bool empty() const { + return objects_.empty(); + } private: // Holder the ownership of the any object @@ -55,7 +59,9 @@ class ObjectPool final : private cpp::NonCopyable, private cpp::NonMovable { explicit OwnershipHolder(T *obj) : obj_(obj), deleteFn_([](void *p) { delete reinterpret_cast(p); }) {} - ~OwnershipHolder() { deleteFn_(obj_); } + ~OwnershipHolder() { + deleteFn_(obj_); + } private: void *obj_; diff --git a/src/common/base/SanitizerOptions.cpp b/src/common/base/SanitizerOptions.cpp index 6cd5052aab6..23720344154 100644 --- a/src/common/base/SanitizerOptions.cpp +++ b/src/common/base/SanitizerOptions.cpp @@ -56,7 +56,9 @@ const char* __lsan_default_suppressions() { } SANITIZER_HOOK_ATTRIBUTES -const char* __ubsan_default_options() { return "print_stacktrace=1 \n"; } +const char* __ubsan_default_options() { + return "print_stacktrace=1 \n"; +} } // extern "C" diff --git a/src/common/base/SignalHandler.h b/src/common/base/SignalHandler.h index 5e639d75214..3d0e699c9ac 100644 --- a/src/common/base/SignalHandler.h +++ b/src/common/base/SignalHandler.h @@ -47,9 +47,15 @@ class SignalHandler final { explicit GeneralSignalInfo(const siginfo_t *info); virtual ~GeneralSignalInfo() = default; virtual const char *toString() const; - int sig() const { return sig_; } - pid_t pid() const { return pid_; } - uid_t uid() const { return uid_; } + int sig() const { + return sig_; + } + pid_t pid() const { + return pid_; + } + uid_t uid() const { + return uid_; + } protected: int sig_{0}; diff --git a/src/common/base/Status.h b/src/common/base/Status.h index 29ee3514bce..2783cb7a70b 100644 --- a/src/common/base/Status.h +++ b/src/common/base/Status.h @@ -27,7 +27,9 @@ class Status final { ~Status() = default; - Status(const Status &rhs) { state_ = !rhs.state_ ? nullptr : copyState(rhs.state_.get()); } + Status(const Status &rhs) { + state_ = (rhs.state_ == nullptr ? nullptr : copyState(rhs.state_.get())); + } Status &operator=(const Status &rhs) { // `state_ == rhs.state_' means either `this == &rhs', @@ -38,7 +40,9 @@ class Status final { return *this; } - Status(Status &&rhs) noexcept { state_ = std::move(rhs.state_); } + Status(Status &&rhs) noexcept { + state_ = std::move(rhs.state_); + } Status &operator=(Status &&rhs) noexcept { // `state_ == rhs.state_' means either `this == &rhs', @@ -49,7 +53,9 @@ class Status final { return *this; } - static Status from(const Status &s) { return s; } + static Status from(const Status &s) { + return s; + } template static Status from(StatusOr &&s) { @@ -70,16 +76,26 @@ class Status final { return code() == rhs.code(); } - bool operator!=(const Status &rhs) const { return !(*this == rhs); } + bool operator!=(const Status &rhs) const { + return !(*this == rhs); + } - bool ok() const { return state_ == nullptr; } + bool ok() const { + return state_ == nullptr; + } - static Status OK() { return Status(); } + static Status OK() { + return Status(); + } #define STATUS_GENERATOR(ERROR) \ - static Status ERROR() { return Status(k##ERROR, ""); } \ + static Status ERROR() { \ + return Status(k##ERROR, ""); \ + } \ \ - static Status ERROR(folly::StringPiece msg) { return Status(k##ERROR, msg); } \ + static Status ERROR(folly::StringPiece msg) { \ + return Status(k##ERROR, msg); \ + } \ \ static Status ERROR(const char *fmt, ...) __attribute__((format(printf, 1, 2))) { \ va_list args; \ @@ -89,7 +105,9 @@ class Status final { return Status(k##ERROR, msg); \ } \ \ - bool is##ERROR() const { return code() == k##ERROR; } + bool is##ERROR() const { \ + return code() == k##ERROR; \ + } // Some succeeded codes STATUS_GENERATOR(Inserted); @@ -180,7 +198,9 @@ class Status final { private: // REQUIRES: stat_ != nullptr - uint16_t size() const { return reinterpret_cast(state_.get())->size_; } + uint16_t size() const { + return reinterpret_cast(state_.get())->size_; + } Status(Code code, folly::StringPiece msg); diff --git a/src/common/base/StatusOr.h b/src/common/base/StatusOr.h index 3962f34642c..05e1721e927 100644 --- a/src/common/base/StatusOr.h +++ b/src/common/base/StatusOr.h @@ -25,7 +25,9 @@ class StatusOr final { // Tell if `U' is of type `StatusOr' template struct is_status_or { - static auto sfinae(...) -> uint8_t { return 0; } + static auto sfinae(...) -> uint8_t { + return 0; + } template static auto sfinae(const StatusOr &) -> uint16_t { return 0; @@ -64,10 +66,14 @@ class StatusOr final { // in the default-constructed case. // From the semantics aspect, it must have been associated with // a Status or value eventually before being used. - StatusOr() { state_ = kVoid; } + StatusOr() { + state_ = kVoid; + } // Destruct the `Status' or value if it's holding one. - ~StatusOr() { destruct(); } + ~StatusOr() { + destruct(); + } // Copy/move construct from `Status' // Not explicit to allow construct from a `Status', e.g. in the `return' @@ -216,10 +222,14 @@ class StatusOr final { } // Tell if `*this' contains a value - bool ok() const { return hasValue(); } + bool ok() const { + return hasValue(); + } // Type conversion operator, i.e. alias of `ok()' - explicit operator bool() const { return ok(); } + explicit operator bool() const { + return ok(); + } // Return the associated `Status' if and only if it has one, // @@ -258,15 +268,25 @@ class StatusOr final { } private: - bool hasValue() const { return state_ == kValue; } + bool hasValue() const { + return state_ == kValue; + } - bool hasStatus() const { return state_ == kStatus; } + bool hasStatus() const { + return state_ == kStatus; + } - bool isVoid() const { return state_ == kVoid; } + bool isVoid() const { + return state_ == kVoid; + } - void destructValue() { variant_.value_.~T(); } + void destructValue() { + variant_.value_.~T(); + } - void destructStatus() { variant_.status_.~Status(); } + void destructStatus() { + variant_.status_.~Status(); + } void resetValue() { destructValue(); diff --git a/src/common/base/StringValue.h b/src/common/base/StringValue.h index d45b601769f..3ae23a352ce 100644 --- a/src/common/base/StringValue.h +++ b/src/common/base/StringValue.h @@ -18,9 +18,13 @@ class StringValue final { public: explicit StringValue(std::string str) : str_(std::move(str)) {} - const std::string& str() const& { return str_; } + const std::string& str() const& { + return str_; + } - std::string&& str() && { return std::move(str_); } + std::string&& str() && { + return std::move(str_); + } private: std::string str_; diff --git a/src/common/base/test/LoggingBenchmark.cpp b/src/common/base/test/LoggingBenchmark.cpp index 54547d7339b..ac63a4eae46 100644 --- a/src/common/base/test/LoggingBenchmark.cpp +++ b/src/common/base/test/LoggingBenchmark.cpp @@ -30,7 +30,9 @@ class XlogInit { public: - explicit XlogInit(folly::StringPiece config) { folly::initLogging(config); } + explicit XlogInit(folly::StringPiece config) { + folly::initLogging(config); + } }; static void xlogRegistFileHandler() { @@ -46,7 +48,9 @@ static void xlogRegistFileHandler() { * **************************/ #include -void loggingUsingGlog(int64_t iters) { LOG_SOMETHING(iters); } +void loggingUsingGlog(int64_t iters) { + LOG_SOMETHING(iters); +} /*************************** * @@ -54,10 +58,14 @@ void loggingUsingGlog(int64_t iters) { LOG_SOMETHING(iters); } * **************************/ #include "common/base/Logging.h" -void loggingOptimized(int64_t iters) { LOG_SOMETHING(iters); } +void loggingOptimized(int64_t iters) { + LOG_SOMETHING(iters); +} #include -void loggingUsingXlog(int64_t iters) { XLOG_SOMETHING(iters); } +void loggingUsingXlog(int64_t iters) { + XLOG_SOMETHING(iters); +} /*************************** * @@ -75,7 +83,9 @@ BENCHMARK_RELATIVE(optimized_output_logs, iters) { } BENCHMARK_RELATIVE(xlog_output_logs, iters) { - BENCHMARK_SUSPEND { static XlogInit init(".=INFO:default"); } + BENCHMARK_SUSPEND { + static XlogInit init(".=INFO:default"); + } loggingUsingXlog(iters); } @@ -99,7 +109,9 @@ BENCHMARK_RELATIVE(optimized_skip_logs, iters) { } BENCHMARK_RELATIVE(xlog_skip_logs, iters) { - BENCHMARK_SUSPEND { static XlogInit init(".=WARN:default"); } + BENCHMARK_SUSPEND { + static XlogInit init(".=WARN:default"); + } loggingUsingXlog(iters); } /*************************** diff --git a/src/common/base/test/ObjectPoolTest.cpp b/src/common/base/test/ObjectPoolTest.cpp index 1b19651df6c..a98a6064cc6 100644 --- a/src/common/base/test/ObjectPoolTest.cpp +++ b/src/common/base/test/ObjectPoolTest.cpp @@ -13,8 +13,12 @@ static int instances = 0; class MyClass { public: - MyClass() { instances++; } - ~MyClass() { instances--; } + MyClass() { + instances++; + } + ~MyClass() { + instances--; + } }; TEST(ObjectPoolTest, TestPooling) { diff --git a/src/common/base/test/RangeVsTransformBenchmark.cpp b/src/common/base/test/RangeVsTransformBenchmark.cpp index f28333a772e..288e5d5e222 100644 --- a/src/common/base/test/RangeVsTransformBenchmark.cpp +++ b/src/common/base/test/RangeVsTransformBenchmark.cpp @@ -63,7 +63,9 @@ BENCHMARK_DRAW_LINE(); BENCHMARK(Test3_RangeTestInt) { std::vector v; - BENCHMARK_SUSPEND { v.resize(1000, 0); } + BENCHMARK_SUSPEND { + v.resize(1000, 0); + } for (auto& i : v) { (void)(i); int a{0}; @@ -73,7 +75,9 @@ BENCHMARK(Test3_RangeTestInt) { BENCHMARK_RELATIVE(Test3_ForEachInt) { std::vector v; - BENCHMARK_SUSPEND { v.resize(1000, 0); } + BENCHMARK_SUSPEND { + v.resize(1000, 0); + } std::for_each(v.begin(), v.end(), [](const auto&) { int a{0}; folly::doNotOptimizeAway(a); diff --git a/src/common/charset/Charset.h b/src/common/charset/Charset.h index dd3c5bdc1c4..1a0d4fa6ec5 100644 --- a/src/common/charset/Charset.h +++ b/src/common/charset/Charset.h @@ -59,10 +59,14 @@ class CharsetInfo final { /** * Get all supported charsets description information */ - std::unordered_map getCharsetDesc() { return charsetDesc_; } + std::unordered_map getCharsetDesc() { + return charsetDesc_; + } private: - CharsetInfo() { charsetDesc_["utf8"] = {"utf8", "utf8_bin", {"utf8_bin"}, "UTF-8 Unicode", 4}; } + CharsetInfo() { + charsetDesc_["utf8"] = {"utf8", "utf8_bin", {"utf8_bin"}, "UTF-8 Unicode", 4}; + } /** * List of supported charsets diff --git a/src/common/concurrent/Latch.cpp b/src/common/concurrent/Latch.cpp index 98d2d5f151b..57e99ed96ed 100644 --- a/src/common/concurrent/Latch.cpp +++ b/src/common/concurrent/Latch.cpp @@ -44,7 +44,9 @@ void Latch::wait() { cond_.wait(unique, [this]() { return counter_ == 0; }); } -bool Latch::isReady() { return counter_ == 0; } +bool Latch::isReady() { + return counter_ == 0; +} } // namespace concurrent } // namespace nebula diff --git a/src/common/datatypes/DataSet.h b/src/common/datatypes/DataSet.h index 49559736376..083958dfcbf 100644 --- a/src/common/datatypes/DataSet.h +++ b/src/common/datatypes/DataSet.h @@ -49,9 +49,13 @@ struct DataSet { return *this; } - const std::vector& keys() const { return colNames; } + const std::vector& keys() const { + return colNames; + } - const std::vector& rowValues(std::size_t index) const { return rows[index].values; } + const std::vector& rowValues(std::size_t index) const { + return rows[index].values; + } std::vector colValues(const std::string& colName) const { std::vector col; @@ -70,13 +74,21 @@ struct DataSet { using iterator = std::vector::iterator; using const_iterator = std::vector::const_iterator; - iterator begin() { return rows.begin(); } + iterator begin() { + return rows.begin(); + } - const_iterator begin() const { return rows.begin(); } + const_iterator begin() const { + return rows.begin(); + } - iterator end() { return rows.end(); } + iterator end() { + return rows.end(); + } - const_iterator end() const { return rows.end(); } + const_iterator end() const { + return rows.end(); + } template ::value, T>::type> @@ -127,13 +139,21 @@ struct DataSet { rows.clear(); } - void __clear() { clear(); } + void __clear() { + clear(); + } - std::size_t size() const { return rowSize(); } + std::size_t size() const { + return rowSize(); + } - std::size_t rowSize() const { return rows.size(); } + std::size_t rowSize() const { + return rows.size(); + } - std::size_t colSize() const { return colNames.size(); } + std::size_t colSize() const { + return colNames.size(); + } std::string toString() const { std::stringstream os; @@ -192,10 +212,14 @@ struct DataSet { return rowJsonObj; } - bool operator==(const DataSet& rhs) const { return colNames == rhs.colNames && rows == rhs.rows; } + bool operator==(const DataSet& rhs) const { + return colNames == rhs.colNames && rows == rhs.rows; + } }; -inline std::ostream& operator<<(std::ostream& os, const DataSet& d) { return os << d.toString(); } +inline std::ostream& operator<<(std::ostream& os, const DataSet& d) { + return os << d.toString(); +} } // namespace nebula #endif // COMMON_DATATYPES_DATASET_H_ diff --git a/src/common/datatypes/Date.cpp b/src/common/datatypes/Date.cpp index bc573962b35..ff1908b44ec 100644 --- a/src/common/datatypes/Date.cpp +++ b/src/common/datatypes/Date.cpp @@ -25,7 +25,9 @@ int8_t dayOfMonth(int16_t year, int8_t month) { : kDaysSoFar[month] - kDaysSoFar[month - 1]; } -Date::Date(uint64_t days) { fromInt(days); } +Date::Date(uint64_t days) { + fromInt(days); +} int64_t Date::toInt() const { // Year @@ -144,7 +146,9 @@ void Date::addDuration(const Duration& duration) { day = tmp; } -void Date::subDuration(const Duration& duration) { return addDuration(-duration); } +void Date::subDuration(const Duration& duration) { + return addDuration(-duration); +} std::string Date::toString() const { // It's in current timezone already @@ -202,7 +206,9 @@ void Time::addDuration(const Duration& duration) { } } -void Time::subDuration(const Duration& duration) { addDuration(-duration); } +void Time::subDuration(const Duration& duration) { + addDuration(-duration); +} std::string Time::toString() const { auto microsecStr = folly::stringPrintf("%.9f", static_cast(microsec) / 1000000.0); @@ -320,7 +326,9 @@ void DateTime::addDuration(const Duration& duration) { day = tmp; } -void DateTime::subDuration(const Duration& duration) { return addDuration(-duration); } +void DateTime::subDuration(const Duration& duration) { + return addDuration(-duration); +} std::string DateTime::toString() const { auto microsecStr = folly::stringPrintf("%.9f", static_cast(microsec) / 1000000.0); diff --git a/src/common/datatypes/Date.h b/src/common/datatypes/Date.h index 0e86018777b..baefd070464 100644 --- a/src/common/datatypes/Date.h +++ b/src/common/datatypes/Date.h @@ -51,7 +51,9 @@ struct Date { day = 1; } - void __clear() { clear(); } + void __clear() { + clear(); + } void reset(int16_t y, int8_t m, int8_t d) { year = y; @@ -83,7 +85,9 @@ struct Date { void subDuration(const Duration& duration); std::string toString() const; - folly::dynamic toJson() const { return toString(); } + folly::dynamic toJson() const { + return toString(); + } // Return the number of days since -32768/1/1 int64_t toInt() const; @@ -124,7 +128,9 @@ struct Time { microsec = 0; } - void __clear() { clear(); } + void __clear() { + clear(); + } bool operator==(const Time& rhs) const { return hour == rhs.hour && minute == rhs.minute && sec == rhs.sec && microsec == rhs.microsec; @@ -151,7 +157,9 @@ struct Time { std::string toString() const; // 'Z' representing UTC timezone - folly::dynamic toJson() const { return toString() + "Z"; } + folly::dynamic toJson() const { + return toString() + "Z"; + } }; inline std::ostream& operator<<(std::ostream& os, const Time& d) { @@ -221,9 +229,13 @@ struct DateTime { microsec = time.microsec; } - Date date() const { return Date(year, month, day); } + Date date() const { + return Date(year, month, day); + } - Time time() const { return Time(hour, minute, sec, microsec); } + Time time() const { + return Time(hour, minute, sec, microsec); + } void clear() { year = 0; @@ -235,7 +247,9 @@ struct DateTime { microsec = 0; } - void __clear() { clear(); } + void __clear() { + clear(); + } bool operator==(const DateTime& rhs) const { return year == rhs.year && month == rhs.month && day == rhs.day && hour == rhs.hour && @@ -271,7 +285,9 @@ struct DateTime { std::string toString() const; // 'Z' representing UTC timezone - folly::dynamic toJson() const { return toString() + "Z"; } + folly::dynamic toJson() const { + return toString() + "Z"; + } }; inline std::ostream& operator<<(std::ostream& os, const DateTime& d) { diff --git a/src/common/datatypes/Duration.h b/src/common/datatypes/Duration.h index b918b84b1aa..730ab1b324d 100644 --- a/src/common/datatypes/Duration.h +++ b/src/common/datatypes/Duration.h @@ -26,21 +26,37 @@ struct Duration { Duration() : seconds(0), microseconds(0), months(0) {} Duration(int32_t m, int64_t s, int32_t us) : seconds(s), microseconds(us), months(m) {} - int64_t years() const { return months / 12; } + int64_t years() const { + return months / 12; + } - int64_t monthsInYear() const { return months % 12; } + int64_t monthsInYear() const { + return months % 12; + } - int64_t days() const { return seconds / time::kSecondsOfDay; } + int64_t days() const { + return seconds / time::kSecondsOfDay; + } - int64_t hours() const { return seconds % time::kSecondsOfDay / time::kSecondsOfHour; } + int64_t hours() const { + return seconds % time::kSecondsOfDay / time::kSecondsOfHour; + } - int64_t minutes() const { return seconds % time::kSecondsOfHour / time::kSecondsOfMinute; } + int64_t minutes() const { + return seconds % time::kSecondsOfHour / time::kSecondsOfMinute; + } - int64_t secondsInMinute() const { return seconds % time::kSecondsOfMinute; } + int64_t secondsInMinute() const { + return seconds % time::kSecondsOfMinute; + } - int64_t microsecondsInSecond() const { return microseconds; } + int64_t microsecondsInSecond() const { + return microseconds; + } - Duration operator-() const { return Duration(-months, -seconds, -microseconds); } + Duration operator-() const { + return Duration(-months, -seconds, -microseconds); + } Duration operator+(const Duration& rhs) const { return Duration(months + rhs.months, seconds + rhs.seconds, microseconds + rhs.microseconds); @@ -115,7 +131,9 @@ struct Duration { return ss.str(); } - folly::dynamic toJson() const { return toString(); } + folly::dynamic toJson() const { + return toString(); + } }; } // namespace nebula diff --git a/src/common/datatypes/Edge.h b/src/common/datatypes/Edge.h index 5fe10af251b..b44772bda7b 100644 --- a/src/common/datatypes/Edge.h +++ b/src/common/datatypes/Edge.h @@ -46,7 +46,9 @@ struct Edge { void clear(); - void __clear() { clear(); } + void __clear() { + clear(); + } std::string toString() const; folly::dynamic toJson() const; @@ -72,7 +74,9 @@ struct Edge { bool keyEqual(const Edge& rhs) const; }; -inline std::ostream& operator<<(std::ostream& os, const Edge& v) { return os << v.toString(); } +inline std::ostream& operator<<(std::ostream& os, const Edge& v) { + return os << v.toString(); +} } // namespace nebula diff --git a/src/common/datatypes/Geography.cpp b/src/common/datatypes/Geography.cpp index 664c4326d66..6336e978863 100644 --- a/src/common/datatypes/Geography.cpp +++ b/src/common/datatypes/Geography.cpp @@ -64,9 +64,13 @@ bool Coordinate::isValid() const { void Point::normalize() {} -bool Point::isValid() const { return coord.isValid(); } +bool Point::isValid() const { + return coord.isValid(); +} -void LineString::normalize() { geo::GeoUtils::removeAdjacentDuplicateCoordinates(coordList); } +void LineString::normalize() { + geo::GeoUtils::removeAdjacentDuplicateCoordinates(coordList); +} bool LineString::isValid() const { // LineString must have at least 2 coordinates; @@ -267,11 +271,17 @@ Point Geography::centroid() const { } } -std::string Geography::asWKT() const { return geo::WKTWriter().write(*this); } +std::string Geography::asWKT() const { + return geo::WKTWriter().write(*this); +} -std::string Geography::asWKB() const { return geo::WKBWriter().write(*this); } +std::string Geography::asWKB() const { + return geo::WKBWriter().write(*this); +} -std::string Geography::asWKBHex() const { return folly::hexlify(geo::WKBWriter().write(*this)); } +std::string Geography::asWKBHex() const { + return folly::hexlify(geo::WKBWriter().write(*this)); +} std::unique_ptr Geography::asS2() const { return geo::GeoUtils::s2RegionFromGeography(*this); diff --git a/src/common/datatypes/Geography.h b/src/common/datatypes/Geography.h index cea5bd9c82e..f3d05cb41c3 100644 --- a/src/common/datatypes/Geography.h +++ b/src/common/datatypes/Geography.h @@ -57,12 +57,16 @@ struct Coordinate { x = 0.0; y = 0.0; } - void __clear() { clear(); } + void __clear() { + clear(); + } bool operator==(const Coordinate& rhs) const { return std::abs(x - rhs.x) < kEpsilon && std::abs(y - rhs.y) < kEpsilon; } - bool operator!=(const Coordinate& rhs) const { return !(*this == rhs); } + bool operator!=(const Coordinate& rhs) const { + return !(*this == rhs); + } bool operator<(const Coordinate& rhs) const { if (x != rhs.x) { return x < rhs.x; @@ -84,11 +88,19 @@ struct Point { void normalize(); bool isValid() const; - void clear() { coord.clear(); } - void __clear() { clear(); } + void clear() { + coord.clear(); + } + void __clear() { + clear(); + } - bool operator==(const Point& rhs) const { return coord == rhs.coord; } - bool operator<(const Point& rhs) const { return coord < rhs.coord; } + bool operator==(const Point& rhs) const { + return coord == rhs.coord; + } + bool operator<(const Point& rhs) const { + return coord < rhs.coord; + } }; struct LineString { @@ -98,16 +110,26 @@ struct LineString { explicit LineString(const std::vector& v) : coordList(v) {} explicit LineString(std::vector&& v) : coordList(std::move(v)) {} - uint32_t numCoord() const { return coordList.size(); } + uint32_t numCoord() const { + return coordList.size(); + } void normalize(); bool isValid() const; - void clear() { coordList.clear(); } - void __clear() { clear(); } + void clear() { + coordList.clear(); + } + void __clear() { + clear(); + } - bool operator==(const LineString& rhs) const { return coordList == rhs.coordList; } - bool operator<(const LineString& rhs) const { return coordList < rhs.coordList; } + bool operator==(const LineString& rhs) const { + return coordList == rhs.coordList; + } + bool operator<(const LineString& rhs) const { + return coordList < rhs.coordList; + } }; struct Polygon { @@ -117,16 +139,26 @@ struct Polygon { explicit Polygon(const std::vector>& v) : coordListList(v) {} explicit Polygon(std::vector>&& v) : coordListList(std::move(v)) {} - uint32_t numCoordList() const { return coordListList.size(); } + uint32_t numCoordList() const { + return coordListList.size(); + } void normalize(); bool isValid() const; - void clear() { coordListList.clear(); } - void __clear() { clear(); } + void clear() { + coordListList.clear(); + } + void __clear() { + clear(); + } - bool operator==(const Polygon& rhs) const { return coordListList == rhs.coordListList; } - bool operator<(const Polygon& rhs) const { return coordListList < rhs.coordListList; } + bool operator==(const Polygon& rhs) const { + return coordListList == rhs.coordListList; + } + bool operator<(const Polygon& rhs) const { + return coordListList < rhs.coordListList; + } }; struct Geography { @@ -172,19 +204,29 @@ struct Geography { std::unique_ptr asS2() const; - std::string toString() const { return asWKT(); } + std::string toString() const { + return asWKT(); + } - folly::dynamic toJson() const { return toString(); } + folly::dynamic toJson() const { + return toString(); + } - void clear() { geo_.~variant(); } + void clear() { + geo_.~variant(); + } - void __clear() { clear(); } + void __clear() { + clear(); + } bool operator==(const Geography& rhs) const; bool operator<(const Geography& rhs) const; }; -inline std::ostream& operator<<(std::ostream& os, const Geography& g) { return os << g.toString(); } +inline std::ostream& operator<<(std::ostream& os, const Geography& g) { + return os << g.toString(); +} } // namespace nebula diff --git a/src/common/datatypes/HostAddr.cpp b/src/common/datatypes/HostAddr.cpp index 930ef89395c..5d32d73539d 100644 --- a/src/common/datatypes/HostAddr.cpp +++ b/src/common/datatypes/HostAddr.cpp @@ -15,7 +15,9 @@ bool HostAddr::operator==(const HostAddr& rhs) const { return host == rhs.host && port == rhs.port; } -bool HostAddr::operator!=(const HostAddr& rhs) const { return !(*this == rhs); } +bool HostAddr::operator!=(const HostAddr& rhs) const { + return !(*this == rhs); +} HostAddr& HostAddr::operator=(const HostAddr& rhs) { host = rhs.host; diff --git a/src/common/datatypes/HostAddr.h b/src/common/datatypes/HostAddr.h index 69316691191..16cfe542db0 100644 --- a/src/common/datatypes/HostAddr.h +++ b/src/common/datatypes/HostAddr.h @@ -34,7 +34,9 @@ struct HostAddr { port = 0; } - void __clear() { clear(); } + void __clear() { + clear(); + } std::string toString() const { std::stringstream os; diff --git a/src/common/datatypes/KeyValue.h b/src/common/datatypes/KeyValue.h index 26d562b5a9f..a9cd39eca12 100644 --- a/src/common/datatypes/KeyValue.h +++ b/src/common/datatypes/KeyValue.h @@ -23,7 +23,21 @@ struct KeyValue { value.clear(); } - void __clear() { clear(); } + void __clear() { + clear(); + } + + auto& operator=(const KeyValue& rhs) { + this->key = rhs.key; + this->value = rhs.value; + return *this; + } + + auto& operator=(KeyValue&& rhs) { + this->key = std::move(rhs.key); + this->value = std::move(rhs.value); + return *this; + } bool operator==(const KeyValue& rhs) const { if (key != rhs.key) { diff --git a/src/common/datatypes/List.h b/src/common/datatypes/List.h index 259034b5a1c..b8056f6c58a 100644 --- a/src/common/datatypes/List.h +++ b/src/common/datatypes/List.h @@ -19,12 +19,18 @@ struct List { List() = default; List(const List&) = default; List(List&&) noexcept = default; - explicit List(std::vector&& vals) { values = std::move(vals); } + explicit List(std::vector&& vals) { + values = std::move(vals); + } explicit List(const std::vector& l) : values(l) {} - bool empty() const { return values.empty(); } + bool empty() const { + return values.empty(); + } - void reserve(std::size_t n) { values.reserve(n); } + void reserve(std::size_t n) { + values.reserve(n); + } template ::value>::type> @@ -32,9 +38,13 @@ struct List { values.emplace_back(std::forward(v)); } - void clear() { values.clear(); } + void clear() { + values.clear(); + } - void __clear() { clear(); } + void __clear() { + clear(); + } List& operator=(const List& rhs) { if (this == &rhs) { @@ -51,17 +61,25 @@ struct List { return *this; } - bool operator==(const List& rhs) const { return values == rhs.values; } + bool operator==(const List& rhs) const { + return values == rhs.values; + } - bool operator<(const List& rhs) const { return values < rhs.values; } + bool operator<(const List& rhs) const { + return values < rhs.values; + } - const Value& operator[](size_t i) const { return values[i]; } + const Value& operator[](size_t i) const { + return values[i]; + } bool contains(const Value& value) const { return std::find(values.begin(), values.end(), value) != values.end(); } - size_t size() const { return values.size(); } + size_t size() const { + return values.size(); + } std::string toString() const; folly::dynamic toJson() const; @@ -69,7 +87,9 @@ struct List { folly::dynamic getMetaData() const; }; -inline std::ostream& operator<<(std::ostream& os, const List& l) { return os << l.toString(); } +inline std::ostream& operator<<(std::ostream& os, const List& l) { + return os << l.toString(); +} } // namespace nebula diff --git a/src/common/datatypes/Map.h b/src/common/datatypes/Map.h index 51b1e4f04c4..26c370baa45 100644 --- a/src/common/datatypes/Map.h +++ b/src/common/datatypes/Map.h @@ -18,7 +18,9 @@ struct Map { Map() = default; Map(const Map&) = default; Map(Map&&) noexcept = default; - explicit Map(std::unordered_map values) { kvs = std::move(values); } + explicit Map(std::unordered_map values) { + kvs = std::move(values); + } Map& operator=(const Map& rhs) { if (this == &rhs) { @@ -35,9 +37,13 @@ struct Map { return *this; } - void clear() { kvs.clear(); } + void clear() { + kvs.clear(); + } - void __clear() { clear(); } + void __clear() { + clear(); + } // the configs of rocksdb will use the interface, so the value need modify to // string @@ -46,7 +52,9 @@ struct Map { // Extract the metadata of the value of each kv pair folly::dynamic getMetaData() const; - bool operator==(const Map& rhs) const { return kvs == rhs.kvs; } + bool operator==(const Map& rhs) const { + return kvs == rhs.kvs; + } bool contains(const Value& value) const { if (!value.isStr()) { @@ -63,10 +71,14 @@ struct Map { return iter->second; } - size_t size() const { return kvs.size(); } + size_t size() const { + return kvs.size(); + } }; -inline std::ostream& operator<<(std::ostream& os, const Map& m) { return os << m.toString(); } +inline std::ostream& operator<<(std::ostream& os, const Map& m) { + return os << m.toString(); +} } // namespace nebula diff --git a/src/common/datatypes/Path.h b/src/common/datatypes/Path.h index ed1f9ea11d3..f0ac650b2f4 100644 --- a/src/common/datatypes/Path.h +++ b/src/common/datatypes/Path.h @@ -43,7 +43,9 @@ struct Step { props.clear(); } - void __clear() { clear(); } + void __clear() { + clear(); + } std::string toString() const { std::stringstream os; @@ -116,7 +118,9 @@ struct Path { steps.clear(); } - void __clear() { clear(); } + void __clear() { + clear(); + } std::string toString() const { std::stringstream os; @@ -194,9 +198,13 @@ struct Path { return *this; } - bool operator==(const Path& rhs) const { return src == rhs.src && steps == rhs.steps; } + bool operator==(const Path& rhs) const { + return src == rhs.src && steps == rhs.steps; + } - void addStep(Step step) { steps.emplace_back(std::move(step)); } + void addStep(Step step) { + steps.emplace_back(std::move(step)); + } void reverse(); @@ -224,7 +232,9 @@ inline void swap(Step& a, Step& b) { b = std::move(tmp); } -inline std::ostream& operator<<(std::ostream& os, const Path& p) { return os << p.toString(); } +inline std::ostream& operator<<(std::ostream& os, const Path& p) { + return os << p.toString(); +} } // namespace nebula diff --git a/src/common/datatypes/Set.h b/src/common/datatypes/Set.h index eaf217a9211..107cf3aee5f 100644 --- a/src/common/datatypes/Set.h +++ b/src/common/datatypes/Set.h @@ -18,11 +18,17 @@ struct Set { Set() = default; Set(const Set&) = default; Set(Set&&) noexcept = default; - explicit Set(std::unordered_set value) { values = std::move(value); } + explicit Set(std::unordered_set value) { + values = std::move(value); + } - void clear() { values.clear(); } + void clear() { + values.clear(); + } - void __clear() { clear(); } + void __clear() { + clear(); + } std::string toString() const; folly::dynamic toJson() const; @@ -45,14 +51,22 @@ struct Set { return *this; } - bool operator==(const Set& rhs) const { return values == rhs.values; } + bool operator==(const Set& rhs) const { + return values == rhs.values; + } - bool contains(const Value& value) const { return values.count(value) != 0; } + bool contains(const Value& value) const { + return values.count(value) != 0; + } - size_t size() const { return values.size(); } + size_t size() const { + return values.size(); + } }; -inline std::ostream& operator<<(std::ostream& os, const Set& s) { return os << s.toString(); } +inline std::ostream& operator<<(std::ostream& os, const Set& s) { + return os << s.toString(); +} } // namespace nebula namespace std { diff --git a/src/common/datatypes/Value.cpp b/src/common/datatypes/Value.cpp index 5ca1e2efafe..176accf42c4 100644 --- a/src/common/datatypes/Value.cpp +++ b/src/common/datatypes/Value.cpp @@ -269,99 +269,173 @@ Value::Value(const Value& rhs) : type_(Value::Type::__EMPTY__) { } } -Value::Value(const NullType& v) { setN(v); } +Value::Value(const NullType& v) { + setN(v); +} -Value::Value(NullType&& v) { setN(std::move(v)); } +Value::Value(NullType&& v) { + setN(std::move(v)); +} -Value::Value(const bool& v) { setB(v); } +Value::Value(const bool& v) { + setB(v); +} -Value::Value(bool&& v) { setB(std::move(v)); } +Value::Value(bool&& v) { + setB(std::move(v)); +} -Value::Value(const int8_t& v) { setI(v); } +Value::Value(const int8_t& v) { + setI(v); +} -Value::Value(int8_t&& v) { setI(std::move(v)); } +Value::Value(int8_t&& v) { + setI(std::move(v)); +} -Value::Value(const int16_t& v) { setI(v); } +Value::Value(const int16_t& v) { + setI(v); +} -Value::Value(int16_t&& v) { setI(std::move(v)); } +Value::Value(int16_t&& v) { + setI(std::move(v)); +} -Value::Value(const int32_t& v) { setI(v); } +Value::Value(const int32_t& v) { + setI(v); +} -Value::Value(int32_t&& v) { setI(std::move(v)); } +Value::Value(int32_t&& v) { + setI(std::move(v)); +} -Value::Value(const int64_t& v) { setI(v); } +Value::Value(const int64_t& v) { + setI(v); +} -Value::Value(int64_t&& v) { setI(std::move(v)); } +Value::Value(int64_t&& v) { + setI(std::move(v)); +} -Value::Value(const double& v) { setF(v); } +Value::Value(const double& v) { + setF(v); +} -Value::Value(double&& v) { setF(std::move(v)); } +Value::Value(double&& v) { + setF(std::move(v)); +} -Value::Value(const std::string& v) { setS(v); } +Value::Value(const std::string& v) { + setS(v); +} -Value::Value(std::string&& v) { setS(std::move(v)); } +Value::Value(std::string&& v) { + setS(std::move(v)); +} -Value::Value(const char* v) { setS(v); } +Value::Value(const char* v) { + setS(v); +} -Value::Value(const Date& v) { setD(v); } +Value::Value(const Date& v) { + setD(v); +} -Value::Value(Date&& v) { setD(std::move(v)); } +Value::Value(Date&& v) { + setD(std::move(v)); +} -Value::Value(const Time& v) { setT(v); } +Value::Value(const Time& v) { + setT(v); +} -Value::Value(Time&& v) { setT(std::move(v)); } +Value::Value(Time&& v) { + setT(std::move(v)); +} -Value::Value(const DateTime& v) { setDT(v); } +Value::Value(const DateTime& v) { + setDT(v); +} -Value::Value(DateTime&& v) { setDT(std::move(v)); } +Value::Value(DateTime&& v) { + setDT(std::move(v)); +} -Value::Value(const Vertex& v) { setV(v); } +Value::Value(const Vertex& v) { + setV(v); +} -Value::Value(Vertex&& v) { setV(std::move(v)); } +Value::Value(Vertex&& v) { + setV(std::move(v)); +} -Value::Value(const Edge& v) { setE(v); } +Value::Value(const Edge& v) { + setE(v); +} -Value::Value(Edge&& v) { setE(std::move(v)); } +Value::Value(Edge&& v) { + setE(std::move(v)); +} -Value::Value(const Path& v) { setP(v); } +Value::Value(const Path& v) { + setP(v); +} -Value::Value(Path&& v) { setP(std::move(v)); } +Value::Value(Path&& v) { + setP(std::move(v)); +} Value::Value(const List& v) { auto c = std::make_unique(v); setL(std::move(c)); } -Value::Value(List&& v) { setL(std::make_unique(std::move(v))); } +Value::Value(List&& v) { + setL(std::make_unique(std::move(v))); +} Value::Value(const Map& v) { auto c = std::make_unique(v); setM(std::move(c)); } -Value::Value(Map&& v) { setM(std::make_unique(std::move(v))); } +Value::Value(Map&& v) { + setM(std::make_unique(std::move(v))); +} Value::Value(const Set& v) { auto c = std::make_unique(v); setU(std::move(c)); } -Value::Value(Set&& v) { setU(std::make_unique(std::move(v))); } +Value::Value(Set&& v) { + setU(std::make_unique(std::move(v))); +} Value::Value(const DataSet& v) { auto c = std::make_unique(v); setG(std::move(c)); } -Value::Value(DataSet&& v) { setG(std::make_unique(std::move(v))); } +Value::Value(DataSet&& v) { + setG(std::make_unique(std::move(v))); +} -Value::Value(const Geography& v) { setGG(std::make_unique(v)); } +Value::Value(const Geography& v) { + setGG(std::make_unique(v)); +} -Value::Value(Geography&& v) { setGG(std::make_unique(std::move(v))); } +Value::Value(Geography&& v) { + setGG(std::make_unique(std::move(v))); +} -Value::Value(const Duration& v) { setDU(std::make_unique(v)); } +Value::Value(const Duration& v) { + setDU(std::make_unique(v)); +} -Value::Value(Duration&& v) { setDU(std::make_unique(std::move(v))); } +Value::Value(Duration&& v) { + setDU(std::make_unique(std::move(v))); +} const std::string& Value::typeName() const { static const std::unordered_map typeNames = { @@ -2865,13 +2939,21 @@ bool operator==(const Value& lhs, const Value& rhs) { return false; } -bool operator!=(const Value& lhs, const Value& rhs) { return !(lhs == rhs); } +bool operator!=(const Value& lhs, const Value& rhs) { + return !(lhs == rhs); +} -bool operator>(const Value& lhs, const Value& rhs) { return rhs < lhs; } +bool operator>(const Value& lhs, const Value& rhs) { + return rhs < lhs; +} -bool operator<=(const Value& lhs, const Value& rhs) { return !(rhs < lhs); } +bool operator<=(const Value& lhs, const Value& rhs) { + return !(rhs < lhs); +} -bool operator>=(const Value& lhs, const Value& rhs) { return !(lhs < rhs); } +bool operator>=(const Value& lhs, const Value& rhs) { + return !(lhs < rhs); +} Value operator&&(const Value& lhs, const Value& rhs) { if (lhs.isNull()) { diff --git a/src/common/datatypes/Value.h b/src/common/datatypes/Value.h index a3e5429af26..74d09718012 100644 --- a/src/common/datatypes/Value.h +++ b/src/common/datatypes/Value.h @@ -134,14 +134,22 @@ struct Value { Value(Geography&& v); // NOLINT Value(const Duration& v); // NOLINT Value(Duration&& v); // NOLINT - ~Value() { clear(); } + ~Value() { + clear(); + } - Type type() const noexcept { return type_; } + Type type() const noexcept { + return type_; + } const std::string& typeName() const; - bool empty() const { return type_ == Type::__EMPTY__; } - bool isNull() const { return type_ == Type::NULLVALUE; } + bool empty() const { + return type_ == Type::__EMPTY__; + } + bool isNull() const { + return type_ == Type::NULLVALUE; + } bool isBadNull() const { if (!isNull()) { return false; @@ -151,27 +159,63 @@ struct Value { null == NullType::ERR_OVERFLOW || null == NullType::UNKNOWN_PROP || null == NullType::DIV_BY_ZERO || null == NullType::OUT_OF_RANGE; } - bool isNumeric() const { return type_ == Type::INT || type_ == Type::FLOAT; } - bool isBool() const { return type_ == Type::BOOL; } - bool isInt() const { return type_ == Type::INT; } - bool isFloat() const { return type_ == Type::FLOAT; } - bool isStr() const { return type_ == Type::STRING; } - bool isDate() const { return type_ == Type::DATE; } - bool isTime() const { return type_ == Type::TIME; } - bool isDateTime() const { return type_ == Type::DATETIME; } - bool isVertex() const { return type_ == Type::VERTEX; } - bool isEdge() const { return type_ == Type::EDGE; } - bool isPath() const { return type_ == Type::PATH; } - bool isList() const { return type_ == Type::LIST; } - bool isMap() const { return type_ == Type::MAP; } - bool isSet() const { return type_ == Type::SET; } - bool isDataSet() const { return type_ == Type::DATASET; } - bool isGeography() const { return type_ == Type::GEOGRAPHY; } - bool isDuration() const { return type_ == Type::DURATION; } + bool isNumeric() const { + return type_ == Type::INT || type_ == Type::FLOAT; + } + bool isBool() const { + return type_ == Type::BOOL; + } + bool isInt() const { + return type_ == Type::INT; + } + bool isFloat() const { + return type_ == Type::FLOAT; + } + bool isStr() const { + return type_ == Type::STRING; + } + bool isDate() const { + return type_ == Type::DATE; + } + bool isTime() const { + return type_ == Type::TIME; + } + bool isDateTime() const { + return type_ == Type::DATETIME; + } + bool isVertex() const { + return type_ == Type::VERTEX; + } + bool isEdge() const { + return type_ == Type::EDGE; + } + bool isPath() const { + return type_ == Type::PATH; + } + bool isList() const { + return type_ == Type::LIST; + } + bool isMap() const { + return type_ == Type::MAP; + } + bool isSet() const { + return type_ == Type::SET; + } + bool isDataSet() const { + return type_ == Type::DATASET; + } + bool isGeography() const { + return type_ == Type::GEOGRAPHY; + } + bool isDuration() const { + return type_ == Type::DURATION; + } void clear(); - void __clear() { clear(); } + void __clear() { + clear(); + } Value& operator=(Value&& rhs) noexcept; Value& operator=(const Value& rhs); @@ -290,7 +334,9 @@ struct Value { Geography& mutableGeography(); Duration& mutableDuration(); - static const Value& null() noexcept { return kNullValue; } + static const Value& null() noexcept { + return kNullValue; + } std::string toString() const; folly::dynamic toJson() const; diff --git a/src/common/datatypes/Vertex.h b/src/common/datatypes/Vertex.h index 48bcb009bb2..1239121b7bb 100644 --- a/src/common/datatypes/Vertex.h +++ b/src/common/datatypes/Vertex.h @@ -30,7 +30,9 @@ struct Tag { props.clear(); } - void __clear() { clear(); } + void __clear() { + clear(); + } std::string toString() const; folly::dynamic toJson() const; @@ -51,7 +53,9 @@ struct Tag { return *this; } - bool operator==(const Tag& rhs) const { return name == rhs.name && props == rhs.props; } + bool operator==(const Tag& rhs) const { + return name == rhs.name && props == rhs.props; + } }; struct Vertex { @@ -68,7 +72,9 @@ struct Vertex { tags.clear(); } - void __clear() { clear(); } + void __clear() { + clear(); + } std::string toString() const; folly::dynamic toJson() const; @@ -79,7 +85,9 @@ struct Vertex { Vertex& operator=(const Vertex& rhs); - bool operator==(const Vertex& rhs) const { return vid == rhs.vid && tags == rhs.tags; } + bool operator==(const Vertex& rhs) const { + return vid == rhs.vid && tags == rhs.tags; + } bool operator<(const Vertex& rhs) const; @@ -94,7 +102,9 @@ inline void swap(Vertex& a, Vertex& b) { b = std::move(temp); } -inline std::ostream& operator<<(std::ostream& os, const Vertex& v) { return os << v.toString(); } +inline std::ostream& operator<<(std::ostream& os, const Vertex& v) { + return os << v.toString(); +} } // namespace nebula diff --git a/src/common/expression/AggregateExpression.cpp b/src/common/expression/AggregateExpression.cpp index 34d128abcbc..8a3d9fac135 100644 --- a/src/common/expression/AggregateExpression.cpp +++ b/src/common/expression/AggregateExpression.cpp @@ -58,26 +58,18 @@ void AggregateExpression::apply(AggData* aggData, const Value& val) { } std::string AggregateExpression::toString() const { - // TODO fix it - std::string arg; - if (arg_->kind() == Expression::Kind::kConstant) { - const auto* argExpr = static_cast(arg_); - if (argExpr->value().isStr()) { - arg = argExpr->value().getStr(); - } else { - arg = arg_->toString(); - } - } else { - arg = arg_->toString(); - } - std::string isDistinct; - if (distinct_) { - isDistinct = "distinct "; - } std::stringstream out; - out << name_ << "(" << isDistinct << arg << ")"; + DCHECK(!!arg_); + auto argStr = arg_->toString(); + if (arg_->kind() == Expression::Kind::kConstant && + static_cast(arg_)->value().isStr()) { + argStr = static_cast(arg_)->value().getStr(); + } + out << name_ << "(" << (distinct_ ? "distinct " : "") << argStr << ")"; return out.str(); } -void AggregateExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void AggregateExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/AggregateExpression.h b/src/common/expression/AggregateExpression.h index 5c9d865f72c..3f8a3212dbc 100644 --- a/src/common/expression/AggregateExpression.h +++ b/src/common/expression/AggregateExpression.h @@ -42,23 +42,41 @@ class AggregateExpression final : public Expression { return AggregateExpression::make(pool_, name_, argCopy, distinct_); } - const std::string& name() const { return name_; } + const std::string& name() const { + return name_; + } - const Expression* arg() const { return arg_; } + const Expression* arg() const { + return arg_; + } - Expression* arg() { return arg_; } + Expression* arg() { + return arg_; + } - void setArg(Expression* arg) { arg_ = arg; } + void setArg(Expression* arg) { + arg_ = arg; + } - bool distinct() { return distinct_; } + bool distinct() { + return distinct_; + } - void setDistinct(bool dist) { distinct_ = dist; } + void setDistinct(bool dist) { + distinct_ = dist; + } - const AggData* aggData() const { return aggData_; } + const AggData* aggData() const { + return aggData_; + } - AggData* aggData() { return aggData_; } + AggData* aggData() { + return aggData_; + } - void setAggData(AggData* agg_data) { aggData_ = agg_data; } + void setAggData(AggData* agg_data) { + aggData_ = agg_data; + } private: explicit AggregateExpression(ObjectPool* pool, diff --git a/src/common/expression/ArithmeticExpression.cpp b/src/common/expression/ArithmeticExpression.cpp index 696e51b8132..58f5991933c 100644 --- a/src/common/expression/ArithmeticExpression.cpp +++ b/src/common/expression/ArithmeticExpression.cpp @@ -57,10 +57,12 @@ std::string ArithmeticExpression::toString() const { op = "illegal symbol "; } std::stringstream out; - out << "(" << lhs_->toString() << op << rhs_->toString() << ")"; + out << "(" << (lhs_ ? lhs_->toString() : "") << op << (rhs_ ? rhs_->toString() : "") << ")"; return out.str(); } -void ArithmeticExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void ArithmeticExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/ArithmeticExpression.h b/src/common/expression/ArithmeticExpression.h index 78b0998148d..68c0b148b72 100644 --- a/src/common/expression/ArithmeticExpression.h +++ b/src/common/expression/ArithmeticExpression.h @@ -58,7 +58,9 @@ class ArithmeticExpression final : public BinaryExpression { return pool_->add(new ArithmeticExpression(pool_, kind(), left()->clone(), right()->clone())); } - bool isArithmeticExpr() const override { return true; } + bool isArithmeticExpr() const override { + return true; + } private: explicit ArithmeticExpression(ObjectPool* pool, Kind kind, Expression* lhs, Expression* rhs) diff --git a/src/common/expression/AttributeExpression.cpp b/src/common/expression/AttributeExpression.cpp index 89abab0f99b..66d166ce844 100644 --- a/src/common/expression/AttributeExpression.cpp +++ b/src/common/expression/AttributeExpression.cpp @@ -69,19 +69,25 @@ const Value &AttributeExpression::eval(ExpressionContext &ctx) { } } -void AttributeExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void AttributeExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} std::string AttributeExpression::toString() const { - CHECK(right()->kind() == Kind::kLabel || right()->kind() == Kind::kConstant); + auto lhs = left(); + auto rhs = right(); std::string buf; buf.reserve(256); - buf += left()->toString(); + buf += lhs ? lhs->toString() : ""; buf += '.'; - auto *constant = static_cast(right()); - if (constant->value().isStr()) { - buf += constant->value().getStr(); - } else { - buf += right()->toString(); + if (rhs) { + DCHECK_EQ(rhs->kind(), Kind::kConstant); + auto *constant = static_cast(rhs); + if (constant->value().isStr()) { + buf += constant->value().getStr(); + } else { + buf += rhs->toString(); + } } return buf; diff --git a/src/common/expression/BinaryExpression.h b/src/common/expression/BinaryExpression.h index bee524caf5f..37ce0e644b5 100644 --- a/src/common/expression/BinaryExpression.h +++ b/src/common/expression/BinaryExpression.h @@ -19,17 +19,29 @@ class BinaryExpression : public Expression { public: bool operator==(const Expression& rhs) const override; - const Expression* left() const { return lhs_; } + const Expression* left() const { + return lhs_; + } - Expression* left() { return lhs_; } + Expression* left() { + return lhs_; + } - void setLeft(Expression* expr) { lhs_ = expr; } + void setLeft(Expression* expr) { + lhs_ = expr; + } - const Expression* right() const { return rhs_; } + const Expression* right() const { + return rhs_; + } - Expression* right() { return rhs_; } + Expression* right() { + return rhs_; + } - void setRight(Expression* expr) { rhs_ = expr; } + void setRight(Expression* expr) { + rhs_ = expr; + } protected: BinaryExpression(ObjectPool* pool, Kind kind, Expression* lhs, Expression* rhs) diff --git a/src/common/expression/CaseExpression.cpp b/src/common/expression/CaseExpression.cpp index 6b017d244a7..1f45b765a94 100644 --- a/src/common/expression/CaseExpression.cpp +++ b/src/common/expression/CaseExpression.cpp @@ -93,9 +93,9 @@ std::string CaseExpression::toString() const { } for (const auto& whenThen : cases_) { buf += " WHEN "; - buf += whenThen.when->toString(); + buf += whenThen.when ? whenThen.when->toString() : ""; buf += " THEN "; - buf += whenThen.then->toString(); + buf += whenThen.then ? whenThen.then->toString() : ""; } if (default_ != nullptr) { buf += " ELSE "; @@ -104,11 +104,13 @@ std::string CaseExpression::toString() const { buf += " END"; } else { buf += "("; - buf += cases_.front().when->toString(); + auto casesWhen = cases_.front().when; + auto casesThen = cases_.front().then; + buf += casesWhen ? casesWhen->toString() : ""; buf += " ? "; - buf += cases_.front().then->toString(); + buf += casesThen ? casesThen->toString() : ""; buf += " : "; - buf += default_->toString(); + buf += default_ ? default_->toString() : ""; buf += ")"; } @@ -158,6 +160,8 @@ void CaseExpression::resetFrom(Decoder& decoder) { } } -void CaseExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void CaseExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/CaseExpression.h b/src/common/expression/CaseExpression.h index 2f49948839f..0abbc11bfda 100644 --- a/src/common/expression/CaseExpression.h +++ b/src/common/expression/CaseExpression.h @@ -12,11 +12,17 @@ namespace nebula { class CaseList final { public: - static CaseList* make(ObjectPool* pool, size_t sz = 0) { return pool->add(new CaseList(sz)); } + static CaseList* make(ObjectPool* pool, size_t sz = 0) { + return pool->add(new CaseList(sz)); + } - void add(Expression* when, Expression* then) { items_.emplace_back(when, then); } + void add(Expression* when, Expression* then) { + items_.emplace_back(when, then); + } - auto items() { return items_; } + auto items() { + return items_; + } struct Item { Item(Expression* wh, Expression* th) : when(wh), then(th) {} @@ -26,7 +32,9 @@ class CaseList final { private: CaseList() = default; - explicit CaseList(size_t sz) { items_.reserve(sz); } + explicit CaseList(size_t sz) { + items_.reserve(sz); + } private: std::vector items_; @@ -48,13 +56,21 @@ class CaseExpression final : public Expression { const Value& eval(ExpressionContext& ctx) override; - void setGeneric(bool isGeneric = true) { isGeneric_ = isGeneric; } + void setGeneric(bool isGeneric = true) { + isGeneric_ = isGeneric; + } - void setCondition(Expression* cond) { condition_ = cond; } + void setCondition(Expression* cond) { + condition_ = cond; + } - void setDefault(Expression* defaultResult) { default_ = defaultResult; } + void setDefault(Expression* defaultResult) { + default_ = defaultResult; + } - void setCases(CaseList* cases) { cases_ = cases->items(); } + void setCases(CaseList* cases) { + cases_ = cases->items(); + } void setWhen(size_t index, Expression* when) { DCHECK_LT(index, cases_.size()); @@ -66,19 +82,33 @@ class CaseExpression final : public Expression { cases_[index].then = then; } - bool hasCondition() const { return condition_ != nullptr; } + bool hasCondition() const { + return condition_ != nullptr; + } - bool hasDefault() const { return default_ != nullptr; } + bool hasDefault() const { + return default_ != nullptr; + } - size_t numCases() const { return cases_.size(); } + size_t numCases() const { + return cases_.size(); + } - bool isGeneric() const { return isGeneric_; } + bool isGeneric() const { + return isGeneric_; + } - Expression* condition() const { return condition_; } + Expression* condition() const { + return condition_; + } - Expression* defaultResult() const { return default_; } + Expression* defaultResult() const { + return default_; + } - const std::vector& cases() const { return cases_; } + const std::vector& cases() const { + return cases_; + } std::string toString() const override; diff --git a/src/common/expression/ColumnExpression.cpp b/src/common/expression/ColumnExpression.cpp index 0660df9af77..41a9192a738 100644 --- a/src/common/expression/ColumnExpression.cpp +++ b/src/common/expression/ColumnExpression.cpp @@ -28,13 +28,17 @@ std::string ColumnExpression::toString() const { return out.str(); } -void ColumnExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void ColumnExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} void ColumnExpression::writeTo(Encoder &encoder) const { encoder << kind_; encoder << index_; } -void ColumnExpression::resetFrom(Decoder &decoder) { index_ = decoder.readValue().getInt(); } +void ColumnExpression::resetFrom(Decoder &decoder) { + index_ = decoder.readValue().getInt(); +} } // namespace nebula diff --git a/src/common/expression/ColumnExpression.h b/src/common/expression/ColumnExpression.h index b1ecef68072..43e2d9b47d9 100644 --- a/src/common/expression/ColumnExpression.h +++ b/src/common/expression/ColumnExpression.h @@ -27,7 +27,9 @@ class ColumnExpression final : public Expression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return ColumnExpression::make(pool_, index_); } + Expression* clone() const override { + return ColumnExpression::make(pool_, index_); + } std::string toString() const override; diff --git a/src/common/expression/ConstantExpression.cpp b/src/common/expression/ConstantExpression.cpp index 40efd8a8531..69e642cdcbc 100644 --- a/src/common/expression/ConstantExpression.cpp +++ b/src/common/expression/ConstantExpression.cpp @@ -31,7 +31,9 @@ void ConstantExpression::resetFrom(Decoder& decoder) { val_ = decoder.readValue(); } -void ConstantExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void ConstantExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} std::string ConstantExpression::toString() const { std::stringstream out; diff --git a/src/common/expression/ConstantExpression.h b/src/common/expression/ConstantExpression.h index ade994ea0fe..c189564cb75 100644 --- a/src/common/expression/ConstantExpression.h +++ b/src/common/expression/ConstantExpression.h @@ -29,15 +29,21 @@ class ConstantExpression : public Expression { return val_; } - const Value& value() const { return val_; } + const Value& value() const { + return val_; + } - void setValue(Value val) { val_ = std::move(val); } + void setValue(Value val) { + val_ = std::move(val); + } void accept(ExprVisitor* visitor) override; std::string toString() const override; - Expression* clone() const override { return ConstantExpression::make(pool_, val_); } + Expression* clone() const override { + return ConstantExpression::make(pool_, val_); + } private: explicit ConstantExpression(ObjectPool* pool, Value v = Value(NullType::__NULL__)) diff --git a/src/common/expression/ContainerExpression.cpp b/src/common/expression/ContainerExpression.cpp index 9a1c15070b8..e5fa37daec5 100644 --- a/src/common/expression/ContainerExpression.cpp +++ b/src/common/expression/ContainerExpression.cpp @@ -18,8 +18,8 @@ std::string ListExpression::toString() const { buf.reserve(256); buf += '['; - for (auto &expr : items_) { - buf += expr->toString(); + for (auto *expr : items_) { + buf += expr ? expr->toString() : ""; buf += ","; } if (items_.empty()) { @@ -79,7 +79,9 @@ void ListExpression::resetFrom(Decoder &decoder) { } } -void ListExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void ListExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} // TODO(jie): toString of set should add `SET` prefix std::string SetExpression::toString() const { @@ -87,8 +89,8 @@ std::string SetExpression::toString() const { buf.reserve(256); buf += '{'; - for (auto &expr : items_) { - buf += expr->toString(); + for (auto *expr : items_) { + buf += expr ? expr->toString() : ""; buf += ","; } if (items_.empty()) { @@ -148,7 +150,9 @@ void SetExpression::resetFrom(Decoder &decoder) { } } -void SetExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void SetExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} // TODO(jie): toString of map should add `MAP` prefix std::string MapExpression::toString() const { @@ -159,7 +163,7 @@ std::string MapExpression::toString() const { for (auto &kv : items_) { buf += kv.first; buf += ":"; - buf += kv.second->toString(); + buf += kv.second ? kv.second->toString() : ""; buf += ","; } if (items_.empty()) { @@ -225,6 +229,8 @@ void MapExpression::resetFrom(Decoder &decoder) { } } -void MapExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void MapExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/ContainerExpression.h b/src/common/expression/ContainerExpression.h index 50d0400f984..69fe29ef348 100644 --- a/src/common/expression/ContainerExpression.h +++ b/src/common/expression/ContainerExpression.h @@ -21,11 +21,15 @@ class ExpressionList final { return *this; } - auto get() { return items_; } + auto get() { + return items_; + } private: ExpressionList() = default; - explicit ExpressionList(size_t sz) { items_.reserve(sz); } + explicit ExpressionList(size_t sz) { + items_.reserve(sz); + } private: std::vector items_; @@ -42,11 +46,15 @@ class MapItemList final { return *this; } - auto get() { return items_; } + auto get() { + return items_; + } private: MapItemList() = default; - explicit MapItemList(size_t sz) { items_.reserve(sz); } + explicit MapItemList(size_t sz) { + items_.reserve(sz); + } private: using Pair = std::pair; @@ -65,18 +73,26 @@ class ListExpression final : public Expression { const Value &eval(ExpressionContext &ctx) override; - const std::vector &items() const { return items_; } + const std::vector &items() const { + return items_; + } void setItem(size_t index, Expression *item) { DCHECK_LT(index, items_.size()); items_[index] = item; } - std::vector get() { return items_; } + std::vector get() { + return items_; + } - void setItems(std::vector items) { items_ = items; } + void setItems(std::vector items) { + items_ = items; + } - size_t size() const { return items_.size(); } + size_t size() const { + return items_.size(); + } bool operator==(const Expression &rhs) const override; @@ -92,7 +108,9 @@ class ListExpression final : public Expression { return ListExpression::make(pool_, items); } - bool isContainerExpr() const override { return true; } + bool isContainerExpr() const override { + return true; + } private: explicit ListExpression(ObjectPool *pool) : Expression(pool, Kind::kList) {} @@ -122,18 +140,26 @@ class SetExpression final : public Expression { const Value &eval(ExpressionContext &ctx) override; - const std::vector &items() const { return items_; } + const std::vector &items() const { + return items_; + } void setItem(size_t index, Expression *item) { DCHECK_LT(index, items_.size()); items_[index] = item; } - std::vector get() { return items_; } + std::vector get() { + return items_; + } - void setItems(std::vector items) { items_ = items; } + void setItems(std::vector items) { + items_ = items; + } - size_t size() const { return items_.size(); } + size_t size() const { + return items_.size(); + } bool operator==(const Expression &rhs) const override; @@ -149,7 +175,9 @@ class SetExpression final : public Expression { return SetExpression::make(pool_, items); } - bool isContainerExpr() const override { return true; } + bool isContainerExpr() const override { + return true; + } private: explicit SetExpression(ObjectPool *pool) : Expression(pool, Kind::kSet) {} @@ -181,18 +209,26 @@ class MapExpression final : public Expression { const Value &eval(ExpressionContext &ctx) override; - const std::vector &items() const { return items_; } + const std::vector &items() const { + return items_; + } - void setItems(std::vector items) { items_ = items; } + void setItems(std::vector items) { + items_ = items; + } void setItem(size_t index, Item item) { DCHECK_LT(index, items_.size()); items_[index] = item; } - std::vector get() { return items_; } + std::vector get() { + return items_; + } - size_t size() const { return items_.size(); } + size_t size() const { + return items_.size(); + } bool operator==(const Expression &rhs) const override; @@ -208,7 +244,9 @@ class MapExpression final : public Expression { return MapExpression::make(pool_, items); } - bool isContainerExpr() const override { return true; } + bool isContainerExpr() const override { + return true; + } private: explicit MapExpression(ObjectPool *pool) : Expression(pool, Kind::kMap) {} diff --git a/src/common/expression/EdgeExpression.cpp b/src/common/expression/EdgeExpression.cpp index 7fb13c74f55..2c8b9655858 100644 --- a/src/common/expression/EdgeExpression.cpp +++ b/src/common/expression/EdgeExpression.cpp @@ -14,6 +14,8 @@ const Value &EdgeExpression::eval(ExpressionContext &ctx) { return result_; } -void EdgeExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void EdgeExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/EdgeExpression.h b/src/common/expression/EdgeExpression.h index 931debfe1b6..1e7fffd5019 100644 --- a/src/common/expression/EdgeExpression.h +++ b/src/common/expression/EdgeExpression.h @@ -21,22 +21,32 @@ class EdgeExpression final : public Expression { EdgeExpression& operator=(const EdgeExpression& rhs) = delete; EdgeExpression& operator=(EdgeExpression&&) = delete; - static EdgeExpression* make(ObjectPool* pool) { return pool->add(new EdgeExpression(pool)); } + static EdgeExpression* make(ObjectPool* pool) { + return pool->add(new EdgeExpression(pool)); + } const Value& eval(ExpressionContext& ctx) override; void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return EdgeExpression::make(pool_); } + Expression* clone() const override { + return EdgeExpression::make(pool_); + } - std::string toString() const override { return "EDGE"; } + std::string toString() const override { + return "EDGE"; + } - bool operator==(const Expression& expr) const override { return kind() == expr.kind(); } + bool operator==(const Expression& expr) const override { + return kind() == expr.kind(); + } private: explicit EdgeExpression(ObjectPool* pool) : Expression(pool, Kind::kEdge) {} - void writeTo(Encoder& encoder) const override { encoder << kind(); } + void writeTo(Encoder& encoder) const override { + encoder << kind(); + } void resetFrom(Decoder&) override {} diff --git a/src/common/expression/Expression.cpp b/src/common/expression/Expression.cpp index 01e8388c848..16ff1c276e6 100644 --- a/src/common/expression/Expression.cpp +++ b/src/common/expression/Expression.cpp @@ -42,9 +42,13 @@ using serializer = apache::thrift::CompactSerializer; * class Expression::Encoder * ***************************************/ -Expression::Encoder::Encoder(size_t bufSizeHint) { buf_.reserve(bufSizeHint); } +Expression::Encoder::Encoder(size_t bufSizeHint) { + buf_.reserve(bufSizeHint); +} -std::string Expression::Encoder::moveStr() { return std::move(buf_); } +std::string Expression::Encoder::moveStr() { + return std::move(buf_); +} Expression::Encoder& Expression::Encoder::operator<<(Kind kind) noexcept { buf_.append(reinterpret_cast(&kind), sizeof(uint8_t)); @@ -88,9 +92,13 @@ Expression::Encoder& Expression::Encoder::operator<<(const Expression& exp) noex Expression::Decoder::Decoder(folly::StringPiece encoded) : encoded_(encoded), ptr_(encoded_.begin()) {} -bool Expression::Decoder::finished() const { return ptr_ >= encoded_.end(); } +bool Expression::Decoder::finished() const { + return ptr_ >= encoded_.end(); +} -std::string Expression::Decoder::getHexStr() const { return toHexStr(encoded_); } +std::string Expression::Decoder::getHexStr() const { + return toHexStr(encoded_); +} Expression::Kind Expression::Decoder::readKind() noexcept { CHECK_LE(ptr_ + sizeof(uint8_t), encoded_.end()); @@ -152,7 +160,9 @@ Expression* Expression::Decoder::readExpression(ObjectPool* pool) noexcept { Expression::Expression(ObjectPool* pool, Kind kind) : pool_(DCHECK_NOTNULL(pool)), kind_(kind) {} // static -std::string Expression::encode(const Expression& exp) { return exp.encode(); } +std::string Expression::encode(const Expression& exp) { + return exp.encode(); +} std::string Expression::encode() const { Encoder encoder; diff --git a/src/common/expression/Expression.h b/src/common/expression/Expression.h index 3ed55d12c7c..1f5a1aacd66 100644 --- a/src/common/expression/Expression.h +++ b/src/common/expression/Expression.h @@ -116,18 +116,26 @@ class Expression { Expression& operator=(Expression&&) = delete; Expression(const Expression&) = delete; - Kind kind() const { return kind_; } + Kind kind() const { + return kind_; + } - static Value eval(Expression* expr, ExpressionContext& ctx) { return expr->eval(ctx); } + static Value eval(Expression* expr, ExpressionContext& ctx) { + return expr->eval(ctx); + } virtual const Value& eval(ExpressionContext& ctx) = 0; virtual bool operator==(const Expression& rhs) const = 0; - bool operator!=(const Expression& rhs) const { return !operator==(rhs); } + bool operator!=(const Expression& rhs) const { + return !operator==(rhs); + } virtual std::string toString() const = 0; - virtual std::string rawString() const { return toString(); } + virtual std::string rawString() const { + return toString(); + } virtual void accept(ExprVisitor* visitor) = 0; @@ -140,15 +148,25 @@ class Expression { static Expression* decode(ObjectPool* pool, folly::StringPiece encoded); - ObjectPool* getObjPool() const { return pool_; } + ObjectPool* getObjPool() const { + return pool_; + } - virtual bool isLogicalExpr() const { return false; } + virtual bool isLogicalExpr() const { + return false; + } - virtual bool isRelExpr() const { return false; } + virtual bool isRelExpr() const { + return false; + } - virtual bool isArithmeticExpr() const { return false; } + virtual bool isArithmeticExpr() const { + return false; + } - virtual bool isContainerExpr() const { return false; } + virtual bool isContainerExpr() const { + return false; + } protected: class Encoder final { diff --git a/src/common/expression/FunctionCallExpression.cpp b/src/common/expression/FunctionCallExpression.cpp index 3fbbc7ed909..a615a5f8531 100644 --- a/src/common/expression/FunctionCallExpression.cpp +++ b/src/common/expression/FunctionCallExpression.cpp @@ -79,16 +79,24 @@ const Value& FunctionCallExpression::eval(ExpressionContext& ctx) { } std::string FunctionCallExpression::toString() const { - std::vector args(args_->numArgs()); - std::transform( - args_->args().begin(), args_->args().end(), args.begin(), [](const auto& arg) -> std::string { - return arg->toString(); - }); std::stringstream out; - out << name_ << "(" << folly::join(",", args) << ")"; + + if (args_ != nullptr) { + std::vector args(args_->numArgs()); + std::transform(args_->args().begin(), + args_->args().end(), + args.begin(), + [](const auto& arg) -> std::string { return arg ? arg->toString() : ""; }); + out << name_ << "(" << folly::join(",", args) << ")"; + + } else { + out << name_ << "()"; + } return out.str(); } -void FunctionCallExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void FunctionCallExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/FunctionCallExpression.h b/src/common/expression/FunctionCallExpression.h index 16312f53eea..c74d94914da 100644 --- a/src/common/expression/FunctionCallExpression.h +++ b/src/common/expression/FunctionCallExpression.h @@ -24,24 +24,34 @@ class ArgumentList final { args_.emplace_back(arg); } - const auto& args() const { return args_; } + const auto& args() const { + return args_; + } - auto& args() { return args_; } + auto& args() { + return args_; + } - size_t numArgs() const { return args_.size(); } + size_t numArgs() const { + return args_.size(); + } void setArg(size_t i, Expression* arg) { DCHECK_LT(i, numArgs()); args_[i] = arg; } - void setArgs(std::vector args) { args_ = args; } + void setArgs(std::vector args) { + args_ = args; + } bool operator==(const ArgumentList& rhs) const; private: ArgumentList() = default; - explicit ArgumentList(size_t sz) { args_.reserve(sz); } + explicit ArgumentList(size_t sz) { + args_.reserve(sz); + } private: std::vector args_; @@ -78,13 +88,21 @@ class FunctionCallExpression final : public Expression { return FunctionCallExpression::make(pool_, name_, arguments); } - const std::string& name() const { return name_; } + const std::string& name() const { + return name_; + } - bool isFunc(const std::string& name) const { return boost::iequals(name, name_); } + bool isFunc(const std::string& name) const { + return boost::iequals(name, name_); + } - const ArgumentList* args() const { return args_; } + const ArgumentList* args() const { + return args_; + } - ArgumentList* args() { return args_; } + ArgumentList* args() { + return args_; + } private: explicit FunctionCallExpression(ObjectPool* pool, const std::string& name, ArgumentList* args) diff --git a/src/common/expression/LabelAttributeExpression.cpp b/src/common/expression/LabelAttributeExpression.cpp index 7bf23365c9c..0155bb9f39a 100644 --- a/src/common/expression/LabelAttributeExpression.cpp +++ b/src/common/expression/LabelAttributeExpression.cpp @@ -10,12 +10,24 @@ namespace nebula { std::string LabelAttributeExpression::toString() const { - if (right()->value().isStr()) { - return left()->toString() + "." + right()->value().getStr(); + auto lhs = left(); + auto rhs = right(); + auto label = lhs ? (lhs->toString()) : ""; + std::string attr; + if (rhs != nullptr) { + DCHECK_EQ(rhs->kind(), Kind::kConstant); + auto *constant = static_cast(rhs); + if (constant->value().isStr()) { + attr = constant->value().getStr(); + } else { + attr = rhs->toString(); + } } - return left()->toString() + "." + right()->toString(); + return label + "." + attr; } -void LabelAttributeExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void LabelAttributeExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/LabelAttributeExpression.h b/src/common/expression/LabelAttributeExpression.h index 809b3c44a5b..315031fefab 100644 --- a/src/common/expression/LabelAttributeExpression.h +++ b/src/common/expression/LabelAttributeExpression.h @@ -46,13 +46,21 @@ class LabelAttributeExpression final : public Expression { static_cast(right()->clone())); } - const LabelExpression* left() const { return lhs_; } + const LabelExpression* left() const { + return lhs_; + } - LabelExpression* left() { return lhs_; } + LabelExpression* left() { + return lhs_; + } - const ConstantExpression* right() const { return rhs_; } + const ConstantExpression* right() const { + return rhs_; + } - ConstantExpression* right() { return rhs_; } + ConstantExpression* right() { + return rhs_; + } std::string toString() const override; diff --git a/src/common/expression/LabelExpression.cpp b/src/common/expression/LabelExpression.cpp index c65f47359bc..d7b0709f3bc 100644 --- a/src/common/expression/LabelExpression.cpp +++ b/src/common/expression/LabelExpression.cpp @@ -14,7 +14,9 @@ const Value& LabelExpression::eval(ExpressionContext&) { return result_; } -std::string LabelExpression::toString() const { return name_; } +std::string LabelExpression::toString() const { + return name_; +} bool LabelExpression::operator==(const Expression& rhs) const { if (kind_ != rhs.kind()) { @@ -37,6 +39,8 @@ void LabelExpression::resetFrom(Decoder& decoder) { name_ = decoder.readStr(); } -void LabelExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void LabelExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/LabelExpression.h b/src/common/expression/LabelExpression.h index cc4fdc3d5be..b91609165f0 100644 --- a/src/common/expression/LabelExpression.h +++ b/src/common/expression/LabelExpression.h @@ -25,13 +25,17 @@ class LabelExpression : public Expression { const Value& eval(ExpressionContext& ctx) override; - const std::string& name() const { return name_; } + const std::string& name() const { + return name_; + } std::string toString() const override; void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return LabelExpression::make(pool_, name()); } + Expression* clone() const override { + return LabelExpression::make(pool_, name()); + } protected: explicit LabelExpression(ObjectPool* pool, const std::string& name = "") diff --git a/src/common/expression/ListComprehensionExpression.cpp b/src/common/expression/ListComprehensionExpression.cpp index e3c647bb6b7..8731ab3d49c 100644 --- a/src/common/expression/ListComprehensionExpression.cpp +++ b/src/common/expression/ListComprehensionExpression.cpp @@ -145,7 +145,7 @@ std::string ListComprehensionExpression::toString() const { buf += "["; buf += innerVar_; buf += " IN "; - buf += collection_->toString(); + buf += collection_ ? collection_->toString() : ""; if (hasFilter()) { buf += " WHERE "; buf += filter_->toString(); @@ -159,6 +159,8 @@ std::string ListComprehensionExpression::toString() const { return buf; } -void ListComprehensionExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void ListComprehensionExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/ListComprehensionExpression.h b/src/common/expression/ListComprehensionExpression.h index 5d45476cb96..26723d1f0ff 100644 --- a/src/common/expression/ListComprehensionExpression.h +++ b/src/common/expression/ListComprehensionExpression.h @@ -31,41 +31,73 @@ class ListComprehensionExpression final : public Expression { std::string toString() const override; - std::string rawString() const override { return hasOriginString() ? originString_ : toString(); } + std::string rawString() const override { + return hasOriginString() ? originString_ : toString(); + } void accept(ExprVisitor* visitor) override; Expression* clone() const override; - const std::string& innerVar() const { return innerVar_; } + const std::string& innerVar() const { + return innerVar_; + } - const Expression* collection() const { return collection_; } + const Expression* collection() const { + return collection_; + } - Expression* collection() { return collection_; } + Expression* collection() { + return collection_; + } - const Expression* filter() const { return filter_; } + const Expression* filter() const { + return filter_; + } - Expression* filter() { return filter_; } + Expression* filter() { + return filter_; + } - const Expression* mapping() const { return mapping_; } + const Expression* mapping() const { + return mapping_; + } - Expression* mapping() { return mapping_; } + Expression* mapping() { + return mapping_; + } - void setInnerVar(const std::string& name) { innerVar_ = name; } + void setInnerVar(const std::string& name) { + innerVar_ = name; + } - void setCollection(Expression* expr) { collection_ = expr; } + void setCollection(Expression* expr) { + collection_ = expr; + } - void setFilter(Expression* expr) { filter_ = expr; } + void setFilter(Expression* expr) { + filter_ = expr; + } - void setMapping(Expression* expr) { mapping_ = expr; } + void setMapping(Expression* expr) { + mapping_ = expr; + } - bool hasFilter() const { return filter_ != nullptr; } + bool hasFilter() const { + return filter_ != nullptr; + } - bool hasMapping() const { return mapping_ != nullptr; } + bool hasMapping() const { + return mapping_ != nullptr; + } - void setOriginString(const std::string& s) { originString_ = s; } + void setOriginString(const std::string& s) { + originString_ = s; + } - bool hasOriginString() const { return !originString_.empty(); } + bool hasOriginString() const { + return !originString_.empty(); + } private: explicit ListComprehensionExpression(ObjectPool* pool, diff --git a/src/common/expression/LogicalExpression.cpp b/src/common/expression/LogicalExpression.cpp index 08b329bdf64..a92e09df06a 100644 --- a/src/common/expression/LogicalExpression.cpp +++ b/src/common/expression/LogicalExpression.cpp @@ -121,17 +121,21 @@ std::string LogicalExpression::toString() const { buf.reserve(256); buf += "("; - buf += operands_[0]->toString(); - for (auto i = 1u; i < operands_.size(); i++) { - buf += op; - buf += operands_[i]->toString(); + if (!operands_.empty()) { + buf += operands_[0]->toString(); + for (auto i = 1u; i < operands_.size(); i++) { + buf += op; + buf += operands_[i]->toString(); + } } buf += ")"; return buf; } -void LogicalExpression::accept(ExprVisitor *visitor) { visitor->visit(this); } +void LogicalExpression::accept(ExprVisitor *visitor) { + visitor->visit(this); +} void LogicalExpression::writeTo(Encoder &encoder) const { encoder << kind(); diff --git a/src/common/expression/LogicalExpression.h b/src/common/expression/LogicalExpression.h index 248ef051922..4fe7a85ac0b 100644 --- a/src/common/expression/LogicalExpression.h +++ b/src/common/expression/LogicalExpression.h @@ -60,24 +60,38 @@ class LogicalExpression final : public Expression { bool operator==(const Expression& rhs) const override; - auto& operands() { return operands_; } + auto& operands() { + return operands_; + } - const auto& operands() const { return operands_; } + const auto& operands() const { + return operands_; + } - auto* operand(size_t index) { return operands_[index]; } + auto* operand(size_t index) { + return operands_[index]; + } - const auto* operand(size_t index) const { return operands_[index]; } + const auto* operand(size_t index) const { + return operands_[index]; + } - void addOperand(Expression* expr) { operands_.emplace_back(expr); } + void addOperand(Expression* expr) { + operands_.emplace_back(expr); + } void setOperand(size_t i, Expression* operand) { DCHECK_LT(i, operands_.size()); operands_[i] = operand; } - void setOperands(std::vector operands) { operands_ = operands; } + void setOperands(std::vector operands) { + operands_ = operands; + } - bool isLogicalExpr() const override { return true; } + bool isLogicalExpr() const override { + return true; + } private: explicit LogicalExpression(ObjectPool* pool, Kind kind) : Expression(pool, kind) {} diff --git a/src/common/expression/PathBuildExpression.cpp b/src/common/expression/PathBuildExpression.cpp index 03a274b83b8..6bf1f2b733d 100644 --- a/src/common/expression/PathBuildExpression.cpp +++ b/src/common/expression/PathBuildExpression.cpp @@ -152,7 +152,9 @@ std::string PathBuildExpression::toString() const { return buf; } -void PathBuildExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void PathBuildExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} Expression* PathBuildExpression::clone() const { auto pathBuild = PathBuildExpression::make(pool_); diff --git a/src/common/expression/PathBuildExpression.h b/src/common/expression/PathBuildExpression.h index aaea497db9d..4736ad7e30c 100644 --- a/src/common/expression/PathBuildExpression.h +++ b/src/common/expression/PathBuildExpression.h @@ -41,11 +41,17 @@ class PathBuildExpression final : public Expression { items_[index] = item; } - size_t size() const { return items_.size(); } + size_t size() const { + return items_.size(); + } - size_t length() const { return size() - 1; } + size_t length() const { + return size() - 1; + } - const auto& items() const { return items_; } + const auto& items() const { + return items_; + } private: explicit PathBuildExpression(ObjectPool* pool) : Expression(pool, Kind::kPathBuild) {} diff --git a/src/common/expression/PredicateExpression.cpp b/src/common/expression/PredicateExpression.cpp index 90563e6ae71..1ff92618e9f 100644 --- a/src/common/expression/PredicateExpression.cpp +++ b/src/common/expression/PredicateExpression.cpp @@ -249,17 +249,19 @@ std::string PredicateExpression::toString() const { if (name_ != "exists") { buf += innerVar_; buf += " IN "; - buf += collection_->toString(); + buf += collection_ ? collection_->toString() : ""; buf += " WHERE "; - buf += filter_->toString(); + buf += filter_ ? filter_->toString() : ""; } else { - buf += collection_->toString(); + buf += collection_ ? collection_->toString() : ""; } buf += ")"; return buf; } -void PredicateExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void PredicateExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/PredicateExpression.h b/src/common/expression/PredicateExpression.h index 227061fedf1..9792e8f425d 100644 --- a/src/common/expression/PredicateExpression.h +++ b/src/common/expression/PredicateExpression.h @@ -39,37 +39,65 @@ class PredicateExpression final : public Expression { std::string toString() const override; - std::string rawString() const override { return hasOriginString() ? originString_ : toString(); } + std::string rawString() const override { + return hasOriginString() ? originString_ : toString(); + } void accept(ExprVisitor* visitor) override; Expression* clone() const override; - const std::string& name() const { return name_; } + const std::string& name() const { + return name_; + } - const std::string& innerVar() const { return innerVar_; } + const std::string& innerVar() const { + return innerVar_; + } - const Expression* collection() const { return collection_; } + const Expression* collection() const { + return collection_; + } - Expression* collection() { return collection_; } + Expression* collection() { + return collection_; + } - const Expression* filter() const { return filter_; } + const Expression* filter() const { + return filter_; + } - Expression* filter() { return filter_; } + Expression* filter() { + return filter_; + } - void setInnerVar(const std::string& name) { innerVar_ = name; } + void setInnerVar(const std::string& name) { + innerVar_ = name; + } - void setCollection(Expression* expr) { collection_ = expr; } + void setCollection(Expression* expr) { + collection_ = expr; + } - void setFilter(Expression* expr) { filter_ = expr; } + void setFilter(Expression* expr) { + filter_ = expr; + } - void setOriginString(const std::string& s) { originString_ = s; } + void setOriginString(const std::string& s) { + originString_ = s; + } - bool hasOriginString() const { return !originString_.empty(); } + bool hasOriginString() const { + return !originString_.empty(); + } - bool hasInnerVar() const { return !innerVar_.empty(); } + bool hasInnerVar() const { + return !innerVar_.empty(); + } - bool hasFilter() const { return filter_ != nullptr; } + bool hasFilter() const { + return filter_ != nullptr; + } private: explicit PredicateExpression(ObjectPool* pool, diff --git a/src/common/expression/PropertyExpression.cpp b/src/common/expression/PropertyExpression.cpp index cbed4c66469..df44262eebd 100644 --- a/src/common/expression/PropertyExpression.cpp +++ b/src/common/expression/PropertyExpression.cpp @@ -54,67 +54,87 @@ const Value& EdgePropertyExpression::eval(ExpressionContext& ctx) { return result_; } -void EdgePropertyExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void EdgePropertyExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& TagPropertyExpression::eval(ExpressionContext& ctx) { result_ = ctx.getTagProp(sym_, prop_); return result_; } -void TagPropertyExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void TagPropertyExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& InputPropertyExpression::eval(ExpressionContext& ctx) { return ctx.getInputProp(prop_); } -void InputPropertyExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void InputPropertyExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& VariablePropertyExpression::eval(ExpressionContext& ctx) { return ctx.getVarProp(sym_, prop_); } -void VariablePropertyExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void VariablePropertyExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& SourcePropertyExpression::eval(ExpressionContext& ctx) { result_ = ctx.getSrcProp(sym_, prop_); return result_; } -void SourcePropertyExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void SourcePropertyExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& DestPropertyExpression::eval(ExpressionContext& ctx) { return ctx.getDstProp(sym_, prop_); } -void DestPropertyExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void DestPropertyExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& EdgeSrcIdExpression::eval(ExpressionContext& ctx) { result_ = ctx.getEdgeProp(sym_, prop_); return result_; } -void EdgeSrcIdExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void EdgeSrcIdExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& EdgeTypeExpression::eval(ExpressionContext& ctx) { result_ = ctx.getEdgeProp(sym_, prop_); return result_; } -void EdgeTypeExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void EdgeTypeExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& EdgeRankExpression::eval(ExpressionContext& ctx) { result_ = ctx.getEdgeProp(sym_, prop_); return result_; } -void EdgeRankExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void EdgeRankExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} const Value& EdgeDstIdExpression::eval(ExpressionContext& ctx) { result_ = ctx.getEdgeProp(sym_, prop_); return result_; } -void EdgeDstIdExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void EdgeDstIdExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} std::string PropertyExpression::toString() const { std::string buf; diff --git a/src/common/expression/PropertyExpression.h b/src/common/expression/PropertyExpression.h index 4f8c86f34e4..4a5e7e8bd23 100644 --- a/src/common/expression/PropertyExpression.h +++ b/src/common/expression/PropertyExpression.h @@ -32,11 +32,17 @@ class PropertyExpression : public Expression { const Value& eval(ExpressionContext& ctx) override; - const std::string& ref() const { return ref_; } + const std::string& ref() const { + return ref_; + } - const std::string& sym() const { return sym_; } + const std::string& sym() const { + return sym_; + } - const std::string& prop() const { return prop_; } + const std::string& prop() const { + return prop_; + } std::string toString() const override; @@ -72,7 +78,9 @@ class EdgePropertyExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return EdgePropertyExpression::make(pool_, sym(), prop()); } + Expression* clone() const override { + return EdgePropertyExpression::make(pool_, sym(), prop()); + } private: explicit EdgePropertyExpression(ObjectPool* pool, @@ -100,7 +108,9 @@ class TagPropertyExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return TagPropertyExpression::make(pool_, sym(), prop()); } + Expression* clone() const override { + return TagPropertyExpression::make(pool_, sym(), prop()); + } private: explicit TagPropertyExpression(ObjectPool* pool, @@ -126,7 +136,9 @@ class InputPropertyExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return InputPropertyExpression::make(pool_, prop()); } + Expression* clone() const override { + return InputPropertyExpression::make(pool_, prop()); + } private: explicit InputPropertyExpression(ObjectPool* pool, const std::string& prop = "") @@ -208,7 +220,9 @@ class DestPropertyExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return DestPropertyExpression::make(pool_, sym(), prop()); } + Expression* clone() const override { + return DestPropertyExpression::make(pool_, sym(), prop()); + } private: explicit DestPropertyExpression(ObjectPool* pool, @@ -231,7 +245,9 @@ class EdgeSrcIdExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return EdgeSrcIdExpression::make(pool_, sym()); } + Expression* clone() const override { + return EdgeSrcIdExpression::make(pool_, sym()); + } private: explicit EdgeSrcIdExpression(ObjectPool* pool, const std::string& edge = "") @@ -255,7 +271,9 @@ class EdgeTypeExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return EdgeTypeExpression::make(pool_, sym()); } + Expression* clone() const override { + return EdgeTypeExpression::make(pool_, sym()); + } private: explicit EdgeTypeExpression(ObjectPool* pool, const std::string& edge = "") @@ -279,7 +297,9 @@ class EdgeRankExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return EdgeRankExpression::make(pool_, sym()); } + Expression* clone() const override { + return EdgeRankExpression::make(pool_, sym()); + } private: explicit EdgeRankExpression(ObjectPool* pool, const std::string& edge = "") @@ -303,7 +323,9 @@ class EdgeDstIdExpression final : public PropertyExpression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return EdgeDstIdExpression::make(pool_, sym()); } + Expression* clone() const override { + return EdgeDstIdExpression::make(pool_, sym()); + } private: explicit EdgeDstIdExpression(ObjectPool* pool, const std::string& edge = "") diff --git a/src/common/expression/ReduceExpression.cpp b/src/common/expression/ReduceExpression.cpp index 728f93ba4b5..6f008cdef99 100644 --- a/src/common/expression/ReduceExpression.cpp +++ b/src/common/expression/ReduceExpression.cpp @@ -112,18 +112,20 @@ std::string ReduceExpression::toString() const { buf += "("; buf += accumulator_; buf += " = "; - buf += initial_->toString(); + buf += initial_ ? initial_->toString() : ""; buf += ", "; buf += innerVar_; buf += " IN "; - buf += collection_->toString(); + buf += collection_ ? collection_->toString() : ""; buf += " | "; - buf += mapping_->toString(); + buf += mapping_ ? mapping_->toString() : ""; buf += ")"; return buf; } -void ReduceExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void ReduceExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/ReduceExpression.h b/src/common/expression/ReduceExpression.h index 8810ef9e8e9..130be05672f 100644 --- a/src/common/expression/ReduceExpression.h +++ b/src/common/expression/ReduceExpression.h @@ -30,41 +30,73 @@ class ReduceExpression final : public Expression { std::string toString() const override; - std::string rawString() const override { return hasOriginString() ? originString_ : toString(); } + std::string rawString() const override { + return hasOriginString() ? originString_ : toString(); + } void accept(ExprVisitor* visitor) override; Expression* clone() const override; - const std::string& accumulator() const { return accumulator_; } + const std::string& accumulator() const { + return accumulator_; + } - const Expression* initial() const { return initial_; } + const Expression* initial() const { + return initial_; + } - Expression* initial() { return initial_; } + Expression* initial() { + return initial_; + } - const std::string& innerVar() const { return innerVar_; } + const std::string& innerVar() const { + return innerVar_; + } - const Expression* collection() const { return collection_; } + const Expression* collection() const { + return collection_; + } - Expression* collection() { return collection_; } + Expression* collection() { + return collection_; + } - const Expression* mapping() const { return mapping_; } + const Expression* mapping() const { + return mapping_; + } - Expression* mapping() { return mapping_; } + Expression* mapping() { + return mapping_; + } - void setAccumulator(const std::string& name) { accumulator_ = name; } + void setAccumulator(const std::string& name) { + accumulator_ = name; + } - void setInitial(Expression* expr) { initial_ = expr; } + void setInitial(Expression* expr) { + initial_ = expr; + } - void setInnerVar(const std::string& name) { innerVar_ = name; } + void setInnerVar(const std::string& name) { + innerVar_ = name; + } - void setCollection(Expression* expr) { collection_ = expr; } + void setCollection(Expression* expr) { + collection_ = expr; + } - void setMapping(Expression* expr) { mapping_ = expr; } + void setMapping(Expression* expr) { + mapping_ = expr; + } - void setOriginString(const std::string& s) { originString_ = s; } + void setOriginString(const std::string& s) { + originString_ = s; + } - bool hasOriginString() const { return !originString_.empty(); } + bool hasOriginString() const { + return !originString_.empty(); + } private: explicit ReduceExpression(ObjectPool* pool, diff --git a/src/common/expression/RelationalExpression.cpp b/src/common/expression/RelationalExpression.cpp index 4b60d0d2434..50cdac11079 100644 --- a/src/common/expression/RelationalExpression.cpp +++ b/src/common/expression/RelationalExpression.cpp @@ -252,10 +252,12 @@ std::string RelationalExpression::toString() const { op = " illegal symbol "; } std::stringstream out; - out << "(" << lhs_->toString() << op << rhs_->toString() << ")"; + out << "(" << (lhs_ ? lhs_->toString() : "") << op << (rhs_ ? rhs_->toString() : "") << ")"; return out.str(); } -void RelationalExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void RelationalExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/RelationalExpression.h b/src/common/expression/RelationalExpression.h index bfc36b1f0a5..e15bc7f12f5 100644 --- a/src/common/expression/RelationalExpression.h +++ b/src/common/expression/RelationalExpression.h @@ -119,7 +119,9 @@ class RelationalExpression final : public BinaryExpression { return pool_->add(new RelationalExpression(pool_, kind(), left()->clone(), right()->clone())); } - bool isRelExpr() const override { return true; } + bool isRelExpr() const override { + return true; + } private: explicit RelationalExpression(ObjectPool* pool, Kind kind, Expression* lhs, Expression* rhs) diff --git a/src/common/expression/SubscriptExpression.cpp b/src/common/expression/SubscriptExpression.cpp index 87cad714067..bbd6f49ef65 100644 --- a/src/common/expression/SubscriptExpression.cpp +++ b/src/common/expression/SubscriptExpression.cpp @@ -105,14 +105,18 @@ const Value& SubscriptExpression::eval(ExpressionContext& ctx) { std::string SubscriptExpression::toString() const { std::string buf; buf.reserve(256); - buf += left()->toString(); + auto lhs = left(); + auto rhs = right(); + buf += lhs ? lhs->toString() : ""; buf += '['; - buf += right()->toString(); + buf += rhs ? rhs->toString() : ""; buf += ']'; return buf; } -void SubscriptExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void SubscriptExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} // For the positive range bound it start from begin, // for the negative range bound it start from end @@ -186,7 +190,7 @@ const Value& SubscriptRangeExpression::eval(ExpressionContext& ctx) { std::string SubscriptRangeExpression::toString() const { std::string buf; buf.reserve(32); - buf += list_->toString(); + buf += list_ ? list_->toString() : ""; buf += '['; if (lo_ != nullptr) { buf += lo_->toString(); @@ -199,7 +203,9 @@ std::string SubscriptRangeExpression::toString() const { return buf; } -void SubscriptRangeExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void SubscriptRangeExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} bool SubscriptRangeExpression::operator==(const Expression& rhs) const { if (kind() != rhs.kind()) { diff --git a/src/common/expression/SubscriptExpression.h b/src/common/expression/SubscriptExpression.h index 98118f64e5c..c1534bffc73 100644 --- a/src/common/expression/SubscriptExpression.h +++ b/src/common/expression/SubscriptExpression.h @@ -65,23 +65,41 @@ class SubscriptRangeExpression final : public Expression { bool operator==(const Expression& rhs) const override; - const Expression* list() const { return list_; } + const Expression* list() const { + return list_; + } - Expression* list() { return list_; } + Expression* list() { + return list_; + } - void setList(Expression* list) { list_ = list; } + void setList(Expression* list) { + list_ = list; + } - const Expression* lo() const { return lo_; } + const Expression* lo() const { + return lo_; + } - Expression* lo() { return lo_; } + Expression* lo() { + return lo_; + } - void setLo(Expression* lo) { lo_ = lo; } + void setLo(Expression* lo) { + lo_ = lo; + } - const Expression* hi() const { return hi_; } + const Expression* hi() const { + return hi_; + } - Expression* hi() { return hi_; } + Expression* hi() { + return hi_; + } - void setHi(Expression* hi) { hi_ = hi; } + void setHi(Expression* hi) { + hi_ = hi; + } private: // for decode ctor diff --git a/src/common/expression/TextSearchExpression.cpp b/src/common/expression/TextSearchExpression.cpp index 013072d18de..69d339d9264 100644 --- a/src/common/expression/TextSearchExpression.cpp +++ b/src/common/expression/TextSearchExpression.cpp @@ -69,7 +69,7 @@ std::string TextSearchExpression::toString() const { LOG(FATAL) << "Unimplemented"; } } - buf += arg_->toString(); + buf += arg_ ? arg_->toString() : ""; buf += ")"; return buf; } diff --git a/src/common/expression/TextSearchExpression.h b/src/common/expression/TextSearchExpression.h index 5d253cf52be..373d7c8f77d 100644 --- a/src/common/expression/TextSearchExpression.h +++ b/src/common/expression/TextSearchExpression.h @@ -22,29 +22,53 @@ class TextSearchArgument final { ~TextSearchArgument() = default; - void setVal(const std::string& val) { val_ = val; } + void setVal(const std::string& val) { + val_ = val; + } - const std::string& from() { return from_; } + const std::string& from() { + return from_; + } - const std::string& prop() { return prop_; } + const std::string& prop() { + return prop_; + } - const std::string& val() const { return val_; } + const std::string& val() const { + return val_; + } - void setOP(const std::string& op) { op_ = op; } + void setOP(const std::string& op) { + op_ = op; + } - const std::string& op() const { return op_; } + const std::string& op() const { + return op_; + } - void setFuzziness(int32_t fuzz) { fuzziness_ = fuzz; } + void setFuzziness(int32_t fuzz) { + fuzziness_ = fuzz; + } - int32_t fuzziness() { return fuzziness_; } + int32_t fuzziness() { + return fuzziness_; + } - void setLimit(int32_t limit) { limit_ = limit; } + void setLimit(int32_t limit) { + limit_ = limit; + } - int32_t limit() { return limit_; } + int32_t limit() { + return limit_; + } - void setTimeout(int32_t timeout) { timeout_ = timeout; } + void setTimeout(int32_t timeout) { + timeout_ = timeout; + } - int32_t timeout() { return timeout_; } + int32_t timeout() { + return timeout_; + } bool operator==(const TextSearchArgument& rhs) const; @@ -89,7 +113,9 @@ class TextSearchExpression : public Expression { return Value::kNullBadData; } - void accept(ExprVisitor*) override { LOG(FATAL) << "TextSearchExpression has to be rewritten"; } + void accept(ExprVisitor*) override { + LOG(FATAL) << "TextSearchExpression has to be rewritten"; + } std::string toString() const override; @@ -98,11 +124,17 @@ class TextSearchExpression : public Expression { return pool_->add(new TextSearchExpression(pool_, kind_, arg)); } - const TextSearchArgument* arg() const { return arg_; } + const TextSearchArgument* arg() const { + return arg_; + } - TextSearchArgument* arg() { return arg_; } + TextSearchArgument* arg() { + return arg_; + } - void setArgs(TextSearchArgument* arg) { arg_ = arg; } + void setArgs(TextSearchArgument* arg) { + arg_ = arg; + } private: TextSearchExpression(ObjectPool* pool, Kind kind, TextSearchArgument* arg) @@ -114,7 +146,9 @@ class TextSearchExpression : public Expression { LOG(FATAL) << "TextSearchExpression has to be rewritten"; } - void resetFrom(Decoder&) override { LOG(FATAL) << "TextSearchExpression has to be reset"; } + void resetFrom(Decoder&) override { + LOG(FATAL) << "TextSearchExpression has to be reset"; + } private: TextSearchArgument* arg_{nullptr}; diff --git a/src/common/expression/TypeCastingExpression.cpp b/src/common/expression/TypeCastingExpression.cpp index b2214f122d4..49bb02bf962 100644 --- a/src/common/expression/TypeCastingExpression.cpp +++ b/src/common/expression/TypeCastingExpression.cpp @@ -126,10 +126,12 @@ void TypeCastingExpression::resetFrom(Decoder& decoder) { std::string TypeCastingExpression::toString() const { std::stringstream out; - out << "(" << vType_ << ")" << operand_->toString(); + out << "(" << vType_ << ")" << (operand_ ? operand_->toString() : ""); return out.str(); } -void TypeCastingExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void TypeCastingExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/TypeCastingExpression.h b/src/common/expression/TypeCastingExpression.h index 98597aae3f8..092b529fb4f 100644 --- a/src/common/expression/TypeCastingExpression.h +++ b/src/common/expression/TypeCastingExpression.h @@ -32,13 +32,21 @@ class TypeCastingExpression final : public Expression { return TypeCastingExpression::make(pool_, type(), operand()->clone()); } - const Expression* operand() const { return operand_; } + const Expression* operand() const { + return operand_; + } - Expression* operand() { return operand_; } + Expression* operand() { + return operand_; + } - void setOperand(Expression* expr) { operand_ = expr; } + void setOperand(Expression* expr) { + operand_ = expr; + } - Value::Type type() const { return vType_; } + Value::Type type() const { + return vType_; + } static bool validateTypeCast(Value::Type operandType, Value::Type type); diff --git a/src/common/expression/UUIDExpression.cpp b/src/common/expression/UUIDExpression.cpp index 42bd8c3bb0d..02393a05c41 100644 --- a/src/common/expression/UUIDExpression.cpp +++ b/src/common/expression/UUIDExpression.cpp @@ -42,6 +42,8 @@ std::string UUIDExpression::toString() const { return folly::stringPrintf("uuid(\"%s\")", field_.c_str()); } -void UUIDExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void UUIDExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/UUIDExpression.h b/src/common/expression/UUIDExpression.h index ff4e84ded18..ed53879e02d 100644 --- a/src/common/expression/UUIDExpression.h +++ b/src/common/expression/UUIDExpression.h @@ -26,7 +26,9 @@ class UUIDExpression final : public Expression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return UUIDExpression::make(pool_, field_); } + Expression* clone() const override { + return UUIDExpression::make(pool_, field_); + } private: explicit UUIDExpression(ObjectPool* pool, const std::string& field = "") diff --git a/src/common/expression/UnaryExpression.cpp b/src/common/expression/UnaryExpression.cpp index 54adcfd7c26..935afc81204 100644 --- a/src/common/expression/UnaryExpression.cpp +++ b/src/common/expression/UnaryExpression.cpp @@ -111,21 +111,23 @@ std::string UnaryExpression::toString() const { op = "--"; break; case Kind::kIsNull: - return operand_->toString() + " IS NULL"; + return (operand_ ? operand_->toString() : "") + " IS NULL"; case Kind::kIsNotNull: - return operand_->toString() + " IS NOT NULL"; + return (operand_ ? operand_->toString() : "") + " IS NOT NULL"; case Kind::kIsEmpty: - return operand_->toString() + " IS EMPTY"; + return (operand_ ? operand_->toString() : "") + " IS EMPTY"; case Kind::kIsNotEmpty: - return operand_->toString() + " IS NOT EMPTY"; + return (operand_ ? operand_->toString() : "") + " IS NOT EMPTY"; default: op = "illegal symbol "; } std::stringstream out; - out << op << "(" << operand_->toString() << ")"; + out << op << "(" << (operand_ ? operand_->toString() : "") << ")"; return out.str(); } -void UnaryExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void UnaryExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/UnaryExpression.h b/src/common/expression/UnaryExpression.h index a0039d02eac..d17d459b59d 100644 --- a/src/common/expression/UnaryExpression.h +++ b/src/common/expression/UnaryExpression.h @@ -62,11 +62,17 @@ class UnaryExpression final : public Expression { return pool_->add(new UnaryExpression(pool_, kind(), operand_->clone())); } - const Expression* operand() const { return operand_; } + const Expression* operand() const { + return operand_; + } - Expression* operand() { return operand_; } + Expression* operand() { + return operand_; + } - void setOperand(Expression* expr) { operand_ = expr; } + void setOperand(Expression* expr) { + operand_ = expr; + } private: explicit UnaryExpression(ObjectPool* pool, Kind kind, Expression* operand = nullptr) diff --git a/src/common/expression/VariableExpression.cpp b/src/common/expression/VariableExpression.cpp index 3e23d7c311d..9dea92f4c98 100644 --- a/src/common/expression/VariableExpression.cpp +++ b/src/common/expression/VariableExpression.cpp @@ -9,9 +9,13 @@ #include "common/expression/ExprVisitor.h" namespace nebula { -const Value& VariableExpression::eval(ExpressionContext& ctx) { return ctx.getVar(var_); } +const Value& VariableExpression::eval(ExpressionContext& ctx) { + return ctx.getVar(var_); +} -void VariableExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void VariableExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} void VariableExpression::writeTo(Encoder& encoder) const { encoder << kind_; @@ -54,11 +58,13 @@ std::string VersionedVariableExpression::toString() const { std::stringstream out; out << "$" << var_; if (version_ != nullptr) { - out << "{" << version_->toString() << "}"; + out << "{" << (version_ ? version_->toString() : "") << "}"; } return out.str(); } -void VersionedVariableExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void VersionedVariableExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/VariableExpression.h b/src/common/expression/VariableExpression.h index 23210860c85..e2b4e03d83d 100644 --- a/src/common/expression/VariableExpression.h +++ b/src/common/expression/VariableExpression.h @@ -17,9 +17,13 @@ class VariableExpression final : public Expression { return pool->add(new VariableExpression(pool, var, isInner)); } - const std::string& var() const { return var_; } + const std::string& var() const { + return var_; + } - bool isInner() const { return isInner_; } + bool isInner() const { + return isInner_; + } const Value& eval(ExpressionContext& ctx) override; @@ -34,7 +38,9 @@ class VariableExpression final : public Expression { void accept(ExprVisitor* visitor) override; - Expression* clone() const override { return VariableExpression::make(pool_, var(), isInner_); } + Expression* clone() const override { + return VariableExpression::make(pool_, var(), isInner_); + } private: explicit VariableExpression(ObjectPool* pool, const std::string& var = "", bool isInner = false) @@ -60,7 +66,9 @@ class VersionedVariableExpression final : public Expression { return pool->add(new VersionedVariableExpression(pool, var, version)); } - const std::string& var() const { return var_; } + const std::string& var() const { + return var_; + } const Value& eval(ExpressionContext& ctx) override; diff --git a/src/common/expression/VertexExpression.cpp b/src/common/expression/VertexExpression.cpp index 3ed5739a593..6159c647a6f 100644 --- a/src/common/expression/VertexExpression.cpp +++ b/src/common/expression/VertexExpression.cpp @@ -35,6 +35,8 @@ void VertexExpression::resetFrom(Decoder& decoder) { name_ = decoder.readStr(); } -void VertexExpression::accept(ExprVisitor* visitor) { visitor->visit(this); } +void VertexExpression::accept(ExprVisitor* visitor) { + visitor->visit(this); +} } // namespace nebula diff --git a/src/common/expression/VertexExpression.h b/src/common/expression/VertexExpression.h index 67c0337e5aa..4f2f550fa15 100644 --- a/src/common/expression/VertexExpression.h +++ b/src/common/expression/VertexExpression.h @@ -28,11 +28,17 @@ class VertexExpression final : public Expression { void accept(ExprVisitor *visitor) override; - Expression *clone() const override { return VertexExpression::make(pool_, name()); } + Expression *clone() const override { + return VertexExpression::make(pool_, name()); + } - std::string toString() const override { return name_; } + std::string toString() const override { + return name_; + } - const std::string &name() const { return name_; } + const std::string &name() const { + return name_; + } bool operator==(const Expression &expr) const override; diff --git a/src/common/expression/test/CMakeLists.txt b/src/common/expression/test/CMakeLists.txt index 4457d468103..b71eb7aac88 100644 --- a/src/common/expression/test/CMakeLists.txt +++ b/src/common/expression/test/CMakeLists.txt @@ -9,6 +9,9 @@ set(expression_test_common_libs $ $ $ + $ + $ + $ $ $ $ diff --git a/src/common/expression/test/ExpressionContextMock.h b/src/common/expression/test/ExpressionContextMock.h index dda2d5369c0..f515bd6f453 100644 --- a/src/common/expression/test/ExpressionContextMock.h +++ b/src/common/expression/test/ExpressionContextMock.h @@ -107,7 +107,9 @@ class ExpressionContextMock final : public ExpressionContext { return Value(); } - Value getEdge() const override { return Value(); } + Value getEdge() const override { + return Value(); + } Value getColumn(int32_t index) const override; diff --git a/src/common/fs/FileUtils.cpp b/src/common/fs/FileUtils.cpp index df76b07f468..f5293de8303 100644 --- a/src/common/fs/FileUtils.cpp +++ b/src/common/fs/FileUtils.cpp @@ -198,13 +198,21 @@ int64_t FileUtils::fileLastUpdateTime(const char* path) { return st.st_mtime; } -bool FileUtils::isStdinTTY() { return isFdTTY(::fileno(stdin)); } +bool FileUtils::isStdinTTY() { + return isFdTTY(::fileno(stdin)); +} -bool FileUtils::isStdoutTTY() { return isFdTTY(::fileno(stdout)); } +bool FileUtils::isStdoutTTY() { + return isFdTTY(::fileno(stdout)); +} -bool FileUtils::isStderrTTY() { return isFdTTY(::fileno(stderr)); } +bool FileUtils::isStderrTTY() { + return isFdTTY(::fileno(stderr)); +} -bool FileUtils::isFdTTY(int fd) { return ::isatty(fd) == 1; } +bool FileUtils::isFdTTY(int fd) { + return ::isatty(fd) == 1; +} std::string FileUtils::joinPath(const folly::StringPiece dir, const folly::StringPiece filename) { std::string buf; diff --git a/src/common/fs/FileUtils.h b/src/common/fs/FileUtils.h index d87c59ec227..1478f80d626 100644 --- a/src/common/fs/FileUtils.h +++ b/src/common/fs/FileUtils.h @@ -179,7 +179,9 @@ class FileUtils final { ~Iterator(); // Whether this iterator is valid - bool valid() const { return status_.ok(); } + bool valid() const { + return status_.ok(); + } // Step to the next line or entry void next(); @@ -224,7 +226,9 @@ class FileUtils final { } // Status to indicates the error - const Status& status() const { return status_; } + const Status& status() const { + return status_; + } private: void openFileOrDirectory(); diff --git a/src/common/fs/TempDir.h b/src/common/fs/TempDir.h index 304c35601f0..b1d8b13113f 100644 --- a/src/common/fs/TempDir.h +++ b/src/common/fs/TempDir.h @@ -30,7 +30,9 @@ class TempDir final { ~TempDir(); - const char* path() const { return dirPath_.get(); } + const char* path() const { + return dirPath_.get(); + } private: std::unique_ptr dirPath_; diff --git a/src/common/fs/TempFile.cpp b/src/common/fs/TempFile.cpp index 2f9e5b741f7..765651341a7 100644 --- a/src/common/fs/TempFile.cpp +++ b/src/common/fs/TempFile.cpp @@ -29,7 +29,9 @@ TempFile::~TempFile() { } } -const char* TempFile::path() const { return path_.get(); } +const char* TempFile::path() const { + return path_.get(); +} } // namespace fs } // namespace nebula diff --git a/src/common/function/AggFunctionManager.h b/src/common/function/AggFunctionManager.h index 8e5f7cecc24..dcd7666c9e1 100644 --- a/src/common/function/AggFunctionManager.h +++ b/src/common/function/AggFunctionManager.h @@ -30,43 +30,81 @@ class AggData final { } } - const Value& cnt() const { return cnt_; } + const Value& cnt() const { + return cnt_; + } - Value& cnt() { return cnt_; } + Value& cnt() { + return cnt_; + } - void setCnt(Value&& cnt) { cnt_ = std::move(cnt); } + void setCnt(Value&& cnt) { + cnt_ = std::move(cnt); + } - const Value& sum() const { return sum_; } + const Value& sum() const { + return sum_; + } - Value& sum() { return sum_; } + Value& sum() { + return sum_; + } - void setSum(Value&& sum) { sum_ = std::move(sum); } + void setSum(Value&& sum) { + sum_ = std::move(sum); + } - const Value& avg() const { return avg_; } + const Value& avg() const { + return avg_; + } - Value& avg() { return avg_; } + Value& avg() { + return avg_; + } - void setAvg(Value&& avg) { avg_ = std::move(avg); } + void setAvg(Value&& avg) { + avg_ = std::move(avg); + } - const Value& deviation() const { return deviation_; } + const Value& deviation() const { + return deviation_; + } - Value& deviation() { return deviation_; } + Value& deviation() { + return deviation_; + } - void setDeviation(Value&& deviation) { deviation_ = std::move(deviation); } + void setDeviation(Value&& deviation) { + deviation_ = std::move(deviation); + } - const Value& result() const { return result_; } + const Value& result() const { + return result_; + } - Value& result() { return result_; } + Value& result() { + return result_; + } - void setResult(Value&& res) { result_ = std::move(res); } + void setResult(Value&& res) { + result_ = std::move(res); + } - void setResult(const Value& res) { result_ = res; } + void setResult(const Value& res) { + result_ = res; + } - const Set* uniques() const { return uniques_.get(); } + const Set* uniques() const { + return uniques_.get(); + } - Set* uniques() { return uniques_.get(); } + Set* uniques() { + return uniques_.get(); + } - void setUniques(Set* uniques) { uniques_.reset(uniques); } + void setUniques(Set* uniques) { + uniques_.reset(uniques); + } private: Value cnt_; diff --git a/src/common/geo/GeoFunction.cpp b/src/common/geo/GeoFunction.cpp index f1340af67bd..7c9d3e89d8d 100644 --- a/src/common/geo/GeoFunction.cpp +++ b/src/common/geo/GeoFunction.cpp @@ -175,7 +175,9 @@ bool GeoFunction::covers(const Geography& a, const Geography& b) { return false; } -bool GeoFunction::coveredBy(const Geography& a, const Geography& b) { return covers(b, a); } +bool GeoFunction::coveredBy(const Geography& a, const Geography& b) { + return covers(b, a); +} bool GeoFunction::dWithin(const Geography& a, const Geography& b, double distance, bool exclusive) { auto aRegion = a.asS2(); diff --git a/src/common/geo/GeoIndex.cpp b/src/common/geo/GeoIndex.cpp index ffd2a3753f6..d09d355cd22 100644 --- a/src/common/geo/GeoIndex.cpp +++ b/src/common/geo/GeoIndex.cpp @@ -44,15 +44,15 @@ nebula::storage::cpp2::IndexColumnHint ScanRange::toIndexColumnHint() const { nebula::storage::cpp2::IndexColumnHint hint; // column_name should be set by the caller if (isRangeScan) { - hint.set_scan_type(nebula::storage::cpp2::ScanType::RANGE); + hint.scan_type_ref() = nebula::storage::cpp2::ScanType::RANGE; // Encode uint64_t as string in advance - hint.set_begin_value(IndexKeyUtils::encodeUint64(rangeMin)); - hint.set_end_value(IndexKeyUtils::encodeUint64(rangeMax)); - hint.set_include_begin(true); - hint.set_include_end(true); + hint.begin_value_ref() = IndexKeyUtils::encodeUint64(rangeMin); + hint.end_value_ref() = IndexKeyUtils::encodeUint64(rangeMax); + hint.include_begin_ref() = true; + hint.include_end_ref() = true; } else { - hint.set_scan_type(nebula::storage::cpp2::ScanType::PREFIX); - hint.set_begin_value(IndexKeyUtils::encodeUint64(rangeMin)); + hint.scan_type_ref() = nebula::storage::cpp2::ScanType::PREFIX; + hint.begin_value_ref() = IndexKeyUtils::encodeUint64(rangeMin); } return hint; } @@ -82,7 +82,9 @@ std::vector GeoIndex::intersects(const Geography& g) const noexcept { } // covers degenerates to intersects currently -std::vector GeoIndex::covers(const Geography& g) const noexcept { return intersects(g); } +std::vector GeoIndex::covers(const Geography& g) const noexcept { + return intersects(g); +} // coveredBy degenerates to intersects currently std::vector GeoIndex::coveredBy(const Geography& g) const noexcept { diff --git a/src/common/geo/io/wkb/ByteOrderDataIOStream.h b/src/common/geo/io/wkb/ByteOrderDataIOStream.h index 6228d8e27b9..193fde71435 100644 --- a/src/common/geo/io/wkb/ByteOrderDataIOStream.h +++ b/src/common/geo/io/wkb/ByteOrderDataIOStream.h @@ -21,11 +21,17 @@ class ByteOrderDataInStream { ~ByteOrderDataInStream() = default; - std::string str() const { return stream_.str(); } + std::string str() const { + return stream_.str(); + } - void setInput(const std::string& s) { stream_.str(s); } + void setInput(const std::string& s) { + stream_.str(s); + } - void setByteOrder(ByteOrder order) { byteOrder_ = order; } + void setByteOrder(ByteOrder order) { + byteOrder_ = order; + } StatusOr readUint8(); @@ -45,9 +51,13 @@ class ByteOrderDataOutStream { ~ByteOrderDataOutStream() = default; - std::string str() const { return stream_.str(); } + std::string str() const { + return stream_.str(); + } - void setByteOrder(ByteOrder order) { byteOrder_ = order; } + void setByteOrder(ByteOrder order) { + byteOrder_ = order; + } void writeUint8(uint8_t v); diff --git a/src/common/geo/io/wkb/WKBWriter.cpp b/src/common/geo/io/wkb/WKBWriter.cpp index d17572ef154..499d3c27411 100644 --- a/src/common/geo/io/wkb/WKBWriter.cpp +++ b/src/common/geo/io/wkb/WKBWriter.cpp @@ -38,7 +38,9 @@ std::string WKBWriter::write(const Geography& geog, ByteOrder byteOrder) { } } -void WKBWriter::writePoint(const Point& point) { writeCoordinate(point.coord); } +void WKBWriter::writePoint(const Point& point) { + writeCoordinate(point.coord); +} void WKBWriter::writeLineString(const LineString& line) { auto coordList = line.coordList; diff --git a/src/common/geo/io/wkt/WKTScanner.h b/src/common/geo/io/wkt/WKTScanner.h index 1664601bb30..4d8abf027e8 100644 --- a/src/common/geo/io/wkt/WKTScanner.h +++ b/src/common/geo/io/wkt/WKTScanner.h @@ -37,7 +37,9 @@ class WKTScanner : public yyFlexLexer { public: // Called by WKTReader to set the `readBuffer' callback, which would be // invoked by LexerInput to fill the stream buffer. - void setReadBuffer(std::function readBuffer) { readBuffer_ = readBuffer; } + void setReadBuffer(std::function readBuffer) { + readBuffer_ = readBuffer; + } // Manually invoked by WKTReader to recover from a failure state. // This makes the scanner reentrant. @@ -45,13 +47,19 @@ class WKTScanner : public yyFlexLexer { yy_flush_buffer(yy_buffer_stack ? yy_buffer_stack[yy_buffer_stack_top] : nullptr); } - void setWKT(std::string *wkt) { wkt_ = wkt; } + void setWKT(std::string *wkt) { + wkt_ = wkt; + } - std::string *wkt() { return wkt_; } + std::string *wkt() { + return wkt_; + } protected: // Called when YY_INPUT is invoked - int LexerInput(char *buf, int maxSize) override { return readBuffer_(buf, maxSize); } + int LexerInput(char *buf, int maxSize) override { + return readBuffer_(buf, maxSize); + } using TokenType = nebula::geo::WKTParser::token; diff --git a/src/common/geo/io/wkt/wkt_parser.yy b/src/common/geo/io/wkt/wkt_parser.yy index 00d3af12b32..7d01a75267d 100644 --- a/src/common/geo/io/wkt/wkt_parser.yy +++ b/src/common/geo/io/wkt/wkt_parser.yy @@ -3,7 +3,7 @@ %no-lines %locations %define api.namespace { nebula::geo } -%define parser_class_name { WKTParser } +%define api.parser.class { WKTParser } %lex-param { nebula::geo::WKTScanner& scanner } %parse-param { nebula::geo::WKTScanner& scanner } %parse-param { std::string &errmsg } diff --git a/src/common/graph/Response.h b/src/common/graph/Response.h index f3f0ef08268..d1d6594b235 100644 --- a/src/common/graph/Response.h +++ b/src/common/graph/Response.h @@ -120,6 +120,7 @@ X(E_GET_META_DIR_FAILURE, -2072) \ \ X(E_QUERY_NOT_FOUND, -2073) \ + X(E_AGENT_HB_FAILUE, -2074) \ /* 3xxx for storaged */ \ X(E_CONSENSUS_ERROR, -3001) \ X(E_KEY_HAS_EXISTS, -3002) \ @@ -215,7 +216,9 @@ struct AuthResponse { errorMsg = nullptr; } - void clear() { __clear(); } + void clear() { + __clear(); + } bool operator==(const AuthResponse &rhs) const { if (errorCode != rhs.errorCode) { @@ -241,6 +244,9 @@ struct AuthResponse { }; struct ProfilingStats { + ProfilingStats() = default; + ProfilingStats(ProfilingStats &&) = default; + void __clear() { rows = 0; execDurationInUs = 0; @@ -248,7 +254,17 @@ struct ProfilingStats { otherStats = nullptr; } - void clear() { __clear(); } + void clear() { + __clear(); + } + + auto &operator=(ProfilingStats &&rhs) { + this->rows = rhs.rows; + this->execDurationInUs = rhs.execDurationInUs; + this->totalDurationInUs = rhs.totalDurationInUs; + this->otherStats = std::move(rhs.otherStats); + return *this; + } bool operator==(const ProfilingStats &rhs) const { if (rows != rhs.rows) { @@ -290,7 +306,15 @@ struct PlanNodeBranchInfo { conditionNodeId = -1; } - void clear() { __clear(); } + void clear() { + __clear(); + } + + auto &operator=(const PlanNodeBranchInfo &rhs) { + this->isDoBranch = rhs.isDoBranch; + this->conditionNodeId = rhs.conditionNodeId; + return *this; + } bool operator==(const PlanNodeBranchInfo &rhs) const { return isDoBranch == rhs.isDoBranch && conditionNodeId == rhs.conditionNodeId; @@ -316,9 +340,13 @@ struct Pair { value.clear(); } - void clear() { __clear(); } + void clear() { + __clear(); + } - bool operator==(const Pair &rhs) const { return key == rhs.key && value == rhs.value; } + bool operator==(const Pair &rhs) const { + return key == rhs.key && value == rhs.value; + } std::string key; std::string value; @@ -330,6 +358,9 @@ struct Pair { }; struct PlanNodeDescription { + PlanNodeDescription() = default; + PlanNodeDescription(PlanNodeDescription &&) = default; + void __clear() { name.clear(); id = -1; @@ -340,7 +371,20 @@ struct PlanNodeDescription { dependencies = nullptr; } - void clear() { __clear(); } + void clear() { + __clear(); + } + + auto &operator=(PlanNodeDescription &&rhs) { + this->name = std::move(rhs.name); + this->id = rhs.id; + this->outputVar = std::move(rhs.outputVar); + this->description = std::move(rhs.description); + this->profiles = std::move(rhs.profiles); + this->branchInfo = std::move(rhs.branchInfo); + this->dependencies = std::move(rhs.dependencies); + return *this; + } bool operator==(const PlanNodeDescription &rhs) const; @@ -383,6 +427,9 @@ struct PlanNodeDescription { }; struct PlanDescription { + PlanDescription() = default; + PlanDescription(PlanDescription &&rhs) = default; + void __clear() { planNodeDescs.clear(); nodeIndexMap.clear(); @@ -390,7 +437,17 @@ struct PlanDescription { optimize_time_in_us = 0; } - void clear() { __clear(); } + void clear() { + __clear(); + } + + auto &operator=(PlanDescription &&rhs) { + this->planNodeDescs = std::move(rhs.planNodeDescs); + this->nodeIndexMap = std::move(rhs.nodeIndexMap); + this->format = std::move(rhs.format); + this->optimize_time_in_us = rhs.optimize_time_in_us; + return *this; + } bool operator==(const PlanDescription &rhs) const { return planNodeDescs == rhs.planNodeDescs && nodeIndexMap == rhs.nodeIndexMap && @@ -440,7 +497,9 @@ struct ExecutionResponse { comment.reset(); } - void clear() { __clear(); } + void clear() { + __clear(); + } bool operator==(const ExecutionResponse &rhs) const { if (errorCode != rhs.errorCode) { diff --git a/src/common/hdfs/HdfsCommandHelper.cpp b/src/common/hdfs/HdfsCommandHelper.cpp index e72fc94f1b5..8930773c609 100644 --- a/src/common/hdfs/HdfsCommandHelper.cpp +++ b/src/common/hdfs/HdfsCommandHelper.cpp @@ -42,7 +42,9 @@ StatusOr HdfsCommandHelper::copyToLocal(const std::string& hdfsHost } } -bool HdfsCommandHelper::checkHadoopPath() { return std::getenv("HADOOP_HOME") != nullptr; } +bool HdfsCommandHelper::checkHadoopPath() { + return std::getenv("HADOOP_HOME") != nullptr; +} } // namespace hdfs } // namespace nebula diff --git a/src/common/http/test/HttpClientTest.cpp b/src/common/http/test/HttpClientTest.cpp index db9d77ee4b6..ed8b28407dc 100644 --- a/src/common/http/test/HttpClientTest.cpp +++ b/src/common/http/test/HttpClientTest.cpp @@ -33,7 +33,9 @@ class HttpClientHandler : public proxygen::RequestHandler { void onUpgrade(proxygen::UpgradeProtocol) noexcept override {} - void requestComplete() noexcept override { delete this; } + void requestComplete() noexcept override { + delete this; + } void onError(proxygen::ProxygenError error) noexcept override { LOG(ERROR) << "HttpClientHandler Error: " << proxygen::getErrorString(error); diff --git a/src/common/memory/test/MemoryUtilsTest.cpp b/src/common/memory/test/MemoryUtilsTest.cpp index f3e8cce8522..a2fab715cfe 100644 --- a/src/common/memory/test/MemoryUtilsTest.cpp +++ b/src/common/memory/test/MemoryUtilsTest.cpp @@ -37,7 +37,7 @@ TEST(MemoryHighWatermarkTest, DISABLED_TestHitsHighWatermarkInContainer) { ASSERT_TRUE(std::move(status).value()); } -TEST(MemoryHighWatermarkTest, TestNotHitsHighWatermarkInContainer) { +TEST(MemoryHighWatermarkTest, DISABLED_TestNotHitsHighWatermarkInContainer) { FLAGS_containerized = true; FLAGS_system_memory_high_watermark_ratio = 0.99; auto status = MemoryUtils::hitsHighWatermark(); diff --git a/src/common/meta/Common.h b/src/common/meta/Common.h index 0f08a8e0aa4..625102c4d71 100644 --- a/src/common/meta/Common.h +++ b/src/common/meta/Common.h @@ -24,7 +24,9 @@ struct PartHosts { this->hosts_ == rhs.hosts_; } - bool operator!=(const PartHosts& rhs) const { return !(*this == rhs); } + bool operator!=(const PartHosts& rhs) const { + return !(*this == rhs); + } }; // ListenerHosts saves the listener type and the peers of the data replica diff --git a/src/common/meta/GflagsManager.cpp b/src/common/meta/GflagsManager.cpp index a7dd8289981..0588d45cde6 100644 --- a/src/common/meta/GflagsManager.cpp +++ b/src/common/meta/GflagsManager.cpp @@ -128,10 +128,10 @@ std::vector GflagsManager::declareGflags(const cpp2::ConfigMod continue; } cpp2::ConfigItem item; - item.set_name(name); - item.set_module(module); - item.set_mode(mode); - item.set_value(std::move(value)); + item.name_ref() = name; + item.module_ref() = module; + item.mode_ref() = mode; + item.value_ref() = std::move(value); configItems.emplace_back(std::move(item)); } LOG(INFO) << "Prepare to register " << configItems.size() << " gflags to meta"; diff --git a/src/common/meta/NebulaSchemaProvider.cpp b/src/common/meta/NebulaSchemaProvider.cpp index 976e8498a9b..535766e5a06 100644 --- a/src/common/meta/NebulaSchemaProvider.cpp +++ b/src/common/meta/NebulaSchemaProvider.cpp @@ -12,11 +12,17 @@ namespace meta { using nebula::cpp2::PropertyType; -SchemaVer NebulaSchemaProvider::getVersion() const noexcept { return ver_; } +SchemaVer NebulaSchemaProvider::getVersion() const noexcept { + return ver_; +} -size_t NebulaSchemaProvider::getNumFields() const noexcept { return fields_.size(); } +size_t NebulaSchemaProvider::getNumFields() const noexcept { + return fields_.size(); +} -size_t NebulaSchemaProvider::getNumNullableFields() const noexcept { return numNullableFields_; } +size_t NebulaSchemaProvider::getNumNullableFields() const noexcept { + return numNullableFields_; +} size_t NebulaSchemaProvider::size() const noexcept { if (fields_.size() > 0) { @@ -177,7 +183,9 @@ void NebulaSchemaProvider::setProp(cpp2::SchemaProp schemaProp) { schemaProp_ = std::move(schemaProp); } -const cpp2::SchemaProp NebulaSchemaProvider::getProp() const { return schemaProp_; } +const cpp2::SchemaProp NebulaSchemaProvider::getProp() const { + return schemaProp_; +} StatusOr> NebulaSchemaProvider::getTTLInfo() const { if (!schemaProp_.ttl_col_ref().has_value()) { diff --git a/src/common/meta/NebulaSchemaProvider.h b/src/common/meta/NebulaSchemaProvider.h index 6c47b33acbf..1a30952b11f 100644 --- a/src/common/meta/NebulaSchemaProvider.h +++ b/src/common/meta/NebulaSchemaProvider.h @@ -40,26 +40,42 @@ class NebulaSchemaProvider : public SchemaProviderIf { nullFlagPos_(nullFlagPos), geoShape_(geoShape) {} - const char* name() const override { return name_.c_str(); } + const char* name() const override { + return name_.c_str(); + } - nebula::cpp2::PropertyType type() const override { return type_; } + nebula::cpp2::PropertyType type() const override { + return type_; + } - bool nullable() const override { return nullable_; } + bool nullable() const override { + return nullable_; + } - bool hasDefault() const override { return hasDefault_; } + bool hasDefault() const override { + return hasDefault_; + } - Expression* defaultValue() const override { return defaultValue_; } + Expression* defaultValue() const override { + return defaultValue_; + } - size_t size() const override { return size_; } + size_t size() const override { + return size_; + } - size_t offset() const override { return offset_; } + size_t offset() const override { + return offset_; + } size_t nullFlagPos() const override { DCHECK(nullable_); return nullFlagPos_; } - cpp2::GeoShape geoShape() const override { return geoShape_; } + cpp2::GeoShape geoShape() const override { + return geoShape_; + } private: std::string name_; diff --git a/src/common/meta/SchemaProviderIf.h b/src/common/meta/SchemaProviderIf.h index a268215ed7b..294fad85f24 100644 --- a/src/common/meta/SchemaProviderIf.h +++ b/src/common/meta/SchemaProviderIf.h @@ -50,9 +50,13 @@ class SchemaProviderIf { friend class SchemaProviderIf; public: - const Field& operator*() const { return *field_; } + const Field& operator*() const { + return *field_; + } - const Field* operator->() const { return field_; } + const Field* operator->() const { + return field_; + } Iterator& operator++() { if (field_) { @@ -70,7 +74,9 @@ class SchemaProviderIf { return *this; } - operator bool() const { return static_cast(field_); } + operator bool() const { + return static_cast(field_); + } bool operator==(const Iterator& rhs) const { return schema_ == rhs.schema_ && (index_ == rhs.index_ || (!field_ && !rhs.field_)); @@ -114,9 +120,13 @@ class SchemaProviderIf { * Iterator implementation * *****************************************/ - Iterator begin() const { return Iterator(this, 0); } + Iterator begin() const { + return Iterator(this, 0); + } - Iterator end() const { return Iterator(this, getNumFields()); } + Iterator end() const { + return Iterator(this, getNumFields()); + } }; } // namespace meta diff --git a/src/common/process/ProcessUtils.cpp b/src/common/process/ProcessUtils.cpp index d33851131fa..64a10d5b3d0 100644 --- a/src/common/process/ProcessUtils.cpp +++ b/src/common/process/ProcessUtils.cpp @@ -153,7 +153,7 @@ StatusOr ProcessUtils::runCommand(const char *command) { if (ferror(f)) { // Something is wrong - fclose(f); + pclose(f); return Status::Error("Failed to read the output of the command"); } diff --git a/src/common/process/test/ProcessTest.cpp b/src/common/process/test/ProcessTest.cpp index a759acc3abc..8347d581a52 100644 --- a/src/common/process/test/ProcessTest.cpp +++ b/src/common/process/test/ProcessTest.cpp @@ -72,7 +72,9 @@ TEST(ProcessUtils, isPidAvailable) { } }; auto pidFile = folly::stringPrintf("/tmp/process_test-%d.pid", ::getpid()); - SCOPE_EXIT { ::unlink(pidFile.c_str()); }; + SCOPE_EXIT { + ::unlink(pidFile.c_str()); + }; auto status = ProcessUtils::makePidFile(pidFile, genPid()); ASSERT_TRUE(status.ok()) << status; // there are chances that the chosen pid was occupied already, diff --git a/src/common/stats/StatsManager.cpp b/src/common/stats/StatsManager.cpp index 083b7c890db..5911566e476 100644 --- a/src/common/stats/StatsManager.cpp +++ b/src/common/stats/StatsManager.cpp @@ -5,7 +5,9 @@ #include "common/stats/StatsManager.h" +#include #include +#include #include "common/base/Base.h" @@ -19,7 +21,9 @@ StatsManager& StatsManager::get() { } // static -void StatsManager::setDomain(folly::StringPiece domain) { get().domain_ = domain.toString(); } +void StatsManager::setDomain(folly::StringPiece domain) { + get().domain_ = domain.toString(); +} // static void StatsManager::setReportInfo(HostAddr addr, int32_t interval) { @@ -51,7 +55,7 @@ void StatsManager::parseStats(const folly::StringPiece stats, // Percentile double pct; if (strToPct(trimmedPart, pct)) { - percentiles.push_back(std::make_pair(trimmedPart, pct)); + percentiles.emplace_back(trimmedPart, pct); } else { LOG(ERROR) << "\"" << trimmedPart << "\" is not a valid percentile form"; } @@ -63,38 +67,45 @@ void StatsManager::parseStats(const folly::StringPiece stats, // static CounterId StatsManager::registerStats(folly::StringPiece counterName, std::string stats) { - using std::chrono::seconds; - - auto& sm = get(); std::vector methods; std::vector> percentiles; parseStats(stats, methods, percentiles); + return registerStats(counterName, methods); +} + +CounterId StatsManager::registerStats(folly::StringPiece counterName, + std::vector methods) { + using std::chrono::seconds; + + auto& sm = get(); std::string name = counterName.toString(); folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); auto it = sm.nameMap_.find(name); if (it != sm.nameMap_.end()) { - DCHECK_GT(it->second.id_.index(), 0); + DCHECK(!it->second.id_.isHisto()); VLOG(2) << "The counter \"" << name << "\" already exists"; it->second.methods_ = methods; - return it->second.id_.index(); + return it->second.id_; } // Insert the Stats - sm.stats_.emplace_back(std::make_pair( - std::make_unique(), - std::make_unique(60, - std::initializer_list( - {seconds(5), seconds(60), seconds(600), seconds(3600)})))); - int32_t index = sm.stats_.size(); - sm.nameMap_.emplace( + sm.stats_.emplace( + counterName, + std::make_pair(std::make_unique(), + std::make_unique( + 60, + std::initializer_list( + {seconds(5), seconds(60), seconds(600), seconds(3600)})))); + std::string index(counterName); + auto it2 = sm.nameMap_.emplace( std::piecewise_construct, std::forward_as_tuple(std::move(name)), std::forward_as_tuple( - index, std::move(methods), std::vector>())); + index, std::move(methods), std::vector>(), false)); VLOG(1) << "Registered stats " << counterName.toString(); - return index; + return it2.first->second.id_; } // static @@ -103,39 +114,147 @@ CounterId StatsManager::registerHisto(folly::StringPiece counterName, StatsManager::VT min, StatsManager::VT max, std::string stats) { - using std::chrono::seconds; std::vector methods; std::vector> percentiles; parseStats(stats, methods, percentiles); + return registerHisto(counterName, bucketSize, min, max, methods, percentiles); +} +// static +CounterId StatsManager::registerHisto(folly::StringPiece counterName, + StatsManager::VT bucketSize, + StatsManager::VT min, + StatsManager::VT max, + std::vector methods, + std::vector> percentiles) { + using std::chrono::seconds; auto& sm = get(); std::string name = counterName.toString(); folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); auto it = sm.nameMap_.find(name); if (it != sm.nameMap_.end()) { - DCHECK_LT(it->second.id_.index(), 0); + DCHECK(it->second.id_.isHisto()); VLOG(2) << "The counter \"" << name << "\" already exists"; it->second.methods_ = methods; it->second.percentiles_ = percentiles; - return it->second.id_.index(); + return it->second.id_; } // Insert the Histogram - sm.histograms_.emplace_back( + sm.histograms_.emplace( + counterName, std::make_pair(std::make_unique(), std::make_unique( bucketSize, min, max, StatsType(60, {seconds(5), seconds(60), seconds(600), seconds(3600)})))); - int32_t index = -sm.histograms_.size(); - sm.nameMap_.emplace(std::piecewise_construct, - std::forward_as_tuple(std::move(name)), - std::forward_as_tuple(index, std::move(methods), std::move(percentiles))); + std::string index(counterName); + auto it2 = sm.nameMap_.emplace( + std::piecewise_construct, + std::forward_as_tuple(std::move(name)), + std::forward_as_tuple( + index, std::move(methods), std::move(percentiles), true, bucketSize, min, max)); VLOG(1) << "Registered histogram " << counterName.toString() << " [bucketSize: " << bucketSize << ", min value: " << min << ", max value: " << max << "]"; - return index; + return it2.first->second.id_; +} + +// static +CounterId StatsManager::counterWithLabels(const CounterId& id, + const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + auto it = sm.nameMap_.find(newIndex); + // Get the counter if it already exists + if (it != sm.nameMap_.end()) { + return it->second.id_; + } + + // Register a new counter if it doesn't exist + auto it2 = sm.nameMap_.find(index); + DCHECK(it2 != sm.nameMap_.end()); + auto& methods = it2->second.methods_; + + return registerStats(newIndex, methods); +} + +// static +CounterId StatsManager::histoWithLabels(const CounterId& id, const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + auto it = sm.nameMap_.find(newIndex); + // Get the counter if it already exists + if (it != sm.nameMap_.end()) { + return it->second.id_; + } + + auto it2 = sm.nameMap_.find(index); + DCHECK(it2 != sm.nameMap_.end()); + auto& methods = it2->second.methods_; + auto& percentiles = it2->second.percentiles_; + + return registerHisto( + newIndex, it2->second.bucketSize_, it2->second.min_, it2->second.max_, methods, percentiles); +} + +// static +void StatsManager::removeCounterWithLabels(const CounterId& id, + const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); + auto it = sm.nameMap_.find(newIndex); + if (it != sm.nameMap_.end()) { + sm.nameMap_.erase(it); + } + sm.stats_.erase(newIndex); +} + +// static +void StatsManager::removeHistoWithLabels(const CounterId& id, + const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); + auto it = sm.nameMap_.find(newIndex); + if (it != sm.nameMap_.end()) { + sm.nameMap_.erase(it); + } + sm.histograms_.erase(newIndex); } // static @@ -143,24 +262,30 @@ void StatsManager::addValue(const CounterId& id, VT value) { using std::chrono::seconds; auto& sm = get(); - int32_t index = id.index(); - if (index > 0) { + if (!id.valid()) { + // The counter is not registered + return; + } + std::string index = id.index(); + bool isHisto = id.isHisto(); + if (!isHisto) { // Stats - --index; - DCHECK_LT(index, sm.stats_.size()); + DCHECK(sm.stats_.find(index) != sm.stats_.end()); std::lock_guard g(*(sm.stats_[index].first)); sm.stats_[index].second->addValue(seconds(time::WallClock::fastNowInSec()), value); - } else if (index < 0) { + } else { // Histogram - index = -(index + 1); - DCHECK_LT(index, sm.histograms_.size()); + DCHECK(sm.histograms_.find(index) != sm.histograms_.end()); std::lock_guard g(*(sm.histograms_[index].first)); sm.histograms_[index].second->addValue(seconds(time::WallClock::fastNowInSec()), value); - } else { - LOG(FATAL) << "Invalid counter id"; } } +// static +void StatsManager::decValue(const CounterId& id, VT value) { + addValue(id, -value); +} + // static bool StatsManager::strToPct(folly::StringPiece part, double& pct) { static const int32_t divisors[] = {1, 1, 10, 100, 1000, 10000}; @@ -322,23 +447,21 @@ StatusOr StatsManager::readStats(const CounterId& id, StatsManager::StatsMethod method) { using std::chrono::seconds; auto& sm = get(); - int32_t index = id.index(); + std::string index = id.index(); - if (index == 0) { + if (index == "") { return Status::Error("Invalid stats"); } - if (index > 0) { + if (!id.isHisto()) { // stats - --index; - DCHECK_LT(index, sm.stats_.size()); + DCHECK(sm.stats_.find(index) != sm.stats_.end()); std::lock_guard g(*(sm.stats_[index].first)); sm.stats_[index].second->update(seconds(time::WallClock::fastNowInSec())); return readValue(*(sm.stats_[index].second), range, method); } else { // histograms_ - index = -(index + 1); - DCHECK_LT(index, sm.histograms_.size()); + DCHECK(sm.histograms_.find(index) != sm.histograms_.end()); std::lock_guard g(*(sm.histograms_[index].first)); sm.histograms_[index].second->update(seconds(time::WallClock::fastNowInSec())); return readValue(*(sm.histograms_[index].second), range, method); @@ -373,13 +496,14 @@ StatusOr StatsManager::readHisto(const CounterId& id, double pct) { using std::chrono::seconds; auto& sm = get(); - int32_t index = id.index(); + std::string index = id.index(); - if (index >= 0) { + if (!id.isHisto()) { return Status::Error("Invalid stats"); } - index = -(index + 1); - if (static_cast(index) >= sm.histograms_.size()) { + + auto it = sm.histograms_.find(index); + if (it == sm.histograms_.end()) { return Status::Error("Invalid stats"); } diff --git a/src/common/stats/StatsManager.h b/src/common/stats/StatsManager.h index 3a1524c088a..45fc586f5e7 100644 --- a/src/common/stats/StatsManager.h +++ b/src/common/stats/StatsManager.h @@ -21,8 +21,9 @@ namespace stats { // A wrapper class of counter index. Each instance can only be writtern once. class CounterId final { public: - CounterId() : index_{0} {} - CounterId(int32_t index) : index_{index} {} // NOLINT + CounterId() = default; + CounterId(const std::string& index, bool isHisto = false) // NOLINT + : index_{index}, isHisto_(isHisto) {} CounterId(const CounterId&) = default; CounterId& operator=(const CounterId& right) { @@ -34,11 +35,12 @@ class CounterId final { LOG(FATAL) << "CounterId cannot be assigned twice"; } index_ = right.index_; + isHisto_ = right.isHisto_; return *this; } - CounterId& operator=(int32_t right) { - if (right == 0) { + CounterId& operator=(const std::string& right) { + if (right == "") { LOG(FATAL) << "Invalid counter id"; } if (valid()) { @@ -49,12 +51,21 @@ class CounterId final { return *this; } - bool valid() const { return index_ != 0; } + bool valid() const { + return index_ != ""; + } + + bool isHisto() const { + return isHisto_; + } - int32_t index() const { return index_; } + std::string index() const { + return index_; + } private: - int32_t index_; + std::string index_; + bool isHisto_{false}; }; /** @@ -84,6 +95,7 @@ class StatsManager final { using VT = int64_t; using StatsType = folly::MultiLevelTimeSeries; using HistogramType = folly::TimeseriesHistogram; + using LabelPair = std::pair; public: enum class StatsMethod { SUM = 1, COUNT, AVG, RATE }; @@ -110,10 +122,24 @@ class StatsManager final { // those specified in the parameter **stats**. If **stats** is empty, nothing // will return from readAllValue() static CounterId registerStats(folly::StringPiece counterName, std::string stats); + static CounterId registerStats(folly::StringPiece counterName, std::vector methods); static CounterId registerHisto( folly::StringPiece counterName, VT bucketSize, VT min, VT max, std::string stats); + static CounterId registerHisto(folly::StringPiece counterName, + VT bucketSize, + VT min, + VT max, + std::vector methods, + std::vector> percentiles); + + static CounterId counterWithLabels(const CounterId& id, const std::vector& labels); + static CounterId histoWithLabels(const CounterId& id, const std::vector& labels); + + static void removeCounterWithLabels(const CounterId& id, const std::vector& labels); + static void removeHistoWithLabels(const CounterId& id, const std::vector& labels); static void addValue(const CounterId& id, VT value = 1); + static void decValue(const CounterId& id, VT value = 1); // The parameter counter here must be a qualified counter name, which includes // all three parts (counter name, method/percentile, and time range). Here are @@ -152,11 +178,21 @@ class StatsManager final { CounterId id_; std::vector methods_; std::vector> percentiles_; + VT bucketSize_, min_, max_; - CounterInfo(int32_t index, + CounterInfo(const std::string& index, std::vector&& methods, - std::vector>&& percentiles) - : id_(index), methods_(std::move(methods)), percentiles_(std::move(percentiles)) {} + std::vector>&& percentiles, + bool isHisto = false, + VT bucketSize = VT(), + VT min = VT(), + VT max = VT()) + : id_(index, isHisto), + methods_(std::move(methods)), + percentiles_(std::move(percentiles)), + bucketSize_(bucketSize), + min_(min), + max_(max) {} }; std::string domain_; @@ -170,10 +206,14 @@ class StatsManager final { std::unordered_map nameMap_; // All time series stats - std::vector, std::unique_ptr>> stats_; + std::unordered_map, std::unique_ptr>> + stats_; // All histogram stats - std::vector, std::unique_ptr>> histograms_; + std::unordered_map, std::unique_ptr>> + histograms_; }; } // namespace stats diff --git a/src/common/stats/test/StatsManagerBenchmark.cpp b/src/common/stats/test/StatsManagerBenchmark.cpp index 933fcc5136a..f1c39fdce81 100644 --- a/src/common/stats/test/StatsManagerBenchmark.cpp +++ b/src/common/stats/test/StatsManagerBenchmark.cpp @@ -31,19 +31,31 @@ void statsBM(const CounterId& counterId, uint32_t numThreads, uint32_t iters) { } } -BENCHMARK(add_stats_value_1t, iters) { statsBM(kCounterStats, 1, iters); } +BENCHMARK(add_stats_value_1t, iters) { + statsBM(kCounterStats, 1, iters); +} -BENCHMARK(add_stats_value_4t, iters) { statsBM(kCounterStats, 4, iters); } +BENCHMARK(add_stats_value_4t, iters) { + statsBM(kCounterStats, 4, iters); +} -BENCHMARK(add_stats_value_8t, iters) { statsBM(kCounterStats, 8, iters); } +BENCHMARK(add_stats_value_8t, iters) { + statsBM(kCounterStats, 8, iters); +} BENCHMARK_DRAW_LINE(); -BENCHMARK(add_histogram_value_1t, iters) { statsBM(kCounterHisto, 1, iters); } +BENCHMARK(add_histogram_value_1t, iters) { + statsBM(kCounterHisto, 1, iters); +} -BENCHMARK(add_histogram_value_4t, iters) { statsBM(kCounterHisto, 4, iters); } +BENCHMARK(add_histogram_value_4t, iters) { + statsBM(kCounterHisto, 4, iters); +} -BENCHMARK(add_histogram_value_8t, iters) { statsBM(kCounterHisto, 8, iters); } +BENCHMARK(add_histogram_value_8t, iters) { + statsBM(kCounterHisto, 8, iters); +} int main(int argc, char** argv) { folly::init(&argc, &argv, true); diff --git a/src/common/stats/test/StatsManagerTest.cpp b/src/common/stats/test/StatsManagerTest.cpp index 513181b400a..92c1f82677e 100644 --- a/src/common/stats/test/StatsManagerTest.cpp +++ b/src/common/stats/test/StatsManagerTest.cpp @@ -107,6 +107,14 @@ TEST(StatsManager, ReadAllTest) { StatsManager::addValue(statId2, 1); StatsManager::addValue(statId2, 2); + // Dynamically register some metrics + auto statId3 = StatsManager::counterWithLabels(statId1, {{"space", "test"}}); + auto statId4 = StatsManager::histoWithLabels(statId2, {{"space", "test"}}); + StatsManager::addValue(statId3, 1); + StatsManager::addValue(statId3, 2); + StatsManager::addValue(statId4, 1); + StatsManager::addValue(statId4, 2); + auto stats = folly::dynamic::array(); StatsManager::readAllValue(stats); @@ -128,6 +136,31 @@ TEST(StatsManager, ReadAllTest) { EXPECT_FALSE(counterExists(stats, "stat04.count.60", val)); EXPECT_FALSE(counterExists(stats, "stat04.avg.3600", val)); EXPECT_FALSE(counterExists(stats, "stat04.p75.5", val)); + + EXPECT_TRUE(counterExists(stats, "space_test_stat04.sum.5", val)); + EXPECT_EQ(3, val); + EXPECT_TRUE(counterExists(stats, "space_test_stat04.p95.5", val)); + EXPECT_EQ(2, val); + EXPECT_TRUE(counterExists(stats, "space_test_stat04.p99.3600", val)); + EXPECT_EQ(2, val); + + EXPECT_TRUE(counterExists(stats, "space_test_stat03.sum.3600", val)); + EXPECT_EQ(3, val); + + EXPECT_FALSE(counterExists(stats, "space_test_stat03.count.600", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat03.avg.3600", val)); + + EXPECT_FALSE(counterExists(stats, "space_test_stat04.rate.600", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat04.count.60", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat04.avg.3600", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat04.p75.5", val)); + // Remove the dynamically registered metrics + StatsManager::removeCounterWithLabels(statId1, {{"space", "test"}}); + StatsManager::removeHistoWithLabels(statId2, {{"space", "test"}}); + auto stats2 = folly::dynamic::array(); + StatsManager::readAllValue(stats2); + EXPECT_FALSE(counterExists(stats2, "space_test_stat03.sum.3600", val)); + EXPECT_FALSE(counterExists(stats2, "space_test_stat04.p95.5", val)); } } // namespace stats diff --git a/src/common/thread/GenericWorker.cpp b/src/common/thread/GenericWorker.cpp index b80076450fb..4f67fcd9397 100644 --- a/src/common/thread/GenericWorker.cpp +++ b/src/common/thread/GenericWorker.cpp @@ -86,7 +86,9 @@ bool GenericWorker::wait() { return true; } -void GenericWorker::loop() { event_base_dispatch(evbase_); } +void GenericWorker::loop() { + event_base_dispatch(evbase_); +} void GenericWorker::notify() { if (notifier_ == nullptr) { @@ -153,7 +155,9 @@ void GenericWorker::onNotify() { } } -GenericWorker::Timer::Timer(std::function cb) { callback_ = std::move(cb); } +GenericWorker::Timer::Timer(std::function cb) { + callback_ = std::move(cb); +} GenericWorker::Timer::~Timer() { if (ev_ != nullptr) { diff --git a/src/common/thread/NamedThread.cpp b/src/common/thread/NamedThread.cpp index fa5495afb67..e3d1e59ca69 100644 --- a/src/common/thread/NamedThread.cpp +++ b/src/common/thread/NamedThread.cpp @@ -14,11 +14,17 @@ namespace detail { class TLSThreadID { public: - TLSThreadID() { tid_ = ::syscall(SYS_gettid); } + TLSThreadID() { + tid_ = ::syscall(SYS_gettid); + } - ~TLSThreadID() { tid_ = 0; } + ~TLSThreadID() { + tid_ = 0; + } - pid_t tid() { return tid_; } + pid_t tid() { + return tid_; + } private: pid_t tid_; diff --git a/src/common/thread/NamedThread.h b/src/common/thread/NamedThread.h index d455309709f..be0524ad0d1 100644 --- a/src/common/thread/NamedThread.h +++ b/src/common/thread/NamedThread.h @@ -36,9 +36,13 @@ class NamedThread final : public std::thread { set(name); } - ~Nominator() { set(prevName_); } + ~Nominator() { + set(prevName_); + } - static void set(const std::string &name) { ::prctl(PR_SET_NAME, name.c_str(), 0, 0, 0); } + static void set(const std::string &name) { + ::prctl(PR_SET_NAME, name.c_str(), 0, 0, 0); + } static void get(std::string &name) { char buf[64]; diff --git a/src/common/thread/test/GenericThreadPoolTest.cpp b/src/common/thread/test/GenericThreadPoolTest.cpp index 2157411d77a..d68db379966 100644 --- a/src/common/thread/test/GenericThreadPoolTest.cpp +++ b/src/common/thread/test/GenericThreadPoolTest.cpp @@ -77,7 +77,9 @@ TEST(GenericThreadPool, addTask) { // member function as task { struct X { - std::string itos(size_t i) { return std::to_string(i); } + std::string itos(size_t i) { + return std::to_string(i); + } } x; ASSERT_EQ("918", pool.addTask(&X::itos, &x, 918).get()); ASSERT_EQ("918", pool.addTask(&X::itos, std::make_shared(), 918).get()); diff --git a/src/common/thread/test/GenericWorkerTest.cpp b/src/common/thread/test/GenericWorkerTest.cpp index bdbeb696906..03991545a04 100644 --- a/src/common/thread/test/GenericWorkerTest.cpp +++ b/src/common/thread/test/GenericWorkerTest.cpp @@ -77,7 +77,9 @@ TEST(GenericWorker, addTask) { // member function as task { struct X { - std::string itos(size_t i) { return std::to_string(i); } + std::string itos(size_t i) { + return std::to_string(i); + } } x; ASSERT_EQ("918", worker.addTask(&X::itos, &x, 918).get()); ASSERT_EQ("918", worker.addTask(&X::itos, std::make_shared(), 918).get()); diff --git a/src/common/thread/test/ThreadTest.cpp b/src/common/thread/test/ThreadTest.cpp index 7f990b2eebd..1612a53b6d7 100644 --- a/src/common/thread/test/ThreadTest.cpp +++ b/src/common/thread/test/ThreadTest.cpp @@ -20,7 +20,9 @@ TEST(NamedThread, ThreadName) { ASSERT_EQ(setname, getname); } -TEST(NamedThread, ThreadID) { ASSERT_EQ(::getpid(), nebula::thread::gettid()); } +TEST(NamedThread, ThreadID) { + ASSERT_EQ(::getpid(), nebula::thread::gettid()); +} } // namespace thread } // namespace nebula diff --git a/src/common/thrift/ThriftClientManager-inl.h b/src/common/thrift/ThriftClientManager-inl.h index bcd35d604db..f823d43a48e 100644 --- a/src/common/thrift/ThriftClientManager-inl.h +++ b/src/common/thrift/ThriftClientManager-inl.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include "common/network/NetworkUtils.h" #include "common/ssl/SSLConfig.h" @@ -30,7 +30,7 @@ std::shared_ptr ThriftClientManager::client(const HostAd auto it = clientMap_->find(std::make_pair(host, evb)); if (it != clientMap_->end()) { do { - auto channel = dynamic_cast(it->second->getChannel()); + auto channel = dynamic_cast(it->second->getChannel()); if (channel == nullptr || !channel->good()) { // Remove bad connection to create a new one. clientMap_->erase(it); @@ -71,27 +71,28 @@ std::shared_ptr ThriftClientManager::client(const HostAd } VLOG(2) << "Connecting to " << host << " for " << ++connectionCount << " times"; - std::shared_ptr socket; + folly::AsyncTransport::UniquePtr socket; evb->runImmediatelyOrRunInEventBaseThreadAndWait([this, &socket, evb, resolved]() { if (enableSSL_) { - socket = folly::AsyncSSLSocket::newSocket(nebula::createSSLContext(), evb); - socket->connect(nullptr, resolved.host, resolved.port, FLAGS_conn_timeout_ms); + auto sock = folly::AsyncSSLSocket::newSocket(nebula::createSSLContext(), evb); + sock->connect(nullptr, resolved.host, resolved.port, FLAGS_conn_timeout_ms); + socket = folly::AsyncTransport::UniquePtr(sock.release()); } else { - socket = - folly::AsyncSocket::newSocket(evb, resolved.host, resolved.port, FLAGS_conn_timeout_ms); + socket = folly::AsyncTransport::UniquePtr( + new folly::AsyncSocket(evb, resolved.host, resolved.port, FLAGS_conn_timeout_ms)); } }); - auto headerClientChannel = apache::thrift::HeaderClientChannel::newChannel(socket); + auto clientChannel = apache::thrift::RocketClientChannel::newChannel(std::move(socket)); if (timeout > 0) { - headerClientChannel->setTimeout(timeout); + clientChannel->setTimeout(timeout); } if (compatibility) { - headerClientChannel->setProtocolId(apache::thrift::protocol::T_BINARY_PROTOCOL); - headerClientChannel->setClientType(THRIFT_UNFRAMED_DEPRECATED); + clientChannel->setProtocolId(apache::thrift::protocol::T_BINARY_PROTOCOL); + // clientChannel->setClientType(THRIFT_UNFRAMED_DEPRECATED); } - std::shared_ptr client( - new ClientType(std::move(headerClientChannel)), - [evb](auto* p) { evb->runImmediatelyOrRunInEventBaseThreadAndWait([p] { delete p; }); }); + std::shared_ptr client(new ClientType(std::move(clientChannel)), [evb](auto* p) { + evb->runImmediatelyOrRunInEventBaseThreadAndWait([p] { delete p; }); + }); clientMap_->emplace(std::make_pair(host, evb), client); return client; } diff --git a/src/common/thrift/ThriftClientManager.h b/src/common/thrift/ThriftClientManager.h index fc7ceaeaa56..71fe614e958 100644 --- a/src/common/thrift/ThriftClientManager.h +++ b/src/common/thrift/ThriftClientManager.h @@ -23,7 +23,9 @@ class ThriftClientManager final { bool compatibility = false, uint32_t timeout = 0); - ~ThriftClientManager() { VLOG(3) << "~ThriftClientManager"; } + ~ThriftClientManager() { + VLOG(3) << "~ThriftClientManager"; + } explicit ThriftClientManager(bool enableSSL = false) : enableSSL_(enableSSL) { VLOG(3) << "ThriftClientManager"; diff --git a/src/common/time/Duration.h b/src/common/time/Duration.h index 2d388047ca7..6b04928d8f3 100644 --- a/src/common/time/Duration.h +++ b/src/common/time/Duration.h @@ -13,14 +13,18 @@ namespace time { class Duration final { public: - explicit Duration(bool paused = false) { reset(paused); } + explicit Duration(bool paused = false) { + reset(paused); + } void reset(bool paused = false); void pause(); void resume(); - bool isPaused() const { return isPaused_; } + bool isPaused() const { + return isPaused_; + } uint64_t elapsedInSec() const; uint64_t elapsedInMSec() const; diff --git a/src/common/time/ScopedTimer.h b/src/common/time/ScopedTimer.h index 2d8431bd938..b6a2230f4c8 100644 --- a/src/common/time/ScopedTimer.h +++ b/src/common/time/ScopedTimer.h @@ -29,9 +29,13 @@ class ScopedTimer final { if (!paused) start(); } - ~ScopedTimer() { stop(); } + ~ScopedTimer() { + stop(); + } - void start() { duration_.reset(); } + void start() { + duration_.reset(); + } void stop() { if (stopped_) return; diff --git a/src/common/time/TimezoneInfo.h b/src/common/time/TimezoneInfo.h index 7adcc150174..a7aba6b10fa 100644 --- a/src/common/time/TimezoneInfo.h +++ b/src/common/time/TimezoneInfo.h @@ -53,7 +53,9 @@ class Timezone { return Status::OK(); } - std::string stdZoneName() const { return DCHECK_NOTNULL(zoneInfo_)->std_zone_name(); } + std::string stdZoneName() const { + return DCHECK_NOTNULL(zoneInfo_)->std_zone_name(); + } // offset in seconds int32_t utcOffsetSecs() const { @@ -66,7 +68,9 @@ class Timezone { // https://man7.org/linux/man-pages/man3/tzset.3.html static Status initializeGlobalTimezone(); - static const auto &getGlobalTimezone() { return globalTimezone; } + static const auto &getGlobalTimezone() { + return globalTimezone; + } private: static ::boost::local_time::tz_database tzdb; diff --git a/src/common/time/WallClock.cpp b/src/common/time/WallClock.cpp index d5ee1d06fd1..d19c2f2e481 100644 --- a/src/common/time/WallClock.cpp +++ b/src/common/time/WallClock.cpp @@ -30,7 +30,9 @@ int64_t WallClock::slowNowInMicroSec() { } #if defined(__x86_64__) -int64_t WallClock::fastNowInSec() { return TscHelper::tickToTimePointInSec(TscHelper::readTsc()); } +int64_t WallClock::fastNowInSec() { + return TscHelper::tickToTimePointInSec(TscHelper::readTsc()); +} int64_t WallClock::fastNowInMilliSec() { return TscHelper::tickToTimePointInMSec(TscHelper::readTsc()); @@ -40,11 +42,17 @@ int64_t WallClock::fastNowInMicroSec() { return TscHelper::tickToTimePointInUSec(TscHelper::readTsc()); } #elif defined(__aarch64__) || defined(__arm64__) || defined(__mips64) -int64_t WallClock::fastNowInSec() { return WallClock::slowNowInSec(); } +int64_t WallClock::fastNowInSec() { + return WallClock::slowNowInSec(); +} -int64_t WallClock::fastNowInMilliSec() { return slowNowInMilliSec(); } +int64_t WallClock::fastNowInMilliSec() { + return slowNowInMilliSec(); +} -int64_t WallClock::fastNowInMicroSec() { return slowNowInMicroSec(); } +int64_t WallClock::fastNowInMicroSec() { + return slowNowInMicroSec(); +} #else // defined(__x86_64__) #error "Only x86_64 and aarch64 are supported" #endif // defined(__x86_64__) diff --git a/src/common/time/detail/TscHelper.cpp b/src/common/time/detail/TscHelper.cpp index d833061312b..f8e3cb11889 100644 --- a/src/common/time/detail/TscHelper.cpp +++ b/src/common/time/detail/TscHelper.cpp @@ -40,7 +40,9 @@ TscHelper& TscHelper::get() { return tscHelper; } -uint64_t TscHelper::readTsc() { return get().readTscImpl(); } +uint64_t TscHelper::readTsc() { + return get().readTscImpl(); +} uint64_t TscHelper::readTscImpl() { #ifdef DURATION_USE_RDTSCP diff --git a/src/common/time/parser/DatetimeReader.h b/src/common/time/parser/DatetimeReader.h index 3fa43d1eb64..dfa8340f1f8 100644 --- a/src/common/time/parser/DatetimeReader.h +++ b/src/common/time/parser/DatetimeReader.h @@ -20,13 +20,21 @@ class DatetimeReader { if (dt_ != nullptr) delete dt_; } - static inline DatetimeReader makeDateReader() { return DatetimeReader(Type::kDate); } + static inline DatetimeReader makeDateReader() { + return DatetimeReader(Type::kDate); + } - static inline DatetimeReader makeTimeReader() { return DatetimeReader(Type::kTime); } + static inline DatetimeReader makeTimeReader() { + return DatetimeReader(Type::kTime); + } - static inline DatetimeReader makeDateTimeReader() { return DatetimeReader(Type::kDateTime); } + static inline DatetimeReader makeDateTimeReader() { + return DatetimeReader(Type::kDateTime); + } - StatusOr readDatetime(std::string input) { return read(std::move(input)); } + StatusOr readDatetime(std::string input) { + return read(std::move(input)); + } StatusOr readDate(std::string input) { auto result = read(std::move(input)); diff --git a/src/common/time/parser/DatetimeScanner.h b/src/common/time/parser/DatetimeScanner.h index e6dc1584d80..2661b3480a0 100644 --- a/src/common/time/parser/DatetimeScanner.h +++ b/src/common/time/parser/DatetimeScanner.h @@ -36,7 +36,9 @@ class DatetimeScanner : public yyFlexLexer { public: // Called by DatetimeReader to set the `readBuffer' callback, which would be // invoked by LexerInput to fill the stream buffer. - void setReadBuffer(std::function readBuffer) { readBuffer_ = readBuffer; } + void setReadBuffer(std::function readBuffer) { + readBuffer_ = readBuffer; + } // Manually invoked by DatetimeReader to recover from a failure state. // This makes the scanner reentrant. @@ -44,13 +46,19 @@ class DatetimeScanner : public yyFlexLexer { yy_flush_buffer(yy_buffer_stack ? yy_buffer_stack[yy_buffer_stack_top] : nullptr); } - void setInput(std::string *input) { input_ = input; } + void setInput(std::string *input) { + input_ = input; + } - std::string *input() { return input_; } + std::string *input() { + return input_; + } protected: // Called when YY_INPUT is invoked - int LexerInput(char *buf, int maxSize) override { return readBuffer_(buf, maxSize); } + int LexerInput(char *buf, int maxSize) override { + return readBuffer_(buf, maxSize); + } using TokenType = nebula::time::DatetimeParser::token; diff --git a/src/common/time/parser/datetime_parser.yy b/src/common/time/parser/datetime_parser.yy index 7a1b212ad43..f6d04d957e9 100644 --- a/src/common/time/parser/datetime_parser.yy +++ b/src/common/time/parser/datetime_parser.yy @@ -3,7 +3,7 @@ %no-lines %locations %define api.namespace { nebula::time } -%define parser_class_name { DatetimeParser } +%define api.parser.class { DatetimeParser } %lex-param { nebula::time::DatetimeScanner& scanner } %parse-param { nebula::time::DatetimeScanner& scanner } %parse-param { std::string &errmsg } diff --git a/src/common/utils/IndexKeyUtils.h b/src/common/utils/IndexKeyUtils.h index 75bb9c3f784..b3dac860ea5 100644 --- a/src/common/utils/IndexKeyUtils.h +++ b/src/common/utils/IndexKeyUtils.h @@ -192,7 +192,9 @@ class IndexKeyUtils final { return val; } - static std::string encodeRank(EdgeRanking rank) { return IndexKeyUtils::encodeInt64(rank); } + static std::string encodeRank(EdgeRanking rank) { + return IndexKeyUtils::encodeInt64(rank); + } static EdgeRanking decodeRank(const folly::StringPiece& raw) { return IndexKeyUtils::decodeInt64(raw); @@ -324,7 +326,9 @@ class IndexKeyUtils final { // NOTE(jie): The decoded data is not the original Geography data, but the uint64 type S2CellID. // decodeValue() should not call this function, it should turn for the data table instead. // It's only used for tests. - static uint64_t decodeGeography(const folly::StringPiece& raw) { return decodeUint64(raw); } + static uint64_t decodeGeography(const folly::StringPiece& raw) { + return decodeUint64(raw); + } static nebula::DateTime decodeDateTime(const folly::StringPiece& raw) { int16_t year = *reinterpret_cast(raw.data()); diff --git a/src/common/utils/LogIterator.h b/src/common/utils/LogIterator.h index 1875d01d71d..64eb57db5d8 100644 --- a/src/common/utils/LogIterator.h +++ b/src/common/utils/LogIterator.h @@ -18,7 +18,9 @@ class LogIterator { virtual LogIterator& operator++() = 0; virtual bool valid() const = 0; - virtual operator bool() const { return valid(); } + virtual operator bool() const { + return valid(); + } virtual LogID logId() const = 0; virtual TermID logTerm() const = 0; diff --git a/src/common/utils/LogStrListIterator.cpp b/src/common/utils/LogStrListIterator.cpp index d33a0ffd0eb..03761944727 100644 --- a/src/common/utils/LogStrListIterator.cpp +++ b/src/common/utils/LogStrListIterator.cpp @@ -22,7 +22,9 @@ LogIterator& LogStrListIterator::operator++() { return *this; } -bool LogStrListIterator::valid() const { return idx_ < logEntries_.size(); } +bool LogStrListIterator::valid() const { + return idx_ < logEntries_.size(); +} LogID LogStrListIterator::logId() const { DCHECK(valid()); diff --git a/src/common/utils/MemoryLockCore.h b/src/common/utils/MemoryLockCore.h index e1f190c0150..ebd6290b6cd 100644 --- a/src/common/utils/MemoryLockCore.h +++ b/src/common/utils/MemoryLockCore.h @@ -22,11 +22,17 @@ class MemoryLockCore { // but may not necessary sort any time. // this may be useful while first lock attempt failed, // and try to retry. - auto try_lockSortedBatch(const std::vector& keys) { return lockBatch(keys); } + auto try_lockSortedBatch(const std::vector& keys) { + return lockBatch(keys); + } - bool try_lock(const Key& key) { return hashMap_.insert(std::make_pair(key, 0)).second; } + bool try_lock(const Key& key) { + return hashMap_.insert(std::make_pair(key, 0)).second; + } - void unlock(const Key& key) { hashMap_.erase(key); } + void unlock(const Key& key) { + hashMap_.erase(key); + } template std::pair lockBatch(Iter begin, Iter end) { @@ -60,9 +66,13 @@ class MemoryLockCore { return unlockBatch(collection.begin(), collection.end()); } - void clear() { hashMap_.clear(); } + void clear() { + hashMap_.clear(); + } - size_t size() { return hashMap_.size(); } + size_t size() { + return hashMap_.size(); + } protected: folly::ConcurrentHashMap hashMap_; diff --git a/src/common/utils/MemoryLockWrapper.h b/src/common/utils/MemoryLockWrapper.h index 7fff4f6bf32..cf0db2d807b 100644 --- a/src/common/utils/MemoryLockWrapper.h +++ b/src/common/utils/MemoryLockWrapper.h @@ -56,9 +56,13 @@ class MemoryLockGuard { } } - bool isLocked() const noexcept { return locked_; } + bool isLocked() const noexcept { + return locked_; + } - operator bool() const noexcept { return isLocked(); } + operator bool() const noexcept { + return isLocked(); + } // return the first conflict key, if any // this has to be called iff locked_ is false; @@ -70,9 +74,13 @@ class MemoryLockGuard { // this will manual set the lock to unlocked state // which mean will not release all locks automatically // please make sure you really know the side effect - void forceLock() { locked_ = true; } + void forceLock() { + locked_ = true; + } - void forceUnlock() { locked_ = false; } + void forceUnlock() { + locked_ = false; + } protected: MemoryLockCore* lock_; diff --git a/src/common/utils/MetaKeyUtils.cpp b/src/common/utils/MetaKeyUtils.cpp index 1c0ae47fed5..68bdc30acf1 100644 --- a/src/common/utils/MetaKeyUtils.cpp +++ b/src/common/utils/MetaKeyUtils.cpp @@ -22,6 +22,7 @@ static const std::unordered_map> syste {"hosts", {"__hosts__", false}}, {"versions", {"__versions__", false}}, {"machines", {"__machines__", false}}, + {"host_dirs", {"__host_dirs__", false}}, {"snapshots", {"__snapshots__", false}}, {"configs", {"__configs__", true}}, {"groups", {"__groups__", true}}, @@ -62,6 +63,7 @@ static const std::string kPartsTable = tableMaps.at("parts").first; static const std::string kVersionsTable = systemTableMaps.at("versions").first; // NOLINT static const std::string kHostsTable = systemTableMaps.at("hosts").first; // NOLINT static const std::string kMachinesTable = systemTableMaps.at("machines").first; // NOLINT +static const std::string kHostDirsTable = systemTableMaps.at("host_dirs").first;// NOLINT static const std::string kTagsTable = tableMaps.at("tags").first; // NOLINT static const std::string kEdgesTable = tableMaps.at("edges").first; // NOLINT static const std::string kIndexesTable = tableMaps.at("indexes").first; // NOLINT @@ -97,7 +99,9 @@ const std::string kLastUpdateTimeTable = systemInfoMaps.at("lastUpdateTime").fir const int kMaxIpAddrLen = 15; // '255.255.255.255' -std::string MetaKeyUtils::getIndexTable() { return tableMaps.at("index").first; } +std::string MetaKeyUtils::getIndexTable() { + return kIndexTable; +} std::unordered_map>> @@ -147,7 +151,9 @@ meta::cpp2::SpaceDesc MetaKeyUtils::parseSpace(folly::StringPiece rawData) { return spaceDesc; } -const std::string& MetaKeyUtils::spacePrefix() { return kSpacesTable; } +const std::string& MetaKeyUtils::spacePrefix() { + return kSpacesTable; +} GraphSpaceID MetaKeyUtils::spaceId(folly::StringPiece rawKey) { return *reinterpret_cast(rawKey.data() + kSpacesTable.size()); @@ -175,7 +181,9 @@ PartitionID MetaKeyUtils::parsePartKeyPartId(folly::StringPiece key) { sizeof(GraphSpaceID)); } -std::string MetaKeyUtils::partVal(const std::vector& hosts) { return partValV2(hosts); } +std::string MetaKeyUtils::partVal(const std::vector& hosts) { + return partValV2(hosts); +} // dataVer(int) + vectorSize(size_t) + vector of (strIp(string) + port(int)) std::string MetaKeyUtils::partValV2(const std::vector& hosts) { @@ -249,14 +257,55 @@ std::string MetaKeyUtils::machineKey(std::string addr, Port port) { return key; } -const std::string& MetaKeyUtils::machinePrefix() { return kMachinesTable; } +const std::string& MetaKeyUtils::machinePrefix() { + return kMachinesTable; +} HostAddr MetaKeyUtils::parseMachineKey(folly::StringPiece key) { key.advance(kMachinesTable.size()); return MetaKeyUtils::deserializeHostAddr(key); } -std::string MetaKeyUtils::hostKey(std::string addr, Port port) { return hostKeyV2(addr, port); } +const std::string& MetaKeyUtils::hostDirPrefix() { + return kHostDirsTable; +} + +const std::string MetaKeyUtils::hostDirHostPrefix(std::string host) { + return kHostDirsTable + host; +} + +std::string MetaKeyUtils::hostDirKey(std::string host, Port port) { + std::string key; + key.reserve(kHostDirsTable.size() + host.size() + sizeof(port)); + key.append(kHostDirsTable.data(), kHostDirsTable.size()).append(host); + key.append(reinterpret_cast(&port), sizeof(Port)); + return key; +} + +HostAddr MetaKeyUtils::parseHostDirKey(folly::StringPiece key) { + HostAddr addr; + auto hostSize = key.size() - kHostDirsTable.size() - sizeof(Port); + addr.host = key.subpiece(kHostDirsTable.size(), hostSize).toString(); + key.advance(kHostDirsTable.size() + hostSize); + addr.port = *reinterpret_cast(key.begin()); + return addr; +} + +std::string MetaKeyUtils::hostDirVal(cpp2::DirInfo dir) { + std::string val; + apache::thrift::CompactSerializer::serialize(dir, &val); + return val; +} + +cpp2::DirInfo MetaKeyUtils::parseHostDir(folly::StringPiece val) { + cpp2::DirInfo dir; + apache::thrift::CompactSerializer::deserialize(val, dir); + return dir; +} + +std::string MetaKeyUtils::hostKey(std::string addr, Port port) { + return hostKeyV2(addr, port); +} std::string MetaKeyUtils::hostKeyV2(std::string addr, Port port) { std::string key; @@ -265,7 +314,9 @@ std::string MetaKeyUtils::hostKeyV2(std::string addr, Port port) { return key; } -const std::string& MetaKeyUtils::hostPrefix() { return kHostsTable; } +const std::string& MetaKeyUtils::hostPrefix() { + return kHostsTable; +} HostAddr MetaKeyUtils::parseHostKey(folly::StringPiece key) { if (key.size() == kHostsTable.size() + sizeof(int64_t)) { @@ -389,7 +440,9 @@ std::tuple MetaKeyUtils::parseLeaderV return ret; } -const std::string& MetaKeyUtils::leaderPrefix() { return kLeaderTermsTable; } +const std::string& MetaKeyUtils::leaderPrefix() { + return kLeaderTermsTable; +} std::string MetaKeyUtils::leaderPrefix(GraphSpaceID spaceId) { std::string key; @@ -639,6 +692,16 @@ std::string MetaKeyUtils::indexSpaceKey(const std::string& name) { return key; } +std::string MetaKeyUtils::parseIndexSpaceKey(folly::StringPiece key) { + auto nameSize = key.size() - kIndexTable.size() - sizeof(EntryType); + return key.subpiece(kIndexTable.size() + sizeof(EntryType), nameSize).str(); +} + +EntryType MetaKeyUtils::parseIndexType(folly::StringPiece key) { + auto type = *reinterpret_cast(key.data() + kIndexTable.size()); + return type; +} + std::string MetaKeyUtils::indexTagKey(GraphSpaceID spaceId, const std::string& name) { EntryType type = EntryType::TAG; std::string key; @@ -704,7 +767,9 @@ std::string MetaKeyUtils::assembleSegmentKey(const std::string& segment, const s return segmentKey; } -std::string MetaKeyUtils::userPrefix() { return kUsersTable; } +std::string MetaKeyUtils::userPrefix() { + return kUsersTable; +} std::string MetaKeyUtils::userKey(const std::string& account) { std::string key; @@ -755,7 +820,9 @@ GraphSpaceID MetaKeyUtils::parseRoleSpace(folly::StringPiece key) { return *reinterpret_cast(key.data() + kRolesTable.size()); } -std::string MetaKeyUtils::rolesPrefix() { return kRolesTable; } +std::string MetaKeyUtils::rolesPrefix() { + return kRolesTable; +} std::string MetaKeyUtils::roleSpacePrefix(GraphSpaceID spaceId) { std::string key; @@ -846,8 +913,8 @@ meta::cpp2::ConfigItem MetaKeyUtils::parseConfigValue(folly::StringPiece rawData value); meta::cpp2::ConfigItem item; - item.set_mode(mode); - item.set_value(value); + item.mode_ref() = mode; + item.value_ref() = value; return item; } @@ -883,7 +950,9 @@ std::string MetaKeyUtils::parseSnapshotName(folly::StringPiece rawData) { return rawData.subpiece(offset, rawData.size() - offset).str(); } -const std::string& MetaKeyUtils::snapshotPrefix() { return kSnapshotsTable; } +const std::string& MetaKeyUtils::snapshotPrefix() { + return kSnapshotsTable; +} std::string MetaKeyUtils::serializeHostAddr(const HostAddr& host) { std::string ret; @@ -914,7 +983,9 @@ std::string MetaKeyUtils::genTimestampStr() { return ch; } -std::string MetaKeyUtils::idKey() { return kIdKey; } +std::string MetaKeyUtils::idKey() { + return kIdKey; +} std::string MetaKeyUtils::balanceTaskKey( JobID jobId, GraphSpaceID spaceId, PartitionID partId, HostAddr src, HostAddr dst) { @@ -991,7 +1062,9 @@ std::string MetaKeyUtils::zoneVal(const std::vector& hosts) { return value; } -const std::string& MetaKeyUtils::zonePrefix() { return kZonesTable; } +const std::string& MetaKeyUtils::zonePrefix() { + return kZonesTable; +} std::string MetaKeyUtils::parseZoneName(folly::StringPiece rawData) { return rawData.subpiece(kZonesTable.size(), rawData.size()).toString(); @@ -1078,7 +1151,9 @@ GraphSpaceID MetaKeyUtils::parseStatsSpace(folly::StringPiece rawData) { return *reinterpret_cast(rawData.data() + offset); } -const std::string& MetaKeyUtils::statsKeyPrefix() { return kStatsTable; } +const std::string& MetaKeyUtils::statsKeyPrefix() { + return kStatsTable; +} std::string MetaKeyUtils::fulltextServiceKey() { std::string key; @@ -1104,7 +1179,9 @@ std::vector MetaKeyUtils::parseFTClients(folly::StringPiec return clients; } -const std::string& MetaKeyUtils::sessionPrefix() { return kSessionsTable; } +const std::string& MetaKeyUtils::sessionPrefix() { + return kSessionsTable; +} std::string MetaKeyUtils::sessionKey(SessionID sessionId) { std::string key; @@ -1153,7 +1230,9 @@ meta::cpp2::FTIndex MetaKeyUtils::parsefulltextIndex(folly::StringPiece val) { return ftIndex; } -std::string MetaKeyUtils::fulltextIndexPrefix() { return kFTIndexTable; } +std::string MetaKeyUtils::fulltextIndexPrefix() { + return kFTIndexTable; +} std::string MetaKeyUtils::localIdKey(GraphSpaceID spaceId) { std::string key; @@ -1195,7 +1274,9 @@ std::string MetaKeyUtils::parseDiskPartsPath(const folly::StringPiece& rawData) return path; } -std::string MetaKeyUtils::diskPartsPrefix() { return kDiskPartsTable; } +std::string MetaKeyUtils::diskPartsPrefix() { + return kDiskPartsTable; +} std::string MetaKeyUtils::diskPartsPrefix(HostAddr addr) { std::string key; diff --git a/src/common/utils/MetaKeyUtils.h b/src/common/utils/MetaKeyUtils.h index 3bd831726e6..bad713be151 100644 --- a/src/common/utils/MetaKeyUtils.h +++ b/src/common/utils/MetaKeyUtils.h @@ -116,9 +116,25 @@ class MetaKeyUtils final { static HostAddr parseMachineKey(folly::StringPiece key); - static std::string hostKey(std::string ip, Port port); + // hostDir store service(metad/storaged/graphd) address -> dir info(root path and data paths) + // agent will use these to start/stop service and backup/restore data + static std::string hostDirKey(std::string ip); - static std::string hostKeyV2(std::string addr, Port port); + static std::string hostDirKey(std::string host, Port port); + + static HostAddr parseHostDirKey(folly::StringPiece key); + + static const std::string& hostDirPrefix(); + + static const std::string hostDirHostPrefix(std::string host); + + static std::string hostDirVal(cpp2::DirInfo dir); + + static cpp2::DirInfo parseHostDir(folly::StringPiece val); + + static std::string hostKey(std::string host, Port port); + + static std::string hostKeyV2(std::string host, Port port); static const std::string& hostPrefix(); @@ -213,6 +229,10 @@ class MetaKeyUtils final { static std::string indexSpaceKey(const std::string& name); + static std::string parseIndexSpaceKey(folly::StringPiece key); + + static EntryType parseIndexType(folly::StringPiece key); + static std::string indexTagKey(GraphSpaceID spaceId, const std::string& name); static std::string indexEdgeKey(GraphSpaceID spaceId, const std::string& name); diff --git a/src/common/utils/NebulaKeyUtils.h b/src/common/utils/NebulaKeyUtils.h index 2cb53d54af5..62767661625 100644 --- a/src/common/utils/NebulaKeyUtils.h +++ b/src/common/utils/NebulaKeyUtils.h @@ -251,7 +251,9 @@ class NebulaKeyUtils final { */ static std::string toLockKey(const folly::StringPiece& rawKey); - static EdgeVerPlaceHolder getLockVersion(const folly::StringPiece&) { return 0; } + static EdgeVerPlaceHolder getLockVersion(const folly::StringPiece&) { + return 0; + } static folly::StringPiece lockWithNoVersion(const folly::StringPiece& rawKey) { // TODO(liuyu) We should change the method if varint data version diff --git a/src/common/utils/test/IndexKeyUtilsTest.cpp b/src/common/utils/test/IndexKeyUtilsTest.cpp index 6e8da0c39bc..d7bb22a57a7 100644 --- a/src/common/utils/test/IndexKeyUtilsTest.cpp +++ b/src/common/utils/test/IndexKeyUtilsTest.cpp @@ -270,10 +270,10 @@ TEST(IndexKeyUtilsTest, nullableValue) { auto nullCol = [](const std::string& name, const PropertyType type) { meta::cpp2::ColumnDef col; col.name = name; - col.type.set_type(type); - col.set_nullable(true); + col.type.type_ref() = type; + col.nullable_ref() = true; if (type == PropertyType::FIXED_STRING) { - col.type.set_type_length(10); + col.type.type_length_ref() = 10; } return col; }; @@ -286,7 +286,7 @@ TEST(IndexKeyUtilsTest, nullableValue) { } // TODO(jie) Add index key tests for geography auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; auto raws = IndexKeyUtils::encodeValues(std::move(values), indexItem.get()); u_short s = 0xfc00; /* the binary is '11111100 00000000'*/ std::string expected; @@ -303,7 +303,7 @@ TEST(IndexKeyUtilsTest, nullableValue) { cols.emplace_back(nullCol(folly::stringPrintf("col%ld", j), PropertyType::BOOL)); } auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; auto raws = IndexKeyUtils::encodeValues(std::move(values), indexItem.get()); u_short s = 0x4000; /* the binary is '01000000 00000000'*/ std::string expected; @@ -320,7 +320,7 @@ TEST(IndexKeyUtilsTest, nullableValue) { cols.emplace_back(nullCol(folly::stringPrintf("col%ld", j), PropertyType::BOOL)); } auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; auto raws = IndexKeyUtils::encodeValues(std::move(values), indexItem.get()); u_short s = 0x0000; /* the binary is '01000000 00000000'*/ std::string expected; @@ -336,7 +336,7 @@ TEST(IndexKeyUtilsTest, nullableValue) { cols.emplace_back(nullCol(folly::stringPrintf("col%ld", i), PropertyType::INT64)); } auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; auto raws = IndexKeyUtils::encodeValues(std::move(values), indexItem.get()); u_short s = 0xfff0; /* the binary is '11111111 11110000'*/ std::string expected; @@ -376,7 +376,7 @@ TEST(IndexKeyUtilsTest, nullableValue) { } } auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; auto raws = IndexKeyUtils::encodeValues(std::move(values), indexItem.get()); u_short s = 0xaaa0; /* the binary is '10101010 10100000'*/ std::string expected; @@ -392,7 +392,7 @@ TEST(IndexKeyUtilsTest, nullableValue) { cols.emplace_back(nullCol(folly::stringPrintf("col%ld", i), PropertyType::BOOL)); } auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; auto raws = IndexKeyUtils::encodeValues(std::move(values), indexItem.get()); u_short s = 0xff80; /* the binary is '11111111 10000000'*/ std::string expected; @@ -439,44 +439,44 @@ TEST(IndexKeyUtilsTest, getValueFromIndexKeyTest) { size_t indexValueSize = 0; { meta::cpp2::ColumnDef col; - col.set_name("col_bool"); - col.type.set_type(PropertyType::BOOL); + col.name_ref() = "col_bool"; + col.type.type_ref() = PropertyType::BOOL; cols.emplace_back(col); indexValueSize += sizeof(bool); } { meta::cpp2::ColumnDef col; - col.set_name("col_int"); - col.type.set_type(PropertyType::INT64); + col.name_ref() = "col_int"; + col.type.type_ref() = PropertyType::INT64; cols.emplace_back(col); indexValueSize += sizeof(int64_t); } { meta::cpp2::ColumnDef col; - col.set_name("col_float"); - col.type.set_type(PropertyType::FLOAT); + col.name_ref() = "col_float"; + col.type.type_ref() = PropertyType::FLOAT; cols.emplace_back(col); indexValueSize += sizeof(double); } { meta::cpp2::ColumnDef col; - col.set_name("col_string"); - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(4); + col.name_ref() = "col_string"; + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 4; cols.emplace_back(col); indexValueSize += 4; } { meta::cpp2::ColumnDef col; - col.set_name("col_date"); - col.type.set_type(PropertyType::DATE); + col.name_ref() = "col_date"; + col.type.type_ref() = PropertyType::DATE; cols.emplace_back(col); indexValueSize += sizeof(int8_t) * 2 + sizeof(int16_t); } { meta::cpp2::ColumnDef col; - col.set_name("col_datetime"); - col.type.set_type(PropertyType::DATETIME); + col.name_ref() = "col_datetime"; + col.type.type_ref() = PropertyType::DATETIME; cols.emplace_back(col); indexValueSize += sizeof(int32_t) + sizeof(int16_t) + sizeof(int8_t) * 5; } @@ -490,7 +490,7 @@ TEST(IndexKeyUtilsTest, getValueFromIndexKeyTest) { auto expected = vertices; auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; std::vector indexKeys; for (auto& row : vertices) { auto values = IndexKeyUtils::encodeValues(std::move(row.second), indexItem.get()); @@ -514,7 +514,7 @@ TEST(IndexKeyUtilsTest, getValueFromIndexKeyTest) { auto expected = edges; auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; std::vector indexKeys; for (auto& row : edges) { auto values = IndexKeyUtils::encodeValues(std::move(row.second), indexItem.get()); @@ -531,7 +531,7 @@ TEST(IndexKeyUtilsTest, getValueFromIndexKeyTest) { } for (auto& col : cols) { - col.set_nullable(true); + col.nullable_ref() = (true); } // since there are nullable columns, there will be two extra bytes to save // nullBitSet @@ -552,7 +552,7 @@ TEST(IndexKeyUtilsTest, getValueFromIndexKeyTest) { auto expected = vertices; auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; std::vector indexKeys; for (auto& row : vertices) { auto values = IndexKeyUtils::encodeValues(std::move(row.second), indexItem.get()); @@ -581,7 +581,7 @@ TEST(IndexKeyUtilsTest, getValueFromIndexKeyTest) { auto expected = edges; auto indexItem = std::make_unique(); - indexItem->set_fields(cols); + indexItem->fields_ref() = cols; std::vector indexKeys; for (auto& row : edges) { auto values = IndexKeyUtils::encodeValues(std::move(row.second), indexItem.get()); diff --git a/src/common/utils/test/MetaKeyUtilsTest.cpp b/src/common/utils/test/MetaKeyUtilsTest.cpp index fba67ddc65a..2f261ad53ae 100644 --- a/src/common/utils/test/MetaKeyUtilsTest.cpp +++ b/src/common/utils/test/MetaKeyUtilsTest.cpp @@ -19,9 +19,9 @@ TEST(MetaKeyUtilsTest, SpaceKeyTest) { auto spaceKey = MetaKeyUtils::spaceKey(101); ASSERT_EQ(101, MetaKeyUtils::spaceId(spaceKey)); meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default"); - spaceDesc.set_partition_num(100); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default"; + spaceDesc.partition_num_ref() = 100; + spaceDesc.replica_factor_ref() = 3; auto spaceVal = MetaKeyUtils::spaceVal(spaceDesc); ASSERT_EQ("default", MetaKeyUtils::spaceName(spaceVal)); auto properties = MetaKeyUtils::parseSpace(spaceVal); @@ -35,11 +35,11 @@ TEST(MetaKeyUtilsTest, SpaceKeyWithZonesTest) { auto spaceKey = MetaKeyUtils::spaceKey(101); ASSERT_EQ(101, MetaKeyUtils::spaceId(spaceKey)); meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default"); - spaceDesc.set_partition_num(100); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default"; + spaceDesc.partition_num_ref() = 100; + spaceDesc.replica_factor_ref() = 3; std::vector zoneNames{"z1", "z2", "z3"}; - spaceDesc.set_zone_names(std::move(zoneNames)); + spaceDesc.zone_names_ref() = std::move(zoneNames); auto spaceVal = MetaKeyUtils::spaceVal(spaceDesc); ASSERT_EQ("default", MetaKeyUtils::spaceName(spaceVal)); auto properties = MetaKeyUtils::parseSpace(spaceVal); @@ -188,23 +188,23 @@ TEST(MetaKeyUtilsTest, TagTest) { std::vector cols; for (auto i = 1; i <= 3; i++) { meta::cpp2::ColumnDef column; - column.set_name(folly::stringPrintf("col_%d", i)); - column.type.set_type(nebula::cpp2::PropertyType::INT64); + column.name_ref() = folly::stringPrintf("col_%d", i); + column.type.type_ref() = nebula::cpp2::PropertyType::INT64; cols.emplace_back(std::move(column)); } for (auto i = 4; i <= 6; i++) { meta::cpp2::ColumnDef column; - column.set_name(folly::stringPrintf("col_%d", i)); - column.type.set_type(nebula::cpp2::PropertyType::FLOAT); + column.name_ref() = folly::stringPrintf("col_%d", i); + column.type.type_ref() = nebula::cpp2::PropertyType::FLOAT; cols.emplace_back(std::move(column)); } for (auto i = 7; i < 10; i++) { meta::cpp2::ColumnDef column; - column.set_name(folly::stringPrintf("col_%d", i)); - column.type.set_type(nebula::cpp2::PropertyType::STRING); + column.name_ref() = folly::stringPrintf("col_%d", i); + column.type.type_ref() = nebula::cpp2::PropertyType::STRING; cols.emplace_back(std::move(column)); } - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); auto val = MetaKeyUtils::schemaVal("test_tag", schema); auto parsedSchema = MetaKeyUtils::parseSchema(val); ASSERT_EQ(parsedSchema, schema); diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt index 292c3936d78..cc0530863f7 100644 --- a/src/daemons/CMakeLists.txt +++ b/src/daemons/CMakeLists.txt @@ -38,6 +38,11 @@ set(common_deps set(storage_meta_deps $ + $ + $ + $ + $ + $ $ $ $ @@ -109,7 +114,9 @@ nebula_add_executable( SetupLogging.cpp SetupBreakpad.cpp OBJECTS - $ + $ + $ + $ $ $ $ diff --git a/src/daemons/GraphDaemon.cpp b/src/daemons/GraphDaemon.cpp index 78cfdd36370..87efa2107be 100644 --- a/src/daemons/GraphDaemon.cpp +++ b/src/daemons/GraphDaemon.cpp @@ -18,7 +18,7 @@ #include "common/time/TimezoneInfo.h" #include "graph/service/GraphFlags.h" #include "graph/service/GraphService.h" -#include "graph/stats/StatsDef.h" +#include "graph/stats/GraphStats.h" #include "version/Version.h" #include "webservice/WebService.h" @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) { if (FLAGS_enable_ssl || FLAGS_enable_graph_ssl || FLAGS_enable_meta_ssl) { folly::ssl::init(); } - nebula::initCounters(); + nebula::initGraphStats(); if (FLAGS_flagfile.empty()) { printHelp(argv[0]); @@ -215,13 +215,15 @@ void signalHandler(int sig) { } } -void printHelp(const char *prog) { fprintf(stderr, "%s --flagfile \n", prog); } +void printHelp(const char *prog) { + fprintf(stderr, "%s --flagfile \n", prog); +} void setupThreadManager() { int numThreads = FLAGS_num_worker_threads > 0 ? FLAGS_num_worker_threads : gServer->getNumIOWorkerThreads(); std::shared_ptr threadManager( - PriorityThreadManager::newPriorityThreadManager(numThreads, false /*stats*/)); + PriorityThreadManager::newPriorityThreadManager(numThreads)); threadManager->setNamePrefix("executor"); threadManager->start(); gServer->setThreadManager(threadManager); diff --git a/src/daemons/MetaDaemon.cpp b/src/daemons/MetaDaemon.cpp index 5aa7521107b..06dd0a9c9b8 100644 --- a/src/daemons/MetaDaemon.cpp +++ b/src/daemons/MetaDaemon.cpp @@ -8,6 +8,7 @@ #include "common/base/Base.h" #include "common/base/SignalHandler.h" +#include "common/fs/FileUtils.h" #include "common/hdfs/HdfsCommandHelper.h" #include "common/hdfs/HdfsHelper.h" #include "common/network/NetworkUtils.h" @@ -27,6 +28,7 @@ #include "meta/http/MetaHttpIngestHandler.h" #include "meta/http/MetaHttpReplaceHostHandler.h" #include "meta/processors/job/JobManager.h" +#include "meta/stats/MetaStats.h" #include "version/Version.h" #include "webservice/Router.h" #include "webservice/WebService.h" @@ -83,11 +85,14 @@ std::unique_ptr initKV(std::vector p auto ioPool = std::make_shared(FLAGS_num_io_threads); std::shared_ptr threadManager( apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager( - FLAGS_num_worker_threads, true /*stats*/)); + FLAGS_num_worker_threads)); threadManager->setNamePrefix("executor"); threadManager->start(); nebula::kvstore::KVOptions options; - options.dataPaths_ = {FLAGS_data_path}; + + auto absolute = boost::filesystem::absolute(FLAGS_data_path); + options.dataPaths_ = {absolute.string()}; + options.partMan_ = std::move(partMan); auto kvstore = std::make_unique( std::move(options), ioPool, localhost, threadManager); @@ -219,6 +224,9 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } + // Init stats + nebula::initMetaStats(); + folly::init(&argc, &argv, true); if (FLAGS_enable_ssl || FLAGS_enable_meta_ssl) { folly::ssl::init(); diff --git a/src/daemons/StorageDaemon.cpp b/src/daemons/StorageDaemon.cpp index 37e5957c4f8..0b7c6f0a104 100644 --- a/src/daemons/StorageDaemon.cpp +++ b/src/daemons/StorageDaemon.cpp @@ -8,10 +8,12 @@ #include "common/base/Base.h" #include "common/base/SignalHandler.h" +#include "common/fs/FileUtils.h" #include "common/network/NetworkUtils.h" #include "common/process/ProcessUtils.h" #include "common/time/TimezoneInfo.h" #include "storage/StorageServer.h" +#include "storage/stats/StorageStats.h" #include "version/Version.h" DEFINE_string(local_ip, "", "IP address which is used to identify this server"); @@ -80,6 +82,9 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } + // Init stats + nebula::initStorageStats(); + folly::init(&argc, &argv, true); if (FLAGS_enable_ssl || FLAGS_enable_meta_ssl) { folly::ssl::init(); @@ -132,9 +137,14 @@ int main(int argc, char *argv[]) { std::vector paths; folly::split(",", FLAGS_data_path, paths, true); - std::transform(paths.begin(), paths.end(), paths.begin(), [](auto &p) { - return folly::trimWhitespace(p).str(); - }); + // make the paths absolute + std::transform( + paths.begin(), paths.end(), paths.begin(), [](const std::string &p) -> std::string { + auto path = folly::trimWhitespace(p).str(); + path = boost::filesystem::absolute(path).string(); + LOG(INFO) << "data path= " << path; + return path; + }); if (paths.empty()) { LOG(ERROR) << "Bad data_path format:" << FLAGS_data_path; return EXIT_FAILURE; diff --git a/src/graph/context/ExecutionContext.cpp b/src/graph/context/ExecutionContext.cpp index dbb064c01af..f63db2ec90b 100644 --- a/src/graph/context/ExecutionContext.cpp +++ b/src/graph/context/ExecutionContext.cpp @@ -22,7 +22,9 @@ void ExecutionContext::setResult(const std::string& name, Result&& result) { hist.emplace_back(std::move(result)); } -void ExecutionContext::dropResult(const std::string& name) { valueMap_[name].clear(); } +void ExecutionContext::dropResult(const std::string& name) { + valueMap_[name].clear(); +} size_t ExecutionContext::numVersions(const std::string& name) const { auto it = valueMap_.find(name); diff --git a/src/graph/context/ExecutionContext.h b/src/graph/context/ExecutionContext.h index ec6c917a557..28aa31d7be5 100644 --- a/src/graph/context/ExecutionContext.h +++ b/src/graph/context/ExecutionContext.h @@ -40,7 +40,9 @@ class ExecutionContext { virtual ~ExecutionContext() = default; - void initVar(const std::string& name) { valueMap_[name]; } + void initVar(const std::string& name) { + valueMap_[name]; + } // Get the latest version of the value const Value& getValue(const std::string& name) const; @@ -64,7 +66,9 @@ class ExecutionContext { // Only keep the last several versions of the Value void truncHistory(const std::string& name, size_t numVersionsToKeep); - bool exist(const std::string& name) const { return valueMap_.find(name) != valueMap_.end(); } + bool exist(const std::string& name) const { + return valueMap_.find(name) != valueMap_.end(); + } private: friend class QueryInstance; diff --git a/src/graph/context/Iterator.cpp b/src/graph/context/Iterator.cpp index e14a4e6ede4..e297048e700 100644 --- a/src/graph/context/Iterator.cpp +++ b/src/graph/context/Iterator.cpp @@ -612,7 +612,9 @@ void SequentialIter::init(std::vector>&& iterators) { iter_ = rows_->begin(); } -bool SequentialIter::valid() const { return Iterator::valid() && iter_ < rows_->end(); } +bool SequentialIter::valid() const { + return Iterator::valid() && iter_ < rows_->end(); +} void SequentialIter::next() { if (valid()) { @@ -621,7 +623,9 @@ void SequentialIter::next() { } } -void SequentialIter::erase() { iter_ = rows_->erase(iter_); } +void SequentialIter::erase() { + iter_ = rows_->erase(iter_); +} void SequentialIter::unstableErase() { std::swap(rows_->back(), *iter_); @@ -649,9 +653,13 @@ const Value& SequentialIter::getColumn(int32_t index) const { return getColumnByIndex(index, iter_); } -Value SequentialIter::getVertex(const std::string& name) const { return getColumn(name); } +Value SequentialIter::getVertex(const std::string& name) const { + return getColumn(name); +} -Value SequentialIter::getEdge() const { return getColumn("EDGE"); } +Value SequentialIter::getEdge() const { + return getColumn("EDGE"); +} PropIter::PropIter(std::shared_ptr value, bool checkMemory) : SequentialIter(value, checkMemory) { @@ -877,7 +885,9 @@ List PropIter::getEdges() { return edges; } -const Value& PropIter::getColumn(int32_t index) const { return getColumnByIndex(index, iter_); } +const Value& PropIter::getColumn(int32_t index) const { + return getColumnByIndex(index, iter_); +} std::ostream& operator<<(std::ostream& os, Iterator::Kind kind) { switch (kind) { diff --git a/src/graph/context/Iterator.h b/src/graph/context/Iterator.h index 562117e99b6..b4536279565 100644 --- a/src/graph/context/Iterator.h +++ b/src/graph/context/Iterator.h @@ -47,11 +47,15 @@ class Iterator { virtual ~Iterator() = default; - Kind kind() const { return kind_; } + Kind kind() const { + return kind_; + } virtual std::unique_ptr copy() const = 0; - virtual bool valid() const { return !hitsSysMemoryHighWatermark(); } + virtual bool valid() const { + return !hitsSysMemoryHighWatermark(); + } virtual void next() = 0; @@ -82,21 +86,35 @@ class Iterator { virtual void clear() = 0; - void operator++() { next(); } + void operator++() { + next(); + } - virtual std::shared_ptr valuePtr() const { return value_; } + virtual std::shared_ptr valuePtr() const { + return value_; + } virtual size_t size() const = 0; - bool empty() const { return size() == 0; } + bool empty() const { + return size() == 0; + } - bool isDefaultIter() const { return kind_ == Kind::kDefault; } + bool isDefaultIter() const { + return kind_ == Kind::kDefault; + } - bool isGetNeighborsIter() const { return kind_ == Kind::kGetNeighbors; } + bool isGetNeighborsIter() const { + return kind_ == Kind::kGetNeighbors; + } - bool isSequentialIter() const { return kind_ == Kind::kSequential; } + bool isSequentialIter() const { + return kind_ == Kind::kSequential; + } - bool isPropIter() const { return kind_ == Kind::kProp; } + bool isPropIter() const { + return kind_ == Kind::kProp; + } // The derived class should rewrite get prop if the Value is kind of dataset. virtual const Value& getColumn(const std::string& col) const = 0; @@ -127,10 +145,16 @@ class Iterator { return Value(); } - virtual Value getEdge() const { return Value(); } + virtual Value getEdge() const { + return Value(); + } - bool checkMemory() const { return checkMemory_; } - void setCheckMemory(bool checkMemory) { checkMemory_ = checkMemory; } + bool checkMemory() const { + return checkMemory_; + } + void setCheckMemory(bool checkMemory) { + checkMemory_ = checkMemory; + } protected: virtual void doReset(size_t pos) = 0; @@ -147,33 +171,47 @@ class DefaultIter final : public Iterator { explicit DefaultIter(std::shared_ptr value, bool checkMemory = false) : Iterator(value, Kind::kDefault, checkMemory) {} - std::unique_ptr copy() const override { return std::make_unique(*this); } + std::unique_ptr copy() const override { + return std::make_unique(*this); + } - bool valid() const override { return Iterator::valid() && !(counter_ > 0); } + bool valid() const override { + return Iterator::valid() && !(counter_ > 0); + } void next() override { numRowsModN_++; counter_++; } - void erase() override { counter_--; } + void erase() override { + counter_--; + } void unstableErase() override { DLOG(ERROR) << "Unimplemented default iterator."; counter_--; } - void eraseRange(size_t, size_t) override { return; } + void eraseRange(size_t, size_t) override { + return; + } void select(std::size_t, std::size_t) override { DLOG(FATAL) << "Unimplemented method for default iterator."; } - void sample(int64_t) override { DLOG(FATAL) << "Unimplemented default iterator."; } + void sample(int64_t) override { + DLOG(FATAL) << "Unimplemented default iterator."; + } - void clear() override { reset(); } + void clear() override { + reset(); + } - size_t size() const override { return 1; } + size_t size() const override { + return 1; + } const Value& getColumn(const std::string& /* col */) const override { DLOG(FATAL) << "This method should not be invoked"; @@ -221,7 +259,9 @@ class GetNeighborsIter final : public Iterator { void erase() override; - void unstableErase() override { erase(); } + void unstableErase() override { + erase(); + } // erase [first, last) void eraseRange(size_t first, size_t last) override { @@ -248,7 +288,9 @@ class GetNeighborsIter final : public Iterator { void sample(int64_t count) override; - size_t size() const override { return 0; } + size_t size() const override { + return 0; + } const Value& getColumn(const std::string& col) const override; @@ -270,7 +312,9 @@ class GetNeighborsIter final : public Iterator { List getEdges(); // only return currentEdge, not currentRow, for test - const Row* row() const override { return currentEdge_; } + const Row* row() const override { + return currentEdge_; + } private: void doReset(size_t pos) override { @@ -285,7 +329,9 @@ class GetNeighborsIter final : public Iterator { return currentDs_->tagEdgeNameIndices.find(colIdx_)->second; } - bool colValid() { return !noEdge_ && valid(); } + bool colValid() { + return !noEdge_ && valid(); + } // move to next List of Edge data void nextCol(); @@ -403,13 +449,21 @@ class SequentialIter : public Iterator { reset(); } - std::vector::iterator begin() { return rows_->begin(); } + std::vector::iterator begin() { + return rows_->begin(); + } - std::vector::iterator end() { return rows_->end(); } + std::vector::iterator end() { + return rows_->end(); + } - const std::unordered_map& getColIndices() const { return colIndices_; } + const std::unordered_map& getColIndices() const { + return colIndices_; + } - size_t size() const override { return rows_->size(); } + size_t size() const override { + return rows_->size(); + } const Value& getColumn(const std::string& col) const override { if (!valid()) { @@ -432,13 +486,17 @@ class SequentialIter : public Iterator { Value getEdge() const override; protected: - const Row* row() const override { return &*iter_; } + const Row* row() const override { + return &*iter_; + } // Notice: We only use this interface when return results to client. friend class DataCollectExecutor; friend class AppendVerticesExecutor; friend class TraverseExecutor; - Row&& moveRow() { return std::move(*iter_); } + Row&& moveRow() { + return std::move(*iter_); + } void doReset(size_t pos) override; @@ -524,7 +582,9 @@ struct equal_to { template <> struct hash { - size_t operator()(const nebula::Row* row) const { return !row ? 0 : hash()(*row); } + size_t operator()(const nebula::Row* row) const { + return !row ? 0 : hash()(*row); + } }; } // namespace std diff --git a/src/graph/context/QueryContext.cpp b/src/graph/context/QueryContext.cpp index d22004a97a9..bebe56492f0 100644 --- a/src/graph/context/QueryContext.cpp +++ b/src/graph/context/QueryContext.cpp @@ -23,7 +23,9 @@ QueryContext::QueryContext(RequestContextPtr rctx, init(); } -QueryContext::QueryContext() { init(); } +QueryContext::QueryContext() { + init(); +} void QueryContext::init() { objPool_ = std::make_unique(); diff --git a/src/graph/context/QueryContext.h b/src/graph/context/QueryContext.h index c8213879689..77aa70c6106 100644 --- a/src/graph/context/QueryContext.h +++ b/src/graph/context/QueryContext.h @@ -51,50 +51,90 @@ class QueryContext { virtual ~QueryContext() = default; - void setRCtx(RequestContextPtr rctx) { rctx_ = std::move(rctx); } + void setRCtx(RequestContextPtr rctx) { + rctx_ = std::move(rctx); + } - void setSchemaManager(meta::SchemaManager* sm) { sm_ = sm; } + void setSchemaManager(meta::SchemaManager* sm) { + sm_ = sm; + } - void setIndexManager(meta::IndexManager* im) { im_ = im; } + void setIndexManager(meta::IndexManager* im) { + im_ = im; + } - void setStorageClient(storage::StorageClient* storage) { storageClient_ = storage; } + void setStorageClient(storage::StorageClient* storage) { + storageClient_ = storage; + } - void setMetaClient(meta::MetaClient* metaClient) { metaClient_ = metaClient; } + void setMetaClient(meta::MetaClient* metaClient) { + metaClient_ = metaClient; + } - void setCharsetInfo(CharsetInfo* charsetInfo) { charsetInfo_ = charsetInfo; } + void setCharsetInfo(CharsetInfo* charsetInfo) { + charsetInfo_ = charsetInfo; + } - RequestContext* rctx() const { return rctx_.get(); } + RequestContext* rctx() const { + return rctx_.get(); + } - ValidateContext* vctx() const { return vctx_.get(); } + ValidateContext* vctx() const { + return vctx_.get(); + } - ExecutionContext* ectx() const { return ectx_.get(); } + ExecutionContext* ectx() const { + return ectx_.get(); + } - ExecutionPlan* plan() const { return ep_.get(); } + ExecutionPlan* plan() const { + return ep_.get(); + } - meta::SchemaManager* schemaMng() const { return sm_; } + meta::SchemaManager* schemaMng() const { + return sm_; + } - meta::IndexManager* indexMng() const { return im_; } + meta::IndexManager* indexMng() const { + return im_; + } - storage::StorageClient* getStorageClient() const { return storageClient_; } + storage::StorageClient* getStorageClient() const { + return storageClient_; + } - meta::MetaClient* getMetaClient() const { return metaClient_; } + meta::MetaClient* getMetaClient() const { + return metaClient_; + } - CharsetInfo* getCharsetInfo() const { return charsetInfo_; } + CharsetInfo* getCharsetInfo() const { + return charsetInfo_; + } - ObjectPool* objPool() const { return objPool_.get(); } + ObjectPool* objPool() const { + return objPool_.get(); + } - int64_t genId() const { return idGen_->id(); } + int64_t genId() const { + return idGen_->id(); + } - SymbolTable* symTable() const { return symTable_.get(); } + SymbolTable* symTable() const { + return symTable_.get(); + } void setPartialSuccess() { DCHECK(rctx_ != nullptr); rctx_->resp().errorCode = ErrorCode::E_PARTIAL_SUCCEEDED; } - void markKilled() { killed_.exchange(true); } + void markKilled() { + killed_.exchange(true); + } - bool isKilled() const { return killed_.load(); } + bool isKilled() const { + return killed_.load(); + } bool existParameter(const std::string& param) const { return ectx_->exist(param) && (ectx_->getValue(param).type() != Value::Type::DATASET); diff --git a/src/graph/context/QueryExpressionContext.h b/src/graph/context/QueryExpressionContext.h index b624fb1d22a..1d7ffb48ab0 100644 --- a/src/graph/context/QueryExpressionContext.h +++ b/src/graph/context/QueryExpressionContext.h @@ -15,7 +15,9 @@ namespace graph { class QueryExpressionContext final : public ExpressionContext { public: - explicit QueryExpressionContext(ExecutionContext* ectx = nullptr) { ectx_ = ectx; } + explicit QueryExpressionContext(ExecutionContext* ectx = nullptr) { + ectx_ = ectx; + } // Get the latest version value for the given variable name, such as $a, $b const Value& getVar(const std::string& var) const override; diff --git a/src/graph/context/Result.h b/src/graph/context/Result.h index 6f475fc501a..a23d701cd6f 100644 --- a/src/graph/context/Result.h +++ b/src/graph/context/Result.h @@ -28,19 +28,33 @@ class Result final { static const Result& EmptyResult(); static const std::vector& EmptyResultList(); - std::shared_ptr valuePtr() const { return core_.value; } + std::shared_ptr valuePtr() const { + return core_.value; + } - const Value& value() const { return *core_.value; } + const Value& value() const { + return *core_.value; + } - State state() const { return core_.state; } + State state() const { + return core_.state; + } - size_t size() const { return core_.iter->size(); } + size_t size() const { + return core_.iter->size(); + } - std::unique_ptr iter() const& { return core_.iter->copy(); } + std::unique_ptr iter() const& { + return core_.iter->copy(); + } - std::unique_ptr iter() && { return std::move(core_.iter); } + std::unique_ptr iter() && { + return std::move(core_.iter); + } - Iterator* iterRef() { return core_.iter.get(); } + Iterator* iterRef() { + return core_.iter.get(); + } void checkMemory(bool checkMemory) { core_.checkMemory = checkMemory; @@ -53,13 +67,17 @@ class Result final { friend class ResultBuilder; friend class ExecutionContext; - Value&& moveValue() { return std::move(*core_.value); } + Value&& moveValue() { + return std::move(*core_.value); + } struct Core { Core() = default; Core(Core&&) = default; Core& operator=(Core&&) = default; - Core(const Core& c) { *this = c; } + Core(const Core& c) { + *this = c; + } Core& operator=(const Core& c) { if (&c != this) { state = c.state; @@ -85,7 +103,9 @@ class Result final { // Default iterator type is sequential. class ResultBuilder final { public: - ResultBuilder() { core_.state = Result::State::kSuccess; } + ResultBuilder() { + core_.state = Result::State::kSuccess; + } Result build() { if (!core_.iter) iter(Iterator::Kind::kSequential); diff --git a/src/graph/context/Symbols.h b/src/graph/context/Symbols.h index 0a65f0aabb8..ba9cb9b36e8 100644 --- a/src/graph/context/Symbols.h +++ b/src/graph/context/Symbols.h @@ -24,7 +24,9 @@ struct ColDef { type = std::move(t); } - bool operator==(const ColDef& rhs) const { return name == rhs.name && type == rhs.type; } + bool operator==(const ColDef& rhs) const { + return name == rhs.name && type == rhs.type; + } std::string name; Value::Type type; diff --git a/src/graph/context/ValidateContext.h b/src/graph/context/ValidateContext.h index d3904e91792..6f511a55afd 100644 --- a/src/graph/context/ValidateContext.h +++ b/src/graph/context/ValidateContext.h @@ -25,7 +25,9 @@ class ValidateContext final { anonColGen_ = std::make_unique(); } - void switchToSpace(SpaceInfo space) { spaces_.emplace_back(std::move(space)); } + void switchToSpace(SpaceInfo space) { + spaces_.emplace_back(std::move(space)); + } const ColsDef& getVar(const std::string& var) const { static const ColsDef kEmptyCols; @@ -35,9 +37,13 @@ class ValidateContext final { return vars_.at(var); } - bool existVar(const std::string& var) const { return vars_.find(var) != vars_.end(); } + bool existVar(const std::string& var) const { + return vars_.find(var) != vars_.end(); + } - void addSpace(const std::string& spaceName) { createSpaces_.emplace(spaceName); } + void addSpace(const std::string& spaceName) { + createSpaces_.emplace(spaceName); + } bool hasSpace(const std::string& spaceName) const { return createSpaces_.find(spaceName) != createSpaces_.end(); @@ -47,13 +53,21 @@ class ValidateContext final { vars_.emplace(std::move(var), std::move(cols)); } - bool spaceChosen() const { return !spaces_.empty(); } + bool spaceChosen() const { + return !spaces_.empty(); + } - const SpaceInfo& whichSpace() const { return spaces_.back(); } + const SpaceInfo& whichSpace() const { + return spaces_.back(); + } - AnonVarGenerator* anonVarGen() const { return anonVarGen_.get(); } + AnonVarGenerator* anonVarGen() const { + return anonVarGen_.get(); + } - AnonColGenerator* anonColGen() const { return anonColGen_.get(); } + AnonColGenerator* anonColGen() const { + return anonColGen_.get(); + } void addSchema(const std::string& name, const std::shared_ptr& schema) { @@ -68,9 +82,13 @@ class ValidateContext final { return find->second; } - void addIndex(const std::string& indexName) { indexes_.emplace(indexName); } + void addIndex(const std::string& indexName) { + indexes_.emplace(indexName); + } - bool hasIndex(const std::string& indexName) { return indexes_.find(indexName) != indexes_.end(); } + bool hasIndex(const std::string& indexName) { + return indexes_.find(indexName) != indexes_.end(); + } private: // spaces_ is the trace of space switch diff --git a/src/graph/context/test/CMakeLists.txt b/src/graph/context/test/CMakeLists.txt index 4fd9cdcef5c..779335bc5a0 100644 --- a/src/graph/context/test/CMakeLists.txt +++ b/src/graph/context/test/CMakeLists.txt @@ -42,6 +42,10 @@ SET(CONTEXT_TEST_LIBS $ $ $ + $ + $ + $ + $ ) nebula_add_test( diff --git a/src/graph/executor/ExecutionError.h b/src/graph/executor/ExecutionError.h index 715fdb42e72..fb986e3732a 100644 --- a/src/graph/executor/ExecutionError.h +++ b/src/graph/executor/ExecutionError.h @@ -19,7 +19,9 @@ class ExecutionError final : public std::runtime_error { status_ = std::move(status); } - Status status() const { return status_; } + Status status() const { + return status_; + } private: Status status_; diff --git a/src/graph/executor/Executor.cpp b/src/graph/executor/Executor.cpp index d52e9bd60ca..4e753d4b013 100644 --- a/src/graph/executor/Executor.cpp +++ b/src/graph/executor/Executor.cpp @@ -12,6 +12,7 @@ #include "common/base/ObjectPool.h" #include "common/memory/MemoryUtils.h" +#include "common/stats/StatsManager.h" #include "common/time/ScopedTimer.h" #include "graph/context/ExecutionContext.h" #include "graph/context/QueryContext.h" @@ -98,6 +99,7 @@ #include "graph/planner/plan/PlanNode.h" #include "graph/planner/plan/Query.h" #include "graph/service/GraphFlags.h" +#include "graph/stats/GraphStats.h" #include "interface/gen-cpp2/graph_types.h" using folly::stringPrintf; @@ -157,9 +159,11 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { return pool->add(new PassThroughExecutor(node, qctx)); } case PlanNode::Kind::kAggregate: { + stats::StatsManager::addValue(kNumAggregateExecutors); return pool->add(new AggregateExecutor(node, qctx)); } case PlanNode::Kind::kSort: { + stats::StatsManager::addValue(kNumSortExecutors); return pool->add(new SortExecutor(node, qctx)); } case PlanNode::Kind::kTopN: { @@ -202,6 +206,7 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { case PlanNode::Kind::kTagIndexFullScan: case PlanNode::Kind::kTagIndexPrefixScan: case PlanNode::Kind::kTagIndexRangeScan: { + stats::StatsManager::addValue(kNumIndexScanExecutors); return pool->add(new IndexScanExecutor(node, qctx)); } case PlanNode::Kind::kStart: { @@ -573,6 +578,7 @@ Status Executor::close() { Status Executor::checkMemoryWatermark() { if (node_->isQueryNode() && MemoryUtils::kHitMemoryHighWatermark.load()) { + stats::StatsManager::addValue(kNumOomExecutors); return Status::Error("Used memory hits the high watermark(%lf) of total system memory.", FLAGS_system_memory_high_watermark_ratio); } diff --git a/src/graph/executor/Executor.h b/src/graph/executor/Executor.h index d9946700399..0ed54b3c7c0 100644 --- a/src/graph/executor/Executor.h +++ b/src/graph/executor/Executor.h @@ -45,17 +45,29 @@ class Executor : private cpp::NonCopyable, private cpp::NonMovable { Status checkMemoryWatermark(); - QueryContext *qctx() const { return qctx_; } + QueryContext *qctx() const { + return qctx_; + } - int64_t id() const { return id_; } + int64_t id() const { + return id_; + } - const std::string &name() const { return name_; } + const std::string &name() const { + return name_; + } - const PlanNode *node() const { return node_; } + const PlanNode *node() const { + return node_; + } - const std::set &depends() const { return depends_; } + const std::set &depends() const { + return depends_; + } - const std::set &successors() const { return successors_; } + const std::set &successors() const { + return successors_; + } Executor *dependsOn(Executor *dep) { depends_.emplace(dep); diff --git a/src/graph/executor/StorageAccessExecutor.cpp b/src/graph/executor/StorageAccessExecutor.cpp index cf348bf2368..ec051b2e7d0 100644 --- a/src/graph/executor/StorageAccessExecutor.cpp +++ b/src/graph/executor/StorageAccessExecutor.cpp @@ -25,12 +25,16 @@ struct Vid; template <> struct Vid { - static int64_t value(const Value &v) { return v.getInt(); } + static int64_t value(const Value &v) { + return v.getInt(); + } }; template <> struct Vid { - static std::string value(const Value &v) { return v.getStr(); } + static std::string value(const Value &v) { + return v.getStr(); + } }; template diff --git a/src/graph/executor/admin/GrantRoleExecutor.cpp b/src/graph/executor/admin/GrantRoleExecutor.cpp index ebc64490727..5cb7813936b 100644 --- a/src/graph/executor/admin/GrantRoleExecutor.cpp +++ b/src/graph/executor/admin/GrantRoleExecutor.cpp @@ -31,9 +31,9 @@ folly::Future GrantRoleExecutor::grantRole() { PermissionManager::canWriteRole(session, grNode->role(), spaceId, *grNode->username())); meta::cpp2::RoleItem item; - item.set_space_id(spaceId); // TODO(shylock) pass space name directly - item.set_user_id(*grNode->username()); - item.set_role_type(grNode->role()); + item.space_id_ref() = spaceId; // TODO(shylock) pass space name directly + item.user_id_ref() = *grNode->username(); + item.role_type_ref() = grNode->role(); return qctx() ->getMetaClient() ->grantToUser(std::move(item)) diff --git a/src/graph/executor/admin/RevokeRoleExecutor.cpp b/src/graph/executor/admin/RevokeRoleExecutor.cpp index f5404e88b6d..37ae972ceb5 100644 --- a/src/graph/executor/admin/RevokeRoleExecutor.cpp +++ b/src/graph/executor/admin/RevokeRoleExecutor.cpp @@ -33,9 +33,9 @@ folly::Future RevokeRoleExecutor::revokeRole() { PermissionManager::canWriteRole(session, rrNode->role(), spaceId, *rrNode->username())); meta::cpp2::RoleItem item; - item.set_space_id(spaceId); - item.set_user_id(*rrNode->username()); - item.set_role_type(rrNode->role()); + item.space_id_ref() = spaceId; + item.user_id_ref() = *rrNode->username(); + item.role_type_ref() = rrNode->role(); return qctx() ->getMetaClient() ->revokeFromUser(std::move(item)) diff --git a/src/graph/executor/admin/SpaceExecutor.cpp b/src/graph/executor/admin/SpaceExecutor.cpp index f2a452482fc..9591b734b32 100644 --- a/src/graph/executor/admin/SpaceExecutor.cpp +++ b/src/graph/executor/admin/SpaceExecutor.cpp @@ -5,10 +5,12 @@ #include "graph/executor/admin/SpaceExecutor.h" +#include "common/stats/StatsManager.h" #include "common/time/ScopedTimer.h" #include "graph/context/QueryContext.h" #include "graph/planner/plan/Admin.h" #include "graph/service/PermissionManager.h" +#include "graph/stats/GraphStats.h" #include "graph/util/FTIndexUtils.h" #include "graph/util/SchemaUtil.h" @@ -140,6 +142,7 @@ folly::Future DropSpaceExecutor::execute() { LOG(ERROR) << "Drop space `" << dsNode->getSpaceName() << "' failed: " << resp.status(); return resp.status(); } + unRegisterSpaceLevelMetrics(dsNode->getSpaceName()); if (dsNode->getSpaceName() == qctx()->rctx()->session()->space().name) { SpaceInfo spaceInfo; spaceInfo.name = ""; @@ -163,6 +166,16 @@ folly::Future DropSpaceExecutor::execute() { }); } +void DropSpaceExecutor::unRegisterSpaceLevelMetrics(const std::string &spaceName) { + if (FLAGS_enable_space_level_metrics) { + stats::StatsManager::removeCounterWithLabels(kNumQueries, {{"space", spaceName}}); + stats::StatsManager::removeCounterWithLabels(kNumSlowQueries, {{"space", spaceName}}); + stats::StatsManager::removeCounterWithLabels(kNumQueryErrors, {{"space", spaceName}}); + stats::StatsManager::removeHistoWithLabels(kQueryLatencyUs, {{"space", spaceName}}); + stats::StatsManager::removeHistoWithLabels(kSlowQueryLatencyUs, {{"space", spaceName}}); + } +} + folly::Future ShowSpacesExecutor::execute() { SCOPED_TIMER(&execTime_); diff --git a/src/graph/executor/admin/SpaceExecutor.h b/src/graph/executor/admin/SpaceExecutor.h index e0c917d93f0..f61e5e3e95a 100644 --- a/src/graph/executor/admin/SpaceExecutor.h +++ b/src/graph/executor/admin/SpaceExecutor.h @@ -40,6 +40,8 @@ class DropSpaceExecutor final : public Executor { DropSpaceExecutor(const PlanNode *node, QueryContext *qctx) : Executor("DropSpaceExecutor", node, qctx) {} + void unRegisterSpaceLevelMetrics(const std::string &spaceName); + folly::Future execute() override; }; diff --git a/src/graph/executor/algo/ProduceSemiShortestPathExecutor.h b/src/graph/executor/algo/ProduceSemiShortestPathExecutor.h index e3cd3a79330..e7b93a84cea 100644 --- a/src/graph/executor/algo/ProduceSemiShortestPathExecutor.h +++ b/src/graph/executor/algo/ProduceSemiShortestPathExecutor.h @@ -21,13 +21,19 @@ class ProduceSemiShortestPathExecutor final : public Executor { double cost_; std::vector paths_; CostPaths() = default; - CostPaths(double cost, std::vector& paths) : cost_(cost) { paths_.swap(paths); } - CostPaths(double cost, std::vector&& paths) : cost_(cost) { paths_.swap(paths); } + CostPaths(double cost, std::vector& paths) : cost_(cost) { + paths_.swap(paths); + } + CostPaths(double cost, std::vector&& paths) : cost_(cost) { + paths_.swap(paths); + } }; struct CostPathsPtr { CostPathsPtr() = default; - CostPathsPtr(double cost, std::vector& paths) : cost_(cost) { paths_.swap(paths); } + CostPathsPtr(double cost, std::vector& paths) : cost_(cost) { + paths_.swap(paths); + } double cost_; std::vector paths_; }; diff --git a/src/graph/executor/logic/LoopExecutor.h b/src/graph/executor/logic/LoopExecutor.h index 22cec5158dd..706930b40ab 100644 --- a/src/graph/executor/logic/LoopExecutor.h +++ b/src/graph/executor/logic/LoopExecutor.h @@ -17,9 +17,13 @@ class LoopExecutor final : public Executor { folly::Future execute() override; - void setLoopBody(Executor *body) { body_ = DCHECK_NOTNULL(body); } + void setLoopBody(Executor *body) { + body_ = DCHECK_NOTNULL(body); + } - Executor *loopBody() const { return body_; } + Executor *loopBody() const { + return body_; + } private: // Hold the last executor node of loop body executors chain diff --git a/src/graph/executor/logic/SelectExecutor.h b/src/graph/executor/logic/SelectExecutor.h index 5ba78fbc8bf..9b5ffa38c3e 100644 --- a/src/graph/executor/logic/SelectExecutor.h +++ b/src/graph/executor/logic/SelectExecutor.h @@ -17,13 +17,21 @@ class SelectExecutor final : public Executor { folly::Future execute() override; - void setThenBody(Executor* then) { then_ = DCHECK_NOTNULL(then); } + void setThenBody(Executor* then) { + then_ = DCHECK_NOTNULL(then); + } - void setElseBody(Executor* els) { else_ = DCHECK_NOTNULL(els); } + void setElseBody(Executor* els) { + else_ = DCHECK_NOTNULL(els); + } - Executor* thenBody() const { return then_; } + Executor* thenBody() const { + return then_; + } - Executor* elseBody() const { return else_; } + Executor* elseBody() const { + return else_; + } private: Executor* then_; diff --git a/src/graph/executor/mutate/DeleteExecutor.cpp b/src/graph/executor/mutate/DeleteExecutor.cpp index a98ea20afe8..3cb1c670c0b 100644 --- a/src/graph/executor/mutate/DeleteExecutor.cpp +++ b/src/graph/executor/mutate/DeleteExecutor.cpp @@ -111,8 +111,8 @@ folly::Future DeleteTagsExecutor::deleteTags() { ss << "Wrong vid type `" << val.type() << "', value `" << val.toString() << "'"; return Status::Error(ss.str()); } - delTag.set_id(val); - delTag.set_tags(dtNode->tagIds()); + delTag.id_ref() = val; + delTag.tags_ref() = dtNode->tagIds(); delTags.emplace_back(std::move(delTag)); } @@ -135,7 +135,9 @@ folly::Future DeleteTagsExecutor::deleteTags() { }); } -folly::Future DeleteEdgesExecutor::execute() { return deleteEdges(); } +folly::Future DeleteEdgesExecutor::execute() { + return deleteEdges(); +} folly::Future DeleteEdgesExecutor::deleteEdges() { SCOPED_TIMER(&execTime_); @@ -183,16 +185,16 @@ folly::Future DeleteEdgesExecutor::deleteEdges() { } // out edge - edgeKey.set_src(srcId); - edgeKey.set_dst(dstId); - edgeKey.set_ranking(rank.getInt()); - edgeKey.set_edge_type(type.getInt()); + edgeKey.src_ref() = srcId; + edgeKey.dst_ref() = dstId; + edgeKey.ranking_ref() = rank.getInt(); + edgeKey.edge_type_ref() = type.getInt(); edgeKeys.emplace_back(edgeKey); // in edge - edgeKey.set_src(std::move(dstId)); - edgeKey.set_dst(std::move(srcId)); - edgeKey.set_edge_type(-type.getInt()); + edgeKey.src_ref() = std::move(dstId); + edgeKey.dst_ref() = std::move(srcId); + edgeKey.edge_type_ref() = -type.getInt(); edgeKeys.emplace_back(std::move(edgeKey)); } diff --git a/src/graph/executor/mutate/InsertExecutor.cpp b/src/graph/executor/mutate/InsertExecutor.cpp index c3511332808..e926d497fe0 100644 --- a/src/graph/executor/mutate/InsertExecutor.cpp +++ b/src/graph/executor/mutate/InsertExecutor.cpp @@ -15,7 +15,9 @@ using nebula::storage::StorageClient; namespace nebula { namespace graph { -folly::Future InsertVerticesExecutor::execute() { return insertVertices(); } +folly::Future InsertVerticesExecutor::execute() { + return insertVertices(); +} folly::Future InsertVerticesExecutor::insertVertices() { SCOPED_TIMER(&execTime_); @@ -43,7 +45,9 @@ folly::Future InsertVerticesExecutor::insertVertices() { }); } -folly::Future InsertEdgesExecutor::execute() { return insertEdges(); } +folly::Future InsertEdgesExecutor::execute() { + return insertEdges(); +} folly::Future InsertEdgesExecutor::insertEdges() { SCOPED_TIMER(&execTime_); diff --git a/src/graph/executor/mutate/UpdateExecutor.cpp b/src/graph/executor/mutate/UpdateExecutor.cpp index 3abfd089973..d151cc63ef7 100644 --- a/src/graph/executor/mutate/UpdateExecutor.cpp +++ b/src/graph/executor/mutate/UpdateExecutor.cpp @@ -92,10 +92,10 @@ folly::Future UpdateEdgeExecutor::execute() { SCOPED_TIMER(&execTime_); auto *ueNode = asNode(node()); storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(ueNode->getSrcId()); - edgeKey.set_ranking(ueNode->getRank()); - edgeKey.set_edge_type(ueNode->getEdgeType()); - edgeKey.set_dst(ueNode->getDstId()); + edgeKey.src_ref() = ueNode->getSrcId(); + edgeKey.ranking_ref() = ueNode->getRank(); + edgeKey.edge_type_ref() = ueNode->getEdgeType(); + edgeKey.dst_ref() = ueNode->getDstId(); yieldNames_ = ueNode->getYieldNames(); time::Duration updateEdgeTime; diff --git a/src/graph/executor/query/AppendVerticesExecutor.cpp b/src/graph/executor/query/AppendVerticesExecutor.cpp index 70e3228b0a4..a89c4dfee8c 100644 --- a/src/graph/executor/query/AppendVerticesExecutor.cpp +++ b/src/graph/executor/query/AppendVerticesExecutor.cpp @@ -11,7 +11,9 @@ using nebula::storage::cpp2::GetPropResponse; namespace nebula { namespace graph { -folly::Future AppendVerticesExecutor::execute() { return appendVertices(); } +folly::Future AppendVerticesExecutor::execute() { + return appendVertices(); +} DataSet AppendVerticesExecutor::buildRequestDataSet(const AppendVertices *av) { if (av == nullptr) { diff --git a/src/graph/executor/query/GetEdgesExecutor.cpp b/src/graph/executor/query/GetEdgesExecutor.cpp index 675aaf42f40..157a56ab92a 100644 --- a/src/graph/executor/query/GetEdgesExecutor.cpp +++ b/src/graph/executor/query/GetEdgesExecutor.cpp @@ -17,7 +17,9 @@ using nebula::storage::cpp2::GetPropResponse; namespace nebula { namespace graph { -folly::Future GetEdgesExecutor::execute() { return getEdges(); } +folly::Future GetEdgesExecutor::execute() { + return getEdges(); +} DataSet GetEdgesExecutor::buildRequestDataSet(const GetEdges *ge) { auto valueIter = ectx_->getResult(ge->inputVar()).iter(); diff --git a/src/graph/executor/query/GetVerticesExecutor.cpp b/src/graph/executor/query/GetVerticesExecutor.cpp index 603b05033c6..0b519945632 100644 --- a/src/graph/executor/query/GetVerticesExecutor.cpp +++ b/src/graph/executor/query/GetVerticesExecutor.cpp @@ -16,7 +16,9 @@ using nebula::storage::cpp2::GetPropResponse; namespace nebula { namespace graph { -folly::Future GetVerticesExecutor::execute() { return getVertices(); } +folly::Future GetVerticesExecutor::execute() { + return getVertices(); +} folly::Future GetVerticesExecutor::getVertices() { SCOPED_TIMER(&execTime_); diff --git a/src/graph/executor/query/IndexScanExecutor.cpp b/src/graph/executor/query/IndexScanExecutor.cpp index 2221ac26ebd..1e863d79155 100644 --- a/src/graph/executor/query/IndexScanExecutor.cpp +++ b/src/graph/executor/query/IndexScanExecutor.cpp @@ -18,7 +18,9 @@ using nebula::storage::cpp2::LookupIndexResp; namespace nebula { namespace graph { -folly::Future IndexScanExecutor::execute() { return indexScan(); } +folly::Future IndexScanExecutor::execute() { + return indexScan(); +} folly::Future IndexScanExecutor::indexScan() { StorageClient *storageClient = qctx_->getStorageClient(); diff --git a/src/graph/executor/query/LeftJoinExecutor.cpp b/src/graph/executor/query/LeftJoinExecutor.cpp index b9743a518b9..5b1558fafa0 100644 --- a/src/graph/executor/query/LeftJoinExecutor.cpp +++ b/src/graph/executor/query/LeftJoinExecutor.cpp @@ -18,7 +18,9 @@ folly::Future LeftJoinExecutor::execute() { return join(); } -Status LeftJoinExecutor::close() { return Executor::close(); } +Status LeftJoinExecutor::close() { + return Executor::close(); +} folly::Future LeftJoinExecutor::join() { auto* join = asNode(node()); diff --git a/src/graph/executor/query/ScanEdgesExecutor.cpp b/src/graph/executor/query/ScanEdgesExecutor.cpp index fd70ad6e86b..cdca90b3eb0 100644 --- a/src/graph/executor/query/ScanEdgesExecutor.cpp +++ b/src/graph/executor/query/ScanEdgesExecutor.cpp @@ -17,7 +17,9 @@ using nebula::storage::cpp2::ScanResponse; namespace nebula { namespace graph { -folly::Future ScanEdgesExecutor::execute() { return scanEdges(); } +folly::Future ScanEdgesExecutor::execute() { + return scanEdges(); +} folly::Future ScanEdgesExecutor::scanEdges() { SCOPED_TIMER(&execTime_); diff --git a/src/graph/executor/query/ScanVerticesExecutor.cpp b/src/graph/executor/query/ScanVerticesExecutor.cpp index 2ff896002b2..b7510fc87a7 100644 --- a/src/graph/executor/query/ScanVerticesExecutor.cpp +++ b/src/graph/executor/query/ScanVerticesExecutor.cpp @@ -16,7 +16,9 @@ using nebula::storage::cpp2::ScanResponse; namespace nebula { namespace graph { -folly::Future ScanVerticesExecutor::execute() { return scanVertices(); } +folly::Future ScanVerticesExecutor::execute() { + return scanVertices(); +} folly::Future ScanVerticesExecutor::scanVertices() { SCOPED_TIMER(&execTime_); diff --git a/src/graph/executor/query/TraverseExecutor.h b/src/graph/executor/query/TraverseExecutor.h index d85d7c44247..ff4c96f3432 100644 --- a/src/graph/executor/query/TraverseExecutor.h +++ b/src/graph/executor/query/TraverseExecutor.h @@ -54,7 +54,9 @@ class TraverseExecutor final : public StorageAccessExecutor { (range_ != nullptr && (currentStep_ == range_->max() || range_->max() == 0)); } - bool zeroStep() const { return range_ != nullptr && range_->min() == 0; } + bool zeroStep() const { + return range_ != nullptr && range_->min() == 0; + } bool hasSameEdge(const Row& prevPath, const Edge& currentEdge); diff --git a/src/graph/executor/test/CMakeLists.txt b/src/graph/executor/test/CMakeLists.txt index 2dc394bfeb0..5f8aba7d7fb 100644 --- a/src/graph/executor/test/CMakeLists.txt +++ b/src/graph/executor/test/CMakeLists.txt @@ -53,6 +53,9 @@ SET(EXEC_QUERY_TEST_OBJS $ $ $ + $ + $ + $ ) SET(EXEC_QUERY_TEST_LIBS diff --git a/src/graph/executor/test/DedupTest.cpp b/src/graph/executor/test/DedupTest.cpp index 3692c49933a..8bf89ba4aac 100644 --- a/src/graph/executor/test/DedupTest.cpp +++ b/src/graph/executor/test/DedupTest.cpp @@ -15,7 +15,9 @@ namespace graph { class DedupTest : public QueryTestBase { public: - void SetUp() override { QueryTestBase::SetUp(); } + void SetUp() override { + QueryTestBase::SetUp(); + } }; #define DEDUP_RESULT_CHECK(inputName, outputName, sentence, expected) \ diff --git a/src/graph/executor/test/FilterTest.cpp b/src/graph/executor/test/FilterTest.cpp index 883e331ef0c..4ab731f26c2 100644 --- a/src/graph/executor/test/FilterTest.cpp +++ b/src/graph/executor/test/FilterTest.cpp @@ -16,7 +16,9 @@ namespace graph { class FilterTest : public QueryTestBase { public: - void SetUp() override { QueryTestBase::SetUp(); } + void SetUp() override { + QueryTestBase::SetUp(); + } }; #define FILTER_RESULT_CHECK(inputName, outputName, sentence, expected) \ diff --git a/src/graph/executor/test/GetNeighborsTest.cpp b/src/graph/executor/test/GetNeighborsTest.cpp index 96175b62d64..9edf1352e05 100644 --- a/src/graph/executor/test/GetNeighborsTest.cpp +++ b/src/graph/executor/test/GetNeighborsTest.cpp @@ -31,13 +31,13 @@ class GetNeighborsTest : public testing::Test { } meta::cpp2::Session session; - session.set_session_id(0); - session.set_user_name("root"); + session.session_id_ref() = 0; + session.user_name_ref() = "root"; auto clientSession = ClientSession::create(std::move(session), nullptr); SpaceInfo spaceInfo; spaceInfo.name = "test_space"; spaceInfo.id = 1; - spaceInfo.spaceDesc.set_space_name("test_space"); + spaceInfo.spaceDesc.space_name_ref() = "test_space"; clientSession->setSpace(std::move(spaceInfo)); auto rctx = std::make_unique>(); rctx->setSession(std::move(clientSession)); diff --git a/src/graph/executor/test/JobTest.cpp b/src/graph/executor/test/JobTest.cpp index 88b48613e50..dbfa5bfab01 100644 --- a/src/graph/executor/test/JobTest.cpp +++ b/src/graph/executor/test/JobTest.cpp @@ -17,16 +17,16 @@ class JobTest : public testing::Test {}; TEST_F(JobTest, JobFinishTime) { { meta::cpp2::AdminJobResult resp; - resp.set_job_id(0); + resp.job_id_ref() = 0; meta::cpp2::JobDesc jobDesc; - jobDesc.set_id(0); - jobDesc.set_start_time(123); - jobDesc.set_stop_time(0); - resp.set_job_desc({std::move(jobDesc)}); + jobDesc.id_ref() = 0; + jobDesc.start_time_ref() = 123; + jobDesc.stop_time_ref() = 0; + resp.job_desc_ref() = {std::move(jobDesc)}; meta::cpp2::TaskDesc taskDesc; - taskDesc.set_start_time(456); - taskDesc.set_stop_time(0); - resp.set_task_desc({std::move(taskDesc)}); + taskDesc.start_time_ref() = 456; + taskDesc.stop_time_ref() = 0; + resp.task_desc_ref() = {std::move(taskDesc)}; auto qctx = std::make_unique(); auto submitJob = SubmitJob::make( @@ -44,12 +44,12 @@ TEST_F(JobTest, JobFinishTime) { } { meta::cpp2::AdminJobResult resp; - resp.set_job_id(0); + resp.job_id_ref() = 0; meta::cpp2::JobDesc jobDesc; - jobDesc.set_id(0); - jobDesc.set_start_time(123); - jobDesc.set_stop_time(0); - resp.set_job_desc({std::move(jobDesc)}); + jobDesc.id_ref() = 0; + jobDesc.start_time_ref() = 123; + jobDesc.stop_time_ref() = 0; + resp.job_desc_ref() = {std::move(jobDesc)}; auto qctx = std::make_unique(); auto submitJob = SubmitJob::make( diff --git a/src/graph/executor/test/SampleTest.cpp b/src/graph/executor/test/SampleTest.cpp index d786b0f802f..59a17d004a0 100644 --- a/src/graph/executor/test/SampleTest.cpp +++ b/src/graph/executor/test/SampleTest.cpp @@ -41,11 +41,17 @@ class SampleTest : public QueryTestBase {}; EXPECT_EQ(proResult.state(), Result::State::kSuccess); \ } while (false) -TEST_F(SampleTest, SequentialInRange2) { SAMPLE_RESULT_CHECK("sample_in_sequential2", 4, 4); } +TEST_F(SampleTest, SequentialInRange2) { + SAMPLE_RESULT_CHECK("sample_in_sequential2", 4, 4); +} -TEST_F(SampleTest, SequentialOutRange1) { SAMPLE_RESULT_CHECK("sample_out_sequential3", 7, 6); } +TEST_F(SampleTest, SequentialOutRange1) { + SAMPLE_RESULT_CHECK("sample_out_sequential3", 7, 6); +} -TEST_F(SampleTest, SequentialOutRange2) { SAMPLE_RESULT_CHECK("sample_out_sequential4", 8, 6); } +TEST_F(SampleTest, SequentialOutRange2) { + SAMPLE_RESULT_CHECK("sample_out_sequential4", 8, 6); +} #define SAMPLE_GN_RESULT_CHECK(outputName, count, expect) \ do { \ @@ -70,11 +76,17 @@ TEST_F(SampleTest, SequentialOutRange2) { SAMPLE_RESULT_CHECK("sample_out_sequen EXPECT_EQ(proResult.state(), Result::State::kSuccess); \ } while (false) -TEST_F(SampleTest, GN2) { SAMPLE_GN_RESULT_CHECK("sample_in_gn2", 4, 4); } +TEST_F(SampleTest, GN2) { + SAMPLE_GN_RESULT_CHECK("sample_in_gn2", 4, 4); +} -TEST_F(SampleTest, GNOutOfRange1) { SAMPLE_GN_RESULT_CHECK("sample_out_gn1", 6, 4); } +TEST_F(SampleTest, GNOutOfRange1) { + SAMPLE_GN_RESULT_CHECK("sample_out_gn1", 6, 4); +} -TEST_F(SampleTest, GNOutOfRange2) { SAMPLE_GN_RESULT_CHECK("sample_out_gn2", 7, 4); } +TEST_F(SampleTest, GNOutOfRange2) { + SAMPLE_GN_RESULT_CHECK("sample_out_gn2", 7, 4); +} } // namespace graph } // namespace nebula diff --git a/src/graph/executor/test/SetExecutorTest.cpp b/src/graph/executor/test/SetExecutorTest.cpp index 9bac46afe25..d9089a32f7e 100644 --- a/src/graph/executor/test/SetExecutorTest.cpp +++ b/src/graph/executor/test/SetExecutorTest.cpp @@ -21,7 +21,9 @@ namespace graph { class SetExecutorTest : public ::testing::Test { public: - void SetUp() override { qctx_ = std::make_unique(); } + void SetUp() override { + qctx_ = std::make_unique(); + } static bool diffDataSet(const DataSet& lhs, const DataSet& rhs) { if (lhs.colNames != rhs.colNames) return false; diff --git a/src/graph/executor/test/ShowQueriesTest.cpp b/src/graph/executor/test/ShowQueriesTest.cpp index 4db62512b93..f4ca21ad578 100644 --- a/src/graph/executor/test/ShowQueriesTest.cpp +++ b/src/graph/executor/test/ShowQueriesTest.cpp @@ -16,30 +16,30 @@ class ShowQueriesTest : public QueryTestBase {}; TEST_F(ShowQueriesTest, TestAddQueryAndTopN) { meta::cpp2::Session session; - session.set_session_id(1); - session.set_create_time(123); - session.set_update_time(456); - session.set_user_name("root"); - session.set_space_name("test"); - session.set_graph_addr(HostAddr("127.0.0.1", 9669)); + session.session_id_ref() = 1; + session.create_time_ref() = 123; + session.update_time_ref() = 456; + session.user_name_ref() = "root"; + session.space_name_ref() = "test"; + session.graph_addr_ref() = HostAddr("127.0.0.1", 9669); { meta::cpp2::QueryDesc desc; - desc.set_start_time(123); - desc.set_status(meta::cpp2::QueryStatus::RUNNING); - desc.set_duration(100); - desc.set_query(""); - desc.set_graph_addr(HostAddr("127.0.0.1", 9669)); + desc.start_time_ref() = 123; + desc.status_ref() = meta::cpp2::QueryStatus::RUNNING; + desc.duration_ref() = 100; + desc.query_ref() = ""; + desc.graph_addr_ref() = HostAddr("127.0.0.1", 9669); session.queries_ref()->emplace(1, std::move(desc)); } { meta::cpp2::QueryDesc desc; - desc.set_start_time(123); - desc.set_status(meta::cpp2::QueryStatus::RUNNING); - desc.set_duration(200); - desc.set_query(""); - desc.set_graph_addr(HostAddr("127.0.0.1", 9669)); + desc.start_time_ref() = 123; + desc.status_ref() = meta::cpp2::QueryStatus::RUNNING; + desc.duration_ref() = 200; + desc.query_ref() = ""; + desc.graph_addr_ref() = HostAddr("127.0.0.1", 9669); session.queries_ref()->emplace(2, std::move(desc)); } diff --git a/src/graph/optimizer/OptContext.h b/src/graph/optimizer/OptContext.h index 55e8940ae1f..6f6b32d6da3 100644 --- a/src/graph/optimizer/OptContext.h +++ b/src/graph/optimizer/OptContext.h @@ -27,13 +27,21 @@ class OptContext final : private cpp::NonCopyable, private cpp::NonMovable { public: explicit OptContext(graph::QueryContext *qctx); - graph::QueryContext *qctx() const { return qctx_; } + graph::QueryContext *qctx() const { + return qctx_; + } - ObjectPool *objPool() const { return objPool_.get(); } + ObjectPool *objPool() const { + return objPool_.get(); + } - bool changed() const { return changed_; } + bool changed() const { + return changed_; + } - void setChanged(bool changed) { changed_ = changed; } + void setChanged(bool changed) { + changed_ = changed; + } void addPlanNodeAndOptGroupNode(int64_t planNodeId, const OptGroupNode *optGroupNode); const OptGroupNode *findOptGroupNodeByPlanNodeId(int64_t planNodeId) const; diff --git a/src/graph/optimizer/OptGroup.cpp b/src/graph/optimizer/OptGroup.cpp index 22f6c1de36c..28337516eb8 100644 --- a/src/graph/optimizer/OptGroup.cpp +++ b/src/graph/optimizer/OptGroup.cpp @@ -23,7 +23,9 @@ using nebula::graph::SingleDependencyNode; namespace nebula { namespace opt { -OptGroup *OptGroup::create(OptContext *ctx) { return ctx->objPool()->add(new OptGroup(ctx)); } +OptGroup *OptGroup::create(OptContext *ctx) { + return ctx->objPool()->add(new OptGroup(ctx)); +} void OptGroup::setUnexplored(const OptRule *rule) { auto iter = std::find(exploredRules_.begin(), exploredRules_.end(), rule); @@ -35,7 +37,9 @@ void OptGroup::setUnexplored(const OptRule *rule) { } } -OptGroup::OptGroup(OptContext *ctx) noexcept : ctx_(ctx) { DCHECK(ctx != nullptr); } +OptGroup::OptGroup(OptContext *ctx) noexcept : ctx_(ctx) { + DCHECK(ctx != nullptr); +} void OptGroup::addGroupNode(OptGroupNode *groupNode) { DCHECK(groupNode != nullptr); @@ -130,7 +134,9 @@ std::pair OptGroup::findMinCostGroupNode() const { return std::make_pair(minCost, minGroupNode); } -double OptGroup::getCost() const { return findMinCostGroupNode().first; } +double OptGroup::getCost() const { + return findMinCostGroupNode().first; +} const PlanNode *OptGroup::getPlan() const { const OptGroupNode *minGroupNode = findMinCostGroupNode().second; @@ -181,7 +187,9 @@ Status OptGroupNode::explore(const OptRule *rule) { return Status::OK(); } -double OptGroupNode::getCost() const { return node_->cost(); } +double OptGroupNode::getCost() const { + return node_->cost(); +} const PlanNode *OptGroupNode::getPlan() const { if (node_->kind() == PlanNode::Kind::kSelect) { diff --git a/src/graph/optimizer/OptGroup.h b/src/graph/optimizer/OptGroup.h index d65fc9d9565..7164dd6246a 100644 --- a/src/graph/optimizer/OptGroup.h +++ b/src/graph/optimizer/OptGroup.h @@ -27,13 +27,17 @@ class OptGroup final { return std::find(exploredRules_.cbegin(), exploredRules_.cend(), rule) != exploredRules_.cend(); } - void setExplored(const OptRule *rule) { exploredRules_.emplace_back(rule); } + void setExplored(const OptRule *rule) { + exploredRules_.emplace_back(rule); + } void setUnexplored(const OptRule *rule); void addGroupNode(OptGroupNode *groupNode); OptGroupNode *makeGroupNode(graph::PlanNode *node); - const std::list &groupNodes() const { return groupNodes_; } + const std::list &groupNodes() const { + return groupNodes_; + } Status explore(const OptRule *rule); Status exploreUntilMaxRound(const OptRule *rule); @@ -56,27 +60,43 @@ class OptGroupNode final { public: static OptGroupNode *create(OptContext *ctx, graph::PlanNode *node, const OptGroup *group); - void dependsOn(OptGroup *dep) { dependencies_.emplace_back(dep); } + void dependsOn(OptGroup *dep) { + dependencies_.emplace_back(dep); + } - const std::vector &dependencies() const { return dependencies_; } + const std::vector &dependencies() const { + return dependencies_; + } - void setDeps(std::vector deps) { dependencies_ = deps; } + void setDeps(std::vector deps) { + dependencies_ = deps; + } - void addBody(OptGroup *body) { bodies_.emplace_back(body); } + void addBody(OptGroup *body) { + bodies_.emplace_back(body); + } - const std::vector &bodies() const { return bodies_; } + const std::vector &bodies() const { + return bodies_; + } bool isExplored(const OptRule *rule) const { return std::find(exploredRules_.cbegin(), exploredRules_.cend(), rule) != exploredRules_.cend(); } - void setExplored(const OptRule *rule) { exploredRules_.emplace_back(rule); } + void setExplored(const OptRule *rule) { + exploredRules_.emplace_back(rule); + } void setUnexplored(const OptRule *rule); - const OptGroup *group() const { return group_; } + const OptGroup *group() const { + return group_; + } - graph::PlanNode *node() const { return node_; } + graph::PlanNode *node() const { + return node_; + } Status explore(const OptRule *rule); double getCost() const; diff --git a/src/graph/optimizer/OptRule.h b/src/graph/optimizer/OptRule.h index ea96bef6ed0..041c9419551 100644 --- a/src/graph/optimizer/OptRule.h +++ b/src/graph/optimizer/OptRule.h @@ -99,7 +99,9 @@ class RuleSet final { void merge(const RuleSet &ruleset); - const std::vector &rules() const { return rules_; } + const std::vector &rules() const { + return rules_; + } private: explicit RuleSet(const std::string &name); diff --git a/src/graph/optimizer/OptimizerUtils.cpp b/src/graph/optimizer/OptimizerUtils.cpp index 527bde6f12e..9f9fd41c78b 100644 --- a/src/graph/optimizer/OptimizerUtils.cpp +++ b/src/graph/optimizer/OptimizerUtils.cpp @@ -69,28 +69,28 @@ Status handleRangeIndex(const meta::cpp2::ColumnDef& field, include = true; [[fallthrough]]; case Expression::Kind::kRelGT: - hint->set_begin_value(value); - hint->set_include_begin(include); + hint->begin_value_ref() = value; + hint->include_begin_ref() = include; break; case Expression::Kind::kRelLE: include = true; [[fallthrough]]; case Expression::Kind::kRelLT: - hint->set_end_value(value); - hint->set_include_end(include); + hint->end_value_ref() = value; + hint->include_end_ref() = include; break; default: break; } - hint->set_scan_type(storage::cpp2::ScanType::RANGE); - hint->set_column_name(field.get_name()); + hint->scan_type_ref() = storage::cpp2::ScanType::RANGE; + hint->column_name_ref() = field.get_name(); return Status::OK(); } void handleEqualIndex(const ColumnDef& field, const Value& value, IndexColumnHint* hint) { - hint->set_scan_type(storage::cpp2::ScanType::PREFIX); - hint->set_column_name(field.get_name()); - hint->set_begin_value(value); + hint->scan_type_ref() = storage::cpp2::ScanType::PREFIX; + hint->column_name_ref() = field.get_name(); + hint->begin_value_ref() = value; } StatusOr selectRelExprIndex(const ColumnDef& field, @@ -233,23 +233,23 @@ bool getIndexColumnHintInExpr(const ColumnDef& field, return false; } ScoredColumnHint h; - h.hint.set_column_name(field.get_name()); + h.hint.column_name_ref() = field.get_name(); if (begin.first < end.first) { - h.hint.set_scan_type(storage::cpp2::ScanType::RANGE); - h.hint.set_begin_value(std::move(begin.first)); - h.hint.set_end_value(std::move(end.first)); - h.hint.set_include_begin(begin.second); - h.hint.set_include_end(end.second); + h.hint.scan_type_ref() = storage::cpp2::ScanType::RANGE; + h.hint.begin_value_ref() = std::move(begin.first); + h.hint.end_value_ref() = std::move(end.first); + h.hint.include_begin_ref() = begin.second; + h.hint.include_end_ref() = end.second; h.score = IndexScore::kRange; } else if (begin.first == end.first) { if (begin.second == false && end.second == false) { return false; } else { - h.hint.set_scan_type(storage::cpp2::ScanType::RANGE); - h.hint.set_begin_value(std::move(begin.first)); - h.hint.set_end_value(std::move(end.first)); - h.hint.set_include_begin(begin.second); - h.hint.set_include_end(end.second); + h.hint.scan_type_ref() = storage::cpp2::ScanType::RANGE; + h.hint.begin_value_ref() = std::move(begin.first); + h.hint.end_value_ref() = std::move(end.first); + h.hint.include_begin_ref() = begin.second; + h.hint.include_end_ref() = end.second; h.score = IndexScore::kRange; } } else { @@ -382,10 +382,10 @@ bool OptimizerUtils::findOptimalIndex(const Expression* condition, } // The filter can always be pushed down for lookup query if (iter != index.hints.end() || !index.unusedExprs.empty()) { - ictx->set_filter(condition->encode()); + ictx->filter_ref() = condition->encode(); } - ictx->set_index_id(index.index->get_index_id()); - ictx->set_column_hints(std::move(hints)); + ictx->index_id_ref() = index.index->get_index_id(); + ictx->column_hints_ref() = std::move(hints); return true; } diff --git a/src/graph/optimizer/rule/CollapseProjectRule.cpp b/src/graph/optimizer/rule/CollapseProjectRule.cpp index a40974c1c0d..6a8ae3d552d 100644 --- a/src/graph/optimizer/rule/CollapseProjectRule.cpp +++ b/src/graph/optimizer/rule/CollapseProjectRule.cpp @@ -20,7 +20,9 @@ namespace opt { std::unique_ptr CollapseProjectRule::kInstance = std::unique_ptr(new CollapseProjectRule()); -CollapseProjectRule::CollapseProjectRule() { RuleSet::QueryRules().addRule(this); } +CollapseProjectRule::CollapseProjectRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern& CollapseProjectRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kProject, @@ -111,7 +113,9 @@ bool CollapseProjectRule::match(OptContext* octx, const MatchedResult& matched) return OptRule::match(octx, matched); } -std::string CollapseProjectRule::toString() const { return "CollapseProjectRule"; } +std::string CollapseProjectRule::toString() const { + return "CollapseProjectRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/CombineFilterRule.cpp b/src/graph/optimizer/rule/CombineFilterRule.cpp index 63903b2818e..148672c7351 100644 --- a/src/graph/optimizer/rule/CombineFilterRule.cpp +++ b/src/graph/optimizer/rule/CombineFilterRule.cpp @@ -19,7 +19,9 @@ namespace opt { std::unique_ptr CombineFilterRule::kInstance = std::unique_ptr(new CombineFilterRule()); -CombineFilterRule::CombineFilterRule() { RuleSet::QueryRules().addRule(this); } +CombineFilterRule::CombineFilterRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern& CombineFilterRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kFilter, @@ -62,7 +64,9 @@ bool CombineFilterRule::match(OptContext* octx, const MatchedResult& matched) co return OptRule::match(octx, matched); } -std::string CombineFilterRule::toString() const { return "CombineFilterRule"; } +std::string CombineFilterRule::toString() const { + return "CombineFilterRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/EdgeIndexFullScanRule.cpp b/src/graph/optimizer/rule/EdgeIndexFullScanRule.cpp index ba7315d48ae..3434b1a7f55 100644 --- a/src/graph/optimizer/rule/EdgeIndexFullScanRule.cpp +++ b/src/graph/optimizer/rule/EdgeIndexFullScanRule.cpp @@ -20,14 +20,18 @@ namespace opt { std::unique_ptr EdgeIndexFullScanRule::kInstance = std::unique_ptr(new EdgeIndexFullScanRule()); -EdgeIndexFullScanRule::EdgeIndexFullScanRule() { RuleSet::DefaultRules().addRule(this); } +EdgeIndexFullScanRule::EdgeIndexFullScanRule() { + RuleSet::DefaultRules().addRule(this); +} const Pattern& EdgeIndexFullScanRule::pattern() const { static Pattern pattern = Pattern::create(Kind::kEdgeIndexFullScan); return pattern; } -std::string EdgeIndexFullScanRule::toString() const { return "EdgeIndexFullScanRule"; } +std::string EdgeIndexFullScanRule::toString() const { + return "EdgeIndexFullScanRule"; +} IndexScan* EdgeIndexFullScanRule::scan(OptContext* ctx, const graph::PlanNode* node) const { auto scan = static_cast(node); diff --git a/src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp b/src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp index 3729afc85b2..b03b7af8dd0 100644 --- a/src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp +++ b/src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp @@ -121,10 +121,10 @@ StatusOr GeoPredicateIndexScanBaseRule::transform( for (auto& scanRange : scanRanges) { IndexQueryContext ictx; auto indexColumnHint = scanRange.toIndexColumnHint(); - indexColumnHint.set_column_name(fieldName); - ictx.set_filter(condition->encode()); - ictx.set_index_id(indexItem->get_index_id()); - ictx.set_column_hints({indexColumnHint}); + indexColumnHint.column_name_ref() = fieldName; + ictx.filter_ref() = condition->encode(); + ictx.index_id_ref() = indexItem->get_index_id(); + ictx.column_hints_ref() = {indexColumnHint}; idxCtxs.emplace_back(std::move(ictx)); } diff --git a/src/graph/optimizer/rule/GetEdgesTransformRule.cpp b/src/graph/optimizer/rule/GetEdgesTransformRule.cpp index bfa8456c57a..df671fe5566 100644 --- a/src/graph/optimizer/rule/GetEdgesTransformRule.cpp +++ b/src/graph/optimizer/rule/GetEdgesTransformRule.cpp @@ -27,7 +27,9 @@ namespace opt { std::unique_ptr GetEdgesTransformRule::kInstance = std::unique_ptr(new GetEdgesTransformRule()); -GetEdgesTransformRule::GetEdgesTransformRule() { RuleSet::QueryRules().addRule(this); } +GetEdgesTransformRule::GetEdgesTransformRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern &GetEdgesTransformRule::pattern() const { static Pattern pattern = @@ -93,7 +95,9 @@ StatusOr GetEdgesTransformRule::transform( return result; } -std::string GetEdgesTransformRule::toString() const { return "GetEdgesTransformRule"; } +std::string GetEdgesTransformRule::toString() const { + return "GetEdgesTransformRule"; +} /*static*/ graph::ScanEdges *GetEdgesTransformRule::traverseToScanEdges( const graph::Traverse *traverse) { diff --git a/src/graph/optimizer/rule/IndexFullScanBaseRule.cpp b/src/graph/optimizer/rule/IndexFullScanBaseRule.cpp index 459826c5f5c..7a359c8b7eb 100644 --- a/src/graph/optimizer/rule/IndexFullScanBaseRule.cpp +++ b/src/graph/optimizer/rule/IndexFullScanBaseRule.cpp @@ -62,7 +62,7 @@ StatusOr IndexFullScanBaseRule::transform(OptContext* ctx, idxId = index->get_index_id(); } } - ictx.set_index_id(idxId); + ictx.index_id_ref() = idxId; idxCtxs.emplace_back(std::move(ictx)); auto scanNode = this->scan(ctx, scan); diff --git a/src/graph/optimizer/rule/IndexScanRule.cpp b/src/graph/optimizer/rule/IndexScanRule.cpp index e44ddf57773..9197e26d119 100644 --- a/src/graph/optimizer/rule/IndexScanRule.cpp +++ b/src/graph/optimizer/rule/IndexScanRule.cpp @@ -30,7 +30,9 @@ namespace opt { std::unique_ptr IndexScanRule::kInstance = std::unique_ptr(new IndexScanRule()); -IndexScanRule::IndexScanRule() { RuleSet::DefaultRules().addRule(this); } +IndexScanRule::IndexScanRule() { + RuleSet::DefaultRules().addRule(this); +} const Pattern& IndexScanRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kIndexScan); @@ -93,7 +95,9 @@ StatusOr IndexScanRule::transform(OptContext* ctx, return result; } -std::string IndexScanRule::toString() const { return "IndexScanRule"; } +std::string IndexScanRule::toString() const { + return "IndexScanRule"; +} Status IndexScanRule::createIndexQueryCtx(IndexQueryCtx& iqctx, ScanKind kind, @@ -175,7 +179,7 @@ Status IndexScanRule::appendIQCtx(const IndexItem& index, if (it != filterItems.items.end()) { // TODO (sky) : rewrite filter expr. NE expr should be add filter expr . if (filter != nullptr) { - ctx.set_filter(Expression::encode(*filter)); + ctx.filter_ref() = Expression::encode(*filter); } break; } @@ -185,22 +189,22 @@ Status IndexScanRule::appendIQCtx(const IndexItem& index, break; } } - ctx.set_index_id(index->get_index_id()); + ctx.index_id_ref() = index->get_index_id(); if (hc > 0) { // TODO (sky) : rewrite expr and set filter if (filter != nullptr) { - ctx.set_filter(Expression::encode(*filter)); + ctx.filter_ref() = Expression::encode(*filter); } } - ctx.set_column_hints(std::move(hints)); + ctx.column_hints_ref() = std::move(hints); iqctx.emplace_back(std::move(ctx)); return Status::OK(); } Status IndexScanRule::appendIQCtx(const IndexItem& index, IndexQueryCtx& iqctx) const { IndexQueryContext ctx; - ctx.set_index_id(index->get_index_id()); - ctx.set_filter(""); + ctx.index_id_ref() = index->get_index_id(); + ctx.filter_ref() = ""; iqctx.emplace_back(std::move(ctx)); return Status::OK(); } @@ -291,19 +295,19 @@ Status IndexScanRule::appendColHint(std::vector& hints, if (isRangeScan) { if (!begin.first.empty()) { - hint.set_begin_value(begin.first); - hint.set_include_begin(begin.second); + hint.begin_value_ref() = begin.first; + hint.include_begin_ref() = begin.second; } if (!end.first.empty()) { - hint.set_end_value(end.first); - hint.set_include_end(end.second); + hint.end_value_ref() = end.first; + hint.include_end_ref() = end.second; } - hint.set_scan_type(storage::cpp2::ScanType::RANGE); + hint.scan_type_ref() = storage::cpp2::ScanType::RANGE; } else { - hint.set_begin_value(begin.first); - hint.set_scan_type(storage::cpp2::ScanType::PREFIX); + hint.begin_value_ref() = begin.first; + hint.scan_type_ref() = storage::cpp2::ScanType::PREFIX; } - hint.set_column_name(col.get_name()); + hint.column_name_ref() = col.get_name(); hints.emplace_back(std::move(hint)); return Status::OK(); } diff --git a/src/graph/optimizer/rule/IndexScanRule.h b/src/graph/optimizer/rule/IndexScanRule.h index c0ffc265725..62dec57d536 100644 --- a/src/graph/optimizer/rule/IndexScanRule.h +++ b/src/graph/optimizer/rule/IndexScanRule.h @@ -43,10 +43,18 @@ class IndexScanRule final : public OptRule { Kind kind_; public: - ScanKind() { kind_ = Kind::kUnknown; } - void setKind(Kind k) { kind_ = k; } - Kind getKind() { return kind_; } - bool isSingleScan() { return kind_ == Kind::kSingleScan; } + ScanKind() { + kind_ = Kind::kUnknown; + } + void setKind(Kind k) { + kind_ = k; + } + Kind getKind() { + return kind_; + } + bool isSingleScan() { + return kind_ == Kind::kSingleScan; + } }; // col_ : index column name @@ -68,7 +76,9 @@ class IndexScanRule final : public OptRule { struct FilterItems { std::vector items; FilterItems() {} - explicit FilterItems(const std::vector& i) { items = i; } + explicit FilterItems(const std::vector& i) { + items = i; + } void addItem(const std::string& field, RelationalExpression::Kind kind, const Value& v) { items.emplace_back(FilterItem(field, kind, v)); } diff --git a/src/graph/optimizer/rule/MergeGetNbrsAndDedupRule.cpp b/src/graph/optimizer/rule/MergeGetNbrsAndDedupRule.cpp index 558c420fcfd..4549367a440 100644 --- a/src/graph/optimizer/rule/MergeGetNbrsAndDedupRule.cpp +++ b/src/graph/optimizer/rule/MergeGetNbrsAndDedupRule.cpp @@ -20,7 +20,9 @@ namespace opt { std::unique_ptr MergeGetNbrsAndDedupRule::kInstance = std::unique_ptr(new MergeGetNbrsAndDedupRule()); -MergeGetNbrsAndDedupRule::MergeGetNbrsAndDedupRule() { RuleSet::QueryRules().addRule(this); } +MergeGetNbrsAndDedupRule::MergeGetNbrsAndDedupRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern &MergeGetNbrsAndDedupRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kGetNeighbors, @@ -52,7 +54,9 @@ StatusOr MergeGetNbrsAndDedupRule::transform( return result; } -std::string MergeGetNbrsAndDedupRule::toString() const { return "MergeGetNbrsAndDedupRule"; } +std::string MergeGetNbrsAndDedupRule::toString() const { + return "MergeGetNbrsAndDedupRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/MergeGetNbrsAndProjectRule.cpp b/src/graph/optimizer/rule/MergeGetNbrsAndProjectRule.cpp index 8e9f0b3fc5d..f2d6732773f 100644 --- a/src/graph/optimizer/rule/MergeGetNbrsAndProjectRule.cpp +++ b/src/graph/optimizer/rule/MergeGetNbrsAndProjectRule.cpp @@ -24,7 +24,9 @@ namespace opt { std::unique_ptr MergeGetNbrsAndProjectRule::kInstance = std::unique_ptr(new MergeGetNbrsAndProjectRule()); -MergeGetNbrsAndProjectRule::MergeGetNbrsAndProjectRule() { RuleSet::QueryRules().addRule(this); } +MergeGetNbrsAndProjectRule::MergeGetNbrsAndProjectRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern &MergeGetNbrsAndProjectRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kGetNeighbors, @@ -74,7 +76,9 @@ StatusOr MergeGetNbrsAndProjectRule::transform( return result; } -std::string MergeGetNbrsAndProjectRule::toString() const { return "MergeGetNbrsAndProjectRule"; } +std::string MergeGetNbrsAndProjectRule::toString() const { + return "MergeGetNbrsAndProjectRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/PushFilterDownAggregateRule.cpp b/src/graph/optimizer/rule/PushFilterDownAggregateRule.cpp index d0d0e9308b3..f4c4adab13a 100644 --- a/src/graph/optimizer/rule/PushFilterDownAggregateRule.cpp +++ b/src/graph/optimizer/rule/PushFilterDownAggregateRule.cpp @@ -22,7 +22,9 @@ namespace opt { std::unique_ptr PushFilterDownAggregateRule::kInstance = std::unique_ptr(new PushFilterDownAggregateRule()); -PushFilterDownAggregateRule::PushFilterDownAggregateRule() { RuleSet::QueryRules().addRule(this); } +PushFilterDownAggregateRule::PushFilterDownAggregateRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern& PushFilterDownAggregateRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kFilter, @@ -109,7 +111,9 @@ StatusOr PushFilterDownAggregateRule::transform( return result; } -std::string PushFilterDownAggregateRule::toString() const { return "PushFilterDownAggregateRule"; } +std::string PushFilterDownAggregateRule::toString() const { + return "PushFilterDownAggregateRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/PushFilterDownGetNbrsRule.cpp b/src/graph/optimizer/rule/PushFilterDownGetNbrsRule.cpp index 741e9981e12..7da272caf8b 100644 --- a/src/graph/optimizer/rule/PushFilterDownGetNbrsRule.cpp +++ b/src/graph/optimizer/rule/PushFilterDownGetNbrsRule.cpp @@ -24,7 +24,9 @@ namespace opt { std::unique_ptr PushFilterDownGetNbrsRule::kInstance = std::unique_ptr(new PushFilterDownGetNbrsRule()); -PushFilterDownGetNbrsRule::PushFilterDownGetNbrsRule() { RuleSet::QueryRules().addRule(this); } +PushFilterDownGetNbrsRule::PushFilterDownGetNbrsRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern &PushFilterDownGetNbrsRule::pattern() const { static Pattern pattern = @@ -99,7 +101,9 @@ StatusOr PushFilterDownGetNbrsRule::transform( return result; } -std::string PushFilterDownGetNbrsRule::toString() const { return "PushFilterDownGetNbrsRule"; } +std::string PushFilterDownGetNbrsRule::toString() const { + return "PushFilterDownGetNbrsRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/PushFilterDownLeftJoinRule.cpp b/src/graph/optimizer/rule/PushFilterDownLeftJoinRule.cpp index 42293d1ffb6..d6c830be679 100644 --- a/src/graph/optimizer/rule/PushFilterDownLeftJoinRule.cpp +++ b/src/graph/optimizer/rule/PushFilterDownLeftJoinRule.cpp @@ -20,7 +20,9 @@ namespace opt { std::unique_ptr PushFilterDownLeftJoinRule::kInstance = std::unique_ptr(new PushFilterDownLeftJoinRule()); -PushFilterDownLeftJoinRule::PushFilterDownLeftJoinRule() { RuleSet::QueryRules().addRule(this); } +PushFilterDownLeftJoinRule::PushFilterDownLeftJoinRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern& PushFilterDownLeftJoinRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kFilter, @@ -124,7 +126,9 @@ StatusOr PushFilterDownLeftJoinRule::transform( return result; } -std::string PushFilterDownLeftJoinRule::toString() const { return "PushFilterDownLeftJoinRule"; } +std::string PushFilterDownLeftJoinRule::toString() const { + return "PushFilterDownLeftJoinRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/PushFilterDownProjectRule.cpp b/src/graph/optimizer/rule/PushFilterDownProjectRule.cpp index 59761a0656d..df410b8378a 100644 --- a/src/graph/optimizer/rule/PushFilterDownProjectRule.cpp +++ b/src/graph/optimizer/rule/PushFilterDownProjectRule.cpp @@ -20,7 +20,9 @@ namespace opt { std::unique_ptr PushFilterDownProjectRule::kInstance = std::unique_ptr(new PushFilterDownProjectRule()); -PushFilterDownProjectRule::PushFilterDownProjectRule() { RuleSet::QueryRules().addRule(this); } +PushFilterDownProjectRule::PushFilterDownProjectRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern& PushFilterDownProjectRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kFilter, @@ -142,7 +144,9 @@ StatusOr PushFilterDownProjectRule::transform( return result; } -std::string PushFilterDownProjectRule::toString() const { return "PushFilterDownProjectRule"; } +std::string PushFilterDownProjectRule::toString() const { + return "PushFilterDownProjectRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/PushLimitDownIndexScanRule.cpp b/src/graph/optimizer/rule/PushLimitDownIndexScanRule.cpp index 089b7d042ed..f434c35d32d 100644 --- a/src/graph/optimizer/rule/PushLimitDownIndexScanRule.cpp +++ b/src/graph/optimizer/rule/PushLimitDownIndexScanRule.cpp @@ -22,7 +22,9 @@ namespace opt { std::unique_ptr PushLimitDownIndexScanRule::kInstance = std::unique_ptr(new PushLimitDownIndexScanRule()); -PushLimitDownIndexScanRule::PushLimitDownIndexScanRule() { RuleSet::QueryRules().addRule(this); } +PushLimitDownIndexScanRule::PushLimitDownIndexScanRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern &PushLimitDownIndexScanRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kLimit, @@ -63,7 +65,9 @@ StatusOr PushLimitDownIndexScanRule::transform( return result; } -std::string PushLimitDownIndexScanRule::toString() const { return "PushLimitDownIndexScanRule"; } +std::string PushLimitDownIndexScanRule::toString() const { + return "PushLimitDownIndexScanRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/PushLimitDownProjectRule.cpp b/src/graph/optimizer/rule/PushLimitDownProjectRule.cpp index 32025332d97..2805e215ee6 100644 --- a/src/graph/optimizer/rule/PushLimitDownProjectRule.cpp +++ b/src/graph/optimizer/rule/PushLimitDownProjectRule.cpp @@ -22,7 +22,9 @@ namespace opt { std::unique_ptr PushLimitDownProjectRule::kInstance = std::unique_ptr(new PushLimitDownProjectRule()); -PushLimitDownProjectRule::PushLimitDownProjectRule() { RuleSet::QueryRules().addRule(this); } +PushLimitDownProjectRule::PushLimitDownProjectRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern &PushLimitDownProjectRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kLimit, @@ -64,7 +66,9 @@ StatusOr PushLimitDownProjectRule::transform( return result; } -std::string PushLimitDownProjectRule::toString() const { return "PushLimitDownProjectRule"; } +std::string PushLimitDownProjectRule::toString() const { + return "PushLimitDownProjectRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/RemoveNoopProjectRule.cpp b/src/graph/optimizer/rule/RemoveNoopProjectRule.cpp index 0c64051e399..79d261dada9 100644 --- a/src/graph/optimizer/rule/RemoveNoopProjectRule.cpp +++ b/src/graph/optimizer/rule/RemoveNoopProjectRule.cpp @@ -19,7 +19,9 @@ namespace opt { std::unique_ptr RemoveNoopProjectRule::kInstance = std::unique_ptr(new RemoveNoopProjectRule()); -RemoveNoopProjectRule::RemoveNoopProjectRule() { RuleSet::QueryRules().addRule(this); } +RemoveNoopProjectRule::RemoveNoopProjectRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern& RemoveNoopProjectRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kProject); @@ -93,7 +95,9 @@ bool RemoveNoopProjectRule::match(OptContext* octx, const MatchedResult& matched return true; } -std::string RemoveNoopProjectRule::toString() const { return "RemoveNoopProjectRule"; } +std::string RemoveNoopProjectRule::toString() const { + return "RemoveNoopProjectRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/TagIndexFullScanRule.cpp b/src/graph/optimizer/rule/TagIndexFullScanRule.cpp index 327bd24e24a..e64be52f00a 100644 --- a/src/graph/optimizer/rule/TagIndexFullScanRule.cpp +++ b/src/graph/optimizer/rule/TagIndexFullScanRule.cpp @@ -16,14 +16,18 @@ namespace opt { std::unique_ptr TagIndexFullScanRule::kInstance = std::unique_ptr(new TagIndexFullScanRule()); -TagIndexFullScanRule::TagIndexFullScanRule() { RuleSet::DefaultRules().addRule(this); } +TagIndexFullScanRule::TagIndexFullScanRule() { + RuleSet::DefaultRules().addRule(this); +} const Pattern& TagIndexFullScanRule::pattern() const { static Pattern pattern = Pattern::create(Kind::kTagIndexFullScan); return pattern; } -std::string TagIndexFullScanRule::toString() const { return "TagIndexFullScanRule"; } +std::string TagIndexFullScanRule::toString() const { + return "TagIndexFullScanRule"; +} graph::IndexScan* TagIndexFullScanRule::scan(OptContext* ctx, const graph::PlanNode* node) const { auto scan = static_cast(node); diff --git a/src/graph/optimizer/rule/TopNRule.cpp b/src/graph/optimizer/rule/TopNRule.cpp index a9a29176a7b..b7877995e5a 100644 --- a/src/graph/optimizer/rule/TopNRule.cpp +++ b/src/graph/optimizer/rule/TopNRule.cpp @@ -21,7 +21,9 @@ namespace opt { std::unique_ptr TopNRule::kInstance = std::unique_ptr(new TopNRule()); -TopNRule::TopNRule() { RuleSet::QueryRules().addRule(this); } +TopNRule::TopNRule() { + RuleSet::QueryRules().addRule(this); +} const Pattern &TopNRule::pattern() const { static Pattern pattern = Pattern::create(graph::PlanNode::Kind::kLimit, @@ -58,7 +60,9 @@ StatusOr TopNRule::transform(OptContext *ctx, return result; } -std::string TopNRule::toString() const { return "TopNRule"; } +std::string TopNRule::toString() const { + return "TopNRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/UnionAllEdgeIndexScanRule.cpp b/src/graph/optimizer/rule/UnionAllEdgeIndexScanRule.cpp index 066a9f0d678..17a6fa998b5 100644 --- a/src/graph/optimizer/rule/UnionAllEdgeIndexScanRule.cpp +++ b/src/graph/optimizer/rule/UnionAllEdgeIndexScanRule.cpp @@ -13,7 +13,9 @@ namespace opt { std::unique_ptr UnionAllEdgeIndexScanRule::kInstance = std::unique_ptr(new UnionAllEdgeIndexScanRule()); -UnionAllEdgeIndexScanRule::UnionAllEdgeIndexScanRule() { RuleSet::DefaultRules().addRule(this); } +UnionAllEdgeIndexScanRule::UnionAllEdgeIndexScanRule() { + RuleSet::DefaultRules().addRule(this); +} const Pattern& UnionAllEdgeIndexScanRule::pattern() const { static Pattern pattern = @@ -21,7 +23,9 @@ const Pattern& UnionAllEdgeIndexScanRule::pattern() const { return pattern; } -std::string UnionAllEdgeIndexScanRule::toString() const { return "UnionAllEdgeIndexScanRule"; } +std::string UnionAllEdgeIndexScanRule::toString() const { + return "UnionAllEdgeIndexScanRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/UnionAllTagIndexScanRule.cpp b/src/graph/optimizer/rule/UnionAllTagIndexScanRule.cpp index 1c75c12f373..99894914d87 100644 --- a/src/graph/optimizer/rule/UnionAllTagIndexScanRule.cpp +++ b/src/graph/optimizer/rule/UnionAllTagIndexScanRule.cpp @@ -13,7 +13,9 @@ namespace opt { std::unique_ptr UnionAllTagIndexScanRule::kInstance = std::unique_ptr(new UnionAllTagIndexScanRule()); -UnionAllTagIndexScanRule::UnionAllTagIndexScanRule() { RuleSet::DefaultRules().addRule(this); } +UnionAllTagIndexScanRule::UnionAllTagIndexScanRule() { + RuleSet::DefaultRules().addRule(this); +} const Pattern& UnionAllTagIndexScanRule::pattern() const { static Pattern pattern = @@ -21,7 +23,9 @@ const Pattern& UnionAllTagIndexScanRule::pattern() const { return pattern; } -std::string UnionAllTagIndexScanRule::toString() const { return "UnionAllTagIndexScanRule"; } +std::string UnionAllTagIndexScanRule::toString() const { + return "UnionAllTagIndexScanRule"; +} } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/test/CMakeLists.txt b/src/graph/optimizer/test/CMakeLists.txt index 0f3c0fc72ad..ae0f1357bb3 100644 --- a/src/graph/optimizer/test/CMakeLists.txt +++ b/src/graph/optimizer/test/CMakeLists.txt @@ -48,6 +48,10 @@ set(OPTIMIZER_TEST_LIB $ $ $ + $ + $ + $ + $ ) nebula_add_test( diff --git a/src/graph/optimizer/test/IndexScanRuleTest.cpp b/src/graph/optimizer/test/IndexScanRuleTest.cpp index c781f82920d..7ebc24020ff 100644 --- a/src/graph/optimizer/test/IndexScanRuleTest.cpp +++ b/src/graph/optimizer/test/IndexScanRuleTest.cpp @@ -35,12 +35,12 @@ TEST(IndexScanRuleTest, IQCtxTest) { std::vector cols; for (int8_t i = 0; i < 5; i++) { meta::cpp2::ColumnDef col; - col.set_name(folly::stringPrintf("col%d", i)); - col.type.set_type(PropertyType::INT64); + col.name_ref() = folly::stringPrintf("col%d", i); + col.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(col)); } - index->set_fields(std::move(cols)); - index->set_index_id(1); + index->fields_ref() = std::move(cols); + index->index_id_ref() = 1; } // setup FilterItems col0 < 1 and col0 <= 6 { @@ -188,8 +188,8 @@ TEST(IndexScanRuleTest, BoundValueRangeTest) { { meta::cpp2::ColumnDef col; - col.set_name("col_int"); - col.type.set_type(PropertyType::INT64); + col.name_ref() = "col_int"; + col.type.type_ref() = PropertyType::INT64; { std::vector hints; // col_int < 2 @@ -287,8 +287,8 @@ TEST(IndexScanRuleTest, BoundValueRangeTest) { } { meta::cpp2::ColumnDef col; - col.set_name("col_bool"); - col.type.set_type(PropertyType::BOOL); + col.name_ref() = "col_bool"; + col.type.type_ref() = PropertyType::BOOL; { std::vector hints; // col_bool < true @@ -308,8 +308,8 @@ TEST(IndexScanRuleTest, BoundValueRangeTest) { } { meta::cpp2::ColumnDef col; - col.set_name("col_double"); - col.type.set_type(PropertyType::DOUBLE); + col.name_ref() = "col_double"; + col.type.type_ref() = PropertyType::DOUBLE; { std::vector hints; // col_double < 1.0 @@ -376,9 +376,9 @@ TEST(IndexScanRuleTest, BoundValueRangeTest) { { meta::cpp2::ColumnDef col; size_t len = 10; - col.set_name("col_str"); - col.type.set_type(PropertyType::STRING); - col.type.set_type_length(len); + col.name_ref() = "col_str"; + col.type.type_ref() = PropertyType::STRING; + col.type.type_length_ref() = len; { std::vector hints; // col_str < "ccc" diff --git a/src/graph/planner/match/LabelIndexSeek.cpp b/src/graph/planner/match/LabelIndexSeek.cpp index baf9e9266d1..93418180e3e 100644 --- a/src/graph/planner/match/LabelIndexSeek.cpp +++ b/src/graph/planner/match/LabelIndexSeek.cpp @@ -69,7 +69,7 @@ StatusOr LabelIndexSeek::transformNode(NodeContext* nodeCtx) { DCHECK_EQ(nodeCtx->scanInfo.indexIds.size(), 1) << "Not supported multiple tag index seek."; using IQC = nebula::storage::cpp2::IndexQueryContext; IQC iqctx; - iqctx.set_index_id(nodeCtx->scanInfo.indexIds.back()); + iqctx.index_id_ref() = nodeCtx->scanInfo.indexIds.back(); auto scan = IndexScan::make(matchClauseCtx->qctx, nullptr, matchClauseCtx->space.id, @@ -119,7 +119,7 @@ StatusOr LabelIndexSeek::transformNode(NodeContext* nodeCtx) { if (canBeEmbedded2IndexScan) { auto* srcFilter = ExpressionUtils::rewriteLabelAttr2TagProp(flattenFilter); storage::cpp2::IndexQueryContext ctx; - ctx.set_filter(Expression::encode(*srcFilter)); + ctx.filter_ref() = Expression::encode(*srcFilter); scan->setIndexQueryContext({ctx}); whereCtx.reset(); } @@ -137,7 +137,7 @@ StatusOr LabelIndexSeek::transformEdge(EdgeContext* edgeCtx) { DCHECK_EQ(edgeCtx->scanInfo.indexIds.size(), 1) << "Not supported multiple edge indices seek."; using IQC = nebula::storage::cpp2::IndexQueryContext; IQC iqctx; - iqctx.set_index_id(edgeCtx->scanInfo.indexIds.back()); + iqctx.index_id_ref() = edgeCtx->scanInfo.indexIds.back(); std::vector columns, columnsName; switch (edgeCtx->scanInfo.direction) { case MatchEdge::Direction::OUT_EDGE: diff --git a/src/graph/planner/match/MatchClausePlanner.cpp b/src/graph/planner/match/MatchClausePlanner.cpp index ec8fa3c2790..2e3fb5f2f33 100644 --- a/src/graph/planner/match/MatchClausePlanner.cpp +++ b/src/graph/planner/match/MatchClausePlanner.cpp @@ -41,9 +41,13 @@ static Expression* genNextTraverseStart(ObjectPool* pool, const EdgeInfo& edge) return FunctionCallExpression::make(pool, "none_direct_dst", args); } -static Expression* genVertexFilter(const NodeInfo& node) { return node.filter; } +static Expression* genVertexFilter(const NodeInfo& node) { + return node.filter; +} -static Expression* genEdgeFilter(const EdgeInfo& edge) { return edge.filter; } +static Expression* genEdgeFilter(const EdgeInfo& edge) { + return edge.filter; +} static StatusOr>> genVertexProps(const NodeInfo& node, QueryContext* qctx, @@ -76,23 +80,23 @@ static std::unique_ptr> genEdgeProps(const } case Direction::BOTH: { EdgeProp edgeProp; - edgeProp.set_type(-edgeType); + edgeProp.type_ref() = -edgeType; std::vector props{kSrc, kType, kRank, kDst}; for (std::size_t i = 0; i < edgeSchema->getNumFields(); ++i) { props.emplace_back(edgeSchema->getFieldName(i)); } - edgeProp.set_props(std::move(props)); + edgeProp.props_ref() = std::move(props); edgeProps->emplace_back(std::move(edgeProp)); break; } } EdgeProp edgeProp; - edgeProp.set_type(edgeType); + edgeProp.type_ref() = edgeType; std::vector props{kSrc, kType, kRank, kDst}; for (std::size_t i = 0; i < edgeSchema->getNumFields(); ++i) { props.emplace_back(edgeSchema->getFieldName(i)); } - edgeProp.set_props(std::move(props)); + edgeProp.props_ref() = std::move(props); edgeProps->emplace_back(std::move(edgeProp)); } return edgeProps; diff --git a/src/graph/planner/match/PropIndexSeek.cpp b/src/graph/planner/match/PropIndexSeek.cpp index ac418dca4d0..3c52530a7b9 100644 --- a/src/graph/planner/match/PropIndexSeek.cpp +++ b/src/graph/planner/match/PropIndexSeek.cpp @@ -56,7 +56,7 @@ StatusOr PropIndexSeek::transformEdge(EdgeContext* edgeCtx) { << "Not supported multiple edge properties seek."; using IQC = nebula::storage::cpp2::IndexQueryContext; IQC iqctx; - iqctx.set_filter(Expression::encode(*edgeCtx->scanInfo.filter)); + iqctx.filter_ref() = Expression::encode(*edgeCtx->scanInfo.filter); std::vector columns, columnsName; switch (edgeCtx->scanInfo.direction) { case MatchEdge::Direction::OUT_EDGE: @@ -165,7 +165,7 @@ StatusOr PropIndexSeek::transformNode(NodeContext* nodeCtx) { DCHECK_EQ(nodeCtx->scanInfo.schemaIds.size(), 1) << "Not supported multiple tag properties seek."; using IQC = nebula::storage::cpp2::IndexQueryContext; IQC iqctx; - iqctx.set_filter(Expression::encode(*nodeCtx->scanInfo.filter)); + iqctx.filter_ref() = Expression::encode(*nodeCtx->scanInfo.filter); auto scan = IndexScan::make(matchClauseCtx->qctx, nullptr, matchClauseCtx->space.id, diff --git a/src/graph/planner/match/ScanSeek.cpp b/src/graph/planner/match/ScanSeek.cpp index b4874039c27..40ee85dc015 100644 --- a/src/graph/planner/match/ScanSeek.cpp +++ b/src/graph/planner/match/ScanSeek.cpp @@ -63,8 +63,8 @@ StatusOr ScanSeek::transformNode(NodeContext *nodeCtx) { for (std::size_t i = 0; i < nodeCtx->scanInfo.schemaIds.size(); ++i) { storage::cpp2::VertexProp vProp; std::vector props{kTag}; - vProp.set_tag(nodeCtx->scanInfo.schemaIds[i]); - vProp.set_props(std::move(props)); + vProp.tag_ref() = nodeCtx->scanInfo.schemaIds[i]; + vProp.props_ref() = std::move(props); vProps->emplace_back(std::move(vProp)); colNames.emplace_back(nodeCtx->scanInfo.schemaNames[i] + "." + kTag); } diff --git a/src/graph/planner/match/ScanSeek.h b/src/graph/planner/match/ScanSeek.h index a323723e751..a87f0add441 100644 --- a/src/graph/planner/match/ScanSeek.h +++ b/src/graph/planner/match/ScanSeek.h @@ -16,7 +16,9 @@ namespace graph { */ class ScanSeek final : public StartVidFinder { public: - static std::unique_ptr make() { return std::unique_ptr(new ScanSeek()); } + static std::unique_ptr make() { + return std::unique_ptr(new ScanSeek()); + } bool matchNode(NodeContext* nodeCtx) override; diff --git a/src/graph/planner/ngql/FetchEdgesPlanner.cpp b/src/graph/planner/ngql/FetchEdgesPlanner.cpp index 8c1157f7159..f515a13296d 100644 --- a/src/graph/planner/ngql/FetchEdgesPlanner.cpp +++ b/src/graph/planner/ngql/FetchEdgesPlanner.cpp @@ -12,8 +12,8 @@ std::unique_ptr FetchEdgesPlanner::buildEdgeProps( const auto &edgePropsMap = fetchCtx_->exprProps.edgeProps(); for (const auto &edgeProp : edgePropsMap) { EdgeProp ep; - ep.set_type(edgeProp.first); - ep.set_props(std::vector(edgeProp.second.begin(), edgeProp.second.end())); + ep.type_ref() = edgeProp.first; + ep.props_ref() = std::vector(edgeProp.second.begin(), edgeProp.second.end()); eProps->emplace_back(std::move(ep)); } return eProps; diff --git a/src/graph/planner/ngql/FetchVerticesPlanner.cpp b/src/graph/planner/ngql/FetchVerticesPlanner.cpp index 76436a3737a..2e017817363 100644 --- a/src/graph/planner/ngql/FetchVerticesPlanner.cpp +++ b/src/graph/planner/ngql/FetchVerticesPlanner.cpp @@ -19,9 +19,9 @@ std::unique_ptr FetchVerticesPlanner::buildVe auto vertexProps = std::make_unique(propsMap.size()); auto fun = [](auto& tag) { VertexProp vp; - vp.set_tag(tag.first); + vp.tag_ref() = tag.first; std::vector props(tag.second.begin(), tag.second.end()); - vp.set_props(std::move(props)); + vp.props_ref() = std::move(props); return vp; }; std::transform(propsMap.begin(), propsMap.end(), vertexProps->begin(), fun); diff --git a/src/graph/planner/ngql/GoPlanner.cpp b/src/graph/planner/ngql/GoPlanner.cpp index 1d7bd036596..9142e40960c 100644 --- a/src/graph/planner/ngql/GoPlanner.cpp +++ b/src/graph/planner/ngql/GoPlanner.cpp @@ -37,24 +37,24 @@ void GoPlanner::doBuildEdgeProps(std::unique_ptr& eProps, bool onlyDs for (const auto& e : goCtx_->over.edgeTypes) { EdgeProp ep; if (isInEdge) { - ep.set_type(-e); + ep.type_ref() = -e; } else { - ep.set_type(e); + ep.type_ref() = e; } if (onlyDst) { - ep.set_props({kDst}); + ep.props_ref() = {kDst}; eProps->emplace_back(std::move(ep)); continue; } auto found = exprProps.edgeProps().find(e); if (found == exprProps.edgeProps().end()) { - ep.set_props({kDst}); + ep.props_ref() = {kDst}; } else { std::set props(found->second.begin(), found->second.end()); props.emplace(kDst); - ep.set_props(std::vector(props.begin(), props.end())); + ep.props_ref() = std::vector(props.begin(), props.end()); } eProps->emplace_back(std::move(ep)); } @@ -68,9 +68,9 @@ std::unique_ptr GoPlanner::buildVertexProps( auto vertexProps = std::make_unique(propsMap.size()); auto fun = [](auto& tag) { VertexProp vp; - vp.set_tag(tag.first); + vp.tag_ref() = tag.first; std::vector props(tag.second.begin(), tag.second.end()); - vp.set_props(std::move(props)); + vp.props_ref() = std::move(props); return vp; }; std::transform(propsMap.begin(), propsMap.end(), vertexProps->begin(), fun); diff --git a/src/graph/planner/ngql/GoPlanner.h b/src/graph/planner/ngql/GoPlanner.h index bfaf0869dc3..49fc2f259c9 100644 --- a/src/graph/planner/ngql/GoPlanner.h +++ b/src/graph/planner/ngql/GoPlanner.h @@ -21,9 +21,13 @@ class GoPlanner final : public Planner { using EdgeProps = std::vector; using VertexProps = std::vector; - static std::unique_ptr make() { return std::unique_ptr(new GoPlanner()); } + static std::unique_ptr make() { + return std::unique_ptr(new GoPlanner()); + } - static bool match(AstContext* astCtx) { return astCtx->sentence->kind() == Sentence::Kind::kGo; } + static bool match(AstContext* astCtx) { + return astCtx->sentence->kind() == Sentence::Kind::kGo; + } StatusOr transform(AstContext* astCtx) override; diff --git a/src/graph/planner/ngql/PathPlanner.cpp b/src/graph/planner/ngql/PathPlanner.cpp index 5b72128b711..297d749d936 100644 --- a/src/graph/planner/ngql/PathPlanner.cpp +++ b/src/graph/planner/ngql/PathPlanner.cpp @@ -40,19 +40,19 @@ void PathPlanner::doBuildEdgeProps(std::unique_ptr>& edgeP for (const auto& e : pathCtx_->over.edgeTypes) { storage::cpp2::EdgeProp ep; if (reverse == isInEdge) { - ep.set_type(e); + ep.type_ref() = e; } else { - ep.set_type(-e); + ep.type_ref() = -e; } const auto& found = exprProps.edgeProps().find(e); if (found == exprProps.edgeProps().end()) { - ep.set_props({kDst, kType, kRank}); + ep.props_ref() = {kDst, kType, kRank}; } else { std::set props(found->second.begin(), found->second.end()); props.emplace(kDst); props.emplace(kType); props.emplace(kRank); - ep.set_props(std::vector(props.begin(), props.end())); + ep.props_ref() = std::vector(props.begin(), props.end()); } edgeProps->emplace_back(std::move(ep)); } diff --git a/src/graph/planner/plan/Admin.h b/src/graph/planner/plan/Admin.h index c95ecfadf2f..f096650a420 100644 --- a/src/graph/planner/plan/Admin.h +++ b/src/graph/planner/plan/Admin.h @@ -29,7 +29,9 @@ class CreateNode : public SingleDependencyNode { std::unique_ptr explain() const override; public: - bool ifNotExist() const { return ifNotExist_; } + bool ifNotExist() const { + return ifNotExist_; + } private: bool ifNotExist_{false}; @@ -43,7 +45,9 @@ class DropNode : public SingleDependencyNode { std::unique_ptr explain() const override; public: - bool ifExist() const { return ifExist_; } + bool ifExist() const { + return ifExist_; + } private: bool ifExist_{false}; @@ -55,7 +59,9 @@ class AddHosts final : public SingleDependencyNode { return qctx->objPool()->add(new AddHosts(qctx, dep, hosts)); } - std::vector getHosts() const { return hosts_; } + std::vector getHosts() const { + return hosts_; + } std::unique_ptr explain() const override; @@ -72,7 +78,9 @@ class DropHosts final : public SingleDependencyNode { return qctx->objPool()->add(new DropHosts(qctx, dep, hosts)); } - std::vector getHosts() const { return hosts_; } + std::vector getHosts() const { + return hosts_; + } std::unique_ptr explain() const override; @@ -90,7 +98,9 @@ class ShowHosts final : public SingleDependencyNode { return qctx->objPool()->add(new ShowHosts(qctx, dep, type)); } - meta::cpp2::ListHostType getType() const { return type_; } + meta::cpp2::ListHostType getType() const { + return type_; + } private: ShowHosts(QueryContext* qctx, PlanNode* dep, meta::cpp2::ListHostType type) @@ -121,9 +131,13 @@ class CreateSpace final : public SingleDependencyNode { std::unique_ptr explain() const override; public: - const meta::cpp2::SpaceDesc& getSpaceDesc() const { return spaceDesc_; } + const meta::cpp2::SpaceDesc& getSpaceDesc() const { + return spaceDesc_; + } - bool getIfNotExists() const { return ifNotExists_; } + bool getIfNotExists() const { + return ifNotExists_; + } private: CreateSpace(QueryContext* qctx, @@ -152,9 +166,13 @@ class CreateSpaceAsNode final : public SingleDependencyNode { std::unique_ptr explain() const override; public: - std::string getOldSpaceName() const { return oldSpaceName_; } + std::string getOldSpaceName() const { + return oldSpaceName_; + } - std::string getNewSpaceName() const { return newSpaceName_; } + std::string getNewSpaceName() const { + return newSpaceName_; + } private: CreateSpaceAsNode(QueryContext* qctx, PlanNode* input, std::string oldName, std::string newName) @@ -178,9 +196,13 @@ class DropSpace final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string& getSpaceName() const { return spaceName_; } + const std::string& getSpaceName() const { + return spaceName_; + } - bool getIfExists() const { return ifExists_; } + bool getIfExists() const { + return ifExists_; + } private: DropSpace(QueryContext* qctx, PlanNode* input, std::string spaceName, bool ifExists) @@ -202,7 +224,9 @@ class DescSpace final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string& getSpaceName() const { return spaceName_; } + const std::string& getSpaceName() const { + return spaceName_; + } private: DescSpace(QueryContext* qctx, PlanNode* input, std::string spaceName) @@ -233,7 +257,9 @@ class ShowConfigs final : public SingleDependencyNode { std::unique_ptr explain() const override; - meta::cpp2::ConfigModule getModule() const { return module_; } + meta::cpp2::ConfigModule getModule() const { + return module_; + } private: ShowConfigs(QueryContext* qctx, PlanNode* input, meta::cpp2::ConfigModule module) @@ -256,11 +282,17 @@ class SetConfig final : public SingleDependencyNode { std::unique_ptr explain() const override; - meta::cpp2::ConfigModule getModule() const { return module_; } + meta::cpp2::ConfigModule getModule() const { + return module_; + } - const std::string& getName() const { return name_; } + const std::string& getName() const { + return name_; + } - const Value& getValue() const { return value_; } + const Value& getValue() const { + return value_; + } private: SetConfig(QueryContext* qctx, @@ -290,9 +322,13 @@ class GetConfig final : public SingleDependencyNode { std::unique_ptr explain() const override; - meta::cpp2::ConfigModule getModule() const { return module_; } + meta::cpp2::ConfigModule getModule() const { + return module_; + } - const std::string& getName() const { return name_; } + const std::string& getName() const { + return name_; + } private: explicit GetConfig(QueryContext* qctx, @@ -316,7 +352,9 @@ class ShowCreateSpace final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string& getSpaceName() const { return spaceName_; } + const std::string& getSpaceName() const { + return spaceName_; + } private: ShowCreateSpace(QueryContext* qctx, PlanNode* input, std::string spaceName) @@ -347,7 +385,9 @@ class DropSnapshot final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string& getSnapshotName() const { return snapshotName_; } + const std::string& getSnapshotName() const { + return snapshotName_; + } private: explicit DropSnapshot(QueryContext* qctx, PlanNode* input, std::string snapshotName) @@ -379,9 +419,13 @@ class AddListener final : public SingleDependencyNode { return qctx->objPool()->add(new AddListener(qctx, input, std::move(type), std::move(hosts))); } - const meta::cpp2::ListenerType& type() const { return type_; } + const meta::cpp2::ListenerType& type() const { + return type_; + } - const std::vector hosts() const { return hosts_; } + const std::vector hosts() const { + return hosts_; + } private: explicit AddListener(QueryContext* qctx, @@ -404,7 +448,9 @@ class RemoveListener final : public SingleDependencyNode { return qctx->objPool()->add(new RemoveListener(qctx, input, std::move(type))); } - const meta::cpp2::ListenerType& type() const { return type_; } + const meta::cpp2::ListenerType& type() const { + return type_; + } private: explicit RemoveListener(QueryContext* qctx, PlanNode* input, meta::cpp2::ListenerType type) @@ -437,11 +483,17 @@ class Download final : public SingleDependencyNode { return qctx->objPool()->add(new Download(qctx, input, hdfsHost, hdfsPort, hdfsPath)); } - const std::string& getHdfsHost() const { return hdfsHost_; } + const std::string& getHdfsHost() const { + return hdfsHost_; + } - int32_t getHdfsPort() const { return hdfsPort_; } + int32_t getHdfsPort() const { + return hdfsPort_; + } - const std::string& getHdfsPath() const { return hdfsPath_; } + const std::string& getHdfsPath() const { + return hdfsPath_; + } private: explicit Download(QueryContext* qctx, @@ -484,9 +536,13 @@ class CreateUser final : public CreateNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } - const std::string* password() const { return password_; } + const std::string* password() const { + return password_; + } private: CreateUser(QueryContext* qctx, @@ -514,7 +570,9 @@ class DropUser final : public DropNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } private: DropUser(QueryContext* qctx, PlanNode* dep, const std::string* username, bool ifNotExists) @@ -535,9 +593,13 @@ class UpdateUser final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } - const std::string* password() const { return password_; } + const std::string* password() const { + return password_; + } private: UpdateUser(QueryContext* qctx, @@ -565,11 +627,17 @@ class GrantRole final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } - const std::string* spaceName() const { return spaceName_; } + const std::string* spaceName() const { + return spaceName_; + } - meta::cpp2::RoleType role() const { return role_; } + meta::cpp2::RoleType role() const { + return role_; + } private: GrantRole(QueryContext* qctx, @@ -600,11 +668,17 @@ class RevokeRole final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } - const std::string* spaceName() const { return spaceName_; } + const std::string* spaceName() const { + return spaceName_; + } - meta::cpp2::RoleType role() const { return role_; } + meta::cpp2::RoleType role() const { + return role_; + } private: RevokeRole(QueryContext* qctx, @@ -635,11 +709,17 @@ class ChangePassword final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } - const std::string* password() const { return password_; } + const std::string* password() const { + return password_; + } - const std::string* newPassword() const { return newPassword_; } + const std::string* newPassword() const { + return newPassword_; + } private: ChangePassword(QueryContext* qctx, @@ -666,7 +746,9 @@ class ListUserRoles final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } private: ListUserRoles(QueryContext* qctx, PlanNode* dep, const std::string* username) @@ -695,7 +777,9 @@ class DescribeUser final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::string* username() const { return username_; } + const std::string* username() const { + return username_; + } private: explicit DescribeUser(QueryContext* qctx, PlanNode* dep, const std::string* username) @@ -712,7 +796,9 @@ class ListRoles final : public SingleDependencyNode { std::unique_ptr explain() const override; - GraphSpaceID space() const { return space_; } + GraphSpaceID space() const { + return space_; + } private: explicit ListRoles(QueryContext* qctx, PlanNode* dep, GraphSpaceID space) @@ -732,9 +818,13 @@ class ShowParts final : public SingleDependencyNode { std::unique_ptr explain() const override; - GraphSpaceID getSpaceId() const { return spaceId_; } + GraphSpaceID getSpaceId() const { + return spaceId_; + } - const std::vector& getPartIds() const { return partIds_; } + const std::vector& getPartIds() const { + return partIds_; + } private: explicit ShowParts(QueryContext* qctx, @@ -764,11 +854,17 @@ class SubmitJob final : public SingleDependencyNode { std::unique_ptr explain() const override; public: - meta::cpp2::AdminJobOp jobOp() const { return op_; } + meta::cpp2::AdminJobOp jobOp() const { + return op_; + } - meta::cpp2::AdminCmd cmd() const { return cmd_; } + meta::cpp2::AdminCmd cmd() const { + return cmd_; + } - const std::vector& params() const { return params_; } + const std::vector& params() const { + return params_; + } private: SubmitJob(QueryContext* qctx, @@ -817,11 +913,17 @@ class AddHostsIntoZone final : public SingleDependencyNode { new AddHostsIntoZone(qctx, input, std::move(zoneName), std::move(addresses), isNew)); } - const std::string& zoneName() const { return zoneName_; } + const std::string& zoneName() const { + return zoneName_; + } - const std::vector& address() const { return addresses_; } + const std::vector& address() const { + return addresses_; + } - bool isNew() const { return isNew_; } + bool isNew() const { + return isNew_; + } private: AddHostsIntoZone(QueryContext* qctx, @@ -851,9 +953,13 @@ class MergeZone final : public SingleDependencyNode { new MergeZone(qctx, input, std::move(zoneName), std::move(zoneNames))); } - const std::string& zoneName() const { return zoneName_; } + const std::string& zoneName() const { + return zoneName_; + } - const std::vector& zones() const { return zones_; } + const std::vector& zones() const { + return zones_; + } private: MergeZone(QueryContext* qctx, @@ -880,9 +986,13 @@ class RenameZone final : public SingleDependencyNode { new RenameZone(qctx, input, std::move(originalZoneName), std::move(zoneName))); } - const std::string& originalZoneName() const { return originalZoneName_; } + const std::string& originalZoneName() const { + return originalZoneName_; + } - const std::string& zoneName() const { return zoneName_; } + const std::string& zoneName() const { + return zoneName_; + } private: RenameZone(QueryContext* qctx, @@ -905,7 +1015,9 @@ class DropZone final : public SingleDependencyNode { return qctx->objPool()->add(new DropZone(qctx, input, std::move(zoneName))); } - const std::string& zoneName() const { return zoneName_; } + const std::string& zoneName() const { + return zoneName_; + } private: DropZone(QueryContext* qctx, PlanNode* input, std::string zoneName) @@ -927,9 +1039,13 @@ class SplitZone final : public SingleDependencyNode { new SplitZone(qctx, input, std::move(zoneName), std::move(zoneNames))); } - const std::string& zoneName() const { return zoneName_; } + const std::string& zoneName() const { + return zoneName_; + } - const std::vector& zones() const { return zones_; } + const std::vector& zones() const { + return zones_; + } private: SplitZone(QueryContext* qctx, @@ -952,7 +1068,9 @@ class DescribeZone final : public SingleDependencyNode { return qctx->objPool()->add(new DescribeZone(qctx, input, std::move(zoneName))); } - const std::string& zoneName() const { return zoneName_; } + const std::string& zoneName() const { + return zoneName_; + } private: DescribeZone(QueryContext* qctx, PlanNode* input, std::string zoneName) @@ -1016,9 +1134,13 @@ class SignInTSService final : public SingleDependencyNode { return qctx->objPool()->add(new SignInTSService(qctx, input, std::move(clients))); } - const std::vector& clients() const { return clients_; } + const std::vector& clients() const { + return clients_; + } - meta::cpp2::FTServiceType type() const { return meta::cpp2::FTServiceType::ELASTICSEARCH; } + meta::cpp2::FTServiceType type() const { + return meta::cpp2::FTServiceType::ELASTICSEARCH; + } private: SignInTSService(QueryContext* qctx, PlanNode* input, std::vector clients) @@ -1047,9 +1169,13 @@ class ShowSessions final : public SingleInputNode { return qctx->objPool()->add(new ShowSessions(qctx, input, isSetSessionID, sessionId)); } - bool isSetSessionID() const { return isSetSessionID_; } + bool isSetSessionID() const { + return isSetSessionID_; + } - SessionID getSessionId() const { return sessionId_; } + SessionID getSessionId() const { + return sessionId_; + } private: explicit ShowSessions(QueryContext* qctx, @@ -1072,7 +1198,9 @@ class UpdateSession final : public SingleInputNode { return qctx->objPool()->add(new UpdateSession(qctx, input, std::move(session))); } - const meta::cpp2::Session& getSession() const { return session_; } + const meta::cpp2::Session& getSession() const { + return session_; + } private: explicit UpdateSession(QueryContext* qctx, PlanNode* input, meta::cpp2::Session session) @@ -1088,7 +1216,9 @@ class ShowQueries final : public SingleInputNode { return qctx->objPool()->add(new ShowQueries(qctx, input, isAll)); } - bool isAll() const { return isAll_; } + bool isAll() const { + return isAll_; + } std::unique_ptr explain() const override; @@ -1108,9 +1238,13 @@ class KillQuery final : public SingleInputNode { return qctx->objPool()->add(new KillQuery(qctx, input, sessionId, epId)); } - Expression* sessionId() const { return sessionId_; } + Expression* sessionId() const { + return sessionId_; + } - Expression* epId() const { return epId_; } + Expression* epId() const { + return epId_; + } std::unique_ptr explain() const override; diff --git a/src/graph/planner/plan/Algo.h b/src/graph/planner/plan/Algo.h index d86396771f9..c6d86565462 100644 --- a/src/graph/planner/plan/Algo.h +++ b/src/graph/planner/plan/Algo.h @@ -47,17 +47,29 @@ class ConjunctPath : public BinaryInputNode { return qctx->objPool()->add(new ConjunctPath(qctx, left, right, pathKind, steps)); } - PathKind pathKind() const { return pathKind_; } + PathKind pathKind() const { + return pathKind_; + } - size_t steps() const { return steps_; } + size_t steps() const { + return steps_; + } - void setConditionalVar(std::string varName) { conditionalVar_ = std::move(varName); } + void setConditionalVar(std::string varName) { + conditionalVar_ = std::move(varName); + } - std::string conditionalVar() const { return conditionalVar_; } + std::string conditionalVar() const { + return conditionalVar_; + } - bool noLoop() const { return noLoop_; } + bool noLoop() const { + return noLoop_; + } - void setNoLoop(bool noLoop) { noLoop_ = noLoop; } + void setNoLoop(bool noLoop) { + noLoop_ = noLoop; + } std::unique_ptr explain() const override; private: @@ -79,9 +91,13 @@ class ProduceAllPaths final : public SingleInputNode { return qctx->objPool()->add(new ProduceAllPaths(qctx, input)); } - bool noLoop() const { return noLoop_; } + bool noLoop() const { + return noLoop_; + } - void setNoLoop(bool noLoop) { noLoop_ = noLoop; } + void setNoLoop(bool noLoop) { + noLoop_ = noLoop; + } std::unique_ptr explain() const override; private: @@ -102,7 +118,9 @@ class CartesianProduct final : public SingleDependencyNode { std::vector inputVars() const; - std::vector> allColNames() const { return allColNames_; } + std::vector> allColNames() const { + return allColNames_; + } std::unique_ptr explain() const override; private: @@ -123,11 +141,17 @@ class Subgraph final : public SingleInputNode { new Subgraph(qctx, input, oneMoreStepOutput, currentStepVar, steps)); } - const std::string& oneMoreStepOutput() const { return oneMoreStepOutput_; } + const std::string& oneMoreStepOutput() const { + return oneMoreStepOutput_; + } - const std::string& currentStepVar() const { return currentStepVar_; } + const std::string& currentStepVar() const { + return currentStepVar_; + } - uint32_t steps() const { return steps_; } + uint32_t steps() const { + return steps_; + } private: Subgraph(QueryContext* qctx, diff --git a/src/graph/planner/plan/ExecutionPlan.h b/src/graph/planner/plan/ExecutionPlan.h index 2692d6e67f6..86bfe10cbbd 100644 --- a/src/graph/planner/plan/ExecutionPlan.h +++ b/src/graph/planner/plan/ExecutionPlan.h @@ -28,21 +28,33 @@ class ExecutionPlan final { explicit ExecutionPlan(PlanNode* root = nullptr); ~ExecutionPlan(); - int64_t id() const { return id_; } + int64_t id() const { + return id_; + } - void setRoot(PlanNode* root) { root_ = root; } + void setRoot(PlanNode* root) { + root_ = root; + } - PlanNode* root() const { return root_; } + PlanNode* root() const { + return root_; + } - int32_t* optimizeTimeInUs() { return &optimizeTimeInUs_; } + int32_t* optimizeTimeInUs() { + return &optimizeTimeInUs_; + } void addProfileStats(int64_t planNodeId, ProfilingStats&& profilingStats); void describe(PlanDescription* planDesc); - void setExplainFormat(const std::string& format) { explainFormat_ = format; } + void setExplainFormat(const std::string& format) { + explainFormat_ = format; + } - bool isProfileEnabled() { return planDescription_ != nullptr; } + bool isProfileEnabled() { + return planDescription_ != nullptr; + } private: uint64_t makePlanNodeDesc(const PlanNode* node); diff --git a/src/graph/planner/plan/Logic.cpp b/src/graph/planner/plan/Logic.cpp index 3ace2a15bdb..dcea1352c3b 100644 --- a/src/graph/planner/plan/Logic.cpp +++ b/src/graph/planner/plan/Logic.cpp @@ -16,7 +16,9 @@ PlanNode* StartNode::clone() const { return newStart; } -void StartNode::cloneMembers(const StartNode& s) { PlanNode::cloneMembers(s); } +void StartNode::cloneMembers(const StartNode& s) { + PlanNode::cloneMembers(s); +} PlanNode* Select::clone() const { auto* newSelect = Select::make(qctx_, nullptr); @@ -24,7 +26,9 @@ PlanNode* Select::clone() const { return newSelect; } -void Select::cloneMembers(const Select& s) { BinarySelect::cloneMembers(s); } +void Select::cloneMembers(const Select& s) { + BinarySelect::cloneMembers(s); +} PlanNode* Loop::clone() const { auto* newLoop = Loop::make(qctx_, nullptr); @@ -32,7 +36,9 @@ PlanNode* Loop::clone() const { return newLoop; } -void Loop::cloneMembers(const Loop& s) { BinarySelect::cloneMembers(s); } +void Loop::cloneMembers(const Loop& s) { + BinarySelect::cloneMembers(s); +} PlanNode* PassThroughNode::clone() const { auto* newPt = PassThroughNode::make(qctx_, nullptr); @@ -40,7 +46,9 @@ PlanNode* PassThroughNode::clone() const { return newPt; } -void PassThroughNode::cloneMembers(const PassThroughNode& s) { SingleInputNode::cloneMembers(s); } +void PassThroughNode::cloneMembers(const PassThroughNode& s) { + SingleInputNode::cloneMembers(s); +} std::unique_ptr BinarySelect::explain() const { auto desc = SingleInputNode::explain(); diff --git a/src/graph/planner/plan/Logic.h b/src/graph/planner/plan/Logic.h index af68307ba03..e41a7f4f527 100644 --- a/src/graph/planner/plan/Logic.h +++ b/src/graph/planner/plan/Logic.h @@ -13,7 +13,9 @@ namespace graph { class StartNode final : public PlanNode { public: - static StartNode* make(QueryContext* qctx) { return qctx->objPool()->add(new StartNode(qctx)); } + static StartNode* make(QueryContext* qctx) { + return qctx->objPool()->add(new StartNode(qctx)); + } PlanNode* clone() const override; @@ -25,7 +27,9 @@ class StartNode final : public PlanNode { class BinarySelect : public SingleInputNode { public: - Expression* condition() const { return condition_; } + Expression* condition() const { + return condition_; + } std::unique_ptr explain() const override; @@ -53,13 +57,21 @@ class Select final : public BinarySelect { return qctx->objPool()->add(new Select(qctx, input, ifBranch, elseBranch, condition)); } - void setIf(PlanNode* ifBranch) { if_ = ifBranch; } + void setIf(PlanNode* ifBranch) { + if_ = ifBranch; + } - void setElse(PlanNode* elseBranch) { else_ = elseBranch; } + void setElse(PlanNode* elseBranch) { + else_ = elseBranch; + } - const PlanNode* then() const { return if_; } + const PlanNode* then() const { + return if_; + } - const PlanNode* otherwise() const { return else_; } + const PlanNode* otherwise() const { + return else_; + } std::unique_ptr explain() const override; @@ -89,9 +101,13 @@ class Loop final : public BinarySelect { return qctx->objPool()->add(new Loop(qctx, input, body, condition)); } - void setBody(PlanNode* body) { body_ = body; } + void setBody(PlanNode* body) { + body_ = body; + } - const PlanNode* body() const { return body_; } + const PlanNode* body() const { + return body_; + } std::unique_ptr explain() const override; diff --git a/src/graph/planner/plan/Maintain.h b/src/graph/planner/plan/Maintain.h index 988be1e51bd..ee3a7c9c127 100644 --- a/src/graph/planner/plan/Maintain.h +++ b/src/graph/planner/plan/Maintain.h @@ -27,11 +27,17 @@ class CreateSchemaNode : public SingleDependencyNode { ifNotExists_(ifNotExists) {} public: - const std::string& getName() const { return name_; } + const std::string& getName() const { + return name_; + } - const meta::cpp2::Schema& getSchema() const { return schema_; } + const meta::cpp2::Schema& getSchema() const { + return schema_; + } - bool getIfNotExists() const { return ifNotExists_; } + bool getIfNotExists() const { + return ifNotExists_; + } std::unique_ptr explain() const override; @@ -99,13 +105,21 @@ class AlterSchemaNode : public SingleDependencyNode { schemaProp_(std::move(schemaProp)) {} public: - const std::string& getName() const { return name_; } + const std::string& getName() const { + return name_; + } - const std::vector& getSchemaItems() const { return schemaItems_; } + const std::vector& getSchemaItems() const { + return schemaItems_; + } - const meta::cpp2::SchemaProp& getSchemaProp() const { return schemaProp_; } + const meta::cpp2::SchemaProp& getSchemaProp() const { + return schemaProp_; + } - GraphSpaceID space() const { return space_; } + GraphSpaceID space() const { + return space_; + } std::unique_ptr explain() const override; @@ -178,7 +192,9 @@ class DescSchemaNode : public SingleDependencyNode { : SingleDependencyNode(qctx, kind, input), name_(std::move(name)) {} public: - const std::string& getName() const { return name_; } + const std::string& getName() const { + return name_; + } std::unique_ptr explain() const override; @@ -258,9 +274,13 @@ class DropSchemaNode : public SingleDependencyNode { : SingleDependencyNode(qctx, kind, input), name_(std::move(name)), ifExists_(ifExists) {} public: - const std::string& getName() const { return name_; } + const std::string& getName() const { + return name_; + } - GraphSpaceID getIfExists() const { return ifExists_; } + GraphSpaceID getIfExists() const { + return ifExists_; + } std::unique_ptr explain() const override; @@ -311,17 +331,29 @@ class CreateIndexNode : public SingleDependencyNode { comment_(comment) {} public: - const std::string& getSchemaName() const { return schemaName_; } + const std::string& getSchemaName() const { + return schemaName_; + } - const std::string& getIndexName() const { return indexName_; } + const std::string& getIndexName() const { + return indexName_; + } - const std::vector& getFields() const { return fields_; } + const std::vector& getFields() const { + return fields_; + } - bool getIfNotExists() const { return ifNotExists_; } + bool getIfNotExists() const { + return ifNotExists_; + } - const meta::cpp2::IndexParams* getIndexParams() const { return indexParams_.get(); } + const meta::cpp2::IndexParams* getIndexParams() const { + return indexParams_.get(); + } - const std::string* getComment() const { return comment_; } + const std::string* getComment() const { + return comment_; + } std::unique_ptr explain() const override; @@ -420,7 +452,9 @@ class DescIndexNode : public SingleDependencyNode { : SingleDependencyNode(qctx, kind, input), indexName_(std::move(indexName)) {} public: - const std::string& getIndexName() const { return indexName_; } + const std::string& getIndexName() const { + return indexName_; + } std::unique_ptr explain() const override; @@ -459,9 +493,13 @@ class DropIndexNode : public SingleDependencyNode { ifExists_(ifExists) {} public: - const std::string& getIndexName() const { return indexName_; } + const std::string& getIndexName() const { + return indexName_; + } - GraphSpaceID getIfExists() const { return ifExists_; } + GraphSpaceID getIfExists() const { + return ifExists_; + } std::unique_ptr explain() const override; @@ -526,7 +564,9 @@ class ShowTagIndexes final : public SingleDependencyNode { return qctx->objPool()->add(new ShowTagIndexes(qctx, input, std::move(name))); } - const std::string& name() const { return name_; } + const std::string& name() const { + return name_; + } private: ShowTagIndexes(QueryContext* qctx, PlanNode* input, std::string name) @@ -544,7 +584,9 @@ class ShowEdgeIndexes final : public SingleDependencyNode { return qctx->objPool()->add(new ShowEdgeIndexes(qctx, input, std::move(name))); } - const std::string& name() const { return name_; } + const std::string& name() const { + return name_; + } private: ShowEdgeIndexes(QueryContext* qctx, PlanNode* input, std::string name) @@ -590,9 +632,13 @@ class CreateFTIndexNode : public SingleInputNode { index_(std::move(index)) {} public: - const std::string& getIndexName() const { return indexName_; } + const std::string& getIndexName() const { + return indexName_; + } - const meta::cpp2::FTIndex& getIndex() const { return index_; } + const meta::cpp2::FTIndex& getIndex() const { + return index_; + } std::unique_ptr explain() const override; @@ -625,7 +671,9 @@ class DropFTIndexNode : public SingleInputNode { : SingleInputNode(qctx, kind, input), name_(std::move(name)) {} public: - const std::string& getName() const { return name_; } + const std::string& getName() const { + return name_; + } std::unique_ptr explain() const override; diff --git a/src/graph/planner/plan/Mutate.h b/src/graph/planner/plan/Mutate.h index b845299f246..f6ffc49ea07 100644 --- a/src/graph/planner/plan/Mutate.h +++ b/src/graph/planner/plan/Mutate.h @@ -35,17 +35,25 @@ class InsertVertices final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::vector& getVertices() const { return vertices_; } + const std::vector& getVertices() const { + return vertices_; + } const std::unordered_map>& getPropNames() const { return tagPropNames_; } - GraphSpaceID getSpace() const { return spaceId_; } + GraphSpaceID getSpace() const { + return spaceId_; + } - bool getIfNotExists() const { return ifNotExists_; } + bool getIfNotExists() const { + return ifNotExists_; + } - bool getIgnoreExistedIndex() const { return ignoreExistedIndex_; } + bool getIgnoreExistedIndex() const { + return ignoreExistedIndex_; + } private: InsertVertices(QueryContext* qctx, @@ -92,17 +100,29 @@ class InsertEdges final : public SingleDependencyNode { std::unique_ptr explain() const override; - const std::vector& getPropNames() const { return propNames_; } + const std::vector& getPropNames() const { + return propNames_; + } - const std::vector& getEdges() const { return edges_; } + const std::vector& getEdges() const { + return edges_; + } - bool getIfNotExists() const { return ifNotExists_; } + bool getIfNotExists() const { + return ifNotExists_; + } - bool getIgnoreExistedIndex() const { return ignoreExistedIndex_; } + bool getIgnoreExistedIndex() const { + return ignoreExistedIndex_; + } - GraphSpaceID getSpace() const { return spaceId_; } + GraphSpaceID getSpace() const { + return spaceId_; + } - bool useChainInsert() const { return useChainInsert_; } + bool useChainInsert() const { + return useChainInsert_; + } private: InsertEdges(QueryContext* qctx, @@ -134,19 +154,33 @@ class InsertEdges final : public SingleDependencyNode { class Update : public SingleDependencyNode { public: - bool getInsertable() const { return insertable_; } + bool getInsertable() const { + return insertable_; + } - const std::vector& getReturnProps() const { return returnProps_; } + const std::vector& getReturnProps() const { + return returnProps_; + } - const std::string getCondition() const { return condition_; } + const std::string getCondition() const { + return condition_; + } - const std::vector& getYieldNames() const { return yieldNames_; } + const std::vector& getYieldNames() const { + return yieldNames_; + } - GraphSpaceID getSpaceId() const { return spaceId_; } + GraphSpaceID getSpaceId() const { + return spaceId_; + } - const std::vector& getUpdatedProps() const { return updatedProps_; } + const std::vector& getUpdatedProps() const { + return updatedProps_; + } - const std::string& getName() const { return schemaName_; } + const std::string& getName() const { + return schemaName_; + } std::unique_ptr explain() const override; @@ -208,9 +242,13 @@ class UpdateVertex final : public Update { std::unique_ptr explain() const override; - const Value& getVId() const { return vId_; } + const Value& getVId() const { + return vId_; + } - TagID getTagId() const { return tagId_; } + TagID getTagId() const { + return tagId_; + } private: UpdateVertex(QueryContext* qctx, @@ -274,15 +312,25 @@ class UpdateEdge final : public Update { std::unique_ptr explain() const override; - const Value& getSrcId() const { return srcId_; } + const Value& getSrcId() const { + return srcId_; + } - const Value& getDstId() const { return dstId_; } + const Value& getDstId() const { + return dstId_; + } - int64_t getRank() const { return rank_; } + int64_t getRank() const { + return rank_; + } - int64_t getEdgeType() const { return edgeType_; } + int64_t getEdgeType() const { + return edgeType_; + } - const std::vector& getUpdatedProps() const { return updatedProps_; } + const std::vector& getUpdatedProps() const { + return updatedProps_; + } private: UpdateEdge(QueryContext* qctx, @@ -331,9 +379,13 @@ class DeleteVertices final : public SingleInputNode { std::unique_ptr explain() const override; - GraphSpaceID getSpace() const { return space_; } + GraphSpaceID getSpace() const { + return space_; + } - Expression* getVidRef() const { return vidRef_; } + Expression* getVidRef() const { + return vidRef_; + } private: DeleteVertices(QueryContext* qctx, PlanNode* input, GraphSpaceID spaceId, Expression* vidRef) @@ -356,11 +408,17 @@ class DeleteTags final : public SingleInputNode { std::unique_ptr explain() const override; - GraphSpaceID getSpace() const { return space_; } + GraphSpaceID getSpace() const { + return space_; + } - Expression* getVidRef() const { return vidRef_; } + Expression* getVidRef() const { + return vidRef_; + } - const std::vector& tagIds() const { return tagIds_; } + const std::vector& tagIds() const { + return tagIds_; + } private: DeleteTags(QueryContext* qctx, @@ -390,9 +448,13 @@ class DeleteEdges final : public SingleInputNode { std::unique_ptr explain() const override; - GraphSpaceID getSpace() const { return space_; } + GraphSpaceID getSpace() const { + return space_; + } - EdgeKeyRef* edgeKeyRef() const { return edgeKeyRef_; } + EdgeKeyRef* edgeKeyRef() const { + return edgeKeyRef_; + } private: DeleteEdges(QueryContext* qctx, PlanNode* input, GraphSpaceID spaceId, EdgeKeyRef* edgeKeyRef) diff --git a/src/graph/planner/plan/PlanNode.cpp b/src/graph/planner/plan/PlanNode.cpp index 6ac02659611..93d51838ed6 100644 --- a/src/graph/planner/plan/PlanNode.cpp +++ b/src/graph/planner/plan/PlanNode.cpp @@ -316,7 +316,9 @@ void PlanNode::readVariable(Variable* varPtr) { qctx_->symTable()->readBy(varPtr->name, this); } -void PlanNode::calcCost() { VLOG(1) << "unimplemented cost calculation."; } +void PlanNode::calcCost() { + VLOG(1) << "unimplemented cost calculation."; +} void PlanNode::setOutputVar(const std::string& var) { DCHECK_EQ(1, outputVars_.size()); diff --git a/src/graph/planner/plan/PlanNode.h b/src/graph/planner/plan/PlanNode.h index 08ab4ae0466..1987c44c746 100644 --- a/src/graph/planner/plan/PlanNode.h +++ b/src/graph/planner/plan/PlanNode.h @@ -177,7 +177,9 @@ class PlanNode { kKillQuery, }; - bool isQueryNode() const { return kind_ < Kind::kStart; } + bool isQueryNode() const { + return kind_ < Kind::kStart; + } // Describe plan node virtual std::unique_ptr explain() const; @@ -186,32 +188,52 @@ class PlanNode { virtual void calcCost(); - Kind kind() const { return kind_; } + Kind kind() const { + return kind_; + } - int64_t id() const { return id_; } + int64_t id() const { + return id_; + } - QueryContext* qctx() const { return qctx_; } + QueryContext* qctx() const { + return qctx_; + } - bool isSingleInput() const { return numDeps() == 1U; } + bool isSingleInput() const { + return numDeps() == 1U; + } void setOutputVar(const std::string& var); - const std::string& outputVar(size_t index = 0) const { return outputVarPtr(index)->name; } + const std::string& outputVar(size_t index = 0) const { + return outputVarPtr(index)->name; + } Variable* outputVarPtr(size_t index = 0) const { DCHECK_LT(index, outputVars_.size()); return outputVars_[index]; } - const std::vector& outputVars() const { return outputVars_; } + const std::vector& outputVars() const { + return outputVars_; + } - const std::vector& colNames() const { return outputVarPtr(0)->colNames; } + const std::vector& colNames() const { + return outputVarPtr(0)->colNames; + } - void setId(int64_t id) { id_ = id; } + void setId(int64_t id) { + id_ = id; + } - void setColNames(std::vector cols) { outputVarPtr(0)->colNames = std::move(cols); } + void setColNames(std::vector cols) { + outputVarPtr(0)->colNames = std::move(cols); + } - const auto& dependencies() const { return dependencies_; } + const auto& dependencies() const { + return dependencies_; + } const PlanNode* dep(size_t index = 0) const { DCHECK_LT(index, dependencies_.size()); @@ -223,9 +245,13 @@ class PlanNode { dependencies_[index] = DCHECK_NOTNULL(dep); } - void addDep(const PlanNode* dep) { dependencies_.emplace_back(dep); } + void addDep(const PlanNode* dep) { + dependencies_.emplace_back(dep); + } - size_t numDeps() const { return dependencies_.size(); } + size_t numDeps() const { + return dependencies_.size(); + } std::string inputVar(size_t idx = 0UL) const { DCHECK_LT(idx, inputVars_.size()); @@ -234,14 +260,18 @@ class PlanNode { void setInputVar(const std::string& varname, size_t idx = 0UL); - const std::vector& inputVars() const { return inputVars_; } + const std::vector& inputVars() const { + return inputVars_; + } void releaseSymbols(); static const char* toString(Kind kind); std::string toString() const; - double cost() const { return cost_; } + double cost() const { + return cost_; + } protected: PlanNode(QueryContext* qctx, Kind kind); @@ -275,7 +305,9 @@ std::ostream& operator<<(std::ostream& os, PlanNode::Kind kind); // node class SingleDependencyNode : public PlanNode { public: - void dependsOn(const PlanNode* dep) { setDep(0, dep); } + void dependsOn(const PlanNode* dep) { + setDep(0, dep); + } PlanNode* clone() const override { LOG(FATAL) << "Shouldn't call the unimplemented method"; @@ -287,7 +319,9 @@ class SingleDependencyNode : public PlanNode { addDep(dep); } - void cloneMembers(const SingleDependencyNode& node) { PlanNode::cloneMembers(node); } + void cloneMembers(const SingleDependencyNode& node) { + PlanNode::cloneMembers(node); + } std::unique_ptr explain() const override; }; @@ -302,7 +336,9 @@ class SingleInputNode : public SingleDependencyNode { } protected: - void cloneMembers(const SingleInputNode& node) { SingleDependencyNode::cloneMembers(node); } + void cloneMembers(const SingleInputNode& node) { + SingleDependencyNode::cloneMembers(node); + } void copyInputColNames(const PlanNode* input) { if (input != nullptr) { @@ -315,21 +351,37 @@ class SingleInputNode : public SingleDependencyNode { class BinaryInputNode : public PlanNode { public: - void setLeftDep(const PlanNode* left) { setDep(0, left); } + void setLeftDep(const PlanNode* left) { + setDep(0, left); + } - void setRightDep(const PlanNode* right) { setDep(1, right); } + void setRightDep(const PlanNode* right) { + setDep(1, right); + } - void setLeftVar(const std::string& leftVar) { setInputVar(leftVar, 0); } + void setLeftVar(const std::string& leftVar) { + setInputVar(leftVar, 0); + } - void setRightVar(const std::string& rightVar) { setInputVar(rightVar, 1); } + void setRightVar(const std::string& rightVar) { + setInputVar(rightVar, 1); + } - const PlanNode* left() const { return dep(0); } + const PlanNode* left() const { + return dep(0); + } - const PlanNode* right() const { return dep(1); } + const PlanNode* right() const { + return dep(1); + } - const std::string& leftInputVar() const { return inputVars_[0]->name; } + const std::string& leftInputVar() const { + return inputVars_[0]->name; + } - const std::string& rightInputVar() const { return inputVars_[1]->name; } + const std::string& rightInputVar() const { + return inputVars_[1]->name; + } PlanNode* clone() const override { LOG(FATAL) << "Shouldn't call the unimplemented method"; @@ -341,7 +393,9 @@ class BinaryInputNode : public PlanNode { protected: BinaryInputNode(QueryContext* qctx, Kind kind, const PlanNode* left, const PlanNode* right); - void cloneMembers(const BinaryInputNode& node) { PlanNode::cloneMembers(node); } + void cloneMembers(const BinaryInputNode& node) { + PlanNode::cloneMembers(node); + } }; // some PlanNode may depend on multiple Nodes(may be one OR more) @@ -358,7 +412,9 @@ class VariableDependencyNode : public PlanNode { protected: VariableDependencyNode(QueryContext* qctx, Kind kind) : PlanNode(qctx, kind) {} - void cloneMembers(const VariableDependencyNode& node) { PlanNode::cloneMembers(node); } + void cloneMembers(const VariableDependencyNode& node) { + PlanNode::cloneMembers(node); + } std::vector dependIds() const { std::vector ids(numDeps()); diff --git a/src/graph/planner/plan/Query.cpp b/src/graph/planner/plan/Query.cpp index 1815d13d13e..dc3c517a344 100644 --- a/src/graph/planner/plan/Query.cpp +++ b/src/graph/planner/plan/Query.cpp @@ -281,7 +281,9 @@ void Filter::cloneMembers(const Filter& f) { needStableFilter_ = f.needStableFilter(); } -void SetOp::cloneMembers(const SetOp& s) { BinaryInputNode::cloneMembers(s); } +void SetOp::cloneMembers(const SetOp& s) { + BinaryInputNode::cloneMembers(s); +} PlanNode* Union::clone() const { auto* newUnion = Union::make(qctx_, nullptr, nullptr); @@ -289,7 +291,9 @@ PlanNode* Union::clone() const { return newUnion; } -void Union::cloneMembers(const Union& f) { SetOp::cloneMembers(f); } +void Union::cloneMembers(const Union& f) { + SetOp::cloneMembers(f); +} PlanNode* Intersect::clone() const { auto* newIntersect = Intersect::make(qctx_, nullptr, nullptr); @@ -297,7 +301,9 @@ PlanNode* Intersect::clone() const { return newIntersect; } -void Intersect::cloneMembers(const Intersect& f) { SetOp::cloneMembers(f); } +void Intersect::cloneMembers(const Intersect& f) { + SetOp::cloneMembers(f); +} PlanNode* Minus::clone() const { auto* newMinus = Minus::make(qctx_, nullptr, nullptr); @@ -305,7 +311,9 @@ PlanNode* Minus::clone() const { return newMinus; } -void Minus::cloneMembers(const Minus& f) { SetOp::cloneMembers(f); } +void Minus::cloneMembers(const Minus& f) { + SetOp::cloneMembers(f); +} Project::Project(QueryContext* qctx, PlanNode* input, YieldColumns* cols) : SingleInputNode(qctx, Kind::kProject, input), cols_(cols) { @@ -514,7 +522,9 @@ PlanNode* SwitchSpace::clone() const { return newSs; } -void SwitchSpace::cloneMembers(const SwitchSpace& l) { SingleInputNode::cloneMembers(l); } +void SwitchSpace::cloneMembers(const SwitchSpace& l) { + SingleInputNode::cloneMembers(l); +} Dedup::Dedup(QueryContext* qctx, PlanNode* input) : SingleInputNode(qctx, Kind::kDedup, input) { copyInputColNames(input); @@ -526,7 +536,9 @@ PlanNode* Dedup::clone() const { return newDedup; } -void Dedup::cloneMembers(const Dedup& l) { SingleInputNode::cloneMembers(l); } +void Dedup::cloneMembers(const Dedup& l) { + SingleInputNode::cloneMembers(l); +} std::unique_ptr DataCollect::explain() const { auto desc = VariableDependencyNode::explain(); @@ -635,7 +647,9 @@ PlanNode* LeftJoin::clone() const { return newLeftJoin; } -void LeftJoin::cloneMembers(const LeftJoin& l) { Join::cloneMembers(l); } +void LeftJoin::cloneMembers(const LeftJoin& l) { + Join::cloneMembers(l); +} std::unique_ptr InnerJoin::explain() const { auto desc = Join::explain(); @@ -649,7 +663,9 @@ PlanNode* InnerJoin::clone() const { return newInnerJoin; } -void InnerJoin::cloneMembers(const InnerJoin& l) { Join::cloneMembers(l); } +void InnerJoin::cloneMembers(const InnerJoin& l) { + Join::cloneMembers(l); +} std::unique_ptr Assign::explain() const { auto desc = SingleDependencyNode::explain(); diff --git a/src/graph/planner/plan/Query.h b/src/graph/planner/plan/Query.h index 941e0bee1c9..ae1c9228820 100644 --- a/src/graph/planner/plan/Query.h +++ b/src/graph/planner/plan/Query.h @@ -28,11 +28,17 @@ namespace graph { */ class Explore : public SingleInputNode { public: - GraphSpaceID space() const { return space_; } + GraphSpaceID space() const { + return space_; + } - void setSpace(GraphSpaceID spaceId) { space_ = spaceId; } + void setSpace(GraphSpaceID spaceId) { + space_ = spaceId; + } - bool dedup() const { return dedup_; } + bool dedup() const { + return dedup_; + } // Get the constant limit value int64_t limit(QueryContext* qctx = nullptr) const; @@ -42,23 +48,41 @@ class Explore : public SingleInputNode { return DCHECK_NOTNULL(limit_)->eval(ctx).getInt(); } - Expression* limitExpr() const { return limit_; } + Expression* limitExpr() const { + return limit_; + } - const Expression* filter() const { return filter_; } + const Expression* filter() const { + return filter_; + } - Expression* filter() { return filter_; } + Expression* filter() { + return filter_; + } - const std::vector& orderBy() const { return orderBy_; } + const std::vector& orderBy() const { + return orderBy_; + } - void setDedup(bool dedup = true) { dedup_ = dedup; } + void setDedup(bool dedup = true) { + dedup_ = dedup; + } - void setLimit(int64_t limit) { limit_ = ConstantExpression::make(qctx_->objPool(), limit); } + void setLimit(int64_t limit) { + limit_ = ConstantExpression::make(qctx_->objPool(), limit); + } - void setLimit(Expression* limit) { limit_ = limit; } + void setLimit(Expression* limit) { + limit_ = limit; + } - void setFilter(Expression* filter) { filter_ = filter; } + void setFilter(Expression* filter) { + filter_ = filter; + } - void setOrderBy(std::vector orderBy) { orderBy_ = std::move(orderBy); } + void setOrderBy(std::vector orderBy) { + orderBy_ = std::move(orderBy); + } std::unique_ptr explain() const override; @@ -153,27 +177,49 @@ class GetNeighbors : public Explore { return gn; } - Expression* src() const { return src_; } + Expression* src() const { + return src_; + } - storage::cpp2::EdgeDirection edgeDirection() const { return edgeDirection_; } + storage::cpp2::EdgeDirection edgeDirection() const { + return edgeDirection_; + } - const std::vector& edgeTypes() const { return edgeTypes_; } + const std::vector& edgeTypes() const { + return edgeTypes_; + } - const std::vector* vertexProps() const { return vertexProps_.get(); } + const std::vector* vertexProps() const { + return vertexProps_.get(); + } - const std::vector* edgeProps() const { return edgeProps_.get(); } + const std::vector* edgeProps() const { + return edgeProps_.get(); + } - const std::vector* statProps() const { return statProps_.get(); } + const std::vector* statProps() const { + return statProps_.get(); + } - const std::vector* exprs() const { return exprs_.get(); } + const std::vector* exprs() const { + return exprs_.get(); + } - bool random() const { return random_; } + bool random() const { + return random_; + } - void setSrc(Expression* src) { src_ = src; } + void setSrc(Expression* src) { + src_ = src; + } - void setEdgeDirection(Direction direction) { edgeDirection_ = direction; } + void setEdgeDirection(Direction direction) { + edgeDirection_ = direction; + } - void setEdgeTypes(std::vector edgeTypes) { edgeTypes_ = std::move(edgeTypes); } + void setEdgeTypes(std::vector edgeTypes) { + edgeTypes_ = std::move(edgeTypes); + } void setVertexProps(std::unique_ptr> vertexProps) { vertexProps_ = std::move(vertexProps); @@ -187,9 +233,13 @@ class GetNeighbors : public Explore { statProps_ = std::move(statProps); } - void setExprs(std::unique_ptr> exprs) { exprs_ = std::move(exprs); } + void setExprs(std::unique_ptr> exprs) { + exprs_ = std::move(exprs); + } - void setRandom(bool random = false) { random_ = random; } + void setRandom(bool random = false) { + random_ = random; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -241,17 +291,29 @@ class GetVertices : public Explore { filter)); } - Expression* src() const { return src_; } + Expression* src() const { + return src_; + } - void setSrc(Expression* src) { src_ = src; } + void setSrc(Expression* src) { + src_ = src; + } - const std::vector* props() const { return props_.get(); } + const std::vector* props() const { + return props_.get(); + } - const std::vector* exprs() const { return exprs_.get(); } + const std::vector* exprs() const { + return exprs_.get(); + } - void setVertexProps(std::unique_ptr> props) { props_ = std::move(props); } + void setVertexProps(std::unique_ptr> props) { + props_ = std::move(props); + } - void setExprs(std::unique_ptr> exprs) { exprs_ = std::move(exprs); } + void setExprs(std::unique_ptr> exprs) { + exprs_ = std::move(exprs); + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -317,21 +379,37 @@ class GetEdges final : public Explore { filter)); } - Expression* src() const { return src_; } + Expression* src() const { + return src_; + } - Expression* type() const { return type_; } + Expression* type() const { + return type_; + } - Expression* ranking() const { return ranking_; } + Expression* ranking() const { + return ranking_; + } - Expression* dst() const { return dst_; } + Expression* dst() const { + return dst_; + } - const std::vector* props() const { return props_.get(); } + const std::vector* props() const { + return props_.get(); + } - const std::vector* exprs() const { return exprs_.get(); } + const std::vector* exprs() const { + return exprs_.get(); + } - void setEdgeProps(std::unique_ptr> props) { props_ = std::move(props); } + void setEdgeProps(std::unique_ptr> props) { + props_ = std::move(props); + } - void setExprs(std::unique_ptr> exprs) { exprs_ = std::move(exprs); } + void setExprs(std::unique_ptr> exprs) { + exprs_ = std::move(exprs); + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -405,27 +483,45 @@ class IndexScan : public Explore { filter)); } - const std::vector& queryContext() const { return contexts_; } + const std::vector& queryContext() const { + return contexts_; + } - const std::vector& returnColumns() const { return returnCols_; } + const std::vector& returnColumns() const { + return returnCols_; + } - bool isEdge() const { return isEdge_; } + bool isEdge() const { + return isEdge_; + } - int32_t schemaId() const { return schemaId_; } + int32_t schemaId() const { + return schemaId_; + } - void setSchemaId(int32_t schema) { schemaId_ = schema; } + void setSchemaId(int32_t schema) { + schemaId_ = schema; + } - bool isEmptyResultSet() const { return isEmptyResultSet_; } + bool isEmptyResultSet() const { + return isEmptyResultSet_; + } - void setEmptyResultSet(bool isEmptyResultSet) { isEmptyResultSet_ = isEmptyResultSet; } + void setEmptyResultSet(bool isEmptyResultSet) { + isEmptyResultSet_ = isEmptyResultSet; + } void setIndexQueryContext(std::vector contexts) { contexts_ = std::move(contexts); } - void setReturnCols(std::vector cols) { returnCols_ = std::move(cols); } + void setReturnCols(std::vector cols) { + returnCols_ = std::move(cols); + } - void setIsEdge(bool isEdge) { isEdge_ = isEdge; } + void setIsEdge(bool isEdge) { + isEdge_ = isEdge; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -489,13 +585,21 @@ class ScanVertices final : public Explore { filter)); } - const std::vector* props() const { return props_.get(); } + const std::vector* props() const { + return props_.get(); + } - const std::vector* exprs() const { return exprs_.get(); } + const std::vector* exprs() const { + return exprs_.get(); + } - void setVertexProps(std::unique_ptr> props) { props_ = std::move(props); } + void setVertexProps(std::unique_ptr> props) { + props_ = std::move(props); + } - void setExprs(std::unique_ptr> exprs) { exprs_ = std::move(exprs); } + void setExprs(std::unique_ptr> exprs) { + exprs_ = std::move(exprs); + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -548,13 +652,21 @@ class ScanEdges final : public Explore { filter)); } - const std::vector* props() const { return props_.get(); } + const std::vector* props() const { + return props_.get(); + } - const std::vector* exprs() const { return exprs_.get(); } + const std::vector* exprs() const { + return exprs_.get(); + } - void setEdgeProps(std::unique_ptr> props) { props_ = std::move(props); } + void setEdgeProps(std::unique_ptr> props) { + props_ = std::move(props); + } - void setExprs(std::unique_ptr> exprs) { exprs_ = std::move(exprs); } + void setExprs(std::unique_ptr> exprs) { + exprs_ = std::move(exprs); + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -594,11 +706,17 @@ class Filter final : public SingleInputNode { return qctx->objPool()->add(new Filter(qctx, input, condition, needStableFilter)); } - Expression* condition() const { return condition_; } + Expression* condition() const { + return condition_; + } - void setCondition(Expression* condition) { condition_ = condition; } + void setCondition(Expression* condition) { + condition_ = condition; + } - bool needStableFilter() const { return needStableFilter_; } + bool needStableFilter() const { + return needStableFilter_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -692,7 +810,9 @@ class Project final : public SingleInputNode { return qctx->objPool()->add(new Project(qctx, input, cols)); } - const YieldColumns* columns() const { return cols_; } + const YieldColumns* columns() const { + return cols_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -715,9 +835,13 @@ class Unwind final : public SingleInputNode { return qctx->objPool()->add(new Unwind(qctx, input, unwindExpr, alias)); } - Expression* unwindExpr() const { return unwindExpr_; } + Expression* unwindExpr() const { + return unwindExpr_; + } - const std::string alias() const { return alias_; } + const std::string alias() const { + return alias_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -744,7 +868,9 @@ class Sort final : public SingleInputNode { return qctx->objPool()->add(new Sort(qctx, input, std::move(factors))); } - const std::vector>& factors() const { return factors_; } + const std::vector>& factors() const { + return factors_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -793,7 +919,9 @@ class Limit final : public SingleInputNode { return qctx->objPool()->add(new Limit(qctx, input, offset, count)); } - int64_t offset() const { return offset_; } + int64_t offset() const { + return offset_; + } // Get constant count value int64_t count(QueryContext* qctx = nullptr) const; @@ -808,7 +936,9 @@ class Limit final : public SingleInputNode { return s; } - const Expression* countExpr() const { return count_; } + const Expression* countExpr() const { + return count_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -846,11 +976,17 @@ class TopN final : public SingleInputNode { return qctx->objPool()->add(new TopN(qctx, input, std::move(factors), offset, count)); } - const std::vector>& factors() const { return factors_; } + const std::vector>& factors() const { + return factors_; + } - int64_t offset() const { return offset_; } + int64_t offset() const { + return offset_; + } - int64_t count() const { return count_; } + int64_t count() const { + return count_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -914,14 +1050,18 @@ class Sample final : public SingleInputNode { return count; } - Expression* countExpr() const { return count_; } + Expression* countExpr() const { + return count_; + } void setCount(int64_t count) { DCHECK_GE(count, 0); count_ = ConstantExpression::make(qctx_->objPool(), count); } - void setCount(Expression* count) { count_ = DCHECK_NOTNULL(count); } + void setCount(Expression* count) { + count_ = DCHECK_NOTNULL(count); + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -954,9 +1094,13 @@ class Aggregate final : public SingleInputNode { new Aggregate(qctx, input, std::move(groupKeys), std::move(groupItems))); } - const std::vector& groupKeys() const { return groupKeys_; } + const std::vector& groupKeys() const { + return groupKeys_; + } - const std::vector& groupItems() const { return groupItems_; } + const std::vector& groupItems() const { + return groupItems_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -984,7 +1128,9 @@ class SwitchSpace final : public SingleInputNode { return qctx->objPool()->add(new SwitchSpace(qctx, input, spaceName)); } - const std::string& getSpaceName() const { return spaceName_; } + const std::string& getSpaceName() const { + return spaceName_; + } PlanNode* clone() const override; std::unique_ptr explain() const override; @@ -1031,9 +1177,13 @@ class DataCollect final : public VariableDependencyNode { return qctx->objPool()->add(new DataCollect(qctx, kind)); } - void setMToN(StepClause step) { step_ = std::move(step); } + void setMToN(StepClause step) { + step_ = std::move(step); + } - void setDistinct(bool distinct) { distinct_ = distinct; } + void setDistinct(bool distinct) { + distinct_ = distinct; + } void setInputVars(const std::vector& vars) { inputVars_.clear(); @@ -1042,7 +1192,9 @@ class DataCollect final : public VariableDependencyNode { } } - DCKind kind() const { return kind_; } + DCKind kind() const { + return kind_; + } std::vector vars() const { std::vector vars(inputVars_.size()); @@ -1051,9 +1203,13 @@ class DataCollect final : public VariableDependencyNode { return vars; } - StepClause step() const { return step_; } + StepClause step() const { + return step_; + } - bool distinct() const { return distinct_; } + bool distinct() const { + return distinct_; + } PlanNode* clone() const override; @@ -1074,9 +1230,13 @@ class DataCollect final : public VariableDependencyNode { class Join : public SingleDependencyNode { public: - const std::pair& leftVar() const { return leftVar_; } + const std::pair& leftVar() const { + return leftVar_; + } - const std::pair& rightVar() const { return rightVar_; } + const std::pair& rightVar() const { + return rightVar_; + } void setLeftVar(std::pair lvar) { setInputVar(lvar.first, 0); @@ -1088,13 +1248,21 @@ class Join : public SingleDependencyNode { rightVar_ = rvar; } - const std::vector& hashKeys() const { return hashKeys_; } + const std::vector& hashKeys() const { + return hashKeys_; + } - const std::vector& probeKeys() const { return probeKeys_; } + const std::vector& probeKeys() const { + return probeKeys_; + } - void setHashKeys(std::vector newHashKeys) { hashKeys_ = newHashKeys; } + void setHashKeys(std::vector newHashKeys) { + hashKeys_ = newHashKeys; + } - void setProbeKeys(std::vector newProbeKeys) { probeKeys_ = newProbeKeys; } + void setProbeKeys(std::vector newProbeKeys) { + probeKeys_ = newProbeKeys; + } std::unique_ptr explain() const override; @@ -1206,7 +1374,9 @@ class Assign final : public SingleInputNode { return qctx->objPool()->add(new Assign(qctx, input)); } - const std::vector>& items() const { return items_; } + const std::vector>& items() const { + return items_; + } void assignVar(std::string var, Expression* value) { auto* varPtr = qctx_->symTable()->getVar(var); @@ -1292,17 +1462,29 @@ class Traverse final : public GetNeighbors { Traverse* clone() const override; - MatchStepRange* stepRange() const { return range_; } + MatchStepRange* stepRange() const { + return range_; + } - Expression* vFilter() const { return vFilter_; } + Expression* vFilter() const { + return vFilter_; + } - Expression* eFilter() const { return eFilter_; } + Expression* eFilter() const { + return eFilter_; + } - void setStepRange(MatchStepRange* range) { range_ = range; } + void setStepRange(MatchStepRange* range) { + range_ = range; + } - void setVertexFilter(Expression* vFilter) { vFilter_ = vFilter; } + void setVertexFilter(Expression* vFilter) { + vFilter_ = vFilter; + } - void setEdgeFilter(Expression* eFilter) { eFilter_ = eFilter; } + void setEdgeFilter(Expression* eFilter) { + eFilter_ = eFilter; + } private: Traverse(QueryContext* qctx, PlanNode* input, GraphSpaceID space) @@ -1328,9 +1510,13 @@ class AppendVertices final : public GetVertices { AppendVertices* clone() const override; - Expression* vFilter() const { return vFilter_; } + Expression* vFilter() const { + return vFilter_; + } - void setVertexFilter(Expression* vFilter) { vFilter_ = vFilter; } + void setVertexFilter(Expression* vFilter) { + vFilter_ = vFilter; + } private: AppendVertices(QueryContext* qctx, PlanNode* input, GraphSpaceID space) diff --git a/src/graph/planner/plan/Scan.h b/src/graph/planner/plan/Scan.h index d7356b6301f..375c78b800e 100644 --- a/src/graph/planner/plan/Scan.h +++ b/src/graph/planner/plan/Scan.h @@ -14,7 +14,9 @@ namespace graph { // Logical Plan class EdgeIndexScan : public IndexScan { public: - const std::string& edgeType() const { return edgeType_; } + const std::string& edgeType() const { + return edgeType_; + } protected: EdgeIndexScan(QueryContext* qctx, @@ -243,7 +245,9 @@ class EdgeIndexFullScan final : public EdgeIndexScan { class TagIndexScan : public IndexScan { public: - const std::string& tagName() const { return tagName_; } + const std::string& tagName() const { + return tagName_; + } protected: TagIndexScan(QueryContext* qctx, diff --git a/src/graph/planner/test/CMakeLists.txt b/src/graph/planner/test/CMakeLists.txt index bb45ebd9201..ac07fbb708f 100644 --- a/src/graph/planner/test/CMakeLists.txt +++ b/src/graph/planner/test/CMakeLists.txt @@ -18,6 +18,7 @@ nebula_add_test( $ $ $ + $ $ $ $ diff --git a/src/graph/service/CloudAuthenticator.cpp b/src/graph/service/CloudAuthenticator.cpp index 14386eb18a5..0729446fe07 100644 --- a/src/graph/service/CloudAuthenticator.cpp +++ b/src/graph/service/CloudAuthenticator.cpp @@ -12,7 +12,9 @@ namespace nebula { namespace graph { -CloudAuthenticator::CloudAuthenticator(meta::MetaClient* client) { metaClient_ = client; } +CloudAuthenticator::CloudAuthenticator(meta::MetaClient* client) { + metaClient_ = client; +} bool CloudAuthenticator::auth(const std::string& user, const std::string& password) { // The shadow account on the nebula side has been created diff --git a/src/graph/service/GraphService.cpp b/src/graph/service/GraphService.cpp index 6854aaa6411..37d5a852e1b 100644 --- a/src/graph/service/GraphService.cpp +++ b/src/graph/service/GraphService.cpp @@ -5,16 +5,19 @@ #include "graph/service/GraphService.h" +#include + #include "clients/storage/StorageClient.h" #include "common/base/Base.h" #include "common/encryption/MD5Utils.h" +#include "common/stats/StatsManager.h" #include "common/time/Duration.h" #include "common/time/TimezoneInfo.h" #include "graph/service/CloudAuthenticator.h" #include "graph/service/GraphFlags.h" #include "graph/service/PasswordAuthenticator.h" #include "graph/service/RequestContext.h" -#include "graph/stats/StatsDef.h" +#include "graph/stats/GraphStats.h" #include "version/Version.h" namespace nebula { @@ -33,6 +36,7 @@ Status GraphService::init(std::shared_ptr ioExecuto options.role_ = meta::cpp2::HostRole::GRAPH; options.localHost_ = hostAddr; options.gitInfoSHA_ = gitInfoSha(); + options.rootPath_ = boost::filesystem::current_path().string(); metaClient_ = std::make_unique(ioExecutor, std::move(addrs.value()), options); @@ -69,6 +73,8 @@ folly::Future GraphService::future_authenticate(const std::string& ctx->resp().errorCode = ErrorCode::E_BAD_USERNAME_PASSWORD; ctx->resp().errorMsg.reset(new std::string("Bad username/password")); ctx->finish(); + stats::StatsManager::addValue(kNumAuthFailedSessions); + stats::StatsManager::addValue(kNumAuthFailedSessionsBadUserNamePassword); return future; } @@ -76,6 +82,8 @@ folly::Future GraphService::future_authenticate(const std::string& ctx->resp().errorCode = ErrorCode::E_TOO_MANY_CONNECTIONS; ctx->resp().errorMsg.reset(new std::string("Too many connections in the cluster")); ctx->finish(); + stats::StatsManager::addValue(kNumAuthFailedSessions); + stats::StatsManager::addValue(kNumAuthFailedSessionsOutOfMaxAllowed); return future; } @@ -96,6 +104,8 @@ folly::Future GraphService::future_authenticate(const std::string& ctx->resp().errorMsg.reset(new std::string("Get session for sessionId is nullptr")); return ctx->finish(); } + stats::StatsManager::addValue(kNumOpenedSessions); + stats::StatsManager::addValue(kNumActiveSessions); ctx->setSession(sessionPtr); ctx->resp().sessionId.reset(new int64_t(ctx->session()->id())); ctx->resp().timeZoneOffsetSeconds.reset( @@ -112,6 +122,7 @@ folly::Future GraphService::future_authenticate(const std::string& void GraphService::signout(int64_t sessionId) { VLOG(2) << "Sign out session " << sessionId; sessionManager_->removeSession(sessionId); + stats::StatsManager::decValue(kNumActiveSessions); } folly::Future GraphService::future_executeWithParameter( @@ -124,6 +135,7 @@ folly::Future GraphService::future_executeWithParameter( ctx->setSessionMgr(sessionManager_.get()); auto future = ctx->future(); stats::StatsManager::addValue(kNumQueries); + stats::StatsManager::addValue(kNumActiveQueries); // When the sessionId is 0, it means the clients to ping the connection is ok if (sessionId == 0) { ctx->resp().errorCode = ErrorCode::E_SESSION_INVALID; @@ -164,6 +176,7 @@ folly::Future GraphService::future_execute(int64_t sessionId, ctx->setSessionMgr(sessionManager_.get()); auto future = ctx->future(); stats::StatsManager::addValue(kNumQueries); + stats::StatsManager::addValue(kNumActiveQueries); // When the sessionId is 0, it means the clients to ping the connection is ok if (sessionId == 0) { ctx->resp().errorCode = ErrorCode::E_SESSION_INVALID; @@ -188,8 +201,12 @@ folly::Future GraphService::future_execute(int64_t sessionId, new std::string(folly::stringPrintf("SessionId[%ld] does not exist", sessionId))); return ctx->finish(); } + stats::StatsManager::addValue(kNumQueries); + stats::StatsManager::addValue( + stats::StatsManager::counterWithLabels(kNumQueries, {{"space", sessionPtr->space().name}})); ctx->setSession(std::move(sessionPtr)); queryEngine_->execute(std::move(ctx)); + stats::StatsManager::decValue(kNumActiveQueries); }; sessionManager_->findSession(sessionId, getThreadManager()).thenValue(std::move(cb)); return future; @@ -241,13 +258,13 @@ folly::Future GraphService::future_verifyClientVe ":", FLAGS_client_white_list, std::inserter(whiteList, whiteList.begin())); cpp2::VerifyClientVersionResp resp; if (FLAGS_enable_client_white_list && whiteList.find(req.get_version()) == whiteList.end()) { - resp.set_error_code(nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE); - resp.set_error_msg(folly::stringPrintf( + resp.error_code_ref() = nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE; + resp.error_msg_ref() = folly::stringPrintf( "Graph client version(%s) is not accepted, current graph client white list: %s.", req.get_version().c_str(), - FLAGS_client_white_list.c_str())); + FLAGS_client_white_list.c_str()); } else { - resp.set_error_code(nebula::cpp2::ErrorCode::SUCCEEDED); + resp.error_code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; } return folly::makeFuture(std::move(resp)); } diff --git a/src/graph/service/PasswordAuthenticator.cpp b/src/graph/service/PasswordAuthenticator.cpp index 833200dec53..2d23587d7fc 100644 --- a/src/graph/service/PasswordAuthenticator.cpp +++ b/src/graph/service/PasswordAuthenticator.cpp @@ -8,7 +8,9 @@ namespace nebula { namespace graph { -PasswordAuthenticator::PasswordAuthenticator(meta::MetaClient* client) { metaClient_ = client; } +PasswordAuthenticator::PasswordAuthenticator(meta::MetaClient* client) { + metaClient_ = client; +} bool PasswordAuthenticator::auth(const std::string& user, const std::string& password) { return metaClient_->authCheckFromCache(user, password); diff --git a/src/graph/service/QueryEngine.h b/src/graph/service/QueryEngine.h index b85f5dc0e78..0e90e9b5950 100644 --- a/src/graph/service/QueryEngine.h +++ b/src/graph/service/QueryEngine.h @@ -38,7 +38,9 @@ class QueryEngine final : public cpp::NonCopyable, public cpp::NonMovable { using RequestContextPtr = std::unique_ptr>; void execute(RequestContextPtr rctx); - meta::MetaClient* metaClient() { return metaClient_; } + meta::MetaClient* metaClient() { + return metaClient_; + } private: Status setupMemoryMonitorThread(); diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index 8fad33c67e4..4b42a5c9a7f 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -6,6 +6,7 @@ #include "graph/service/QueryInstance.h" #include "common/base/Base.h" +#include "common/stats/StatsManager.h" #include "common/time/ScopedTimer.h" #include "graph/executor/ExecutionError.h" #include "graph/executor/Executor.h" @@ -14,10 +15,12 @@ #include "graph/planner/plan/PlanNode.h" #include "graph/scheduler/AsyncMsgNotifyBasedScheduler.h" #include "graph/scheduler/Scheduler.h" -#include "graph/stats/StatsDef.h" +#include "graph/stats/GraphStats.h" #include "graph/util/AstUtils.h" #include "graph/validator/Validator.h" #include "parser/ExplainSentence.h" +#include "parser/Sentence.h" +#include "parser/SequentialSentences.h" using nebula::opt::Optimizer; using nebula::opt::OptRule; @@ -65,9 +68,16 @@ Status QueryInstance::validateAndOptimize() { auto result = GQLParser(qctx()).parse(rctx->query()); NG_RETURN_IF_ERROR(result); sentence_ = std::move(result).value(); + if (sentence_->kind() == Sentence::Kind::kSequential) { + size_t num = static_cast(sentence_.get())->numSentences(); + stats::StatsManager::addValue(kNumSentences, num); + } else { + stats::StatsManager::addValue(kNumSentences); + } NG_RETURN_IF_ERROR(Validator::validate(sentence_.get(), qctx())); NG_RETURN_IF_ERROR(findBestPlan()); + stats::StatsManager::addValue(kOptimizerLatencyUs, *(qctx_->plan()->optimizeTimeInUs())); return Status::OK(); } @@ -92,7 +102,7 @@ void QueryInstance::onFinish() { auto latency = rctx->duration().elapsedInUSec(); rctx->resp().latencyInUs = latency; - addSlowQueryStats(latency); + addSlowQueryStats(latency, spaceName); rctx->finish(); rctx->session()->deleteQuery(qctx_.get()); @@ -123,6 +133,9 @@ void QueryInstance::onError(Status status) { case Status::Code::kPermissionError: rctx->resp().errorCode = ErrorCode::E_BAD_PERMISSION; break; + case Status::Code::kLeaderChanged: + stats::StatsManager::addValue(kNumQueryErrorsLeaderChanges); + [[fallthrough]]; case Status::Code::kBalanced: case Status::Code::kEdgeNotFound: case Status::Code::kError: @@ -131,7 +144,6 @@ void QueryInstance::onError(Status status) { case Status::Code::kInserted: case Status::Code::kKeyNotFound: case Status::Code::kPartialSuccess: - case Status::Code::kLeaderChanged: case Status::Code::kNoSuchFile: case Status::Code::kNotSupported: case Status::Code::kPartNotFound: @@ -151,17 +163,30 @@ void QueryInstance::onError(Status status) { auto latency = rctx->duration().elapsedInUSec(); rctx->resp().latencyInUs = latency; stats::StatsManager::addValue(kNumQueryErrors); - addSlowQueryStats(latency); + stats::StatsManager::addValue( + stats::StatsManager::counterWithLabels(kNumQueryErrors, {{"space", spaceName}})); + addSlowQueryStats(latency, spaceName); rctx->session()->deleteQuery(qctx_.get()); rctx->finish(); delete this; } -void QueryInstance::addSlowQueryStats(uint64_t latency) const { +void QueryInstance::addSlowQueryStats(uint64_t latency, const std::string &spaceName) const { stats::StatsManager::addValue(kQueryLatencyUs, latency); + if (FLAGS_enable_space_level_metrics) { + stats::StatsManager::addValue( + stats::StatsManager::histoWithLabels(kQueryLatencyUs, {{"space", spaceName}}), latency); + } if (latency > static_cast(FLAGS_slow_query_threshold_us)) { stats::StatsManager::addValue(kNumSlowQueries); stats::StatsManager::addValue(kSlowQueryLatencyUs, latency); + if (FLAGS_enable_space_level_metrics) { + stats::StatsManager::addValue( + stats::StatsManager::counterWithLabels(kNumSlowQueries, {{"space", spaceName}})); + stats::StatsManager::addValue( + stats::StatsManager::histoWithLabels(kSlowQueryLatencyUs, {{"space", spaceName}}), + latency); + } } } diff --git a/src/graph/service/QueryInstance.h b/src/graph/service/QueryInstance.h index c8c51bb46cf..a7b8ccc489c 100644 --- a/src/graph/service/QueryInstance.h +++ b/src/graph/service/QueryInstance.h @@ -29,7 +29,9 @@ class QueryInstance final : public cpp::NonCopyable, public cpp::NonMovable { void execute(); - QueryContext* qctx() const { return qctx_.get(); } + QueryContext* qctx() const { + return qctx_.get(); + } private: /** @@ -49,7 +51,7 @@ class QueryInstance final : public cpp::NonCopyable, public cpp::NonMovable { Status validateAndOptimize(); // return true if continue to execute bool explainOrContinue(); - void addSlowQueryStats(uint64_t latency) const; + void addSlowQueryStats(uint64_t latency, const std::string& spaceName) const; void fillRespData(ExecutionResponse* resp); Status findBestPlan(); diff --git a/src/graph/service/RequestContext.h b/src/graph/service/RequestContext.h index ae669e64a49..19fa52a1853 100644 --- a/src/graph/service/RequestContext.h +++ b/src/graph/service/RequestContext.h @@ -37,13 +37,21 @@ class RequestContext final : public cpp::NonCopyable, public cpp::NonMovable { } } - void setQuery(std::string query) { query_ = std::move(query); } + void setQuery(std::string query) { + query_ = std::move(query); + } - const std::string& query() const { return query_; } + const std::string& query() const { + return query_; + } - Response& resp() { return resp_; } + Response& resp() { + return resp_; + } - folly::Future future() { return promise_.getFuture(); } + folly::Future future() { + return promise_.getFuture(); + } void setSession(std::shared_ptr session) { session_ = std::move(session); @@ -53,25 +61,41 @@ class RequestContext final : public cpp::NonCopyable, public cpp::NonMovable { } } - ClientSession* session() const { return session_.get(); } + ClientSession* session() const { + return session_.get(); + } - folly::Executor* runner() const { return runner_; } + folly::Executor* runner() const { + return runner_; + } - void setRunner(folly::Executor* runner) { runner_ = runner; } + void setRunner(folly::Executor* runner) { + runner_ = runner; + } - const time::Duration& duration() const { return duration_; } + const time::Duration& duration() const { + return duration_; + } - void finish() { promise_.setValue(std::move(resp_)); } + void finish() { + promise_.setValue(std::move(resp_)); + } - void setSessionMgr(GraphSessionManager* mgr) { sessionMgr_ = mgr; } + void setSessionMgr(GraphSessionManager* mgr) { + sessionMgr_ = mgr; + } - GraphSessionManager* sessionMgr() const { return sessionMgr_; } + GraphSessionManager* sessionMgr() const { + return sessionMgr_; + } void setParameterMap(std::unordered_map parameterMap) { parameterMap_ = std::move(parameterMap); } - const std::unordered_map& parameterMap() const { return parameterMap_; } + const std::unordered_map& parameterMap() const { + return parameterMap_; + } private: time::Duration duration_; diff --git a/src/graph/session/ClientSession.cpp b/src/graph/session/ClientSession.cpp index c27e60166f3..d812ee586a8 100644 --- a/src/graph/session/ClientSession.cpp +++ b/src/graph/session/ClientSession.cpp @@ -5,8 +5,10 @@ #include "graph/session/ClientSession.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "graph/context/QueryContext.h" +#include "graph/stats/GraphStats.h" namespace nebula { namespace graph { @@ -24,7 +26,7 @@ std::shared_ptr ClientSession::create(meta::cpp2::Session&& sessi void ClientSession::charge() { folly::RWSpinLock::WriteHolder wHolder(rwSpinLock_); idleDuration_.reset(); - session_.set_update_time(time::WallClock::fastNowInMicroSec()); + session_.update_time_ref() = time::WallClock::fastNowInMicroSec(); } uint64_t ClientSession::idleSeconds() { @@ -35,10 +37,10 @@ uint64_t ClientSession::idleSeconds() { void ClientSession::addQuery(QueryContext* qctx) { auto epId = qctx->plan()->id(); meta::cpp2::QueryDesc queryDesc; - queryDesc.set_start_time(time::WallClock::fastNowInMicroSec()); - queryDesc.set_status(meta::cpp2::QueryStatus::RUNNING); - queryDesc.set_query(qctx->rctx()->query()); - queryDesc.set_graph_addr(session_.get_graph_addr()); + queryDesc.start_time_ref() = time::WallClock::fastNowInMicroSec(); + queryDesc.status_ref() = meta::cpp2::QueryStatus::RUNNING; + queryDesc.query_ref() = qctx->rctx()->query(); + queryDesc.graph_addr_ref() = session_.get_graph_addr(); VLOG(1) << "Add query: " << qctx->rctx()->query() << ", epId: " << epId; folly::RWSpinLock::WriteHolder wHolder(rwSpinLock_); @@ -75,13 +77,14 @@ void ClientSession::markQueryKilled(nebula::ExecutionPlanID epId) { return; } context->second->markKilled(); + stats::StatsManager::addValue(kNumKilledQueries); VLOG(1) << "Mark query killed in local cache, epId: " << epId; auto query = session_.queries_ref()->find(epId); if (query == session_.queries_ref()->end()) { return; } - query->second.set_status(meta::cpp2::QueryStatus::KILLING); + query->second.status_ref() = meta::cpp2::QueryStatus::KILLING; VLOG(1) << "Mark query killed in meta, epId: " << epId; } @@ -91,6 +94,7 @@ void ClientSession::markAllQueryKilled() { context.second->markKilled(); session_.queries_ref()->clear(); } + stats::StatsManager::addValue(kNumKilledQueries, contexts_.size()); } } // namespace graph } // namespace nebula diff --git a/src/graph/session/ClientSession.h b/src/graph/session/ClientSession.h index 78e26b91483..2568a07c01d 100644 --- a/src/graph/session/ClientSession.h +++ b/src/graph/session/ClientSession.h @@ -42,7 +42,7 @@ class ClientSession final { { folly::RWSpinLock::WriteHolder wHolder(rwSpinLock_); space_ = std::move(space); - session_.set_space_name(space_.name); + session_.space_name_ref() = space_.name; } } @@ -103,7 +103,7 @@ class ClientSession final { void setTimezone(int32_t timezone) { { folly::RWSpinLock::WriteHolder wHolder(rwSpinLock_); - session_.set_timezone(timezone); + session_.timezone_ref() = timezone; // TODO: if support ngql to set client's timezone, // need to update the timezone config to metad when timezone executor } @@ -115,7 +115,7 @@ class ClientSession final { if (session_.get_graph_addr() == hostAddr) { return; } - session_.set_graph_addr(hostAddr); + session_.graph_addr_ref() = hostAddr; } } @@ -126,7 +126,7 @@ class ClientSession final { void updateSpaceName(const std::string& spaceName) { folly::RWSpinLock::WriteHolder wHolder(rwSpinLock_); - session_.set_space_name(spaceName); + session_.space_name_ref() = spaceName; } void addQuery(QueryContext* qctx); diff --git a/src/graph/session/GraphSessionManager.cpp b/src/graph/session/GraphSessionManager.cpp index c11003d9eb1..282f04a3b6d 100644 --- a/src/graph/session/GraphSessionManager.cpp +++ b/src/graph/session/GraphSessionManager.cpp @@ -6,8 +6,10 @@ #include "graph/session/GraphSessionManager.h" #include "common/base/Base.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "graph/service/GraphFlags.h" +#include "graph/stats/GraphStats.h" namespace nebula { namespace graph { @@ -72,7 +74,7 @@ folly::Future>> GraphSessionManager::fin auto findPtr = activeSessions_.find(id); if (findPtr == activeSessions_.end()) { VLOG(1) << "Add session id: " << id << " from metad"; - session.set_graph_addr(myAddr_); + session.graph_addr_ref() = myAddr_; auto sessionPtr = ClientSession::create(std::move(session), metaClient_); sessionPtr->charge(); auto ret = activeSessions_.emplace(id, sessionPtr); @@ -181,6 +183,8 @@ void GraphSessionManager::reclaimExpiredSessions() { LOG(ERROR) << "Remove session `" << iter->first << "' failed: " << resp.status(); } iter = activeSessions_.erase(iter); + stats::StatsManager::decValue(kNumActiveSessions); + stats::StatsManager::addValue(kNumReclaimedExpiredSessions); // TODO: Disconnect the connection of the session } } @@ -196,8 +200,8 @@ void GraphSessionManager::updateSessionsToMeta() { VLOG(3) << "Add Update session id: " << ses.second->getSession().get_session_id(); auto sessionCopy = ses.second->getSession(); for (auto& query : *sessionCopy.queries_ref()) { - query.second.set_duration(time::WallClock::fastNowInMicroSec() - - query.second.get_start_time()); + query.second.duration_ref() = + time::WallClock::fastNowInMicroSec() - query.second.get_start_time(); } sessions.emplace_back(std::move(sessionCopy)); } diff --git a/src/graph/stats/CMakeLists.txt b/src/graph/stats/CMakeLists.txt index a1cd2878085..e837ad66cf8 100644 --- a/src/graph/stats/CMakeLists.txt +++ b/src/graph/stats/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under Apache 2.0 License. nebula_add_library( - stats_def_obj + graph_stats_obj OBJECT - StatsDef.cpp + GraphStats.cpp ) diff --git a/src/graph/stats/GraphStats.cpp b/src/graph/stats/GraphStats.cpp new file mode 100644 index 00000000000..adab4a84352 --- /dev/null +++ b/src/graph/stats/GraphStats.cpp @@ -0,0 +1,83 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "graph/stats/GraphStats.h" + +#include "clients/meta/stats/MetaClientStats.h" +#include "clients/storage/stats/StorageClientStats.h" +#include "common/base/Base.h" + +DEFINE_int32(slow_query_threshold_us, + 200000, + "Any query slower than this threshold value will be considered" + " as a slow query"); +DEFINE_bool(enable_space_level_metrics, false, "Whether to enable space level metrircs"); + +namespace nebula { + +stats::CounterId kNumQueries; +stats::CounterId kNumActiveQueries; +stats::CounterId kNumSlowQueries; +stats::CounterId kNumQueryErrors; +stats::CounterId kNumQueryErrorsLeaderChanges; +stats::CounterId kNumSentences; +stats::CounterId kQueryLatencyUs; +stats::CounterId kSlowQueryLatencyUs; +stats::CounterId kNumKilledQueries; + +stats::CounterId kOptimizerLatencyUs; + +stats::CounterId kNumAggregateExecutors; +stats::CounterId kNumSortExecutors; +stats::CounterId kNumIndexScanExecutors; +stats::CounterId kNumOomExecutors; + +stats::CounterId kNumOpenedSessions; +stats::CounterId kNumAuthFailedSessions; +stats::CounterId kNumAuthFailedSessionsBadUserNamePassword; +stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed; +stats::CounterId kNumActiveSessions; +stats::CounterId kNumReclaimedExpiredSessions; + +void initGraphStats() { + kNumQueries = stats::StatsManager::registerStats("num_queries", "rate, sum"); + kNumActiveQueries = stats::StatsManager::registerStats("num_active_queries", "sum"); + kNumSlowQueries = stats::StatsManager::registerStats("num_slow_queries", "rate, sum"); + kNumSentences = stats::StatsManager::registerStats("num_sentences", "rate, sum"); + kNumQueryErrors = stats::StatsManager::registerStats("num_query_errors", "rate, sum"); + kNumQueryErrorsLeaderChanges = + stats::StatsManager::registerStats("num_query_errors_leader_changes", "rate, sum"); + kQueryLatencyUs = stats::StatsManager::registerHisto( + "query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kSlowQueryLatencyUs = stats::StatsManager::registerHisto( + "slow_query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kNumKilledQueries = stats::StatsManager::registerStats("num_killed_queries", "rate, sum"); + + kOptimizerLatencyUs = stats::StatsManager::registerHisto( + "optimizer_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + + kNumAggregateExecutors = + stats::StatsManager::registerStats("num_aggregate_executors", "rate, sum"); + kNumSortExecutors = stats::StatsManager::registerStats("num_sort_executors", "rate, sum"); + kNumIndexScanExecutors = + stats::StatsManager::registerStats("num_indexscan_executors", "rate, sum"); + kNumOomExecutors = stats::StatsManager::registerStats("num_oom_executors", "rate, sum"); + + kNumOpenedSessions = stats::StatsManager::registerStats("num_opened_sessions", "rate, sum"); + kNumAuthFailedSessions = + stats::StatsManager::registerStats("num_auth_failed_sessions", "rate, sum"); + kNumAuthFailedSessionsBadUserNamePassword = stats::StatsManager::registerStats( + "num_auth_failed_sessions_bad_username_password", "rate, sum"); + kNumAuthFailedSessionsOutOfMaxAllowed = stats::StatsManager::registerStats( + "num_auth_failed_sessions_out_of_max_allowed", "rate, sum"); + kNumActiveSessions = stats::StatsManager::registerStats("num_active_sessions", "sum"); + kNumReclaimedExpiredSessions = + stats::StatsManager::registerStats("num_reclaimed_expired_sessions", "rate, sum"); + + initMetaClientStats(); + initStorageClientStats(); +} + +} // namespace nebula diff --git a/src/graph/stats/GraphStats.h b/src/graph/stats/GraphStats.h new file mode 100644 index 00000000000..70bb6a1efd1 --- /dev/null +++ b/src/graph/stats/GraphStats.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include "common/base/Base.h" +#include "common/stats/StatsManager.h" + +DECLARE_int32(slow_query_threshold_us); +DECLARE_bool(enable_space_level_metrics); + +namespace nebula { + +// Query +extern stats::CounterId kNumQueries; +extern stats::CounterId kNumActiveQueries; +extern stats::CounterId kNumSlowQueries; +extern stats::CounterId kNumQueryErrors; +extern stats::CounterId kNumQueryErrorsLeaderChanges; +extern stats::CounterId kNumSentences; +extern stats::CounterId kQueryLatencyUs; +extern stats::CounterId kSlowQueryLatencyUs; +extern stats::CounterId kNumKilledQueries; + +extern stats::CounterId kOptimizerLatencyUs; + +// Executor +extern stats::CounterId kNumAggregateExecutors; +extern stats::CounterId kNumSortExecutors; +extern stats::CounterId kNumIndexScanExecutors; +extern stats::CounterId kNumOomExecutors; + +// Server client traffic +// extern stats::CounterId kReceivedBytes; +// extern stats::CounterId kSentBytes; + +// Session +extern stats::CounterId kNumOpenedSessions; +extern stats::CounterId kNumAuthFailedSessions; +extern stats::CounterId kNumAuthFailedSessionsBadUserNamePassword; +extern stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed; +extern stats::CounterId kNumActiveSessions; +extern stats::CounterId kNumReclaimedExpiredSessions; + +void initGraphStats(); + +} // namespace nebula diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/StatsDef.cpp deleted file mode 100644 index 762f07c8585..00000000000 --- a/src/graph/stats/StatsDef.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (c) 2021 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License. - */ - -#include "graph/stats/StatsDef.h" - -#include "common/base/Base.h" -#include "common/stats/StatsManager.h" - -DEFINE_int32(slow_query_threshold_us, - 200000, - "Any query slower than this threshold value will be considered" - " as a slow query"); - -namespace nebula { - -stats::CounterId kNumQueries; -stats::CounterId kNumSlowQueries; -stats::CounterId kNumQueryErrors; -stats::CounterId kQueryLatencyUs; -stats::CounterId kSlowQueryLatencyUs; - -void initCounters() { - kNumQueries = stats::StatsManager::registerStats("num_queries", "rate, sum"); - kNumSlowQueries = stats::StatsManager::registerStats("num_slow_queries", "rate, sum"); - kNumQueryErrors = stats::StatsManager::registerStats("num_query_errors", "rate, sum"); - kQueryLatencyUs = stats::StatsManager::registerHisto( - "query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); - kSlowQueryLatencyUs = stats::StatsManager::registerHisto( - "slow_query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); -} - -} // namespace nebula diff --git a/src/graph/stats/StatsDef.h b/src/graph/stats/StatsDef.h deleted file mode 100644 index 0ac0a878e45..00000000000 --- a/src/graph/stats/StatsDef.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (c) 2021 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License. - */ - -#ifndef GRAPH_STATS_STATSDEF_H_ -#define GRAPH_STATS_STATSDEF_H_ - -#include "common/base/Base.h" -#include "common/stats/StatsManager.h" - -DECLARE_int32(slow_query_threshold_us); - -namespace nebula { - -extern stats::CounterId kNumQueries; -extern stats::CounterId kNumSlowQueries; -extern stats::CounterId kNumQueryErrors; -extern stats::CounterId kQueryLatencyUs; -extern stats::CounterId kSlowQueryLatencyUs; - -void initCounters(); - -} // namespace nebula -#endif // GRAPH_STATS_STATSDEF_H_ diff --git a/src/graph/util/AnonColGenerator.h b/src/graph/util/AnonColGenerator.h index 390745cf027..2cf942d9e89 100644 --- a/src/graph/util/AnonColGenerator.h +++ b/src/graph/util/AnonColGenerator.h @@ -24,9 +24,13 @@ constexpr char kCostStr[] = "_cost"; */ class AnonColGenerator final { public: - AnonColGenerator() { idGen_ = std::make_unique(); } + AnonColGenerator() { + idGen_ = std::make_unique(); + } - std::string getCol() const { return folly::stringPrintf("__COL_%ld", idGen_->id()); } + std::string getCol() const { + return folly::stringPrintf("__COL_%ld", idGen_->id()); + } private: std::unique_ptr idGen_; diff --git a/src/graph/util/IdGenerator.h b/src/graph/util/IdGenerator.h index 36bf62bbad0..c22c516d908 100644 --- a/src/graph/util/IdGenerator.h +++ b/src/graph/util/IdGenerator.h @@ -18,7 +18,9 @@ class IdGenerator { // The valid id starts from 0. static constexpr int64_t INVALID_ID = -1; - int64_t id() { return counter_++; } + int64_t id() { + return counter_++; + } private: std::atomic counter_{0}; @@ -29,7 +31,9 @@ class EPIdGenerator final : public IdGenerator { EPIdGenerator(EPIdGenerator&) = delete; EPIdGenerator& operator=(const EPIdGenerator) = delete; - static EPIdGenerator& instance() { return instance_; } + static EPIdGenerator& instance() { + return instance_; + } private: EPIdGenerator() = default; diff --git a/src/graph/util/IndexUtil.cpp b/src/graph/util/IndexUtil.cpp index 67f2e7c0a50..b08461cc6d3 100644 --- a/src/graph/util/IndexUtil.cpp +++ b/src/graph/util/IndexUtil.cpp @@ -31,13 +31,13 @@ Status IndexUtil::validateIndexParams(const std::vector ¶m case IndexParamItem::S2_MAX_LEVEL: { auto ret = param->getS2MaxLevel(); NG_RETURN_IF_ERROR(ret); - indexParams.set_s2_max_level(std::move(ret).value()); + indexParams.s2_max_level_ref() = std::move(ret).value(); break; } case IndexParamItem::S2_MAX_CELLS: { auto ret2 = param->getS2MaxCells(); NG_RETURN_IF_ERROR(ret2); - indexParams.set_s2_max_cells(std::move(ret2).value()); + indexParams.s2_max_cells_ref() = std::move(ret2).value(); break; } } diff --git a/src/graph/util/SchemaUtil.cpp b/src/graph/util/SchemaUtil.cpp index f0ef3b93bae..d5b5e5e3934 100644 --- a/src/graph/util/SchemaUtil.cpp +++ b/src/graph/util/SchemaUtil.cpp @@ -81,7 +81,7 @@ Status SchemaUtil::setTTLDuration(SchemaPropItem *schemaProp, meta::cpp2::Schema } auto ttlDuration = ret.value(); - schema.schema_prop_ref().value().set_ttl_duration(ttlDuration); + schema.schema_prop_ref().value().ttl_duration_ref() = ttlDuration; return Status::OK(); } @@ -94,7 +94,7 @@ Status SchemaUtil::setTTLCol(SchemaPropItem *schemaProp, meta::cpp2::Schema &sch auto ttlColName = ret.value(); if (ttlColName.empty()) { - schema.schema_prop_ref().value().set_ttl_col(""); + schema.schema_prop_ref().value().ttl_col_ref() = ""; return Status::OK(); } // Check the legality of the ttl column name @@ -106,7 +106,7 @@ Status SchemaUtil::setTTLCol(SchemaPropItem *schemaProp, meta::cpp2::Schema &sch col.type.type != nebula::cpp2::PropertyType::TIMESTAMP) { return Status::Error("Ttl column type illegal"); } - schema.schema_prop_ref().value().set_ttl_col(ttlColName); + schema.schema_prop_ref().value().ttl_col_ref() = ttlColName; return Status::OK(); } } @@ -117,7 +117,7 @@ Status SchemaUtil::setTTLCol(SchemaPropItem *schemaProp, meta::cpp2::Schema &sch Status SchemaUtil::setComment(SchemaPropItem *schemaProp, meta::cpp2::Schema &schema) { auto ret = schemaProp->getComment(); if (ret.ok()) { - schema.schema_prop_ref()->set_comment(std::move(ret).value()); + schema.schema_prop_ref()->comment_ref() = std::move(ret).value(); } return Status::OK(); } @@ -349,9 +349,9 @@ StatusOr>> SchemaUtil::ge } storage::cpp2::VertexProp vProp; const auto tagId = tag.first; - vProp.set_tag(tagId); + vProp.tag_ref() = tagId; propNames.emplace_back(nebula::kTag); // "_tag" - vProp.set_props(std::move(propNames)); + vProp.props_ref() = std::move(propNames); vertexProps->emplace_back(std::move(vProp)); } return vertexProps; @@ -373,8 +373,8 @@ StatusOr>> SchemaUtil::getE } } storage::cpp2::EdgeProp prop; - prop.set_type(edgeType); - prop.set_props(std::move(propNames)); + prop.type_ref() = edgeType; + prop.props_ref() = std::move(propNames); edgeProps->emplace_back(std::move(prop)); } return edgeProps; diff --git a/src/graph/util/ToJson.cpp b/src/graph/util/ToJson.cpp index 6f7084662e6..6a9bb6634d6 100644 --- a/src/graph/util/ToJson.cpp +++ b/src/graph/util/ToJson.cpp @@ -24,25 +24,45 @@ namespace nebula { namespace util { -std::string toJson(const std::string &str) { return str; } +std::string toJson(const std::string &str) { + return str; +} -std::string toJson(int32_t i) { return folly::to(i); } +std::string toJson(int32_t i) { + return folly::to(i); +} -std::string toJson(int64_t i) { return folly::to(i); } +std::string toJson(int64_t i) { + return folly::to(i); +} -std::string toJson(size_t i) { return folly::to(i); } +std::string toJson(size_t i) { + return folly::to(i); +} -std::string toJson(bool b) { return b ? "true" : "false"; } +std::string toJson(bool b) { + return b ? "true" : "false"; +} -std::string toJson(const HostAddr &addr) { return addr.toString(); } +std::string toJson(const HostAddr &addr) { + return addr.toString(); +} -std::string toJson(const List &list) { return list.toString(); } +std::string toJson(const List &list) { + return list.toString(); +} -std::string toJson(const Value &value) { return value.toString(); } +std::string toJson(const Value &value) { + return value.toString(); +} -std::string toJson(const EdgeKeyRef *ref) { return ref->toString(); } +std::string toJson(const EdgeKeyRef *ref) { + return ref->toString(); +} -std::string toJson(const Expression *expr) { return expr->toString(); } +std::string toJson(const Expression *expr) { + return expr->toString(); +} folly::dynamic toJson(const meta::cpp2::SpaceDesc &desc) { folly::dynamic obj = folly::dynamic::object(); diff --git a/src/graph/util/test/CMakeLists.txt b/src/graph/util/test/CMakeLists.txt index 4e0b0235e0e..05d1b74119b 100644 --- a/src/graph/util/test/CMakeLists.txt +++ b/src/graph/util/test/CMakeLists.txt @@ -45,6 +45,10 @@ nebula_add_test( $ $ $ + $ + $ + $ + $ LIBRARIES gtest gtest_main diff --git a/src/graph/util/test/ExpressionUtilsTest.cpp b/src/graph/util/test/ExpressionUtilsTest.cpp index 5b9c93366a3..70a96f3d58b 100644 --- a/src/graph/util/test/ExpressionUtilsTest.cpp +++ b/src/graph/util/test/ExpressionUtilsTest.cpp @@ -23,7 +23,9 @@ class ExpressionUtilsTest : public ::testing::Test { pool = qctx_->objPool(); } - void TearDown() override { qctx_.reset(); } + void TearDown() override { + qctx_.reset(); + } Expression *parse(const std::string &expr) { std::string query = "LOOKUP on t1 WHERE " + expr; diff --git a/src/graph/validator/ACLValidator.cpp b/src/graph/validator/ACLValidator.cpp index 3f570f2e67a..c0b3656e666 100644 --- a/src/graph/validator/ACLValidator.cpp +++ b/src/graph/validator/ACLValidator.cpp @@ -69,9 +69,13 @@ Status UpdateUserValidator::toPlan() { } // show users -Status ShowUsersValidator::validateImpl() { return Status::OK(); } +Status ShowUsersValidator::validateImpl() { + return Status::OK(); +} -Status ShowUsersValidator::toPlan() { return genSingleNodePlan(); } +Status ShowUsersValidator::toPlan() { + return genSingleNodePlan(); +} // change password Status ChangePasswordValidator::validateImpl() { @@ -169,7 +173,9 @@ Status ShowRolesInSpaceValidator::checkPermission() { return PermissionManager::canReadSpace(qctx_->rctx()->session(), targetSpaceId_); } -Status ShowRolesInSpaceValidator::toPlan() { return genSingleNodePlan(targetSpaceId_); } +Status ShowRolesInSpaceValidator::toPlan() { + return genSingleNodePlan(targetSpaceId_); +} } // namespace graph } // namespace nebula diff --git a/src/graph/validator/AdminValidator.cpp b/src/graph/validator/AdminValidator.cpp index fb32c5d21ad..abd41df68f6 100644 --- a/src/graph/validator/AdminValidator.cpp +++ b/src/graph/validator/AdminValidator.cpp @@ -19,9 +19,9 @@ Status CreateSpaceValidator::validateImpl() { auto sentence = static_cast(sentence_); ifNotExist_ = sentence->isIfNotExist(); auto status = Status::OK(); - spaceDesc_.set_space_name(std::move(*(sentence->spaceName()))); + spaceDesc_.space_name_ref() = std::move(*(sentence->spaceName())); if (sentence->zoneNames()) { - spaceDesc_.set_zone_names(sentence->zoneNames()->zoneNames()); + spaceDesc_.zone_names_ref() = sentence->zoneNames()->zoneNames(); } StatusOr retStatusOr; std::string result; @@ -33,14 +33,14 @@ Status CreateSpaceValidator::validateImpl() { for (auto &item : sentence->getOpts()) { switch (item->getOptType()) { case SpaceOptItem::PARTITION_NUM: { - spaceDesc_.set_partition_num(item->getPartitionNum()); + spaceDesc_.partition_num_ref() = item->getPartitionNum(); if (*spaceDesc_.partition_num_ref() <= 0) { return Status::SemanticError("Partition_num value should be greater than zero"); } break; } case SpaceOptItem::REPLICA_FACTOR: { - spaceDesc_.set_replica_factor(item->getReplicaFactor()); + spaceDesc_.replica_factor_ref() = item->getReplicaFactor(); if (*spaceDesc_.replica_factor_ref() <= 0) { return Status::SemanticError("Replica_factor value should be greater than zero"); } @@ -55,10 +55,10 @@ Status CreateSpaceValidator::validateImpl() { << apache::thrift::util::enumNameSafe(typeDef.type); return Status::SemanticError(ss.str()); } - spaceDesc_.vid_type_ref().value().set_type(typeDef.type); + spaceDesc_.vid_type_ref().value().type_ref() = typeDef.type; if (typeDef.type == nebula::cpp2::PropertyType::INT64) { - spaceDesc_.vid_type_ref().value().set_type_length(8); + spaceDesc_.vid_type_ref().value().type_length_ref() = 8; } else { if (!typeDef.type_length_ref().has_value()) { return Status::SemanticError("type length is not set for fixed string type"); @@ -67,7 +67,7 @@ Status CreateSpaceValidator::validateImpl() { return Status::SemanticError("Vid size should be a positive number: %d", *typeDef.type_length_ref()); } - spaceDesc_.vid_type_ref().value().set_type_length(*typeDef.type_length_ref()); + spaceDesc_.vid_type_ref().value().type_length_ref() = *typeDef.type_length_ref(); } break; } @@ -75,21 +75,21 @@ Status CreateSpaceValidator::validateImpl() { result = item->getCharset(); folly::toLowerAscii(result); NG_RETURN_IF_ERROR(charsetInfo->isSupportCharset(result)); - spaceDesc_.set_charset_name(std::move(result)); + spaceDesc_.charset_name_ref() = std::move(result); break; } case SpaceOptItem::COLLATE: { result = item->getCollate(); folly::toLowerAscii(result); NG_RETURN_IF_ERROR(charsetInfo->isSupportCollate(result)); - spaceDesc_.set_collate_name(std::move(result)); + spaceDesc_.collate_name_ref() = std::move(result); break; } case SpaceOptItem::ATOMIC_EDGE: { if (item->getAtomicEdge()) { - spaceDesc_.set_isolation_level(meta::cpp2::IsolationLevel::TOSS); + spaceDesc_.isolation_level_ref() = meta::cpp2::IsolationLevel::TOSS; } else { - spaceDesc_.set_isolation_level(meta::cpp2::IsolationLevel::DEFAULT); + spaceDesc_.isolation_level_ref() = meta::cpp2::IsolationLevel::DEFAULT; } break; } @@ -100,7 +100,7 @@ Status CreateSpaceValidator::validateImpl() { } // check comment if (sentence->comment() != nullptr) { - spaceDesc_.set_comment(*sentence->comment()); + spaceDesc_.comment_ref() = *sentence->comment(); } // if charset and collate are not specified, set default value @@ -112,13 +112,13 @@ Status CreateSpaceValidator::validateImpl() { if (!retStatusOr.ok()) { return retStatusOr.status(); } - spaceDesc_.set_collate_name(std::move(retStatusOr.value())); + spaceDesc_.collate_name_ref() = std::move(retStatusOr.value()); } else if (!(*spaceDesc_.collate_name_ref()).empty()) { retStatusOr = charsetInfo->getCharsetbyCollation(*spaceDesc_.collate_name_ref()); if (!retStatusOr.ok()) { return retStatusOr.status(); } - spaceDesc_.set_charset_name(std::move(retStatusOr.value())); + spaceDesc_.charset_name_ref() = std::move(retStatusOr.value()); } if ((*spaceDesc_.charset_name_ref()).empty() && (*spaceDesc_.collate_name_ref()).empty()) { @@ -130,8 +130,8 @@ Status CreateSpaceValidator::validateImpl() { folly::toLowerAscii(collateName); NG_RETURN_IF_ERROR(charsetInfo->isSupportCollate(collateName)); - spaceDesc_.set_charset_name(std::move(charsetName)); - spaceDesc_.set_collate_name(std::move(collateName)); + spaceDesc_.charset_name_ref() = std::move(charsetName); + spaceDesc_.collate_name_ref() = std::move(collateName); NG_RETURN_IF_ERROR(charsetInfo->charsetAndCollateMatch(*spaceDesc_.charset_name_ref(), *spaceDesc_.collate_name_ref())); @@ -163,7 +163,9 @@ Status CreateSpaceAsValidator::toPlan() { return Status::OK(); } -Status DescSpaceValidator::validateImpl() { return Status::OK(); } +Status DescSpaceValidator::validateImpl() { + return Status::OK(); +} Status DescSpaceValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -173,7 +175,9 @@ Status DescSpaceValidator::toPlan() { return Status::OK(); } -Status ShowSpacesValidator::validateImpl() { return Status::OK(); } +Status ShowSpacesValidator::validateImpl() { + return Status::OK(); +} Status ShowSpacesValidator::toPlan() { auto *doNode = ShowSpaces::make(qctx_, nullptr); @@ -182,7 +186,9 @@ Status ShowSpacesValidator::toPlan() { return Status::OK(); } -Status DropSpaceValidator::validateImpl() { return Status::OK(); } +Status DropSpaceValidator::validateImpl() { + return Status::OK(); +} Status DropSpaceValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -192,7 +198,9 @@ Status DropSpaceValidator::toPlan() { return Status::OK(); } -Status ShowCreateSpaceValidator::validateImpl() { return Status::OK(); } +Status ShowCreateSpaceValidator::validateImpl() { + return Status::OK(); +} Status ShowCreateSpaceValidator::checkPermission() { auto sentence = static_cast(sentence_); @@ -211,7 +219,9 @@ Status ShowCreateSpaceValidator::toPlan() { return Status::OK(); } -Status CreateSnapshotValidator::validateImpl() { return Status::OK(); } +Status CreateSnapshotValidator::validateImpl() { + return Status::OK(); +} Status CreateSnapshotValidator::toPlan() { auto *doNode = CreateSnapshot::make(qctx_, nullptr); @@ -220,7 +230,9 @@ Status CreateSnapshotValidator::toPlan() { return Status::OK(); } -Status DropSnapshotValidator::validateImpl() { return Status::OK(); } +Status DropSnapshotValidator::validateImpl() { + return Status::OK(); +} Status DropSnapshotValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -230,7 +242,9 @@ Status DropSnapshotValidator::toPlan() { return Status::OK(); } -Status ShowSnapshotsValidator::validateImpl() { return Status::OK(); } +Status ShowSnapshotsValidator::validateImpl() { + return Status::OK(); +} Status ShowSnapshotsValidator::toPlan() { auto *doNode = ShowSnapshots::make(qctx_, nullptr); @@ -272,7 +286,9 @@ Status AddListenerValidator::toPlan() { return Status::OK(); } -Status RemoveListenerValidator::validateImpl() { return Status::OK(); } +Status RemoveListenerValidator::validateImpl() { + return Status::OK(); +} Status RemoveListenerValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -282,7 +298,9 @@ Status RemoveListenerValidator::toPlan() { return Status::OK(); } -Status ShowListenerValidator::validateImpl() { return Status::OK(); } +Status ShowListenerValidator::validateImpl() { + return Status::OK(); +} Status ShowListenerValidator::toPlan() { auto *doNode = ShowListener::make(qctx_, nullptr); @@ -291,7 +309,9 @@ Status ShowListenerValidator::toPlan() { return Status::OK(); } -Status AddHostsValidator::validateImpl() { return Status::OK(); } +Status AddHostsValidator::validateImpl() { + return Status::OK(); +} Status AddHostsValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -311,7 +331,9 @@ Status AddHostsValidator::toPlan() { return Status::OK(); } -Status DropHostsValidator::validateImpl() { return Status::OK(); } +Status DropHostsValidator::validateImpl() { + return Status::OK(); +} Status DropHostsValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -331,7 +353,9 @@ Status DropHostsValidator::toPlan() { return Status::OK(); } -Status ShowHostsValidator::validateImpl() { return Status::OK(); } +Status ShowHostsValidator::validateImpl() { + return Status::OK(); +} Status ShowHostsValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -341,7 +365,9 @@ Status ShowHostsValidator::toPlan() { return Status::OK(); } -Status ShowMetaLeaderValidator::validateImpl() { return Status::OK(); } +Status ShowMetaLeaderValidator::validateImpl() { + return Status::OK(); +} Status ShowMetaLeaderValidator::toPlan() { auto *node = ShowMetaLeaderNode::make(qctx_, nullptr); @@ -350,7 +376,9 @@ Status ShowMetaLeaderValidator::toPlan() { return Status::OK(); } -Status ShowPartsValidator::validateImpl() { return Status::OK(); } +Status ShowPartsValidator::validateImpl() { + return Status::OK(); +} Status ShowPartsValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -364,7 +392,9 @@ Status ShowPartsValidator::toPlan() { return Status::OK(); } -Status ShowCharsetValidator::validateImpl() { return Status::OK(); } +Status ShowCharsetValidator::validateImpl() { + return Status::OK(); +} Status ShowCharsetValidator::toPlan() { auto *node = ShowCharset::make(qctx_, nullptr); @@ -373,7 +403,9 @@ Status ShowCharsetValidator::toPlan() { return Status::OK(); } -Status ShowCollationValidator::validateImpl() { return Status::OK(); } +Status ShowCollationValidator::validateImpl() { + return Status::OK(); +} Status ShowCollationValidator::toPlan() { auto *node = ShowCollation::make(qctx_, nullptr); @@ -382,7 +414,9 @@ Status ShowCollationValidator::toPlan() { return Status::OK(); } -Status ShowConfigsValidator::validateImpl() { return Status::OK(); } +Status ShowConfigsValidator::validateImpl() { + return Status::OK(); +} Status ShowConfigsValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -473,7 +507,9 @@ Status GetConfigValidator::toPlan() { return Status::OK(); } -Status ShowStatusValidator::validateImpl() { return Status::OK(); } +Status ShowStatusValidator::validateImpl() { + return Status::OK(); +} Status ShowStatusValidator::toPlan() { auto *node = ShowStats::make(qctx_, nullptr); @@ -482,7 +518,9 @@ Status ShowStatusValidator::toPlan() { return Status::OK(); } -Status ShowTSClientsValidator::validateImpl() { return Status::OK(); } +Status ShowTSClientsValidator::validateImpl() { + return Status::OK(); +} Status ShowTSClientsValidator::toPlan() { auto *doNode = ShowTSClients::make(qctx_, nullptr); @@ -491,7 +529,9 @@ Status ShowTSClientsValidator::toPlan() { return Status::OK(); } -Status SignInTSServiceValidator::validateImpl() { return Status::OK(); } +Status SignInTSServiceValidator::validateImpl() { + return Status::OK(); +} Status SignInTSServiceValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -505,7 +545,9 @@ Status SignInTSServiceValidator::toPlan() { return Status::OK(); } -Status SignOutTSServiceValidator::validateImpl() { return Status::OK(); } +Status SignOutTSServiceValidator::validateImpl() { + return Status::OK(); +} Status SignOutTSServiceValidator::toPlan() { auto *node = SignOutTSService::make(qctx_, nullptr); diff --git a/src/graph/validator/AdminValidator.h b/src/graph/validator/AdminValidator.h index 0ae1864b9f3..a7b33aef779 100644 --- a/src/graph/validator/AdminValidator.h +++ b/src/graph/validator/AdminValidator.h @@ -349,7 +349,9 @@ class ShowSessionsValidator final : public Validator { } private: - Status validateImpl() override { return Status::OK(); } + Status validateImpl() override { + return Status::OK(); + } Status toPlan() override; }; @@ -361,7 +363,9 @@ class GetSessionValidator final : public Validator { } private: - Status validateImpl() override { return Status::OK(); } + Status validateImpl() override { + return Status::OK(); + } Status toPlan() override; diff --git a/src/graph/validator/DownloadValidator.h b/src/graph/validator/DownloadValidator.h index 6c7893406c5..27ff4bab89a 100644 --- a/src/graph/validator/DownloadValidator.h +++ b/src/graph/validator/DownloadValidator.h @@ -17,7 +17,9 @@ class DownloadValidator final : public Validator { DownloadValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {} private: - Status validateImpl() override { return Status::OK(); } + Status validateImpl() override { + return Status::OK(); + } Status toPlan() override; }; diff --git a/src/graph/validator/FetchEdgesValidator.cpp b/src/graph/validator/FetchEdgesValidator.cpp index df527c3af7a..26b6e50cb55 100644 --- a/src/graph/validator/FetchEdgesValidator.cpp +++ b/src/graph/validator/FetchEdgesValidator.cpp @@ -136,18 +136,6 @@ Status FetchEdgesValidator::validateEdgeKey() { return Status::OK(); } -void FetchEdgesValidator::extractEdgeProp(ExpressionProps &exprProps) { - exprProps.insertEdgeProp(edgeType_, kSrc); - exprProps.insertEdgeProp(edgeType_, kDst); - exprProps.insertEdgeProp(edgeType_, kRank); - exprProps.insertEdgeProp(edgeType_, kType); - - for (std::size_t i = 0; i < edgeSchema_->getNumFields(); ++i) { - const auto propName = edgeSchema_->getFieldName(i); - exprProps.insertEdgeProp(edgeType_, propName); - } -} - Status FetchEdgesValidator::validateYield(const YieldClause *yield) { if (yield == nullptr) { return Status::SemanticError("Missing yield clause."); @@ -158,12 +146,6 @@ Status FetchEdgesValidator::validateYield(const YieldClause *yield) { exprProps.insertEdgeProp(edgeType_, nebula::kDst); exprProps.insertEdgeProp(edgeType_, nebula::kRank); - for (const auto &col : yield->columns()) { - if (ExpressionUtils::hasAny(col->expr(), {Expression::Kind::kEdge})) { - extractEdgeProp(exprProps); - break; - } - } auto size = yield->columns().size(); outputs_.reserve(size); @@ -182,8 +164,8 @@ Status FetchEdgesValidator::validateYield(const YieldClause *yield) { NG_RETURN_IF_ERROR(typeStatus); outputs_.emplace_back(col->name(), typeStatus.value()); newCols->addColumn(col->clone().release()); - - NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps)); + std::vector edgeTypes{edgeType_}; + NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps, nullptr, &edgeTypes)); } if (exprProps.hasInputVarProperty()) { diff --git a/src/graph/validator/FetchEdgesValidator.h b/src/graph/validator/FetchEdgesValidator.h index d78e3c012e6..0d1ce562640 100644 --- a/src/graph/validator/FetchEdgesValidator.h +++ b/src/graph/validator/FetchEdgesValidator.h @@ -26,11 +26,11 @@ class FetchEdgesValidator final : public Validator { Status validateEdgeKey(); - void extractEdgeProp(ExpressionProps& exprProps); - Status validateYield(const YieldClause* yieldClause); - AstContext* getAstContext() override { return fetchCtx_.get(); } + AstContext* getAstContext() override { + return fetchCtx_.get(); + } private: std::string edgeName_; diff --git a/src/graph/validator/FetchVerticesValidator.cpp b/src/graph/validator/FetchVerticesValidator.cpp index dd902d79002..40bbd3a2b60 100644 --- a/src/graph/validator/FetchVerticesValidator.cpp +++ b/src/graph/validator/FetchVerticesValidator.cpp @@ -30,6 +30,7 @@ Status FetchVerticesValidator::validateTag(const NameLabelList *nameLabels) { NG_RETURN_IF_ERROR(tagStatus); for (const auto &tag : tagStatus.value()) { tagsSchema_.emplace(tag.first, tag.second); + tagIds_.emplace_back(tag.first); } } else { auto labels = nameLabels->labels(); @@ -43,6 +44,7 @@ Status FetchVerticesValidator::validateTag(const NameLabelList *nameLabels) { return Status::SemanticError("no schema found for `%s'", label->c_str()); } tagsSchema_.emplace(tagID, tagSchema); + tagIds_.emplace_back(tagID); } } return Status::OK(); @@ -76,12 +78,8 @@ Status FetchVerticesValidator::validateYield(YieldClause *yield) { col->setAlias(col->name()); col->setExpr(InputPropertyExpression::make(pool, nebula::kVid)); } - if (ExpressionUtils::hasAny(colExpr, {Expression::Kind::kVertex})) { - extractVertexProp(exprProps); - } newCols->addColumn(col->clone().release()); - - NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps)); + NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps, &tagIds_)); } if (exprProps.tagProps().empty()) { for (const auto &tagSchema : tagsSchema_) { @@ -105,16 +103,5 @@ Status FetchVerticesValidator::validateYield(YieldClause *yield) { return Status::OK(); } -void FetchVerticesValidator::extractVertexProp(ExpressionProps &exprProps) { - for (const auto &tagSchema : tagsSchema_) { - auto tagID = tagSchema.first; - exprProps.insertTagProp(tagID, nebula::kTag); - for (std::size_t i = 0; i < tagSchema.second->getNumFields(); ++i) { - const auto propName = tagSchema.second->getFieldName(i); - exprProps.insertTagProp(tagID, propName); - } - } -} - } // namespace graph } // namespace nebula diff --git a/src/graph/validator/FetchVerticesValidator.h b/src/graph/validator/FetchVerticesValidator.h index 88f87f6762a..bd4d81233be 100644 --- a/src/graph/validator/FetchVerticesValidator.h +++ b/src/graph/validator/FetchVerticesValidator.h @@ -25,12 +25,13 @@ class FetchVerticesValidator final : public Validator { Status validateYield(YieldClause* yield); - AstContext* getAstContext() override { return fetchCtx_.get(); } - - void extractVertexProp(ExpressionProps& exprProps); + AstContext* getAstContext() override { + return fetchCtx_.get(); + } private: std::map> tagsSchema_; + std::vector tagIds_; std::unique_ptr fetchCtx_; }; diff --git a/src/graph/validator/FindPathValidator.h b/src/graph/validator/FindPathValidator.h index 95a5f64a2ad..c09a106abca 100644 --- a/src/graph/validator/FindPathValidator.h +++ b/src/graph/validator/FindPathValidator.h @@ -19,7 +19,9 @@ class FindPathValidator final : public Validator { private: Status validateImpl() override; - AstContext* getAstContext() override { return pathCtx_.get(); } + AstContext* getAstContext() override { + return pathCtx_.get(); + } Status validateWhere(WhereClause* where); diff --git a/src/graph/validator/GetSubgraphValidator.h b/src/graph/validator/GetSubgraphValidator.h index 358c65bd0b6..ae8caa5dfba 100644 --- a/src/graph/validator/GetSubgraphValidator.h +++ b/src/graph/validator/GetSubgraphValidator.h @@ -27,7 +27,9 @@ class GetSubgraphValidator final : public Validator { Status validateYield(YieldClause* yield); - AstContext* getAstContext() override { return subgraphCtx_.get(); } + AstContext* getAstContext() override { + return subgraphCtx_.get(); + } private: std::unique_ptr subgraphCtx_; diff --git a/src/graph/validator/GoValidator.cpp b/src/graph/validator/GoValidator.cpp index 2f2bb84fa3d..69b5a9bbd39 100644 --- a/src/graph/validator/GoValidator.cpp +++ b/src/graph/validator/GoValidator.cpp @@ -15,10 +15,6 @@ namespace nebula { namespace graph { -static const char* COLNAME_EDGE = "EDGE"; -static const char* SRC_VERTEX = "$^"; -static const char* DST_VERTEX = "$$"; - Status GoValidator::validateImpl() { auto* goSentence = static_cast(sentence_); goCtx_ = getContext(); @@ -27,6 +23,7 @@ Status GoValidator::validateImpl() { NG_RETURN_IF_ERROR(ValidateUtil::validateStep(goSentence->stepClause(), goCtx_->steps)); NG_RETURN_IF_ERROR(validateStarts(goSentence->fromClause(), goCtx_->from)); NG_RETURN_IF_ERROR(ValidateUtil::validateOver(qctx_, goSentence->overClause(), goCtx_->over)); + NG_RETURN_IF_ERROR(extractTagIds()); NG_RETURN_IF_ERROR(validateWhere(goSentence->whereClause())); NG_RETURN_IF_ERROR(validateYield(goSentence->yieldClause())); NG_RETURN_IF_ERROR(validateTruncate(goSentence->truncateClause())); @@ -90,7 +87,7 @@ Status GoValidator::validateWhere(WhereClause* where) { return Status::SemanticError(ss.str()); } - NG_RETURN_IF_ERROR(deduceProps(filter, goCtx_->exprProps)); + NG_RETURN_IF_ERROR(deduceProps(filter, goCtx_->exprProps, &tagIds_, &goCtx_->over.edgeTypes)); goCtx_->filter = filter; return Status::OK(); } @@ -140,32 +137,21 @@ Status GoValidator::validateYield(YieldClause* yield) { return Status::SemanticError("`%s' is not support in go sentence.", col->toString().c_str()); } - const auto& vertexExprs = ExpressionUtils::collectAll(col->expr(), {Expression::Kind::kVertex}); - for (const auto* expr : vertexExprs) { - const auto& colName = static_cast(expr)->name(); - if (colName == SRC_VERTEX) { - NG_RETURN_IF_ERROR(extractVertexProp(exprProps, true)); - } else if (colName == DST_VERTEX) { - NG_RETURN_IF_ERROR(extractVertexProp(exprProps, false)); - } else { - return Status::SemanticError("`%s' is not support in go sentence.", - col->toString().c_str()); - } + auto vertexExpr = ExpressionUtils::findAny(col->expr(), {Expression::Kind::kVertex}); + if (vertexExpr != nullptr && + static_cast(vertexExpr)->name() == "VERTEX") { + return Status::SemanticError("`%s' is not support in go sentence.", col->toString().c_str()); } col->setExpr(ExpressionUtils::rewriteLabelAttr2EdgeProp(col->expr())); NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr())); auto* colExpr = col->expr(); - if (ExpressionUtils::hasAny(colExpr, {Expression::Kind::kEdge})) { - extractEdgeProp(exprProps); - } - auto typeStatus = deduceExprType(colExpr); NG_RETURN_IF_ERROR(typeStatus); auto type = typeStatus.value(); outputs_.emplace_back(col->name(), type); - NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps)); + NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps, &tagIds_, &goCtx_->over.edgeTypes)); } const auto& over = goCtx_->over; @@ -180,43 +166,23 @@ Status GoValidator::validateYield(YieldClause* yield) { return Status::OK(); } -Status GoValidator::extractVertexProp(ExpressionProps& exprProps, bool isSrc) { - const auto tagStatus = qctx_->schemaMng()->getAllLatestVerTagSchema(space_.id); +Status GoValidator::extractTagIds() { + auto tagStatus = qctx_->schemaMng()->getAllLatestVerTagSchema(space_.id); NG_RETURN_IF_ERROR(tagStatus); for (const auto& tag : tagStatus.value()) { - auto tagID = tag.first; - const auto& tagSchema = tag.second; - if (isSrc) { - for (size_t i = 0; i < tagSchema->getNumFields(); ++i) { - exprProps.insertSrcTagProp(tagID, tagSchema->getFieldName(i)); - } - } else { - for (size_t i = 0; i < tagSchema->getNumFields(); ++i) { - exprProps.insertDstTagProp(tagID, tagSchema->getFieldName(i)); - } - } + tagIds_.emplace_back(tag.first); } return Status::OK(); } -Status GoValidator::extractEdgeProp(ExpressionProps& exprProps) { - const auto& edgeTypes = goCtx_->over.edgeTypes; - for (const auto& edgeType : edgeTypes) { - const auto& edgeSchema = qctx_->schemaMng()->getEdgeSchema(space_.id, std::abs(edgeType)); - exprProps.insertEdgeProp(edgeType, kType); - exprProps.insertEdgeProp(edgeType, kSrc); - exprProps.insertEdgeProp(edgeType, kDst); - exprProps.insertEdgeProp(edgeType, kRank); - for (size_t i = 0; i < edgeSchema->getNumFields(); ++i) { - exprProps.insertEdgeProp(edgeType, edgeSchema->getFieldName(i)); - } - } - return Status::OK(); -} - -void GoValidator::extractPropExprs(const Expression* expr) { - ExtractPropExprVisitor visitor( - vctx_, goCtx_->srcEdgePropsExpr, goCtx_->dstPropsExpr, inputPropCols_, propExprColMap_); +void GoValidator::extractPropExprs(const Expression* expr, + std::unordered_set& uniqueExpr) { + ExtractPropExprVisitor visitor(vctx_, + goCtx_->srcEdgePropsExpr, + goCtx_->dstPropsExpr, + inputPropCols_, + propExprColMap_, + uniqueExpr); const_cast(expr)->accept(&visitor); } @@ -258,42 +224,17 @@ Status GoValidator::buildColumns() { inputPropCols_ = pool->add(new YieldColumns()); } + std::unordered_set uniqueEdgeVertexExpr; auto filter = goCtx_->filter; if (filter != nullptr) { - extractPropExprs(filter); - auto newFilter = filter->clone(); - goCtx_->filter = rewrite2VarProp(newFilter); + extractPropExprs(filter, uniqueEdgeVertexExpr); + goCtx_->filter = rewrite2VarProp(filter); } - std::unordered_set existExpr; auto* newYieldExpr = pool->add(new YieldColumns()); for (auto* col : goCtx_->yieldExpr->columns()) { - const auto& vertexExprs = ExpressionUtils::collectAll(col->expr(), {Expression::Kind::kVertex}); - auto existEdge = ExpressionUtils::hasAny(col->expr(), {Expression::Kind::kEdge}); - if (!existEdge && vertexExprs.empty()) { - extractPropExprs(col->expr()); - newYieldExpr->addColumn(new YieldColumn(rewrite2VarProp(col->expr()), col->alias())); - } else { - if (existEdge) { - if (existExpr.emplace(COLNAME_EDGE).second) { - goCtx_->srcEdgePropsExpr->addColumn( - new YieldColumn(EdgeExpression::make(pool), COLNAME_EDGE)); - } - } - for (const auto* expr : vertexExprs) { - const auto& colName = static_cast(expr)->name(); - if (existExpr.emplace(colName).second) { - if (colName == SRC_VERTEX) { - goCtx_->srcEdgePropsExpr->addColumn( - new YieldColumn(VertexExpression::make(pool), SRC_VERTEX)); - } else { - goCtx_->dstPropsExpr->addColumn( - new YieldColumn(VertexExpression::make(pool), DST_VERTEX)); - } - } - } - newYieldExpr->addColumn(col->clone().release()); - } + extractPropExprs(col->expr(), uniqueEdgeVertexExpr); + newYieldExpr->addColumn(new YieldColumn(rewrite2VarProp(col->expr()), col->alias())); } goCtx_->yieldExpr = newYieldExpr; return Status::OK(); diff --git a/src/graph/validator/GoValidator.h b/src/graph/validator/GoValidator.h index 3c42ec13023..176c7027ac5 100644 --- a/src/graph/validator/GoValidator.h +++ b/src/graph/validator/GoValidator.h @@ -22,7 +22,9 @@ class GoValidator final : public Validator { private: Status validateImpl() override; - AstContext* getAstContext() override { return goCtx_.get(); } + AstContext* getAstContext() override { + return goCtx_.get(); + } Status validateWhere(WhereClause* where); @@ -32,19 +34,18 @@ class GoValidator final : public Validator { Status buildColumns(); - void extractPropExprs(const Expression* expr); + Status extractTagIds(); - Expression* rewrite2VarProp(const Expression* expr); - - Status extractVertexProp(ExpressionProps& exprProps, bool isSrc); + void extractPropExprs(const Expression* expr, std::unordered_set& uniqueCols); - Status extractEdgeProp(ExpressionProps& exprProps); + Expression* rewrite2VarProp(const Expression* expr); private: std::unique_ptr goCtx_; YieldColumns* inputPropCols_{nullptr}; std::unordered_map propExprColMap_; + std::vector tagIds_; }; } // namespace graph } // namespace nebula diff --git a/src/graph/validator/IngestValidator.h b/src/graph/validator/IngestValidator.h index 8c9887037f0..eb560626963 100644 --- a/src/graph/validator/IngestValidator.h +++ b/src/graph/validator/IngestValidator.h @@ -16,7 +16,9 @@ class IngestValidator final : public Validator { IngestValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {} private: - Status validateImpl() override { return Status::OK(); } + Status validateImpl() override { + return Status::OK(); + } Status toPlan() override; }; diff --git a/src/graph/validator/LookupValidator.cpp b/src/graph/validator/LookupValidator.cpp index 001a9ac49d2..9c6e9b618ab 100644 --- a/src/graph/validator/LookupValidator.cpp +++ b/src/graph/validator/LookupValidator.cpp @@ -31,17 +31,23 @@ const LookupSentence* LookupValidator::sentence() const { return static_cast(sentence_); } -int32_t LookupValidator::schemaId() const { return DCHECK_NOTNULL(lookupCtx_)->schemaId; } +int32_t LookupValidator::schemaId() const { + return DCHECK_NOTNULL(lookupCtx_)->schemaId; +} -GraphSpaceID LookupValidator::spaceId() const { return DCHECK_NOTNULL(lookupCtx_)->space.id; } +GraphSpaceID LookupValidator::spaceId() const { + return DCHECK_NOTNULL(lookupCtx_)->space.id; +} -AstContext* LookupValidator::getAstContext() { return lookupCtx_.get(); } +AstContext* LookupValidator::getAstContext() { + return lookupCtx_.get(); +} Status LookupValidator::validateImpl() { lookupCtx_ = getContext(); NG_RETURN_IF_ERROR(validateFrom()); - NG_RETURN_IF_ERROR(validateFilter()); + NG_RETURN_IF_ERROR(validateWhere()); NG_RETURN_IF_ERROR(validateYield()); return Status::OK(); } @@ -53,19 +59,7 @@ Status LookupValidator::validateFrom() { NG_RETURN_IF_ERROR(ret); lookupCtx_->isEdge = ret.value().first; lookupCtx_->schemaId = ret.value().second; - return Status::OK(); -} - -Status LookupValidator::extractSchemaProp() { - shared_ptr schema; - NG_RETURN_IF_ERROR(getSchemaProvider(&schema)); - for (std::size_t i = 0; i < schema->getNumFields(); ++i) { - const auto& propName = schema->getFieldName(i); - auto iter = std::find(idxReturnCols_.begin(), idxReturnCols_.end(), propName); - if (iter == idxReturnCols_.end()) { - idxReturnCols_.emplace_back(propName); - } - } + schemaIds_.emplace_back(ret.value().second); return Status::OK(); } @@ -107,9 +101,6 @@ Status LookupValidator::validateYieldEdge() { {Expression::Kind::kAggregate, Expression::Kind::kVertex})) { return Status::SemanticError("illegal yield clauses `%s'", col->toString().c_str()); } - if (ExpressionUtils::hasAny(col->expr(), {Expression::Kind::kEdge})) { - NG_RETURN_IF_ERROR(extractSchemaProp()); - } if (col->expr()->kind() == Expression::Kind::kLabelAttribute) { const auto& schemaName = static_cast(col->expr())->left()->name(); if (schemaName != sentence()->from()) { @@ -124,7 +115,7 @@ Status LookupValidator::validateYieldEdge() { NG_RETURN_IF_ERROR(typeStatus); outputs_.emplace_back(col->name(), typeStatus.value()); yieldExpr->addColumn(col->clone().release()); - NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps_)); + NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps_, nullptr, &schemaIds_)); } return Status::OK(); } @@ -137,9 +128,6 @@ Status LookupValidator::validateYieldTag() { {Expression::Kind::kAggregate, Expression::Kind::kEdge})) { return Status::SemanticError("illegal yield clauses `%s'", col->toString().c_str()); } - if (ExpressionUtils::hasAny(col->expr(), {Expression::Kind::kVertex})) { - NG_RETURN_IF_ERROR(extractSchemaProp()); - } if (col->expr()->kind() == Expression::Kind::kLabelAttribute) { const auto& schemaName = static_cast(col->expr())->left()->name(); if (schemaName != sentence()->from()) { @@ -154,7 +142,7 @@ Status LookupValidator::validateYieldTag() { NG_RETURN_IF_ERROR(typeStatus); outputs_.emplace_back(col->name(), typeStatus.value()); yieldExpr->addColumn(col->clone().release()); - NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps_)); + NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps_, &schemaIds_)); } return Status::OK(); } @@ -187,7 +175,7 @@ Status LookupValidator::validateYield() { return Status::OK(); } -Status LookupValidator::validateFilter() { +Status LookupValidator::validateWhere() { auto whereClause = sentence()->whereClause(); if (whereClause == nullptr) { return Status::OK(); @@ -211,7 +199,11 @@ Status LookupValidator::validateFilter() { // Make sure the type of the rewritted filter expr is right NG_RETURN_IF_ERROR(deduceExprType(lookupCtx_->filter)); } - NG_RETURN_IF_ERROR(deduceProps(lookupCtx_->filter, exprProps_)); + if (lookupCtx_->isEdge) { + NG_RETURN_IF_ERROR(deduceProps(lookupCtx_->filter, exprProps_, nullptr, &schemaIds_)); + } else { + NG_RETURN_IF_ERROR(deduceProps(lookupCtx_->filter, exprProps_, &schemaIds_)); + } return Status::OK(); } diff --git a/src/graph/validator/LookupValidator.h b/src/graph/validator/LookupValidator.h index 54713d46ef4..9889d99971e 100644 --- a/src/graph/validator/LookupValidator.h +++ b/src/graph/validator/LookupValidator.h @@ -29,7 +29,7 @@ class LookupValidator final : public Validator { Status validateFrom(); Status validateYield(); - Status validateFilter(); + Status validateWhere(); Status validateYieldTag(); Status validateYieldEdge(); @@ -53,13 +53,13 @@ class LookupValidator final : public Validator { Status getSchemaProvider(std::shared_ptr* provider) const; StatusOr genTsFilter(Expression* filter); StatusOr handleLogicalExprOperands(LogicalExpression* lExpr); - Status extractSchemaProp(); void extractExprProps(); std::unique_ptr lookupCtx_; std::vector tsClients_; ExpressionProps exprProps_; std::vector idxReturnCols_; + std::vector schemaIds_; }; } // namespace graph diff --git a/src/graph/validator/MaintainValidator.cpp b/src/graph/validator/MaintainValidator.cpp index 56a906f15e3..d1d9b29ef7a 100644 --- a/src/graph/validator/MaintainValidator.cpp +++ b/src/graph/validator/MaintainValidator.cpp @@ -29,16 +29,16 @@ static Status validateColumns(const std::vector &columnSp for (auto &spec : columnSpecs) { meta::cpp2::ColumnDef column; auto type = spec->type(); - column.set_name(*spec->name()); - column.type.set_type(type); + column.name_ref() = *spec->name(); + column.type.type_ref() = type; if (nebula::cpp2::PropertyType::FIXED_STRING == type) { - column.type.set_type_length(spec->typeLen()); + column.type.type_length_ref() = spec->typeLen(); } else if (nebula::cpp2::PropertyType::GEOGRAPHY == type) { - column.type.set_geo_shape(spec->geoShape()); + column.type.geo_shape_ref() = spec->geoShape(); } for (const auto &property : spec->properties()->properties()) { if (property->isNullable()) { - column.set_nullable(property->nullable()); + column.nullable_ref() = property->nullable(); } else if (property->isDefaultValue()) { if (!ExpressionUtils::isEvaluableExpr(property->defaultValue())) { return Status::SemanticError("Wrong default value expression `%s'", @@ -48,13 +48,13 @@ static Status validateColumns(const std::vector &columnSp // some expression is evaluable but not pure so only fold instead of eval here auto foldRes = ExpressionUtils::foldConstantExpr(defaultValueExpr); NG_RETURN_IF_ERROR(foldRes); - column.set_default_value(foldRes.value()->encode()); + column.default_value_ref() = foldRes.value()->encode(); } else if (property->isComment()) { - column.set_comment(*DCHECK_NOTNULL(property->comment())); + column.comment_ref() = *DCHECK_NOTNULL(property->comment()); } } if (!column.nullable_ref().has_value()) { - column.set_nullable(true); + column.nullable_ref() = true; } schema.columns_ref().value().emplace_back(std::move(column)); } @@ -68,7 +68,7 @@ static StatusOr> validateSchemaOpts( for (const auto &schemaOpt : schemaOpts) { meta::cpp2::AlterSchemaItem schemaItem; auto opType = schemaOpt->toType(); - schemaItem.set_op(opType); + schemaItem.op_ref() = opType; meta::cpp2::Schema schema; if (opType == meta::cpp2::AlterSchemaOp::DROP) { @@ -91,7 +91,7 @@ static StatusOr> validateSchemaOpts( NG_LOG_AND_RETURN_IF_ERROR(validateColumns(specs, schema)); } - schemaItem.set_schema(std::move(schema)); + schemaItem.schema_ref() = std::move(schema); schemaItems.emplace_back(std::move(schemaItem)); } return schemaItems; @@ -106,21 +106,21 @@ static StatusOr validateSchemaProps( case SchemaPropItem::TTL_DURATION: { auto ttlDur = prop->getTtlDuration(); NG_RETURN_IF_ERROR(ttlDur); - schemaProp.set_ttl_duration(ttlDur.value()); + schemaProp.ttl_duration_ref() = ttlDur.value(); break; } case SchemaPropItem::TTL_COL: { // Check the legality of the column in meta auto ttlCol = prop->getTtlCol(); NG_RETURN_IF_ERROR(ttlCol); - schemaProp.set_ttl_col(ttlCol.value()); + schemaProp.ttl_col_ref() = ttlCol.value(); break; } case SchemaPropItem::COMMENT: { // Check the legality of the column in meta auto comment = prop->getComment(); NG_RETURN_IF_ERROR(comment); - schemaProp.set_comment(comment.value()); + schemaProp.comment_ref() = comment.value(); break; } default: { @@ -188,7 +188,9 @@ Status CreateEdgeValidator::validateImpl() { return Status::OK(); } -Status DescTagValidator::validateImpl() { return Status::OK(); } +Status DescTagValidator::validateImpl() { + return Status::OK(); +} Status DescTagValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -199,7 +201,9 @@ Status DescTagValidator::toPlan() { return Status::OK(); } -Status DescEdgeValidator::validateImpl() { return Status::OK(); } +Status DescEdgeValidator::validateImpl() { + return Status::OK(); +} Status DescEdgeValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -234,7 +238,9 @@ Status AlterEdgeValidator::validateImpl() { return Status::OK(); } -Status ShowTagsValidator::validateImpl() { return Status::OK(); } +Status ShowTagsValidator::validateImpl() { + return Status::OK(); +} Status ShowTagsValidator::toPlan() { auto *doNode = ShowTags::make(qctx_, nullptr); @@ -243,7 +249,9 @@ Status ShowTagsValidator::toPlan() { return Status::OK(); } -Status ShowEdgesValidator::validateImpl() { return Status::OK(); } +Status ShowEdgesValidator::validateImpl() { + return Status::OK(); +} Status ShowEdgesValidator::toPlan() { auto *doNode = ShowEdges::make(qctx_, nullptr); @@ -252,7 +260,9 @@ Status ShowEdgesValidator::toPlan() { return Status::OK(); } -Status ShowCreateTagValidator::validateImpl() { return Status::OK(); } +Status ShowCreateTagValidator::validateImpl() { + return Status::OK(); +} Status ShowCreateTagValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -262,7 +272,9 @@ Status ShowCreateTagValidator::toPlan() { return Status::OK(); } -Status ShowCreateEdgeValidator::validateImpl() { return Status::OK(); } +Status ShowCreateEdgeValidator::validateImpl() { + return Status::OK(); +} Status ShowCreateEdgeValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -272,7 +284,9 @@ Status ShowCreateEdgeValidator::toPlan() { return Status::OK(); } -Status DropTagValidator::validateImpl() { return Status::OK(); } +Status DropTagValidator::validateImpl() { + return Status::OK(); +} Status DropTagValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -282,7 +296,9 @@ Status DropTagValidator::toPlan() { return Status::OK(); } -Status DropEdgeValidator::validateImpl() { return Status::OK(); } +Status DropEdgeValidator::validateImpl() { + return Status::OK(); +} Status DropEdgeValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -459,7 +475,9 @@ Status ShowEdgeIndexesValidator::toPlan() { return Status::OK(); } -Status ShowTagIndexStatusValidator::validateImpl() { return Status::OK(); } +Status ShowTagIndexStatusValidator::validateImpl() { + return Status::OK(); +} Status ShowTagIndexStatusValidator::toPlan() { auto *doNode = ShowTagIndexStatus::make(qctx_, nullptr); @@ -468,7 +486,9 @@ Status ShowTagIndexStatusValidator::toPlan() { return Status::OK(); } -Status ShowEdgeIndexStatusValidator::validateImpl() { return Status::OK(); } +Status ShowEdgeIndexStatusValidator::validateImpl() { + return Status::OK(); +} Status ShowEdgeIndexStatusValidator::toPlan() { auto *doNode = ShowEdgeIndexStatus::make(qctx_, nullptr); @@ -477,7 +497,9 @@ Status ShowEdgeIndexStatusValidator::toPlan() { return Status::OK(); } -Status MergeZoneValidator::validateImpl() { return Status::OK(); } +Status MergeZoneValidator::validateImpl() { + return Status::OK(); +} Status MergeZoneValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -488,7 +510,9 @@ Status MergeZoneValidator::toPlan() { return Status::OK(); } -Status RenameZoneValidator::validateImpl() { return Status::OK(); } +Status RenameZoneValidator::validateImpl() { + return Status::OK(); +} Status RenameZoneValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -499,7 +523,9 @@ Status RenameZoneValidator::toPlan() { return Status::OK(); } -Status DropZoneValidator::validateImpl() { return Status::OK(); } +Status DropZoneValidator::validateImpl() { + return Status::OK(); +} Status DropZoneValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -509,7 +535,9 @@ Status DropZoneValidator::toPlan() { return Status::OK(); } -Status SplitZoneValidator::validateImpl() { return Status::OK(); } +Status SplitZoneValidator::validateImpl() { + return Status::OK(); +} Status SplitZoneValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -520,7 +548,9 @@ Status SplitZoneValidator::toPlan() { return Status::OK(); } -Status DescribeZoneValidator::validateImpl() { return Status::OK(); } +Status DescribeZoneValidator::validateImpl() { + return Status::OK(); +} Status DescribeZoneValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -530,7 +560,9 @@ Status DescribeZoneValidator::toPlan() { return Status::OK(); } -Status ListZonesValidator::validateImpl() { return Status::OK(); } +Status ListZonesValidator::validateImpl() { + return Status::OK(); +} Status ListZonesValidator::toPlan() { auto *doNode = ListZones::make(qctx_, nullptr); @@ -539,7 +571,9 @@ Status ListZonesValidator::toPlan() { return Status::OK(); } -Status AddHostsIntoZoneValidator::validateImpl() { return Status::OK(); } +Status AddHostsIntoZoneValidator::validateImpl() { + return Status::OK(); +} Status AddHostsIntoZoneValidator::toPlan() { auto sentence = static_cast(sentence_); @@ -570,13 +604,13 @@ Status CreateFTIndexValidator::validateImpl() { NG_RETURN_IF_ERROR(status); nebula::cpp2::SchemaID id; if (sentence->isEdge()) { - id.set_edge_type(status.value()); + id.edge_type_ref() = status.value(); } else { - id.set_tag_id(status.value()); + id.tag_id_ref() = status.value(); } - index_.set_space_id(space.id); - index_.set_depend_schema(std::move(id)); - index_.set_fields(sentence->fields()); + index_.space_id_ref() = space.id; + index_.depend_schema_ref() = std::move(id); + index_.fields_ref() = sentence->fields(); return Status::OK(); } @@ -602,7 +636,9 @@ Status DropFTIndexValidator::toPlan() { return Status::OK(); } -Status ShowFTIndexesValidator::validateImpl() { return Status::OK(); } +Status ShowFTIndexesValidator::validateImpl() { + return Status::OK(); +} Status ShowFTIndexesValidator::toPlan() { auto *doNode = ShowFTIndexes::make(qctx_, nullptr); diff --git a/src/graph/validator/MaintainValidator.h b/src/graph/validator/MaintainValidator.h index 508dd2c1598..24933de39b9 100644 --- a/src/graph/validator/MaintainValidator.h +++ b/src/graph/validator/MaintainValidator.h @@ -19,7 +19,9 @@ class CreateTagValidator final : public Validator { public: CreateTagValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {} - AstContext* getAstContext() override { return createCtx_.get(); } + AstContext* getAstContext() override { + return createCtx_.get(); + } private: Status validateImpl() override; @@ -31,7 +33,9 @@ class CreateEdgeValidator final : public Validator { public: CreateEdgeValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {} - AstContext* getAstContext() override { return createCtx_.get(); } + AstContext* getAstContext() override { + return createCtx_.get(); + } private: Status validateImpl() override; @@ -85,7 +89,9 @@ class AlterTagValidator final : public Validator { public: AlterTagValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {} - AstContext* getAstContext() override { return alterCtx_.get(); } + AstContext* getAstContext() override { + return alterCtx_.get(); + } private: Status validateImpl() override; @@ -97,7 +103,9 @@ class AlterEdgeValidator final : public Validator { public: AlterEdgeValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {} - AstContext* getAstContext() override { return alterCtx_.get(); } + AstContext* getAstContext() override { + return alterCtx_.get(); + } private: Status validateImpl() override; diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index f28d7732311..ecfb268b714 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -16,7 +16,9 @@ MatchValidator::MatchValidator(Sentence *sentence, QueryContext *context) matchCtx_ = getContext(); } -AstContext *MatchValidator::getAstContext() { return matchCtx_.get(); } +AstContext *MatchValidator::getAstContext() { + return matchCtx_.get(); +} Status MatchValidator::validateImpl() { auto *sentence = static_cast(sentence_); diff --git a/src/graph/validator/MutateValidator.cpp b/src/graph/validator/MutateValidator.cpp index da4c5d3b4e4..ee32fc00f44 100644 --- a/src/graph/validator/MutateValidator.cpp +++ b/src/graph/validator/MutateValidator.cpp @@ -127,13 +127,13 @@ Status InsertVerticesValidator::prepareVertices() { handleValueNum++; } auto &tag = tags[count]; - tag.set_tag_id(tagId); - tag.set_props(std::move(props)); + tag.tag_id_ref() = tagId; + tag.props_ref() = std::move(props); } storage::cpp2::NewVertex vertex; - vertex.set_id(vertexId); - vertex.set_tags(std::move(tags)); + vertex.id_ref() = vertexId; + vertex.tags_ref() = std::move(tags); vertices_.emplace_back(std::move(vertex)); } return Status::OK(); @@ -274,19 +274,19 @@ Status InsertEdgesValidator::prepareEdges() { storage::cpp2::NewEdge edge; storage::cpp2::EdgeKey key; - key.set_src(srcId); - key.set_dst(dstId); - key.set_edge_type(edgeType_); - key.set_ranking(rank); - edge.set_key(key); - edge.set_props(std::move(entirePropValues)); + key.src_ref() = srcId; + key.dst_ref() = dstId; + key.edge_type_ref() = edgeType_; + key.ranking_ref() = rank; + edge.key_ref() = key; + edge.props_ref() = std::move(entirePropValues); edges_.emplace_back(edge); if (!FLAGS_enable_experimental_feature) { // inbound - key.set_src(dstId); - key.set_dst(srcId); - key.set_edge_type(-edgeType_); - edge.set_key(key); + key.src_ref() = dstId; + key.dst_ref() = srcId; + key.edge_type_ref() = -edgeType_; + edge.key_ref() = key; edges_.emplace_back(std::move(edge)); } } @@ -374,14 +374,14 @@ Status DeleteVerticesValidator::toPlan() { edgeKeyRefs_.emplace_back(edgeKeyRef); storage::cpp2::EdgeProp edgeProp; - edgeProp.set_type(edgeTypes_[index]); + edgeProp.type_ref() = edgeTypes_[index]; edgeProp.props_ref().value().emplace_back(kSrc); edgeProp.props_ref().value().emplace_back(kDst); edgeProp.props_ref().value().emplace_back(kType); edgeProp.props_ref().value().emplace_back(kRank); edgeProps.emplace_back(edgeProp); - edgeProp.set_type(-edgeTypes_[index]); + edgeProp.type_ref() = -edgeTypes_[index]; edgeProps.emplace_back(std::move(edgeProp)); index++; } @@ -684,8 +684,8 @@ Status UpdateValidator::getUpdateProps() { std::string encodeStr; auto copyValueExpr = valueExpr->clone(); NG_LOG_AND_RETURN_IF_ERROR(checkAndResetSymExpr(copyValueExpr, symName, encodeStr)); - updatedProp.set_value(std::move(encodeStr)); - updatedProp.set_name(fieldName); + updatedProp.value_ref() = std::move(encodeStr); + updatedProp.name_ref() = fieldName; updatedProps_.emplace_back(std::move(updatedProp)); } diff --git a/src/graph/validator/SequentialValidator.h b/src/graph/validator/SequentialValidator.h index 6d8c8f57505..a2a13f767cd 100644 --- a/src/graph/validator/SequentialValidator.h +++ b/src/graph/validator/SequentialValidator.h @@ -29,13 +29,17 @@ class SequentialValidator final : public Validator { Status validateImpl() override; - AstContext* getAstContext() override { return seqAstCtx_.get(); } + AstContext* getAstContext() override { + return seqAstCtx_.get(); + } private: /** * Will not check the space from the beginning of a query. */ - bool spaceChosen() override { return true; } + bool spaceChosen() override { + return true; + } const Sentence* getFirstSentence(const Sentence* sentence) const; diff --git a/src/graph/validator/UseValidator.h b/src/graph/validator/UseValidator.h index 76333f5ff16..c0a7c88af36 100644 --- a/src/graph/validator/UseValidator.h +++ b/src/graph/validator/UseValidator.h @@ -20,7 +20,9 @@ class UseValidator final : public Validator { /** * Will not check the space for use space sentence. */ - bool spaceChosen() override { return true; } + bool spaceChosen() override { + return true; + } Status validateImpl() override; diff --git a/src/graph/validator/Validator.cpp b/src/graph/validator/Validator.cpp index 750fd0c42ce..eb6a17fa558 100644 --- a/src/graph/validator/Validator.cpp +++ b/src/graph/validator/Validator.cpp @@ -305,7 +305,9 @@ Status Validator::appendPlan(PlanNode* node, PlanNode* appended) { return Status::OK(); } -Status Validator::appendPlan(PlanNode* root) { return appendPlan(tail_, root); } +Status Validator::appendPlan(PlanNode* root) { + return appendPlan(tail_, root); +} Status Validator::validate() { if (!vctx_) { @@ -347,7 +349,9 @@ Status Validator::validate() { return Status::OK(); } -bool Validator::spaceChosen() { return vctx_->spaceChosen(); } +bool Validator::spaceChosen() { + return vctx_->spaceChosen(); +} StatusOr Validator::deduceExprType(const Expression* expr) const { DeduceTypeVisitor visitor(qctx_, vctx_, inputs_, space_.id); @@ -358,8 +362,12 @@ StatusOr Validator::deduceExprType(const Expression* expr) const { return visitor.type(); } -Status Validator::deduceProps(const Expression* expr, ExpressionProps& exprProps) { - DeducePropsVisitor visitor(qctx_, space_.id, &exprProps, &userDefinedVarNameList_); +Status Validator::deduceProps(const Expression* expr, + ExpressionProps& exprProps, + std::vector* tagIds, + std::vector* edgeTypes) { + DeducePropsVisitor visitor( + qctx_, space_.id, &exprProps, &userDefinedVarNameList_, tagIds, edgeTypes); const_cast(expr)->accept(&visitor); return std::move(visitor).status(); } diff --git a/src/graph/validator/Validator.h b/src/graph/validator/Validator.h index 0568d0eb054..b1206769fc8 100644 --- a/src/graph/validator/Validator.h +++ b/src/graph/validator/Validator.h @@ -33,35 +33,63 @@ class Validator { NG_MUST_USE_RESULT Status appendPlan(PlanNode* tail); - void setInputVarName(std::string name) { inputVarName_ = std::move(name); } + void setInputVarName(std::string name) { + inputVarName_ = std::move(name); + } - QueryContext* qctx() { return qctx_; } + QueryContext* qctx() { + return qctx_; + } - PlanNode* root() const { return root_; } + PlanNode* root() const { + return root_; + } - PlanNode* tail() const { return tail_; } + PlanNode* tail() const { + return tail_; + } - ColsDef outputCols() const { return outputs_; } + ColsDef outputCols() const { + return outputs_; + } - void setOutputCols(const ColsDef&& outputCols) { outputs_ = std::move(outputCols); } + void setOutputCols(const ColsDef&& outputCols) { + outputs_ = std::move(outputCols); + } - void setOutputCols(ColsDef& outputCols) { outputs_ = outputCols; } + void setOutputCols(ColsDef& outputCols) { + outputs_ = outputCols; + } std::vector getOutColNames() const; - ColsDef inputCols() const { return inputs_; } + ColsDef inputCols() const { + return inputs_; + } - void setInputCols(ColsDef&& inputCols) { inputs_ = std::move(inputCols); } + void setInputCols(ColsDef&& inputCols) { + inputs_ = std::move(inputCols); + } - void setInputCols(const ColsDef& inputCols) { inputs_ = inputCols; } + void setInputCols(const ColsDef& inputCols) { + inputs_ = inputCols; + } - ExpressionProps exprProps() const { return exprProps_; } + ExpressionProps exprProps() const { + return exprProps_; + } - void setExprProps(ExpressionProps&& exprProps) { exprProps_ = std::move(exprProps); } + void setExprProps(ExpressionProps&& exprProps) { + exprProps_ = std::move(exprProps); + } - void setExprProps(const ExpressionProps& exprProps) { exprProps_ = exprProps; } + void setExprProps(const ExpressionProps& exprProps) { + exprProps_ = exprProps; + } - const std::set& userDefinedVarNameList() const { return userDefinedVarNameList_; } + const std::set& userDefinedVarNameList() const { + return userDefinedVarNameList_; + } void setUserDefinedVarNameList(std::set&& userDefinedVarNameList) { userDefinedVarNameList_ = std::move(userDefinedVarNameList); @@ -71,12 +99,18 @@ class Validator { userDefinedVarNameList_ = userDefinedVarNameList; } - void setNoSpaceRequired() { noSpaceRequired_ = true; } + void setNoSpaceRequired() { + noSpaceRequired_ = true; + } // Whether require chosen space - bool noSpaceRequired() const { return noSpaceRequired_; } + bool noSpaceRequired() const { + return noSpaceRequired_; + } - const Sentence* sentence() const { return sentence_; } + const Sentence* sentence() const { + return sentence_; + } protected: Validator(Sentence* sentence, QueryContext* qctx); @@ -103,11 +137,16 @@ class Validator { */ virtual Status toPlan(); - virtual AstContext* getAstContext() { return nullptr; } + virtual AstContext* getAstContext() { + return nullptr; + } StatusOr deduceExprType(const Expression* expr) const; - Status deduceProps(const Expression* expr, ExpressionProps& exprProps); + Status deduceProps(const Expression* expr, + ExpressionProps& exprProps, + std::vector* tagIds = nullptr, + std::vector* edgeTypes = nullptr); static StatusOr checkPropNonexistOrDuplicate(const ColsDef& cols, folly::StringPiece prop, diff --git a/src/graph/validator/test/CMakeLists.txt b/src/graph/validator/test/CMakeLists.txt index 0363a74afc5..ae4362aee0d 100644 --- a/src/graph/validator/test/CMakeLists.txt +++ b/src/graph/validator/test/CMakeLists.txt @@ -26,6 +26,9 @@ set(VALIDATOR_TEST_LIBS $ $ $ + $ + $ + $ $ $ $ diff --git a/src/graph/validator/test/ExplainValidatorTest.cpp b/src/graph/validator/test/ExplainValidatorTest.cpp index d16aae1b1a1..631863326d5 100644 --- a/src/graph/validator/test/ExplainValidatorTest.cpp +++ b/src/graph/validator/test/ExplainValidatorTest.cpp @@ -11,7 +11,9 @@ namespace graph { class ExplainValidatorTest : public ValidatorTestBase { public: - void SetUp() override { ValidatorTestBase::SetUp(); } + void SetUp() override { + ValidatorTestBase::SetUp(); + } }; TEST_F(ExplainValidatorTest, TestExplainSingleStmt) { diff --git a/src/graph/validator/test/FetchEdgesTest.cpp b/src/graph/validator/test/FetchEdgesTest.cpp index 5651c0b391c..4874bbc4f02 100644 --- a/src/graph/validator/test/FetchEdgesTest.cpp +++ b/src/graph/validator/test/FetchEdgesTest.cpp @@ -33,9 +33,9 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) { ASSERT_TRUE(edgeTypeResult.ok()); auto edgeType = edgeTypeResult.value(); storage::cpp2::EdgeProp prop; - prop.set_type(edgeType); + prop.type_ref() = edgeType; std::set propNames{kSrc, kDst, kRank, kType, "start", "end", "likeness"}; - prop.set_props(std::vector(propNames.begin(), propNames.end())); + prop.props_ref() = std::vector(propNames.begin(), propNames.end()); auto props = std::make_unique>(); props->emplace_back(std::move(prop)); auto *ge = GetEdges::make(qctx, start, 1, src, type, rank, dst, std::move(props)); @@ -59,16 +59,16 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) { ASSERT_TRUE(edgeTypeResult.ok()); auto edgeType = edgeTypeResult.value(); storage::cpp2::EdgeProp prop; - prop.set_type(edgeType); + prop.type_ref() = edgeType; std::set propNames{kSrc, kDst, kRank, "start", "end"}; - prop.set_props(std::vector(propNames.begin(), propNames.end())); + prop.props_ref() = std::vector(propNames.begin(), propNames.end()); auto props = std::make_unique>(); props->emplace_back(std::move(prop)); auto exprs = std::make_unique>(); storage::cpp2::Expr expr1; - expr1.set_expr(EdgePropertyExpression::make(pool, "like", "start")->encode()); + expr1.expr_ref() = EdgePropertyExpression::make(pool, "like", "start")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(EdgePropertyExpression::make(pool, "like", "end")->encode()); + expr2.expr_ref() = EdgePropertyExpression::make(pool, "like", "end")->encode(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); auto *ge = @@ -94,16 +94,16 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) { ASSERT_TRUE(edgeTypeResult.ok()); auto edgeType = edgeTypeResult.value(); storage::cpp2::EdgeProp prop; - prop.set_type(edgeType); + prop.type_ref() = edgeType; std::set propNames{kSrc, kDst, kRank, "start", "end"}; - prop.set_props(std::vector(propNames.begin(), propNames.end())); + prop.props_ref() = std::vector(propNames.begin(), propNames.end()); auto props = std::make_unique>(); props->emplace_back(std::move(prop)); auto exprs = std::make_unique>(); storage::cpp2::Expr expr1; - expr1.set_expr(EdgePropertyExpression::make(pool, "like", "start")->encode()); + expr1.expr_ref() = EdgePropertyExpression::make(pool, "like", "start")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(EdgePropertyExpression::make(pool, "like", "end")->encode()); + expr2.expr_ref() = EdgePropertyExpression::make(pool, "like", "end")->encode(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); auto *ge = @@ -130,17 +130,18 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) { ASSERT_TRUE(edgeTypeResult.ok()); auto edgeType = edgeTypeResult.value(); storage::cpp2::EdgeProp prop; - prop.set_type(edgeType); + prop.type_ref() = edgeType; std::set propNames{kSrc, kDst, kRank, "start", "end"}; - prop.set_props(std::vector(propNames.begin(), propNames.end())); + prop.props_ref() = std::vector(propNames.begin(), propNames.end()); auto props = std::make_unique>(); props->emplace_back(std::move(prop)); auto exprs = std::make_unique>(); storage::cpp2::Expr expr1; - expr1.set_expr(RelationalExpression::makeGT(pool, - EdgePropertyExpression::make(pool, "like", "start"), - EdgePropertyExpression::make(pool, "like", "end")) - ->encode()); + expr1.expr_ref() = + RelationalExpression::makeGT(pool, + EdgePropertyExpression::make(pool, "like", "start"), + EdgePropertyExpression::make(pool, "like", "end")) + ->encode(); exprs->emplace_back(std::move(expr1)); auto *ge = GetEdges::make(qctx, start, 1, src, type, rank, dst, std::move(props), std::move(exprs)); @@ -166,16 +167,16 @@ TEST_F(FetchEdgesValidatorTest, FetchEdgesProp) { ASSERT_TRUE(edgeTypeResult.ok()); auto edgeType = edgeTypeResult.value(); storage::cpp2::EdgeProp prop; - prop.set_type(edgeType); + prop.type_ref() = edgeType; std::set propNames{kSrc, kDst, kRank, "start", "end"}; - prop.set_props(std::vector(propNames.begin(), propNames.end())); + prop.props_ref() = std::vector(propNames.begin(), propNames.end()); auto props = std::make_unique>(); props->emplace_back(std::move(prop)); auto exprs = std::make_unique>(); storage::cpp2::Expr expr1; - expr1.set_expr(EdgePropertyExpression::make(pool, "like", "start")->encode()); + expr1.expr_ref() = EdgePropertyExpression::make(pool, "like", "start")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(EdgePropertyExpression::make(pool, "like", "end")->encode()); + expr2.expr_ref() = EdgePropertyExpression::make(pool, "like", "end")->encode(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); auto *ge = diff --git a/src/graph/validator/test/FetchVerticesTest.cpp b/src/graph/validator/test/FetchVerticesTest.cpp index 52bcf7eef41..a7e62c4b24d 100644 --- a/src/graph/validator/test/FetchVerticesTest.cpp +++ b/src/graph/validator/test/FetchVerticesTest.cpp @@ -32,7 +32,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp prop; - prop.set_tag(tagId); + prop.tag_ref() = tagId; auto props = std::make_unique>(); props->emplace_back(std::move(prop)); auto *gv = GetVertices::make(qctx, start, 1, src, std::move(props)); @@ -55,13 +55,13 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp personProp; - personProp.set_tag(tagId); + personProp.tag_ref() = tagId; // book tagIdResult = schemaMng_->toTagID(1, "book"); ASSERT_TRUE(tagIdResult.ok()); tagId = tagIdResult.value(); storage::cpp2::VertexProp bookProp; - bookProp.set_tag(tagId); + bookProp.tag_ref() = tagId; auto props = std::make_unique>(); props->emplace_back(std::move(personProp)); props->emplace_back(std::move(bookProp)); @@ -84,14 +84,14 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp prop; - prop.set_tag(tagId); - prop.set_props(std::vector{"name", "age"}); + prop.tag_ref() = tagId; + prop.props_ref() = std::vector{"name", "age"}; auto props = std::make_unique>(); props->emplace_back(std::move(prop)); storage::cpp2::Expr expr1; - expr1.set_expr(TagPropertyExpression::make(pool, "person", "name")->encode()); + expr1.expr_ref() = TagPropertyExpression::make(pool, "person", "name")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(TagPropertyExpression::make(pool, "person", "age")->encode()); + expr2.expr_ref() = TagPropertyExpression::make(pool, "person", "age")->encode(); auto exprs = std::make_unique>(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); @@ -121,24 +121,24 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp personProp; - personProp.set_tag(tagId); - personProp.set_props(std::vector{"name", "age"}); + personProp.tag_ref() = tagId; + personProp.props_ref() = std::vector{"name", "age"}; // book tagIdResult = schemaMng_->toTagID(1, "book"); ASSERT_TRUE(tagIdResult.ok()); tagId = tagIdResult.value(); storage::cpp2::VertexProp bookProp; - bookProp.set_tag(tagId); - bookProp.set_props(std::vector{"name"}); + bookProp.tag_ref() = tagId; + bookProp.props_ref() = std::vector{"name"}; auto props = std::make_unique>(); props->emplace_back(std::move(personProp)); props->emplace_back(std::move(bookProp)); storage::cpp2::Expr expr1; - expr1.set_expr(TagPropertyExpression::make(pool, "person", "name")->encode()); + expr1.expr_ref() = TagPropertyExpression::make(pool, "person", "name")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(TagPropertyExpression::make(pool, "person", "age")->encode()); + expr2.expr_ref() = TagPropertyExpression::make(pool, "person", "age")->encode(); storage::cpp2::Expr expr3; - expr3.set_expr(TagPropertyExpression::make(pool, "book", "name")->encode()); + expr3.expr_ref() = TagPropertyExpression::make(pool, "book", "name")->encode(); auto exprs = std::make_unique>(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); @@ -168,14 +168,14 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp prop; - prop.set_tag(tagId); - prop.set_props(std::vector{"name", "age"}); + prop.tag_ref() = tagId; + prop.props_ref() = std::vector{"name", "age"}; auto props = std::make_unique>(); props->emplace_back(std::move(prop)); storage::cpp2::Expr expr1; - expr1.set_expr(TagPropertyExpression::make(pool, "person", "name")->encode()); + expr1.expr_ref() = TagPropertyExpression::make(pool, "person", "name")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(TagPropertyExpression::make(pool, "person", "age")->encode()); + expr2.expr_ref() = TagPropertyExpression::make(pool, "person", "age")->encode(); auto exprs = std::make_unique>(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); @@ -208,25 +208,25 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp personProp; - personProp.set_tag(tagId); - personProp.set_props(std::vector{"name", "age"}); + personProp.tag_ref() = tagId; + personProp.props_ref() = std::vector{"name", "age"}; // book tagIdResult = schemaMng_->toTagID(1, "book"); ASSERT_TRUE(tagIdResult.ok()); tagId = tagIdResult.value(); storage::cpp2::VertexProp bookProp; - bookProp.set_tag(tagId); - bookProp.set_props(std::vector{"name"}); + bookProp.tag_ref() = tagId; + bookProp.props_ref() = std::vector{"name"}; auto props = std::make_unique>(); props->emplace_back(std::move(personProp)); props->emplace_back(std::move(bookProp)); storage::cpp2::Expr expr1; - expr1.set_expr(TagPropertyExpression::make(pool, "person", "name")->encode()); + expr1.expr_ref() = TagPropertyExpression::make(pool, "person", "name")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(TagPropertyExpression::make(pool, "book", "name")->encode()); + expr2.expr_ref() = TagPropertyExpression::make(pool, "book", "name")->encode(); storage::cpp2::Expr expr3; - expr3.set_expr(TagPropertyExpression::make(pool, "person", "age")->encode()); + expr3.expr_ref() = TagPropertyExpression::make(pool, "person", "age")->encode(); auto exprs = std::make_unique>(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); @@ -257,16 +257,16 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp prop; - prop.set_tag(tagId); - prop.set_props(std::vector{"name", "age"}); + prop.tag_ref() = tagId; + prop.props_ref() = std::vector{"name", "age"}; auto props = std::make_unique>(); props->emplace_back(std::move(prop)); storage::cpp2::Expr expr1; - expr1.set_expr( + expr1.expr_ref() = ArithmeticExpression::makeAdd(pool, TagPropertyExpression::make(pool, "person", "name"), TagPropertyExpression::make(pool, "person", "age")) - ->encode()); + ->encode(); auto exprs = std::make_unique>(); exprs->emplace_back(std::move(expr1)); @@ -296,25 +296,25 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp personProp; - personProp.set_tag(tagId); - personProp.set_props(std::vector{"name"}); + personProp.tag_ref() = tagId; + personProp.props_ref() = std::vector{"name"}; // book tagIdResult = schemaMng_->toTagID(1, "book"); ASSERT_TRUE(tagIdResult.ok()); tagId = tagIdResult.value(); storage::cpp2::VertexProp bookProp; - bookProp.set_tag(tagId); - bookProp.set_props(std::vector{"name"}); + bookProp.tag_ref() = tagId; + bookProp.props_ref() = std::vector{"name"}; auto props = std::make_unique>(); props->emplace_back(std::move(personProp)); props->emplace_back(std::move(bookProp)); storage::cpp2::Expr expr1; - expr1.set_expr( + expr1.expr_ref() = ArithmeticExpression::makeAdd(pool, TagPropertyExpression::make(pool, "person", "name"), TagPropertyExpression::make(pool, "book", "name")) - ->encode()); + ->encode(); auto exprs = std::make_unique>(); exprs->emplace_back(std::move(expr1)); auto *gv = GetVertices::make(qctx, start, 1, src, std::move(props), std::move(exprs)); @@ -342,14 +342,14 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { ASSERT_TRUE(tagIdResult.ok()); auto tagId = tagIdResult.value(); storage::cpp2::VertexProp prop; - prop.set_tag(tagId); - prop.set_props(std::vector{"name", "age"}); + prop.tag_ref() = tagId; + prop.props_ref() = std::vector{"name", "age"}; auto props = std::make_unique>(); props->emplace_back(std::move(prop)); storage::cpp2::Expr expr1; - expr1.set_expr(TagPropertyExpression::make(pool, "person", "name")->encode()); + expr1.expr_ref() = TagPropertyExpression::make(pool, "person", "name")->encode(); storage::cpp2::Expr expr2; - expr2.set_expr(TagPropertyExpression::make(pool, "person", "age")->encode()); + expr2.expr_ref() = TagPropertyExpression::make(pool, "person", "age")->encode(); auto exprs = std::make_unique>(); exprs->emplace_back(std::move(expr1)); exprs->emplace_back(std::move(expr2)); diff --git a/src/graph/validator/test/MockIndexManager.cpp b/src/graph/validator/test/MockIndexManager.cpp index f094401984e..ac3d86e7470 100644 --- a/src/graph/validator/test/MockIndexManager.cpp +++ b/src/graph/validator/test/MockIndexManager.cpp @@ -20,36 +20,36 @@ namespace graph { void MockIndexManager::init() { // index related meta::cpp2::IndexItem person_no_props_index; - person_no_props_index.set_index_id(233); - person_no_props_index.set_index_name("person_no_props_index"); + person_no_props_index.index_id_ref() = 233; + person_no_props_index.index_name_ref() = "person_no_props_index"; nebula::cpp2::SchemaID personSchemaId; - personSchemaId.set_tag_id(2); - person_no_props_index.set_schema_id(std::move(personSchemaId)); - person_no_props_index.set_schema_name("person"); + personSchemaId.tag_id_ref() = 2; + person_no_props_index.schema_id_ref() = std::move(personSchemaId); + person_no_props_index.schema_name_ref() = "person"; meta::cpp2::IndexItem book_name_index; - book_name_index.set_index_id(234); - book_name_index.set_index_name("book_name_index"); + book_name_index.index_id_ref() = 234; + book_name_index.index_name_ref() = "book_name_index"; nebula::cpp2::SchemaID bookSchemaId; - bookSchemaId.set_tag_id(5); - book_name_index.set_schema_id(std::move(bookSchemaId)); - book_name_index.set_schema_name("book"); + bookSchemaId.tag_id_ref() = 5; + book_name_index.schema_id_ref() = std::move(bookSchemaId); + book_name_index.schema_name_ref() = "book"; meta::cpp2::ColumnDef field; - field.set_name("name"); + field.name_ref() = "name"; meta::cpp2::ColumnTypeDef type; - type.set_type(nebula::cpp2::PropertyType::FIXED_STRING); - type.set_type_length(32); - field.set_type(std::move(type)); - book_name_index.set_fields({}); + type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING; + type.type_length_ref() = 32; + field.type_ref() = std::move(type); + book_name_index.fields_ref() = {}; book_name_index.fields_ref().value().emplace_back(std::move(field)); meta::cpp2::IndexItem like_index; - like_index.set_index_id(235); - like_index.set_index_name("like_index"); + like_index.index_id_ref() = 235; + like_index.index_name_ref() = "like_index"; nebula::cpp2::SchemaID likeSchemaId; - likeSchemaId.set_edge_type(3); - like_index.set_schema_id(std::move(likeSchemaId)); - like_index.set_schema_name("like"); + likeSchemaId.edge_type_ref() = 3; + like_index.schema_id_ref() = std::move(likeSchemaId); + like_index.schema_name_ref() = "like"; tagIndexes_.emplace(1, std::vector>{}); tagIndexes_[1].emplace_back( diff --git a/src/graph/validator/test/MockSchemaManager.h b/src/graph/validator/test/MockSchemaManager.h index e13ef680d21..350153067d8 100644 --- a/src/graph/validator/test/MockSchemaManager.h +++ b/src/graph/validator/test/MockSchemaManager.h @@ -110,7 +110,9 @@ class MockSchemaManager final : public nebula::meta::SchemaManager { StatusOr> getFTClients() override; - StatusOr getPartsNum(GraphSpaceID) override { LOG(FATAL) << "Unimplemented."; } + StatusOr getPartsNum(GraphSpaceID) override { + LOG(FATAL) << "Unimplemented."; + } StatusOr> getFTIndex(GraphSpaceID, int32_t) override { diff --git a/src/graph/validator/test/ValidatorTestBase.h b/src/graph/validator/test/ValidatorTestBase.h index 38ccf3fbb75..84c6e67c837 100644 --- a/src/graph/validator/test/ValidatorTestBase.h +++ b/src/graph/validator/test/ValidatorTestBase.h @@ -30,13 +30,13 @@ class ValidatorTestBase : public ::testing::Test { protected: void SetUp() override { meta::cpp2::Session session; - session.set_session_id(0); - session.set_user_name("root"); + session.session_id_ref() = 0; + session.user_name_ref() = "root"; session_ = ClientSession::create(std::move(session), nullptr); SpaceInfo spaceInfo; spaceInfo.name = "test_space"; spaceInfo.id = 1; - spaceInfo.spaceDesc.set_space_name("test_space"); + spaceInfo.spaceDesc.space_name_ref() = "test_space"; session_->setSpace(std::move(spaceInfo)); schemaMng_ = CHECK_NOTNULL(MockSchemaManager::makeUnique()); indexMng_ = CHECK_NOTNULL(MockIndexManager::makeUnique()); diff --git a/src/graph/visitor/DeducePropsVisitor.cpp b/src/graph/visitor/DeducePropsVisitor.cpp index a9ac325364f..6e728407f82 100644 --- a/src/graph/visitor/DeducePropsVisitor.cpp +++ b/src/graph/visitor/DeducePropsVisitor.cpp @@ -18,7 +18,9 @@ void ExpressionProps::insertVarProp(const std::string &outputVar, folly::StringP props.emplace(prop); } -void ExpressionProps::insertInputProp(folly::StringPiece prop) { inputProps_.emplace(prop); } +void ExpressionProps::insertInputProp(folly::StringPiece prop) { + inputProps_.emplace(prop); +} void ExpressionProps::insertSrcTagProp(TagID tagId, folly::StringPiece prop) { auto &props = srcTagProps_[tagId]; @@ -108,17 +110,23 @@ void ExpressionProps::unionProps(ExpressionProps exprProps) { DeducePropsVisitor::DeducePropsVisitor(QueryContext *qctx, GraphSpaceID space, ExpressionProps *exprProps, - std::set *userDefinedVarNameList) + std::set *userDefinedVarNameList, + std::vector *tagIds, + std::vector *edgeTypes) : qctx_(qctx), space_(space), exprProps_(exprProps), - userDefinedVarNameList_(userDefinedVarNameList) { + userDefinedVarNameList_(userDefinedVarNameList), + tagIds_(tagIds), + edgeTypes_(edgeTypes) { DCHECK(qctx != nullptr); DCHECK(exprProps != nullptr); DCHECK(userDefinedVarNameList != nullptr); } -void DeducePropsVisitor::visit(EdgePropertyExpression *expr) { visitEdgePropExpr(expr); } +void DeducePropsVisitor::visit(EdgePropertyExpression *expr) { + visitEdgePropExpr(expr); +} void DeducePropsVisitor::visit(TagPropertyExpression *expr) { auto status = qctx_->schemaMng()->toTagID(space_, expr->sym()); @@ -157,33 +165,93 @@ void DeducePropsVisitor::visit(SourcePropertyExpression *expr) { exprProps_->insertSrcTagProp(std::move(status).value(), expr->prop()); } -void DeducePropsVisitor::visit(EdgeSrcIdExpression *expr) { visitEdgePropExpr(expr); } - -void DeducePropsVisitor::visit(EdgeTypeExpression *expr) { visitEdgePropExpr(expr); } +void DeducePropsVisitor::visit(EdgeSrcIdExpression *expr) { + visitEdgePropExpr(expr); +} -void DeducePropsVisitor::visit(EdgeRankExpression *expr) { visitEdgePropExpr(expr); } +void DeducePropsVisitor::visit(EdgeTypeExpression *expr) { + visitEdgePropExpr(expr); +} -void DeducePropsVisitor::visit(EdgeDstIdExpression *expr) { visitEdgePropExpr(expr); } +void DeducePropsVisitor::visit(EdgeRankExpression *expr) { + visitEdgePropExpr(expr); +} -void DeducePropsVisitor::visit(UUIDExpression *expr) { reportError(expr); } +void DeducePropsVisitor::visit(EdgeDstIdExpression *expr) { + visitEdgePropExpr(expr); +} -void DeducePropsVisitor::visit(VariableExpression *expr) { UNUSED(expr); } +void DeducePropsVisitor::visit(UUIDExpression *expr) { + reportError(expr); +} -void DeducePropsVisitor::visit(VersionedVariableExpression *expr) { reportError(expr); } +void DeducePropsVisitor::visit(VariableExpression *expr) { + UNUSED(expr); +} -void DeducePropsVisitor::visit(LabelExpression *expr) { reportError(expr); } +void DeducePropsVisitor::visit(VersionedVariableExpression *expr) { + reportError(expr); +} -void DeducePropsVisitor::visit(AttributeExpression *expr) { UNUSED(expr); } +void DeducePropsVisitor::visit(LabelExpression *expr) { + reportError(expr); +} -void DeducePropsVisitor::visit(LabelAttributeExpression *expr) { reportError(expr); } +void DeducePropsVisitor::visit(LabelAttributeExpression *expr) { + reportError(expr); +} -void DeducePropsVisitor::visit(ConstantExpression *expr) { UNUSED(expr); } +void DeducePropsVisitor::visit(ConstantExpression *expr) { + UNUSED(expr); +} -void DeducePropsVisitor::visit(VertexExpression *expr) { UNUSED(expr); } +void DeducePropsVisitor::visit(ColumnExpression *expr) { + UNUSED(expr); +} -void DeducePropsVisitor::visit(EdgeExpression *expr) { UNUSED(expr); } +void DeducePropsVisitor::visit(VertexExpression *expr) { + if (tagIds_ == nullptr) { + UNUSED(expr); + return; + } + const auto &colName = expr->name(); + for (const auto &tagID : *tagIds_) { + const auto &tagSchema = qctx_->schemaMng()->getTagSchema(space_, tagID); + if (colName == "$^") { + exprProps_->insertSrcTagProp(tagID, nebula::kTag); + for (size_t i = 0; i < tagSchema->getNumFields(); ++i) { + exprProps_->insertSrcTagProp(tagID, tagSchema->getFieldName(i)); + } + } else if (colName == "$$") { + exprProps_->insertDstTagProp(tagID, nebula::kTag); + for (size_t i = 0; i < tagSchema->getNumFields(); ++i) { + exprProps_->insertDstTagProp(tagID, tagSchema->getFieldName(i)); + } + } else { + exprProps_->insertTagProp(tagID, nebula::kTag); + for (size_t i = 0; i < tagSchema->getNumFields(); ++i) { + exprProps_->insertTagProp(tagID, tagSchema->getFieldName(i)); + } + } + } +} -void DeducePropsVisitor::visit(ColumnExpression *expr) { UNUSED(expr); } +void DeducePropsVisitor::visit(EdgeExpression *expr) { + if (edgeTypes_ == nullptr) { + UNUSED(expr); + return; + } + for (const auto &edgeType : *edgeTypes_) { + const auto &edgeSchema = qctx_->schemaMng()->getEdgeSchema(space_, std::abs(edgeType)); + exprProps_->insertEdgeProp(edgeType, kType); + exprProps_->insertEdgeProp(edgeType, kSrc); + exprProps_->insertEdgeProp(edgeType, kDst); + exprProps_->insertEdgeProp(edgeType, kRank); + for (size_t i = 0; i < edgeSchema->getNumFields(); ++i) { + exprProps_->insertEdgeProp(edgeType, edgeSchema->getFieldName(i)); + } + } +} void DeducePropsVisitor::visitEdgePropExpr(PropertyExpression *expr) { auto status = qctx_->schemaMng()->toEdgeType(space_, expr->sym()); diff --git a/src/graph/visitor/DeducePropsVisitor.h b/src/graph/visitor/DeducePropsVisitor.h index bf71f25d7b3..a7bb0674380 100644 --- a/src/graph/visitor/DeducePropsVisitor.h +++ b/src/graph/visitor/DeducePropsVisitor.h @@ -28,17 +28,35 @@ class ExpressionProps final { ExpressionProps() = default; ~ExpressionProps() = default; - const std::set& inputProps() const { return inputProps_; } - const TagIDPropsMap& srcTagProps() const { return srcTagProps_; } - const TagIDPropsMap& dstTagProps() const { return dstTagProps_; } - const TagIDPropsMap& tagProps() const { return tagProps_; } - const TagNameIds& tagNameIds() const { return tagNameIds_; } - const EdgePropMap& edgeProps() const { return edgeProps_; } - const VarPropMap& varProps() const { return varProps_; } + const std::set& inputProps() const { + return inputProps_; + } + const TagIDPropsMap& srcTagProps() const { + return srcTagProps_; + } + const TagIDPropsMap& dstTagProps() const { + return dstTagProps_; + } + const TagIDPropsMap& tagProps() const { + return tagProps_; + } + const TagNameIds& tagNameIds() const { + return tagNameIds_; + } + const EdgePropMap& edgeProps() const { + return edgeProps_; + } + const VarPropMap& varProps() const { + return varProps_; + } - bool hasInputVarProperty() const { return !inputProps_.empty() || !varProps_.empty(); } + bool hasInputVarProperty() const { + return !inputProps_.empty() || !varProps_.empty(); + } - bool hasSrcDstTagProperty() const { return !srcTagProps_.empty() || !dstTagProps_.empty(); } + bool hasSrcDstTagProperty() const { + return !srcTagProps_.empty() || !dstTagProps_.empty(); + } bool isAllPropsEmpty() const { return inputProps_.empty() && varProps_.empty() && srcTagProps_.empty() && edgeProps_.empty() && @@ -71,11 +89,17 @@ class DeducePropsVisitor : public ExprVisitorImpl { DeducePropsVisitor(QueryContext* qctx, GraphSpaceID space, ExpressionProps* exprProps, - std::set* userDefinedVarNameList); + std::set* userDefinedVarNameList, + std::vector* tagIds, + std::vector* edgeTypes); - bool ok() const override { return status_.ok(); } + bool ok() const override { + return status_.ok(); + } - const Status& status() const { return status_; } + const Status& status() const { + return status_; + } private: using ExprVisitorImpl::visit; @@ -93,7 +117,6 @@ class DeducePropsVisitor : public ExprVisitorImpl { void visit(VariableExpression* expr) override; void visit(VersionedVariableExpression* expr) override; void visit(LabelExpression* expr) override; - void visit(AttributeExpression* expr) override; void visit(LabelAttributeExpression* expr) override; void visit(ConstantExpression* expr) override; void visit(VertexExpression* expr) override; @@ -107,6 +130,8 @@ class DeducePropsVisitor : public ExprVisitorImpl { GraphSpaceID space_; ExpressionProps* exprProps_{nullptr}; std::set* userDefinedVarNameList_{nullptr}; + std::vector* tagIds_{nullptr}; + std::vector* edgeTypes_{nullptr}; Status status_; }; diff --git a/src/graph/visitor/DeduceTypeVisitor.cpp b/src/graph/visitor/DeduceTypeVisitor.cpp index 0ae98f328f2..aea115cc358 100644 --- a/src/graph/visitor/DeduceTypeVisitor.cpp +++ b/src/graph/visitor/DeduceTypeVisitor.cpp @@ -210,7 +210,9 @@ void DeduceTypeVisitor::visit(TypeCastingExpression *expr) { status_ = Status::OK(); } -void DeduceTypeVisitor::visit(LabelExpression *) { type_ = Value::Type::__EMPTY__; } +void DeduceTypeVisitor::visit(LabelExpression *) { + type_ = Value::Type::__EMPTY__; +} void DeduceTypeVisitor::visit(ArithmeticExpression *expr) { switch (expr->kind()) { @@ -430,7 +432,9 @@ void DeduceTypeVisitor::visit(AggregateExpression *expr) { type_ = Value::Type::__EMPTY__; } -void DeduceTypeVisitor::visit(UUIDExpression *) { type_ = Value::Type::STRING; } +void DeduceTypeVisitor::visit(UUIDExpression *) { + type_ = Value::Type::STRING; +} void DeduceTypeVisitor::visit(VariableExpression *) { // Will not deduce the actual value type of variable expression. @@ -442,13 +446,21 @@ void DeduceTypeVisitor::visit(VersionedVariableExpression *) { type_ = Value::Type::__EMPTY__; } -void DeduceTypeVisitor::visit(ListExpression *) { type_ = Value::Type::LIST; } +void DeduceTypeVisitor::visit(ListExpression *) { + type_ = Value::Type::LIST; +} -void DeduceTypeVisitor::visit(SetExpression *) { type_ = Value::Type::SET; } +void DeduceTypeVisitor::visit(SetExpression *) { + type_ = Value::Type::SET; +} -void DeduceTypeVisitor::visit(MapExpression *) { type_ = Value::Type::MAP; } +void DeduceTypeVisitor::visit(MapExpression *) { + type_ = Value::Type::MAP; +} -void DeduceTypeVisitor::visit(TagPropertyExpression *expr) { visitVertexPropertyExpr(expr); } +void DeduceTypeVisitor::visit(TagPropertyExpression *expr) { + visitVertexPropertyExpr(expr); +} void DeduceTypeVisitor::visit(EdgePropertyExpression *expr) { const auto &edge = expr->sym(); @@ -505,23 +517,41 @@ void DeduceTypeVisitor::visit(VariablePropertyExpression *expr) { type_ = found->type; } -void DeduceTypeVisitor::visit(DestPropertyExpression *expr) { visitVertexPropertyExpr(expr); } +void DeduceTypeVisitor::visit(DestPropertyExpression *expr) { + visitVertexPropertyExpr(expr); +} -void DeduceTypeVisitor::visit(SourcePropertyExpression *expr) { visitVertexPropertyExpr(expr); } +void DeduceTypeVisitor::visit(SourcePropertyExpression *expr) { + visitVertexPropertyExpr(expr); +} -void DeduceTypeVisitor::visit(EdgeSrcIdExpression *) { type_ = vidType_; } +void DeduceTypeVisitor::visit(EdgeSrcIdExpression *) { + type_ = vidType_; +} -void DeduceTypeVisitor::visit(EdgeTypeExpression *) { type_ = Value::Type::INT; } +void DeduceTypeVisitor::visit(EdgeTypeExpression *) { + type_ = Value::Type::INT; +} -void DeduceTypeVisitor::visit(EdgeRankExpression *) { type_ = Value::Type::INT; } +void DeduceTypeVisitor::visit(EdgeRankExpression *) { + type_ = Value::Type::INT; +} -void DeduceTypeVisitor::visit(EdgeDstIdExpression *) { type_ = vidType_; } +void DeduceTypeVisitor::visit(EdgeDstIdExpression *) { + type_ = vidType_; +} -void DeduceTypeVisitor::visit(VertexExpression *) { type_ = Value::Type::VERTEX; } +void DeduceTypeVisitor::visit(VertexExpression *) { + type_ = Value::Type::VERTEX; +} -void DeduceTypeVisitor::visit(EdgeExpression *) { type_ = Value::Type::EDGE; } +void DeduceTypeVisitor::visit(EdgeExpression *) { + type_ = Value::Type::EDGE; +} -void DeduceTypeVisitor::visit(ColumnExpression *) { type_ = Value::Type::__EMPTY__; } +void DeduceTypeVisitor::visit(ColumnExpression *) { + type_ = Value::Type::__EMPTY__; +} void DeduceTypeVisitor::visit(CaseExpression *expr) { if (expr->hasCondition()) { @@ -696,7 +726,9 @@ void DeduceTypeVisitor::visitVertexPropertyExpr(PropertyExpression *expr) { type_ = SchemaUtil::propTypeToValueType(field->type()); } -void DeduceTypeVisitor::visit(PathBuildExpression *) { type_ = Value::Type::PATH; } +void DeduceTypeVisitor::visit(PathBuildExpression *) { + type_ = Value::Type::PATH; +} #undef DETECT_NARYEXPR_TYPE #undef DETECT_UNARYEXPR_TYPE #undef DETECT_BIEXPR_TYPE diff --git a/src/graph/visitor/DeduceTypeVisitor.h b/src/graph/visitor/DeduceTypeVisitor.h index 8ffa078bcd7..9a32675ed8a 100644 --- a/src/graph/visitor/DeduceTypeVisitor.h +++ b/src/graph/visitor/DeduceTypeVisitor.h @@ -27,11 +27,17 @@ class DeduceTypeVisitor final : public ExprVisitor { GraphSpaceID space); ~DeduceTypeVisitor() = default; - bool ok() const { return status_.ok(); } + bool ok() const { + return status_.ok(); + } - Status status() && { return std::move(status_); } + Status status() && { + return std::move(status_); + } - Value::Type type() const { return type_; } + Value::Type type() const { + return type_; + } private: void visit(ConstantExpression *expr) override; diff --git a/src/graph/visitor/EvaluableExprVisitor.cpp b/src/graph/visitor/EvaluableExprVisitor.cpp index 0169334ab02..db75d098dfa 100644 --- a/src/graph/visitor/EvaluableExprVisitor.cpp +++ b/src/graph/visitor/EvaluableExprVisitor.cpp @@ -12,23 +12,37 @@ namespace graph { EvaluableExprVisitor::EvaluableExprVisitor(const QueryContext *qctx) : qctx_(qctx) {} -void EvaluableExprVisitor::visit(ConstantExpression *) { isEvaluable_ = true; } +void EvaluableExprVisitor::visit(ConstantExpression *) { + isEvaluable_ = true; +} -void EvaluableExprVisitor::visit(LabelExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(LabelExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(UUIDExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(UUIDExpression *) { + isEvaluable_ = false; +} void EvaluableExprVisitor::visit(VariableExpression *expr) { isEvaluable_ = (qctx_ && qctx_->existParameter(expr->var())) ? true : false; } -void EvaluableExprVisitor::visit(VersionedVariableExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(VersionedVariableExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(TagPropertyExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(TagPropertyExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(EdgePropertyExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(EdgePropertyExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(InputPropertyExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(InputPropertyExpression *) { + isEvaluable_ = false; +} void EvaluableExprVisitor::visit(VariablePropertyExpression *expr) { isEvaluable_ = (qctx_ && qctx_->existParameter(static_cast(expr)->sym())) @@ -36,25 +50,45 @@ void EvaluableExprVisitor::visit(VariablePropertyExpression *expr) { : false; } -void EvaluableExprVisitor::visit(DestPropertyExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(DestPropertyExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(SourcePropertyExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(SourcePropertyExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(EdgeSrcIdExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(EdgeSrcIdExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(EdgeTypeExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(EdgeTypeExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(EdgeRankExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(EdgeRankExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(EdgeDstIdExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(EdgeDstIdExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(VertexExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(VertexExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(EdgeExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(EdgeExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(ColumnExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(ColumnExpression *) { + isEvaluable_ = false; +} -void EvaluableExprVisitor::visit(SubscriptRangeExpression *) { isEvaluable_ = false; } +void EvaluableExprVisitor::visit(SubscriptRangeExpression *) { + isEvaluable_ = false; +} void EvaluableExprVisitor::visitBinaryExpr(BinaryExpression *expr) { expr->left()->accept(this); diff --git a/src/graph/visitor/EvaluableExprVisitor.h b/src/graph/visitor/EvaluableExprVisitor.h index 241e720e8b4..f47a681d388 100644 --- a/src/graph/visitor/EvaluableExprVisitor.h +++ b/src/graph/visitor/EvaluableExprVisitor.h @@ -15,7 +15,9 @@ class QueryContext; class EvaluableExprVisitor : public ExprVisitorImpl { public: explicit EvaluableExprVisitor(const QueryContext *qctx = nullptr); - bool ok() const override { return isEvaluable_; } + bool ok() const override { + return isEvaluable_; + } private: using ExprVisitorImpl::visit; diff --git a/src/graph/visitor/ExprVisitorImpl.cpp b/src/graph/visitor/ExprVisitorImpl.cpp index 03683ba8155..f742a7560ca 100644 --- a/src/graph/visitor/ExprVisitorImpl.cpp +++ b/src/graph/visitor/ExprVisitorImpl.cpp @@ -19,13 +19,21 @@ void ExprVisitorImpl::visit(TypeCastingExpression *expr) { } // binary expression -void ExprVisitorImpl::visit(ArithmeticExpression *expr) { visitBinaryExpr(expr); } +void ExprVisitorImpl::visit(ArithmeticExpression *expr) { + visitBinaryExpr(expr); +} -void ExprVisitorImpl::visit(RelationalExpression *expr) { visitBinaryExpr(expr); } +void ExprVisitorImpl::visit(RelationalExpression *expr) { + visitBinaryExpr(expr); +} -void ExprVisitorImpl::visit(SubscriptExpression *expr) { visitBinaryExpr(expr); } +void ExprVisitorImpl::visit(SubscriptExpression *expr) { + visitBinaryExpr(expr); +} -void ExprVisitorImpl::visit(AttributeExpression *expr) { visitBinaryExpr(expr); } +void ExprVisitorImpl::visit(AttributeExpression *expr) { + visitBinaryExpr(expr); +} void ExprVisitorImpl::visit(LogicalExpression *expr) { for (auto &operand : expr->operands()) { diff --git a/src/graph/visitor/ExtractFilterExprVisitor.cpp b/src/graph/visitor/ExtractFilterExprVisitor.cpp index ce97ddd8cba..ab156c12f4c 100644 --- a/src/graph/visitor/ExtractFilterExprVisitor.cpp +++ b/src/graph/visitor/ExtractFilterExprVisitor.cpp @@ -8,17 +8,25 @@ namespace nebula { namespace graph { -void ExtractFilterExprVisitor::visit(ConstantExpression *) { canBePushed_ = true; } +void ExtractFilterExprVisitor::visit(ConstantExpression *) { + canBePushed_ = true; +} -void ExtractFilterExprVisitor::visit(LabelExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(LabelExpression *) { + canBePushed_ = false; +} -void ExtractFilterExprVisitor::visit(UUIDExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(UUIDExpression *) { + canBePushed_ = false; +} void ExtractFilterExprVisitor::visit(VariableExpression *expr) { canBePushed_ = static_cast(expr)->isInner(); } -void ExtractFilterExprVisitor::visit(VersionedVariableExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(VersionedVariableExpression *) { + canBePushed_ = false; +} void ExtractFilterExprVisitor::visit(TagPropertyExpression *) { switch (pushType_) { @@ -46,11 +54,17 @@ void ExtractFilterExprVisitor::visit(EdgePropertyExpression *) { } } -void ExtractFilterExprVisitor::visit(InputPropertyExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(InputPropertyExpression *) { + canBePushed_ = false; +} -void ExtractFilterExprVisitor::visit(VariablePropertyExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(VariablePropertyExpression *) { + canBePushed_ = false; +} -void ExtractFilterExprVisitor::visit(DestPropertyExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(DestPropertyExpression *) { + canBePushed_ = false; +} void ExtractFilterExprVisitor::visit(SourcePropertyExpression *) { switch (pushType_) { @@ -112,11 +126,17 @@ void ExtractFilterExprVisitor::visit(EdgeDstIdExpression *) { } } -void ExtractFilterExprVisitor::visit(VertexExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(VertexExpression *) { + canBePushed_ = false; +} -void ExtractFilterExprVisitor::visit(EdgeExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(EdgeExpression *) { + canBePushed_ = false; +} -void ExtractFilterExprVisitor::visit(ColumnExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(ColumnExpression *) { + canBePushed_ = false; +} void ExtractFilterExprVisitor::visit(LogicalExpression *expr) { if (expr->kind() != Expression::Kind::kLogicalAnd) { @@ -156,7 +176,9 @@ void ExtractFilterExprVisitor::visit(LogicalExpression *expr) { } } -void ExtractFilterExprVisitor::visit(SubscriptRangeExpression *) { canBePushed_ = false; } +void ExtractFilterExprVisitor::visit(SubscriptRangeExpression *) { + canBePushed_ = false; +} } // namespace graph } // namespace nebula diff --git a/src/graph/visitor/ExtractFilterExprVisitor.h b/src/graph/visitor/ExtractFilterExprVisitor.h index 33db050234b..2b08c905407 100644 --- a/src/graph/visitor/ExtractFilterExprVisitor.h +++ b/src/graph/visitor/ExtractFilterExprVisitor.h @@ -16,9 +16,13 @@ class ExtractFilterExprVisitor final : public ExprVisitorImpl { public: explicit ExtractFilterExprVisitor(ObjectPool *ObjPool) : pool_(ObjPool) {} - bool ok() const override { return canBePushed_; } + bool ok() const override { + return canBePushed_; + } - Expression *remainedExpr() { return remainedExpr_; } + Expression *remainedExpr() { + return remainedExpr_; + } static ExtractFilterExprVisitor makePushGetNeighbors(ObjectPool *pool) { ExtractFilterExprVisitor visitor(pool); diff --git a/src/graph/visitor/ExtractPropExprVisitor.cpp b/src/graph/visitor/ExtractPropExprVisitor.cpp index 52c3cbd1b08..213ba07e5eb 100644 --- a/src/graph/visitor/ExtractPropExprVisitor.cpp +++ b/src/graph/visitor/ExtractPropExprVisitor.cpp @@ -13,32 +13,63 @@ ExtractPropExprVisitor::ExtractPropExprVisitor( YieldColumns* srcAndEdgePropCols, YieldColumns* dstPropCols, YieldColumns* inputPropCols, - std::unordered_map& propExprColMap) + std::unordered_map& propExprColMap, + std::unordered_set& uniqueEdgeVertexCol) : vctx_(DCHECK_NOTNULL(vctx)), srcAndEdgePropCols_(srcAndEdgePropCols), dstPropCols_(dstPropCols), inputPropCols_(inputPropCols), - propExprColMap_(propExprColMap) {} + propExprColMap_(propExprColMap), + uniqueEdgeVertexCol_(uniqueEdgeVertexCol) {} -void ExtractPropExprVisitor::visit(ConstantExpression* expr) { UNUSED(expr); } +void ExtractPropExprVisitor::visit(ConstantExpression* expr) { + UNUSED(expr); +} -void ExtractPropExprVisitor::visit(VertexExpression* expr) { UNUSED(expr); } +void ExtractPropExprVisitor::visit(VertexExpression* expr) { + const auto& colName = expr->name(); + if (uniqueEdgeVertexCol_.emplace(colName).second) { + if (colName == "$^") { + srcAndEdgePropCols_->addColumn(new YieldColumn(expr->clone(), colName)); + } else { + dstPropCols_->addColumn(new YieldColumn(expr->clone(), colName)); + } + } +} -void ExtractPropExprVisitor::visit(EdgeExpression* expr) { UNUSED(expr); } +void ExtractPropExprVisitor::visit(EdgeExpression* expr) { + if (uniqueEdgeVertexCol_.emplace(expr->toString()).second) { + srcAndEdgePropCols_->addColumn(new YieldColumn(expr->clone(), expr->toString())); + } +} -void ExtractPropExprVisitor::visit(VariableExpression* expr) { UNUSED(expr); } +void ExtractPropExprVisitor::visit(VariableExpression* expr) { + UNUSED(expr); +} -void ExtractPropExprVisitor::visit(SubscriptExpression* expr) { reportError(expr); } +void ExtractPropExprVisitor::visit(SubscriptExpression* expr) { + reportError(expr); +} -void ExtractPropExprVisitor::visit(LabelExpression* expr) { reportError(expr); } +void ExtractPropExprVisitor::visit(LabelExpression* expr) { + reportError(expr); +} -void ExtractPropExprVisitor::visit(LabelAttributeExpression* expr) { reportError(expr); } +void ExtractPropExprVisitor::visit(LabelAttributeExpression* expr) { + reportError(expr); +} -void ExtractPropExprVisitor::visit(VersionedVariableExpression* expr) { reportError(expr); } +void ExtractPropExprVisitor::visit(VersionedVariableExpression* expr) { + reportError(expr); +} -void ExtractPropExprVisitor::visit(UUIDExpression* expr) { reportError(expr); } +void ExtractPropExprVisitor::visit(UUIDExpression* expr) { + reportError(expr); +} -void ExtractPropExprVisitor::visit(ColumnExpression* expr) { reportError(expr); } +void ExtractPropExprVisitor::visit(ColumnExpression* expr) { + reportError(expr); +} void ExtractPropExprVisitor::visit(UnaryExpression* expr) { switch (expr->kind()) { @@ -87,9 +118,13 @@ void ExtractPropExprVisitor::visitPropertyExpr(PropertyExpression* expr) { } } -void ExtractPropExprVisitor::visit(VariablePropertyExpression* expr) { visitPropertyExpr(expr); } +void ExtractPropExprVisitor::visit(VariablePropertyExpression* expr) { + visitPropertyExpr(expr); +} -void ExtractPropExprVisitor::visit(InputPropertyExpression* expr) { visitPropertyExpr(expr); } +void ExtractPropExprVisitor::visit(InputPropertyExpression* expr) { + visitPropertyExpr(expr); +} void ExtractPropExprVisitor::visitVertexEdgePropExpr(PropertyExpression* expr) { PropertyExpression* propExpr = nullptr; @@ -135,21 +170,33 @@ void ExtractPropExprVisitor::visitVertexEdgePropExpr(PropertyExpression* expr) { } } -void ExtractPropExprVisitor::visit(TagPropertyExpression* expr) { visitVertexEdgePropExpr(expr); } +void ExtractPropExprVisitor::visit(TagPropertyExpression* expr) { + visitVertexEdgePropExpr(expr); +} void ExtractPropExprVisitor::visit(SourcePropertyExpression* expr) { visitVertexEdgePropExpr(expr); } -void ExtractPropExprVisitor::visit(EdgePropertyExpression* expr) { visitVertexEdgePropExpr(expr); } +void ExtractPropExprVisitor::visit(EdgePropertyExpression* expr) { + visitVertexEdgePropExpr(expr); +} -void ExtractPropExprVisitor::visit(EdgeSrcIdExpression* expr) { visitVertexEdgePropExpr(expr); } +void ExtractPropExprVisitor::visit(EdgeSrcIdExpression* expr) { + visitVertexEdgePropExpr(expr); +} -void ExtractPropExprVisitor::visit(EdgeTypeExpression* expr) { visitVertexEdgePropExpr(expr); } +void ExtractPropExprVisitor::visit(EdgeTypeExpression* expr) { + visitVertexEdgePropExpr(expr); +} -void ExtractPropExprVisitor::visit(EdgeRankExpression* expr) { visitVertexEdgePropExpr(expr); } +void ExtractPropExprVisitor::visit(EdgeRankExpression* expr) { + visitVertexEdgePropExpr(expr); +} -void ExtractPropExprVisitor::visit(EdgeDstIdExpression* expr) { visitVertexEdgePropExpr(expr); } +void ExtractPropExprVisitor::visit(EdgeDstIdExpression* expr) { + visitVertexEdgePropExpr(expr); +} void ExtractPropExprVisitor::visit(DestPropertyExpression* expr) { auto found = propExprColMap_.find(expr->toString()); diff --git a/src/graph/visitor/ExtractPropExprVisitor.h b/src/graph/visitor/ExtractPropExprVisitor.h index 5eda485de80..63e3c7bbc2c 100644 --- a/src/graph/visitor/ExtractPropExprVisitor.h +++ b/src/graph/visitor/ExtractPropExprVisitor.h @@ -20,13 +20,18 @@ class ExtractPropExprVisitor final : public ExprVisitorImpl { YieldColumns *srcAndEdgePropCols, YieldColumns *dstPropCols, YieldColumns *inputPropCols, - std::unordered_map &propExprColMap); + std::unordered_map &propExprColMap, + std::unordered_set &uniqueEdgeVertexCol); ~ExtractPropExprVisitor() = default; - bool ok() const override { return status_.ok(); } + bool ok() const override { + return status_.ok(); + } - const Status &status() const { return status_; } + const Status &status() const { + return status_; + } private: using ExprVisitorImpl::visit; @@ -68,6 +73,7 @@ class ExtractPropExprVisitor final : public ExprVisitorImpl { YieldColumns *dstPropCols_{nullptr}; YieldColumns *inputPropCols_{nullptr}; std::unordered_map &propExprColMap_; + std::unordered_set &uniqueEdgeVertexCol_; Status status_; }; diff --git a/src/graph/visitor/FindVisitor.cpp b/src/graph/visitor/FindVisitor.cpp index 1c31af18c97..ad9b26bca3e 100644 --- a/src/graph/visitor/FindVisitor.cpp +++ b/src/graph/visitor/FindVisitor.cpp @@ -129,35 +129,65 @@ void FindVisitor::visit(LogicalExpression* expr) { } } -void FindVisitor::visit(ConstantExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(ConstantExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(EdgePropertyExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(EdgePropertyExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(TagPropertyExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(TagPropertyExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(InputPropertyExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(InputPropertyExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(VariablePropertyExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(VariablePropertyExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(SourcePropertyExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(SourcePropertyExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(DestPropertyExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(DestPropertyExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(EdgeSrcIdExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(EdgeSrcIdExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(EdgeTypeExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(EdgeTypeExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(EdgeRankExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(EdgeRankExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(EdgeDstIdExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(EdgeDstIdExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(UUIDExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(UUIDExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(VariableExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(VariableExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(VersionedVariableExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(VersionedVariableExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(LabelExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(LabelExpression* expr) { + findInCurrentExpr(expr); +} void FindVisitor::visit(LabelAttributeExpression* expr) { findInCurrentExpr(expr); @@ -167,11 +197,17 @@ void FindVisitor::visit(LabelAttributeExpression* expr) { expr->right()->accept(this); } -void FindVisitor::visit(VertexExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(VertexExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(EdgeExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(EdgeExpression* expr) { + findInCurrentExpr(expr); +} -void FindVisitor::visit(ColumnExpression* expr) { findInCurrentExpr(expr); } +void FindVisitor::visit(ColumnExpression* expr) { + findInCurrentExpr(expr); +} void FindVisitor::visit(PathBuildExpression* expr) { findInCurrentExpr(expr); diff --git a/src/graph/visitor/FindVisitor.h b/src/graph/visitor/FindVisitor.h index 32d6446f891..d09717b38c9 100644 --- a/src/graph/visitor/FindVisitor.h +++ b/src/graph/visitor/FindVisitor.h @@ -23,13 +23,21 @@ class FindVisitor final : public ExprVisitorImpl { return true; } - bool needFindAll() const { return needFindAll_; } + bool needFindAll() const { + return needFindAll_; + } - void setNeedFindAll(bool needFindAll) { needFindAll_ = needFindAll; } + void setNeedFindAll(bool needFindAll) { + needFindAll_ = needFindAll; + } - bool found() const { return !foundExprs_.empty(); } + bool found() const { + return !foundExprs_.empty(); + } - std::vector results() const { return foundExprs_; } + std::vector results() const { + return foundExprs_; + } private: using ExprVisitorImpl::visit; diff --git a/src/graph/visitor/FoldConstantExprVisitor.cpp b/src/graph/visitor/FoldConstantExprVisitor.cpp index 5b5015e2279..0e437749299 100644 --- a/src/graph/visitor/FoldConstantExprVisitor.cpp +++ b/src/graph/visitor/FoldConstantExprVisitor.cpp @@ -50,11 +50,17 @@ void FoldConstantExprVisitor::visit(LabelAttributeExpression *expr) { } // binary expression -void FoldConstantExprVisitor::visit(ArithmeticExpression *expr) { visitBinaryExpr(expr); } +void FoldConstantExprVisitor::visit(ArithmeticExpression *expr) { + visitBinaryExpr(expr); +} -void FoldConstantExprVisitor::visit(RelationalExpression *expr) { visitBinaryExpr(expr); } +void FoldConstantExprVisitor::visit(RelationalExpression *expr) { + visitBinaryExpr(expr); +} -void FoldConstantExprVisitor::visit(SubscriptExpression *expr) { visitBinaryExpr(expr); } +void FoldConstantExprVisitor::visit(SubscriptExpression *expr) { + visitBinaryExpr(expr); +} void FoldConstantExprVisitor::visit(AttributeExpression *expr) { UNUSED(expr); diff --git a/src/graph/visitor/FoldConstantExprVisitor.h b/src/graph/visitor/FoldConstantExprVisitor.h index 0aa77b798d4..8caf1961c65 100644 --- a/src/graph/visitor/FoldConstantExprVisitor.h +++ b/src/graph/visitor/FoldConstantExprVisitor.h @@ -16,13 +16,21 @@ class FoldConstantExprVisitor final : public ExprVisitor { public: explicit FoldConstantExprVisitor(ObjectPool *pool) : pool_(pool) {} - bool canBeFolded() const { return canBeFolded_; } + bool canBeFolded() const { + return canBeFolded_; + } - bool isConstant(Expression *expr) const { return expr->kind() == Expression::Kind::kConstant; } + bool isConstant(Expression *expr) const { + return expr->kind() == Expression::Kind::kConstant; + } - bool ok() const { return status_.ok(); } + bool ok() const { + return status_.ok(); + } - Status status() && { return std::move(status_); } + Status status() && { + return std::move(status_); + } void visit(ConstantExpression *expr) override; void visit(UnaryExpression *expr) override; diff --git a/src/graph/visitor/RewriteSymExprVisitor.cpp b/src/graph/visitor/RewriteSymExprVisitor.cpp index 6f4d14a4814..192dd966fcb 100644 --- a/src/graph/visitor/RewriteSymExprVisitor.cpp +++ b/src/graph/visitor/RewriteSymExprVisitor.cpp @@ -51,9 +51,13 @@ void RewriteSymExprVisitor::visit(LabelAttributeExpression *expr) { } } -void RewriteSymExprVisitor::visit(ArithmeticExpression *expr) { visitBinaryExpr(expr); } +void RewriteSymExprVisitor::visit(ArithmeticExpression *expr) { + visitBinaryExpr(expr); +} -void RewriteSymExprVisitor::visit(RelationalExpression *expr) { visitBinaryExpr(expr); } +void RewriteSymExprVisitor::visit(RelationalExpression *expr) { + visitBinaryExpr(expr); +} void RewriteSymExprVisitor::visit(SubscriptExpression *expr) { UNUSED(expr); diff --git a/src/graph/visitor/RewriteSymExprVisitor.h b/src/graph/visitor/RewriteSymExprVisitor.h index f7210d672f4..cdd6e3a29e2 100644 --- a/src/graph/visitor/RewriteSymExprVisitor.h +++ b/src/graph/visitor/RewriteSymExprVisitor.h @@ -20,9 +20,13 @@ class RewriteSymExprVisitor final : public ExprVisitor { public: RewriteSymExprVisitor(ObjectPool *objPool, const std::string &sym, bool isEdge); - bool hasWrongType() const { return hasWrongType_; } + bool hasWrongType() const { + return hasWrongType_; + } - Expression *expr() { return expr_; } + Expression *expr() { + return expr_; + } void visit(ConstantExpression *expr) override; void visit(UnaryExpression *expr) override; diff --git a/src/graph/visitor/RewriteVisitor.h b/src/graph/visitor/RewriteVisitor.h index a11d3cc5ed9..0df5dc4b797 100644 --- a/src/graph/visitor/RewriteVisitor.h +++ b/src/graph/visitor/RewriteVisitor.h @@ -26,9 +26,13 @@ class RewriteVisitor final : public ExprVisitorImpl { Rewriter rewriter, const std::unordered_set& needVisitedTypes); - const Matcher matcher() const { return matcher_; } + const Matcher matcher() const { + return matcher_; + } - const Rewriter rewriter() const { return rewriter_; } + const Rewriter rewriter() const { + return rewriter_; + } private: explicit RewriteVisitor(Matcher matcher, Rewriter rewriter) @@ -41,7 +45,9 @@ class RewriteVisitor final : public ExprVisitorImpl { rewriter_(std::move(rewriter)), needVisitedTypes_(std::move(needVisitedTypes)) {} - bool ok() const override { return true; } + bool ok() const override { + return true; + } private: using ExprVisitorImpl::visit; diff --git a/src/graph/visitor/VidExtractVisitor.h b/src/graph/visitor/VidExtractVisitor.h index bad1c5365ae..c31a7d965ec 100644 --- a/src/graph/visitor/VidExtractVisitor.h +++ b/src/graph/visitor/VidExtractVisitor.h @@ -44,7 +44,9 @@ class VidExtractVisitor final : public ExprVisitor { std::unordered_map nodes; }; - VidPattern moveVidPattern() { return std::move(vidPattern_); } + VidPattern moveVidPattern() { + return std::move(vidPattern_); + } static VidPattern intersect(VidPattern &&left, VidPattern &&right); diff --git a/src/graph/visitor/test/CMakeLists.txt b/src/graph/visitor/test/CMakeLists.txt index bbf2e21b564..d3e9d5e2638 100644 --- a/src/graph/visitor/test/CMakeLists.txt +++ b/src/graph/visitor/test/CMakeLists.txt @@ -31,6 +31,9 @@ nebula_add_test( $ $ $ + $ + $ + $ $ $ $ diff --git a/src/graph/visitor/test/VisitorTestBase.h b/src/graph/visitor/test/VisitorTestBase.h index 003bf7ccd61..04009c0ae5a 100644 --- a/src/graph/visitor/test/VisitorTestBase.h +++ b/src/graph/visitor/test/VisitorTestBase.h @@ -102,7 +102,9 @@ class VisitorTestBase : public ::testing::Test { return TypeCastingExpression::make(pool, type, expr); } - UnaryExpression *notExpr(Expression *expr) { return UnaryExpression::makeNot(pool, expr); } + UnaryExpression *notExpr(Expression *expr) { + return UnaryExpression::makeNot(pool, expr); + } LogicalExpression *andExpr(Expression *lhs, Expression *rhs) { return LogicalExpression::makeAnd(pool, lhs, rhs); @@ -164,7 +166,9 @@ class VisitorTestBase : public ::testing::Test { return expr; } - LabelExpression *labelExpr(const std::string &name) { return LabelExpression::make(pool, name); } + LabelExpression *labelExpr(const std::string &name) { + return LabelExpression::make(pool, name); + } LabelAttributeExpression *laExpr(const std::string &name, Value value) { return LabelAttributeExpression::make( diff --git a/src/interface/common.thrift b/src/interface/common.thrift index 02349e48502..04a91d62b40 100644 --- a/src/interface/common.thrift +++ b/src/interface/common.thrift @@ -244,19 +244,11 @@ struct DirInfo { 2: list data, } -struct NodeInfo { - 1: HostAddr host, - 2: DirInfo dir, -} - -struct PartitionBackupInfo { - 1: map (cpp.template = "std::unordered_map") info, -} - struct CheckpointInfo { - 1: PartitionBackupInfo partition_info, + 1: GraphSpaceID space_id, + 2: map (cpp.template = "std::unordered_map") parts, // storage checkpoint directory name - 2: binary path, + 3: binary path, } // used for raft and drainer @@ -410,6 +402,7 @@ enum ErrorCode { E_GET_META_DIR_FAILURE = -2072, E_QUERY_NOT_FOUND = -2073, + E_AGENT_HB_FAILUE = -2074, // 3xxx for storaged E_CONSENSUS_ERROR = -3001, diff --git a/src/interface/graph.thrift b/src/interface/graph.thrift index 98204d058cd..bfdad9cd1e1 100644 --- a/src/interface/graph.thrift +++ b/src/interface/graph.thrift @@ -38,7 +38,7 @@ struct ProfilingStats { // Other profiling stats data map 4: optional map (cpp.template = "std::unordered_map") other_stats; -} (cpp.type = "nebula::ProfilingStats") +} (cpp.type = "nebula::ProfilingStats", cpp.noncopyable) // The info used for select/loop. struct PlanNodeBranchInfo { @@ -64,7 +64,7 @@ struct PlanNodeDescription { 5: optional list profiles; 6: optional PlanNodeBranchInfo branch_info; 7: optional list dependencies; -} (cpp.type = "nebula::PlanNodeDescription") +} (cpp.type = "nebula::PlanNodeDescription", cpp.noncopyable) struct PlanDescription { 1: required list plan_node_descs; @@ -75,7 +75,7 @@ struct PlanDescription { 3: required binary format; // the time optimizer spent 4: required i32 optimize_time_in_us; -} (cpp.type = "nebula::PlanDescription") +} (cpp.type = "nebula::PlanDescription", cpp.noncopyable) struct ExecutionResponse { @@ -86,7 +86,7 @@ struct ExecutionResponse { 5: optional binary error_msg; 6: optional PlanDescription plan_desc; 7: optional binary comment; // Supplementary instruction -} (cpp.type = "nebula::ExecutionResponse") +} (cpp.type = "nebula::ExecutionResponse", cpp.noncopyable) struct AuthResponse { @@ -95,7 +95,7 @@ struct AuthResponse { 3: optional i64 session_id; 4: optional i32 time_zone_offset_seconds; 5: optional binary time_zone_name; -} (cpp.type = "nebula::AuthResponse") +} (cpp.type = "nebula::AuthResponse", cpp.noncopyable) struct VerifyClientVersionResp { diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift index 931b014cf58..bec430b9424 100644 --- a/src/interface/meta.thrift +++ b/src/interface/meta.thrift @@ -560,7 +560,8 @@ enum HostRole { META = 0x01, STORAGE = 0x02, LISTENER = 0x03, - UNKNOWN = 0x04 + AGENT = 0x04, + UNKNOWN = 0x05 } (cpp.enum_strict) struct LeaderInfo { @@ -573,15 +574,40 @@ struct PartitionList { } struct HBReq { - 1: HostRole role, - 2: common.HostAddr host, - 3: ClusterID cluster_id, + 1: HostRole role, + 2: common.HostAddr host, + 3: ClusterID cluster_id, 4: optional map> (cpp.template = "std::unordered_map") leader_partIds; - 5: binary git_info_sha, + 5: binary git_info_sha, 6: optional map (cpp.template = "std::unordered_map")> (cpp.template = "std::unordered_map") disk_parts; + 7: optional common.DirInfo dir, + // version of binary + 8: optional binary version, +} + +// service(agent/metad/storaged/graphd) info +struct ServiceInfo { + 1: common.DirInfo dir, + 2: common.HostAddr addr, + 3: HostRole role, +} + +struct AgentHBReq { + 1: common.HostAddr host, + 2: binary git_info_sha, + // version of binary + 3: optional binary version, +} + +struct AgentHBResp { + 1: common.ErrorCode code, + 2: common.HostAddr leader, + // metad/graphd/storaged may in the same host + // do not include agent it self + 3: list service_list, } struct IndexFieldDef { @@ -923,25 +949,26 @@ struct GetStatsResp { 3: StatsItem stats, } -struct BackupInfo { - 1: common.HostAddr host, - 2: list info, +struct HostBackupInfo { + 1: common.HostAddr host, + // each for one data path + 2: list checkpoints, } struct SpaceBackupInfo { - 1: SpaceDesc space, - 2: list info, + 1: SpaceDesc space, + 2: list host_backups, } struct BackupMeta { // space_name => SpaceBackupInfo - 1: map (cpp.template = "std::unordered_map") backup_info, + 1: map(cpp.template = "std::unordered_map") space_backups, // sst file 2: list meta_files, // backup 3: binary backup_name, 4: bool full, - 5: bool include_system_space, + 5: bool all_spaces, 6: i64 create_time, } @@ -1106,10 +1133,9 @@ struct ReportTaskReq { } struct ListClusterInfoResp { - 1: common.ErrorCode code, - 2: common.HostAddr leader, - 3: list meta_servers, - 4: list storage_servers, + 1: common.ErrorCode code, + 2: common.HostAddr leader, + 3: map>(cpp.template = "std::unordered_map") host_services, } struct ListClusterInfoReq { @@ -1195,6 +1221,7 @@ service MetaService { ExecResp changePassword(1: ChangePasswordReq req); HBResp heartBeat(1: HBReq req); + AgentHBResp agentHeartbeat(1: AgentHBReq req); ExecResp regConfig(1: RegConfigReq req); GetConfigResp getConfig(1: GetConfigReq req); @@ -1214,10 +1241,8 @@ service MetaService { GetZoneResp getZone(1: GetZoneReq req); ListZonesResp listZones(1: ListZonesReq req); - CreateBackupResp createBackup(1: CreateBackupReq req); - ExecResp restoreMeta(1: RestoreMetaReq req); - ExecResp addListener(1: AddListenerReq req); - ExecResp removeListener(1: RemoveListenerReq req); + ExecResp addListener(1: AddListenerReq req); + ExecResp removeListener(1: RemoveListenerReq req); ListListenerResp listListener(1: ListListenerReq req); GetStatsResp getStats(1: GetStatsReq req); @@ -1238,6 +1263,9 @@ service MetaService { ExecResp reportTaskFinish(1: ReportTaskReq req); + // Interfaces for backup and restore + CreateBackupResp createBackup(1: CreateBackupReq req); + ExecResp restoreMeta(1: RestoreMetaReq req); ListClusterInfoResp listCluster(1: ListClusterInfoReq req); GetMetaDirInfoResp getMetaDirInfo(1: GetMetaDirInfoReq req); diff --git a/src/interface/storage.thrift b/src/interface/storage.thrift index 1cf3b675bd4..2fee5c79ab3 100644 --- a/src/interface/storage.thrift +++ b/src/interface/storage.thrift @@ -750,14 +750,14 @@ struct GetLeaderReq { } struct CreateCPRequest { - 1: common.GraphSpaceID space_id, - 2: binary name, + 1: list space_ids, + 2: binary name, } struct DropCPRequest { - 1: common.GraphSpaceID space_id, - 2: binary name, + 1: list space_ids, + 2: binary name, } @@ -768,8 +768,8 @@ enum EngineSignType { struct BlockingSignRequest { - 1: common.GraphSpaceID space_id, - 2: required EngineSignType sign, + 1: list space_ids, + 2: required EngineSignType sign, } @@ -845,8 +845,6 @@ service StorageAdminService { AdminExecResp addAdminTask(1: AddAdminTaskRequest req); AdminExecResp stopAdminTask(1: StopAdminTaskRequest req); - - ListClusterInfoResp listClusterInfo(1: ListClusterInfoReq req); } diff --git a/src/kvstore/CMakeLists.txt b/src/kvstore/CMakeLists.txt index ffcc13401ab..549be980087 100644 --- a/src/kvstore/CMakeLists.txt +++ b/src/kvstore/CMakeLists.txt @@ -19,6 +19,7 @@ nebula_add_library( nebula_add_subdirectory(raftex) nebula_add_subdirectory(wal) +nebula_add_subdirectory(stats) nebula_add_subdirectory(test) #nebula_add_subdirectory(plugins) diff --git a/src/kvstore/CompactionFilter.h b/src/kvstore/CompactionFilter.h index d1c2e65b964..7fdc88731b3 100644 --- a/src/kvstore/CompactionFilter.h +++ b/src/kvstore/CompactionFilter.h @@ -32,7 +32,9 @@ class KVCompactionFilter final : public rocksdb::CompactionFilter { folly::StringPiece(val.data(), val.size())); } - const char* Name() const override { return "KVCompactionFilter"; } + const char* Name() const override { + return "KVCompactionFilter"; + } private: GraphSpaceID spaceId_; @@ -64,7 +66,9 @@ class KVCompactionFilterFactory : public rocksdb::CompactionFilterFactory { } } - const char* Name() const override { return "KVCompactionFilterFactory"; } + const char* Name() const override { + return "KVCompactionFilterFactory"; + } virtual std::unique_ptr createKVFilter() = 0; diff --git a/src/kvstore/DiskManager.cpp b/src/kvstore/DiskManager.cpp index 8070b64f51d..69cc7954054 100644 --- a/src/kvstore/DiskManager.cpp +++ b/src/kvstore/DiskManager.cpp @@ -69,6 +69,7 @@ void DiskManager::addPartToPath(GraphSpaceID spaceId, PartitionID partId, const try { auto canonical = boost::filesystem::canonical(path); auto dataPath = canonical.parent_path().parent_path(); + dataPath = boost::filesystem::absolute(dataPath); auto iter = std::find(dataPaths_.begin(), dataPaths_.end(), dataPath); CHECK(iter != dataPaths_.end()); partIndex_[spaceId][partId] = iter - dataPaths_.begin(); @@ -85,6 +86,7 @@ void DiskManager::removePartFromPath(GraphSpaceID spaceId, try { auto canonical = boost::filesystem::canonical(path); auto dataPath = canonical.parent_path().parent_path(); + dataPath = boost::filesystem::absolute(dataPath); auto iter = std::find(dataPaths_.begin(), dataPaths_.end(), dataPath); CHECK(iter != dataPaths_.end()); partIndex_[spaceId].erase(partId); @@ -104,7 +106,7 @@ void DiskManager::getDiskParts(SpaceDiskPartsMap& diskParts) { tmpPartitions.emplace_back(partition); } meta::cpp2::PartitionList ps; - ps.set_part_list(tmpPartitions); + ps.part_list_ref() = tmpPartitions; tmpPartPaths[path] = ps; } diskParts.emplace(space, std::move(tmpPartPaths)); diff --git a/src/kvstore/KVEngine.h b/src/kvstore/KVEngine.h index 5f902bc9665..d178c056f68 100644 --- a/src/kvstore/KVEngine.h +++ b/src/kvstore/KVEngine.h @@ -120,7 +120,7 @@ class KVEngine { virtual nebula::cpp2::ErrorCode flush() = 0; - virtual nebula::cpp2::ErrorCode createCheckpoint(const std::string& name) = 0; + virtual nebula::cpp2::ErrorCode createCheckpoint(const std::string& checkpointPath) = 0; // For meta virtual ErrorOr backupTable( diff --git a/src/kvstore/KVStore.h b/src/kvstore/KVStore.h index a9d12e732f3..dcda46ae7fd 100644 --- a/src/kvstore/KVStore.h +++ b/src/kvstore/KVStore.h @@ -74,7 +74,9 @@ class KVStore { virtual ErrorOr partLeader(GraphSpaceID spaceId, PartitionID partID) = 0; - virtual PartManager* partManager() const { return nullptr; } + virtual PartManager* partManager() const { + return nullptr; + } // Read a single key virtual nebula::cpp2::ErrorCode get(GraphSpaceID spaceId, diff --git a/src/kvstore/Listener.h b/src/kvstore/Listener.h index 104950f89d7..1252ff894af 100644 --- a/src/kvstore/Listener.h +++ b/src/kvstore/Listener.h @@ -106,7 +106,9 @@ class Listener : public raftex::RaftPart { // Stop listener void stop() override; - LogID getApplyId() { return lastApplyLogId_; } + LogID getApplyId() { + return lastApplyLogId_; + } void cleanup() override { CHECK(!raftLock_.try_lock()); @@ -129,11 +131,17 @@ class Listener : public raftex::RaftPart { virtual bool persist(LogID, TermID, LogID) = 0; - void onLostLeadership(TermID) override { LOG(FATAL) << "Should not reach here"; } + void onLostLeadership(TermID) override { + LOG(FATAL) << "Should not reach here"; + } - void onElected(TermID) override { LOG(FATAL) << "Should not reach here"; } + void onElected(TermID) override { + LOG(FATAL) << "Should not reach here"; + } - void onLeaderReady(TermID) override { LOG(FATAL) << "Should not reach here"; } + void onLeaderReady(TermID) override { + LOG(FATAL) << "Should not reach here"; + } void onDiscoverNewLeader(HostAddr nLeader) override { LOG(INFO) << idStr_ << "Find the new leader " << nLeader; diff --git a/src/kvstore/LogEncoder.h b/src/kvstore/LogEncoder.h index 775ce30b21b..c4d4ba3d427 100644 --- a/src/kvstore/LogEncoder.h +++ b/src/kvstore/LogEncoder.h @@ -80,14 +80,18 @@ class BatchHolder : public nebula::cpp::NonCopyable, public nebula::cpp::NonMova batch_.emplace_back(std::move(op)); } - void reserve(int32_t size) { batch_.reserve(size); } + void reserve(int32_t size) { + batch_.reserve(size); + } const std::vector>& getBatch() { return batch_; } // size of the batch, in bytes - size_t size() { return size_; } + size_t size() { + return size_; + } private: std::vector> batch_; diff --git a/src/kvstore/NebulaStore.cpp b/src/kvstore/NebulaStore.cpp index 11d05f36009..b6be72e3209 100644 --- a/src/kvstore/NebulaStore.cpp +++ b/src/kvstore/NebulaStore.cpp @@ -887,61 +887,85 @@ nebula::cpp2::ErrorCode NebulaStore::flush(GraphSpaceID spaceId) { ErrorOr> NebulaStore::createCheckpoint( GraphSpaceID spaceId, const std::string& name) { + /* + * The default checkpoint directory structure is : + * |--FLAGS_data_path + * |----nebula + * |------space1 + * |--------data + * |--------wal + * |--------checkpoints + * |----------snapshot1 + * |------------data + * |------------wal + * |----------snapshot2 + * |----------snapshot3 + * + */ auto spaceRet = space(spaceId); if (!ok(spaceRet)) { return error(spaceRet); } - auto space = nebula::value(spaceRet); - std::string cpPath; - std::unordered_map partitionInfo; - std::vector cpInfo; + std::vector cpInfoList; DCHECK(!space->engines_.empty()); - for (auto& engine : space->engines_) { - auto code = engine->createCheckpoint(name); + std::string path = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), name); + if (!fs::FileUtils::exist(path)) { + if (!fs::FileUtils::makeDir(path)) { + LOG(ERROR) << "Make checkpoint dir: " << path << " failed"; + return nebula::cpp2::ErrorCode::E_UNKNOWN; + } + } + + // create data checkpoint + std::string dataPath = folly::sformat("{}/data", path); + auto code = engine->createCheckpoint(dataPath); if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { return code; } - // Maybe there's a judgment call here. - cpPath = folly::stringPrintf("%s/checkpoints/%s", engine->getDataRoot(), name.c_str()); - // create wal hard link for all parts + + // create wal checkpoints: make hard link for all parts + std::unordered_map partsInfo; auto parts = engine->allParts(); - for (auto& part : parts) { - auto ret = this->part(spaceId, part); + for (auto& partId : parts) { + auto ret = this->part(spaceId, partId); if (!ok(ret)) { - LOG(ERROR) << "Part not found. space : " << spaceId << " Part : " << part; + LOG(ERROR) << "Part not found. space : " << spaceId << " Part : " << partId; return error(ret); } - auto walPath = - folly::stringPrintf("%s/checkpoints/%s/wal/%d", engine->getWalRoot(), name.c_str(), part); + auto p = nebula::value(ret); + auto walPath = folly::sformat("{}/wal/{}", path, partId); if (!p->linkCurrentWAL(walPath.data())) { return nebula::cpp2::ErrorCode::E_FAILED_TO_CHECKPOINT; } + // return last wal info of each part if (p->isLeader()) { auto logInfo = p->lastLogInfo(); cpp2::LogInfo info; - info.set_log_id(logInfo.first); - info.set_term_id(logInfo.second); - partitionInfo.emplace(part, std::move(info)); + info.log_id_ref() = logInfo.first; + info.term_id_ref() = logInfo.second; + partsInfo.emplace(partId, std::move(info)); } } - auto result = nebula::fs::FileUtils::realPath(cpPath.c_str()); + + auto result = nebula::fs::FileUtils::realPath(path.c_str()); if (!result.ok()) { + LOG(ERROR) << "Failed to get path:" << path << "'s real path"; return nebula::cpp2::ErrorCode::E_FAILED_TO_CHECKPOINT; } - nebula::cpp2::PartitionBackupInfo backupInfo; - nebula::cpp2::CheckpointInfo info; - backupInfo.set_info(std::move(partitionInfo)); - info.set_path(std::move(result.value())); - info.set_partition_info(std::move(backupInfo)); - cpInfo.emplace_back(std::move(info)); + + nebula::cpp2::CheckpointInfo cpInfo; + cpInfo.path_ref() = std::move(result.value()); + cpInfo.parts_ref() = std::move(partsInfo); + cpInfo.space_id_ref() = spaceId; + cpInfoList.emplace_back(std::move(cpInfo)); } - return cpInfo; + return cpInfoList; } nebula::cpp2::ErrorCode NebulaStore::dropCheckpoint(GraphSpaceID spaceId, const std::string& name) { @@ -954,12 +978,12 @@ nebula::cpp2::ErrorCode NebulaStore::dropCheckpoint(GraphSpaceID spaceId, const /** * Drop checkpoint and wal together **/ - auto checkpointPath = - folly::stringPrintf("%s/checkpoints/%s", engine->getDataRoot(), name.c_str()); + auto checkpointPath = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), name); LOG(INFO) << "Drop checkpoint : " << checkpointPath; if (!fs::FileUtils::exist(checkpointPath)) { continue; } + if (!fs::FileUtils::remove(checkpointPath.data(), true)) { LOG(ERROR) << "Drop checkpoint dir failed : " << checkpointPath; return nebula::cpp2::ErrorCode::E_STORE_FAILURE; @@ -1049,8 +1073,8 @@ int32_t NebulaStore::allLeader( auto partId = partIt.first; if (partIt.second->isLeader()) { meta::cpp2::LeaderInfo partInfo; - partInfo.set_part_id(partId); - partInfo.set_term(partIt.second->termId()); + partInfo.part_id_ref() = partId; + partInfo.term_ref() = partIt.second->termId(); leaderIds[spaceId].emplace_back(std::move(partInfo)); ++count; } diff --git a/src/kvstore/NebulaStore.h b/src/kvstore/NebulaStore.h index 2e48f1e0407..720bc8c2ee9 100644 --- a/src/kvstore/NebulaStore.h +++ b/src/kvstore/NebulaStore.h @@ -87,25 +87,41 @@ class NebulaStore : public KVStore, public Handler { void stop() override; - uint32_t capability() const override { return 0; } + uint32_t capability() const override { + return 0; + } - HostAddr address() const { return storeSvcAddr_; } + HostAddr address() const { + return storeSvcAddr_; + } - std::shared_ptr getIoPool() const { return ioPool_; } + std::shared_ptr getIoPool() const { + return ioPool_; + } - std::shared_ptr getBgWorkers() const { return bgWorkers_; } + std::shared_ptr getBgWorkers() const { + return bgWorkers_; + } - std::shared_ptr getExecutors() const { return workers_; } + std::shared_ptr getExecutors() const { + return workers_; + } // Return the current leader ErrorOr partLeader(GraphSpaceID spaceId, PartitionID partId) override; - PartManager* partManager() const override { return options_.partMan_.get(); } + PartManager* partManager() const override { + return options_.partMan_.get(); + } - bool isListener() const { return !options_.listenerPath_.empty(); } + bool isListener() const { + return !options_.listenerPath_.empty(); + } - std::vector getDataRoot() const override { return options_.dataPaths_; } + std::vector getDataRoot() const override { + return options_.dataPaths_; + } nebula::cpp2::ErrorCode get(GraphSpaceID spaceId, PartitionID partId, @@ -283,13 +299,17 @@ class NebulaStore : public KVStore, public Handler { std::function&)> func, std::vector>& existParts); - void unregisterOnNewPartAdded(const std::string& funcName) { onNewPartAdded_.erase(funcName); } + void unregisterOnNewPartAdded(const std::string& funcName) { + onNewPartAdded_.erase(funcName); + } void registerBeforeRemoveSpace(std::function func) { beforeRemoveSpace_ = func; } - void unregisterBeforeRemoveSpace() { beforeRemoveSpace_ = nullptr; } + void unregisterBeforeRemoveSpace() { + beforeRemoveSpace_ = nullptr; + } private: void loadPartFromDataPath(); diff --git a/src/kvstore/Part.cpp b/src/kvstore/Part.cpp index f3f2830fcd4..00ee16768e9 100644 --- a/src/kvstore/Part.cpp +++ b/src/kvstore/Part.cpp @@ -5,6 +5,7 @@ #include "kvstore/Part.h" +#include "common/time/ScopedTimer.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" @@ -169,7 +170,9 @@ void Part::asyncRemovePeer(const HostAddr& peer, KVCallback cb) { }); } -void Part::setBlocking(bool sign) { blocking_ = sign; } +void Part::setBlocking(bool sign) { + blocking_ = sign; +} void Part::onLostLeadership(TermID term) { VLOG(1) << "Lost the leadership for the term " << term; @@ -201,9 +204,13 @@ void Part::onLeaderReady(TermID term) { } } -void Part::registerOnLeaderReady(LeaderChangeCB cb) { leaderReadyCB_.emplace_back(std::move(cb)); } +void Part::registerOnLeaderReady(LeaderChangeCB cb) { + leaderReadyCB_.emplace_back(std::move(cb)); +} -void Part::registerOnLeaderLost(LeaderChangeCB cb) { leaderLostCB_.emplace_back(std::move(cb)); } +void Part::registerOnLeaderLost(LeaderChangeCB cb) { + leaderLostCB_.emplace_back(std::move(cb)); +} void Part::onDiscoverNewLeader(HostAddr nLeader) { LOG(INFO) << idStr_ << "Find the new leader " << nLeader; @@ -213,6 +220,7 @@ void Part::onDiscoverNewLeader(HostAddr nLeader) { } cpp2::ErrorCode Part::commitLogs(std::unique_ptr iter, bool wait) { + SCOPED_TIMER(&execTime_); auto batch = engine_->startBatchWrite(); LogID lastId = -1; TermID lastTerm = -1; @@ -354,6 +362,7 @@ std::pair Part::commitSnapshot(const std::vector& LogID committedLogId, TermID committedLogTerm, bool finished) { + SCOPED_TIMER(&execTime_); auto batch = engine_->startBatchWrite(); int64_t count = 0; int64_t size = 0; diff --git a/src/kvstore/Part.h b/src/kvstore/Part.h index c11a43ba4e7..d634528288c 100644 --- a/src/kvstore/Part.h +++ b/src/kvstore/Part.h @@ -36,9 +36,13 @@ class Part : public raftex::RaftPart { std::shared_ptr diskMan, int32_t vIdLen); - virtual ~Part() { LOG(INFO) << idStr_ << "~Part()"; } + virtual ~Part() { + LOG(INFO) << idStr_ << "~Part()"; + } - KVEngine* engine() { return engine_; } + KVEngine* engine() { + return engine_; + } void asyncPut(folly::StringPiece key, folly::StringPiece value, KVCallback cb); void asyncMultiPut(const std::vector& keyValues, KVCallback cb); @@ -64,9 +68,13 @@ class Part : public raftex::RaftPart { // Sync the information committed on follower. void sync(KVCallback cb); - void registerNewLeaderCb(NewLeaderCallback cb) { newLeaderCb_ = std::move(cb); } + void registerNewLeaderCb(NewLeaderCallback cb) { + newLeaderCb_ = std::move(cb); + } - void unRegisterNewLeaderCb() { newLeaderCb_ = nullptr; } + void unRegisterNewLeaderCb() { + newLeaderCb_ = nullptr; + } // clean up all data about this part. void resetPart() { diff --git a/src/kvstore/PartManager.cpp b/src/kvstore/PartManager.cpp index 0800ebc23ab..75046050b1f 100644 --- a/src/kvstore/PartManager.cpp +++ b/src/kvstore/PartManager.cpp @@ -8,9 +8,13 @@ namespace nebula { namespace kvstore { -meta::PartsMap MemPartManager::parts(const HostAddr&) { return partsMap_; } +meta::PartsMap MemPartManager::parts(const HostAddr&) { + return partsMap_; +} -meta::ListenersMap MemPartManager::listeners(const HostAddr&) { return listenersMap_; } +meta::ListenersMap MemPartManager::listeners(const HostAddr&) { + return listenersMap_; +} StatusOr> MemPartManager::listenerPeerExist( GraphSpaceID spaceId, PartitionID partId) { diff --git a/src/kvstore/PartManager.h b/src/kvstore/PartManager.h index ec8efd8c42c..a04644a068d 100644 --- a/src/kvstore/PartManager.h +++ b/src/kvstore/PartManager.h @@ -92,7 +92,9 @@ class PartManager { /** * Register Handler * */ - void registerHandler(Handler* handler) { handler_ = handler; } + void registerHandler(Handler* handler) { + handler_ = handler; + } protected: Handler* handler_ = nullptr; @@ -163,7 +165,9 @@ class MemPartManager final : public PartManager { } } - meta::PartsMap& partsMap() { return partsMap_; } + meta::PartsMap& partsMap() { + return partsMap_; + } meta::ListenersMap listeners(const HostAddr& host) override; diff --git a/src/kvstore/RocksEngine.cpp b/src/kvstore/RocksEngine.cpp index e386743c415..fd9c1a03851 100644 --- a/src/kvstore/RocksEngine.cpp +++ b/src/kvstore/RocksEngine.cpp @@ -62,7 +62,9 @@ class RocksWriteBatch : public WriteBatch { } } - rocksdb::WriteBatch* data() { return &batch_; } + rocksdb::WriteBatch* data() { + return &batch_; + } }; } // Anonymous namespace @@ -388,7 +390,9 @@ std::vector RocksEngine::allParts() { return parts; } -int32_t RocksEngine::totalPartsNum() { return partsNum_; } +int32_t RocksEngine::totalPartsNum() { + return partsNum_; +} nebula::cpp2::ErrorCode RocksEngine::ingest(const std::vector& files, bool verifyFileChecksum) { @@ -523,48 +527,21 @@ void RocksEngine::openBackupEngine(GraphSpaceID spaceId) { } } -nebula::cpp2::ErrorCode RocksEngine::createCheckpoint(const std::string& name) { - LOG(INFO) << "Begin checkpoint : " << dataPath_; - - /* - * The default checkpoint directory structure is : - * |--FLAGS_data_path - * |----nebula - * |------space1 - * |--------data - * |--------wal - * |--------checkpoints - * |----------snapshot1 - * |------------data - * |------------wal - * |----------snapshot2 - * |----------snapshot3 - * - */ - - auto checkpointPath = - folly::stringPrintf("%s/checkpoints/%s/data", dataPath_.c_str(), name.c_str()); - LOG(INFO) << "Target checkpoint path : " << checkpointPath; +nebula::cpp2::ErrorCode RocksEngine::createCheckpoint(const std::string& checkpointPath) { + LOG(INFO) << "Target checkpoint data path : " << checkpointPath; if (fs::FileUtils::exist(checkpointPath) && !fs::FileUtils::remove(checkpointPath.data(), true)) { - LOG(ERROR) << "Remove exist dir failed of checkpoint : " << checkpointPath; + LOG(ERROR) << "Remove exist checkpoint data dir failed: " << checkpointPath; return nebula::cpp2::ErrorCode::E_STORE_FAILURE; } - auto parent = checkpointPath.substr(0, checkpointPath.rfind('/')); - if (!FileUtils::exist(parent)) { - if (!FileUtils::makeDir(parent)) { - LOG(ERROR) << "Make dir " << parent << " failed"; - return nebula::cpp2::ErrorCode::E_UNKNOWN; - } - } - rocksdb::Checkpoint* checkpoint; rocksdb::Status status = rocksdb::Checkpoint::Create(db_.get(), &checkpoint); - std::unique_ptr cp(checkpoint); if (!status.ok()) { LOG(ERROR) << "Init checkpoint Failed: " << status.ToString(); return nebula::cpp2::ErrorCode::E_FAILED_TO_CHECKPOINT; } + + std::unique_ptr cp(checkpoint); status = cp->CreateCheckpoint(checkpointPath, 0); if (!status.ok()) { LOG(ERROR) << "Create checkpoint Failed: " << status.ToString(); @@ -590,47 +567,43 @@ ErrorOr RocksEngine::backupTable( } } - rocksdb::Options options; - options.file_checksum_gen_factory = rocksdb::GetFileChecksumGenCrc32cFactory(); - rocksdb::SstFileWriter sstFileWriter(rocksdb::EnvOptions(), options); - std::unique_ptr iter; auto ret = prefix(tablePrefix, &iter); if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { return nebula::cpp2::ErrorCode::E_BACKUP_EMPTY_TABLE; } - if (!iter->valid()) { return nebula::cpp2::ErrorCode::E_BACKUP_EMPTY_TABLE; } + rocksdb::Options options; + options.file_checksum_gen_factory = rocksdb::GetFileChecksumGenCrc32cFactory(); + rocksdb::SstFileWriter sstFileWriter(rocksdb::EnvOptions(), options); auto s = sstFileWriter.Open(backupPath); if (!s.ok()) { LOG(ERROR) << "BackupTable failed, path: " << backupPath << ", error: " << s.ToString(); return nebula::cpp2::ErrorCode::E_BACKUP_TABLE_FAILED; } - while (iter->valid()) { + for (; iter->valid(); iter->next()) { if (filter && filter(iter->key())) { - iter->next(); continue; } + s = sstFileWriter.Put(iter->key().toString(), iter->val().toString()); if (!s.ok()) { LOG(ERROR) << "BackupTable failed, path: " << backupPath << ", error: " << s.ToString(); sstFileWriter.Finish(); return nebula::cpp2::ErrorCode::E_BACKUP_TABLE_FAILED; } - iter->next(); } s = sstFileWriter.Finish(); if (!s.ok()) { - LOG(WARNING) << "Failure to insert data when backupTable, " << backupPath + LOG(WARNING) << "Failed to insert data when backupTable, " << backupPath << ", error: " << s.ToString(); return nebula::cpp2::ErrorCode::E_BACKUP_EMPTY_TABLE; } - if (sstFileWriter.FileSize() == 0) { return nebula::cpp2::ErrorCode::E_BACKUP_EMPTY_TABLE; } @@ -638,8 +611,7 @@ ErrorOr RocksEngine::backupTable( if (backupPath[0] == '/') { return backupPath; } - - auto result = nebula::fs::FileUtils::realPath(backupPath.c_str()); + auto result = FileUtils::realPath(backupPath.c_str()); if (!result.ok()) { return nebula::cpp2::ErrorCode::E_BACKUP_TABLE_FAILED; } diff --git a/src/kvstore/RocksEngine.h b/src/kvstore/RocksEngine.h index 06226b5789c..66bf1c358cd 100644 --- a/src/kvstore/RocksEngine.h +++ b/src/kvstore/RocksEngine.h @@ -30,9 +30,13 @@ class RocksRangeIter : public KVIterator { return !!iter_ && iter_->Valid() && (iter_->key().compare(end_) < 0); } - void next() override { iter_->Next(); } + void next() override { + iter_->Next(); + } - void prev() override { iter_->Prev(); } + void prev() override { + iter_->Prev(); + } folly::StringPiece key() const override { return folly::StringPiece(iter_->key().data(), iter_->key().size()); @@ -58,9 +62,13 @@ class RocksPrefixIter : public KVIterator { return !!iter_ && iter_->Valid() && (iter_->key().starts_with(prefix_)); } - void next() override { iter_->Next(); } + void next() override { + iter_->Next(); + } - void prev() override { iter_->Prev(); } + void prev() override { + iter_->Prev(); + } folly::StringPiece key() const override { return folly::StringPiece(iter_->key().data(), iter_->key().size()); @@ -81,11 +89,17 @@ class RocksCommonIter : public KVIterator { ~RocksCommonIter() = default; - bool valid() const override { return !!iter_ && iter_->Valid(); } + bool valid() const override { + return !!iter_ && iter_->Valid(); + } - void next() override { iter_->Next(); } + void next() override { + iter_->Next(); + } - void prev() override { iter_->Prev(); } + void prev() override { + iter_->Prev(); + } folly::StringPiece key() const override { return folly::StringPiece(iter_->key().data(), iter_->key().size()); @@ -116,15 +130,21 @@ class RocksEngine : public KVEngine { std::shared_ptr cfFactory = nullptr, bool readonly = false); - ~RocksEngine() { LOG(INFO) << "Release rocksdb on " << dataPath_; } + ~RocksEngine() { + LOG(INFO) << "Release rocksdb on " << dataPath_; + } void stop() override; // return path to a spaceId, e.g. "/DataPath/nebula/spaceId", usually it should // contain two subdir: data and wal. - const char* getDataRoot() const override { return dataPath_.c_str(); } + const char* getDataRoot() const override { + return dataPath_.c_str(); + } - const char* getWalRoot() const override { return walPath_.c_str(); } + const char* getWalRoot() const override { + return walPath_.c_str(); + } std::unique_ptr startBatchWrite() override; @@ -203,7 +223,7 @@ class RocksEngine : public KVEngine { /********************* * Checkpoint operation ********************/ - nebula::cpp2::ErrorCode createCheckpoint(const std::string& path) override; + nebula::cpp2::ErrorCode createCheckpoint(const std::string& checkpointPath) override; ErrorOr backupTable( const std::string& path, diff --git a/src/kvstore/plugins/hbase/HBaseStore.cpp b/src/kvstore/plugins/hbase/HBaseStore.cpp index 3d2e55270db..78784ef57cb 100644 --- a/src/kvstore/plugins/hbase/HBaseStore.cpp +++ b/src/kvstore/plugins/hbase/HBaseStore.cpp @@ -400,7 +400,9 @@ void HBaseStore::asyncRemovePrefix(GraphSpaceID spaceId, return cb(removePrefix()); } -ResultCode HBaseStore::ingest(GraphSpaceID) { LOG(FATAL) << "Unimplement"; } +ResultCode HBaseStore::ingest(GraphSpaceID) { + LOG(FATAL) << "Unimplement"; +} int32_t HBaseStore::allLeader(std::unordered_map>&) { LOG(FATAL) << "Unimplement"; diff --git a/src/kvstore/plugins/hbase/HBaseStore.h b/src/kvstore/plugins/hbase/HBaseStore.h index 3ceff2be77c..a8d628758c0 100644 --- a/src/kvstore/plugins/hbase/HBaseStore.h +++ b/src/kvstore/plugins/hbase/HBaseStore.h @@ -25,7 +25,9 @@ class HBaseRangeIter : public KVIterator { ~HBaseRangeIter() = default; - bool valid() const override { return current_ != end_; } + bool valid() const override { + return current_ != end_; + } void next() override { CHECK(current_ != end_); @@ -37,9 +39,13 @@ class HBaseRangeIter : public KVIterator { current_--; } - folly::StringPiece key() const override { return folly::StringPiece(current_->first); } + folly::StringPiece key() const override { + return folly::StringPiece(current_->first); + } - folly::StringPiece val() const override { return folly::StringPiece(current_->second); } + folly::StringPiece val() const override { + return folly::StringPiece(current_->second); + } private: KVArrayIterator current_; @@ -58,7 +64,9 @@ class HBaseStore : public KVStore { void stop() override {} - uint32_t capability() const override { return 0; } + uint32_t capability() const override { + return 0; + } // Return the current leader ErrorOr partLeader(GraphSpaceID spaceId, PartitionID partId) override { @@ -172,9 +180,13 @@ class HBaseStore : public KVStore { return ResultCode::ERR_UNSUPPORTED; } - ResultCode compact(GraphSpaceID) override { return ResultCode::ERR_UNSUPPORTED; } + ResultCode compact(GraphSpaceID) override { + return ResultCode::ERR_UNSUPPORTED; + } - ResultCode flush(GraphSpaceID) override { return ResultCode::ERR_UNSUPPORTED; } + ResultCode flush(GraphSpaceID) override { + return ResultCode::ERR_UNSUPPORTED; + } ResultCode createCheckpoint(GraphSpaceID, const std::string&) override { return ResultCode::ERR_UNSUPPORTED; @@ -184,7 +196,9 @@ class HBaseStore : public KVStore { return ResultCode::ERR_UNSUPPORTED; } - ResultCode setWriteBlocking(GraphSpaceID, bool) override { return ResultCode::ERR_UNSUPPORTED; } + ResultCode setWriteBlocking(GraphSpaceID, bool) override { + return ResultCode::ERR_UNSUPPORTED; + } private: std::string getRowKey(const std::string& key) { diff --git a/src/kvstore/raftex/Host.cpp b/src/kvstore/raftex/Host.cpp index e57dd9cb6bb..088d9fc118e 100644 --- a/src/kvstore/raftex/Host.cpp +++ b/src/kvstore/raftex/Host.cpp @@ -61,7 +61,7 @@ folly::Future Host::askForVote(const cpp2::AskForVoteR if (res != cpp2::ErrorCode::SUCCEEDED) { VLOG(2) << idStr_ << "The Host is not in a proper status, do not send"; cpp2::AskForVoteResponse resp; - resp.set_error_code(res); + resp.error_code_ref() = res; return resp; } } @@ -101,7 +101,7 @@ folly::Future Host::appendLogs(folly::EventBase* eb, if (res != cpp2::ErrorCode::SUCCEEDED) { VLOG(2) << idStr_ << "The host is not in a proper status, just return"; cpp2::AppendLogResponse r; - r.set_error_code(res); + r.error_code_ref() = res; return r; } @@ -132,7 +132,7 @@ folly::Future Host::appendLogs(folly::EventBase* eb, } else { // target host is waiting for a snapshot or wal not found cpp2::AppendLogResponse r; - r.set_error_code(error(result)); + r.error_code_ref() = error(result); return r; } } @@ -177,7 +177,7 @@ void Host::appendLogsInternal(folly::EventBase* eb, std::shared_ptrcheckStatus(); if (res != cpp2::ErrorCode::SUCCEEDED) { cpp2::AppendLogResponse r; - r.set_error_code(res); + r.error_code_ref() = res; self->setResponse(r); return; } @@ -193,7 +193,7 @@ void Host::appendLogsInternal(folly::EventBase* eb, std::shared_ptrsetResponse(r); return; } @@ -230,7 +230,7 @@ void Host::appendLogsInternal(folly::EventBase* eb, std::shared_ptridStr_ << ex.what(); cpp2::AppendLogResponse r; - r.set_error_code(cpp2::ErrorCode::E_RPC_EXCEPTION); + r.error_code_ref() = cpp2::ErrorCode::E_RPC_EXCEPTION; { std::lock_guard g(self->lock_); if (ex.getType() == TransportException::TIMED_OUT) { @@ -253,7 +253,7 @@ void Host::appendLogsInternal(folly::EventBase* eb, std::shared_ptr{}, [self = shared_from_this()](std::exception&& ex) { VLOG(2) << self->idStr_ << ex.what(); cpp2::AppendLogResponse r; - r.set_error_code(cpp2::ErrorCode::E_RPC_EXCEPTION); + r.error_code_ref() = cpp2::ErrorCode::E_RPC_EXCEPTION; { std::lock_guard g(self->lock_); self->setResponse(r); @@ -278,27 +278,27 @@ ErrorOr> Host::prepareA if (it->valid()) { auto term = it->logTerm(); auto req = std::make_shared(); - req->set_space(part_->spaceId()); - req->set_part(part_->partitionId()); - req->set_current_term(logTermToSend_); - req->set_last_log_id(logIdToSend_); - req->set_leader_addr(part_->address().host); - req->set_leader_port(part_->address().port); - req->set_committed_log_id(committedLogId_); - req->set_last_log_term_sent(lastLogTermSent_); - req->set_last_log_id_sent(lastLogIdSent_); - req->set_log_term(term); + req->space_ref() = part_->spaceId(); + req->part_ref() = part_->partitionId(); + req->current_term_ref() = logTermToSend_; + req->last_log_id_ref() = logIdToSend_; + req->leader_addr_ref() = part_->address().host; + req->leader_port_ref() = part_->address().port; + req->committed_log_id_ref() = committedLogId_; + req->last_log_term_sent_ref() = lastLogTermSent_; + req->last_log_id_sent_ref() = lastLogIdSent_; + req->log_term_ref() = term; std::vector logs; for (size_t cnt = 0; it->valid() && it->logTerm() == term && cnt < FLAGS_max_appendlog_batch_size; ++(*it), ++cnt) { nebula::cpp2::LogEntry le; - le.set_cluster(it->logSource()); - le.set_log_str(it->logMsg().toString()); + le.cluster_ref() = it->logSource(); + le.log_str_ref() = it->logMsg().toString(); logs.emplace_back(std::move(le)); } - req->set_log_str_list(std::move(logs)); + req->log_str_list_ref() = std::move(logs); return req; } else { if (!sendingSnapshot_) { @@ -342,7 +342,7 @@ folly::Future Host::sendAppendLogRequest( if (res != cpp2::ErrorCode::SUCCEEDED) { LOG(WARNING) << idStr_ << "The Host is not in a proper status, do not send"; cpp2::AppendLogResponse resp; - resp.set_error_code(res); + resp.error_code_ref() = res; return resp; } } @@ -367,15 +367,15 @@ folly::Future Host::sendHeartbeat(folly::EventBase* eb, TermID lastLogTerm, LogID lastLogId) { auto req = std::make_shared(); - req->set_space(part_->spaceId()); - req->set_part(part_->partitionId()); - req->set_current_term(term); - req->set_last_log_id(latestLogId); - req->set_committed_log_id(commitLogId); - req->set_leader_addr(part_->address().host); - req->set_leader_port(part_->address().port); - req->set_last_log_term_sent(lastLogTerm); - req->set_last_log_id_sent(lastLogId); + req->space_ref() = part_->spaceId(); + req->part_ref() = part_->partitionId(); + req->current_term_ref() = term; + req->last_log_id_ref() = latestLogId; + req->committed_log_id_ref() = commitLogId; + req->leader_addr_ref() = part_->address().host; + req->leader_port_ref() = part_->address().port; + req->last_log_term_sent_ref() = lastLogTerm; + req->last_log_id_sent_ref() = lastLogId; folly::Promise promise; auto future = promise.getFuture(); sendHeartbeatRequest(eb, std::move(req)) @@ -385,7 +385,7 @@ folly::Future Host::sendHeartbeat(folly::EventBase* eb, VLOG(3) << self->idStr_ << "heartbeat call got response"; if (t.hasException()) { cpp2::HeartbeatResponse resp; - resp.set_error_code(cpp2::ErrorCode::E_RPC_EXCEPTION); + resp.error_code_ref() = cpp2::ErrorCode::E_RPC_EXCEPTION; pro.setValue(std::move(resp)); return; } else { @@ -405,7 +405,7 @@ folly::Future Host::sendHeartbeatRequest( if (res != cpp2::ErrorCode::SUCCEEDED) { LOG(WARNING) << idStr_ << "The Host is not in a proper status, do not send"; cpp2::HeartbeatResponse resp; - resp.set_error_code(res); + resp.error_code_ref() = res; return resp; } } @@ -457,7 +457,7 @@ std::shared_ptr Host::getPendingReqIfAny(std::shared_ptr return value(result); } else { cpp2::AppendLogResponse r; - r.set_error_code(error(result)); + r.error_code_ref() = error(result); self->setResponse(r); return nullptr; } diff --git a/src/kvstore/raftex/Host.h b/src/kvstore/raftex/Host.h index db52bee54ec..d622b4a9b0b 100644 --- a/src/kvstore/raftex/Host.h +++ b/src/kvstore/raftex/Host.h @@ -7,6 +7,7 @@ #define RAFTEX_HOST_H_ #include +#include #include "common/base/Base.h" #include "common/base/ErrorOr.h" @@ -29,9 +30,13 @@ class Host final : public std::enable_shared_from_this { public: Host(const HostAddr& addr, std::shared_ptr part, bool isLearner = false); - ~Host() { LOG(INFO) << idStr_ << " The host has been destroyed!"; } + ~Host() { + LOG(INFO) << idStr_ << " The host has been destroyed!"; + } - const char* idStr() const { return idStr_.c_str(); } + const char* idStr() const { + return idStr_.c_str(); + } void stop() { std::lock_guard g(lock_); @@ -52,9 +57,13 @@ class Host final : public std::enable_shared_from_this { void waitForStop(); - bool isLearner() const { return isLearner_; } + bool isLearner() const { + return isLearner_; + } - void setLearner(bool isLearner) { isLearner_ = isLearner; } + void setLearner(bool isLearner) { + isLearner_ = isLearner; + } folly::Future askForVote(const cpp2::AskForVoteRequest& req, folly::EventBase* eb); @@ -75,7 +84,9 @@ class Host final : public std::enable_shared_from_this { TermID lastLogTerm, LogID lastLogId); - const HostAddr& address() const { return addr_; } + const HostAddr& address() const { + return addr_; + } private: cpp2::ErrorCode checkStatus() const; diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index bfa99392102..4b0678935bc 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -14,6 +14,7 @@ #include "common/base/CollectNSucceeded.h" #include "common/base/SlowOpTracker.h" #include "common/network/NetworkUtils.h" +#include "common/stats/StatsManager.h" #include "common/thread/NamedThread.h" #include "common/thrift/ThriftClientManager.h" #include "common/time/WallClock.h" @@ -21,6 +22,7 @@ #include "interface/gen-cpp2/RaftexServiceAsyncClient.h" #include "kvstore/LogEncoder.h" #include "kvstore/raftex/Host.h" +#include "kvstore/stats/KVStats.h" #include "kvstore/wal/FileBasedWal.h" DEFINE_uint32(raft_heartbeat_interval_secs, 5, "Seconds between each heartbeat"); @@ -69,13 +71,21 @@ class AppendLogsIterator final : public LogIterator { AppendLogsIterator& operator=(const AppendLogsIterator&) = delete; AppendLogsIterator& operator=(AppendLogsIterator&&) = default; - bool leadByAtomicOp() const { return leadByAtomicOp_; } + bool leadByAtomicOp() const { + return leadByAtomicOp_; + } - bool hasNonAtomicOpLogs() const { return hasNonAtomicOpLogs_; } + bool hasNonAtomicOpLogs() const { + return hasNonAtomicOpLogs_; + } - LogID firstLogId() const { return firstLogId_; } + LogID firstLogId() const { + return firstLogId_; + } - LogID lastLogId() const { return firstLogId_ + logs_.size() - 1; } + LogID lastLogId() const { + return firstLogId_ + logs_.size() - 1; + } // Return true if the current log is a AtomicOp, otherwise return false bool processAtomicOp() { @@ -123,14 +133,18 @@ class AppendLogsIterator final : public LogIterator { // The iterator becomes invalid when exhausting the logs // **OR** running into a AtomicOp log - bool valid() const override { return valid_; } + bool valid() const override { + return valid_; + } LogID logId() const override { DCHECK(valid()); return logId_; } - TermID logTerm() const override { return termId_; } + TermID logTerm() const override { + return termId_; + } ClusterID logSource() const override { DCHECK(valid()); @@ -148,7 +162,9 @@ class AppendLogsIterator final : public LogIterator { } // Return true when there is no more log left for processing - bool empty() const { return idx_ >= logs_.size(); } + bool empty() const { + return idx_ >= logs_.size(); + } // Resume the iterator so that we can continue to process the remaining logs void resume() { @@ -163,7 +179,9 @@ class AppendLogsIterator final : public LogIterator { } } - LogType logType() const { return std::get<1>(logs_.at(idx_)); } + LogType logType() const { + return std::get<1>(logs_.at(idx_)); + } private: size_t idx_{0}; @@ -872,6 +890,7 @@ void RaftPart::processAppendLogResponses(const AppendLogResponses& resps, SlowOpTracker tracker; // Step 3: Commit the batch if (commitLogs(std::move(walIt), true) == nebula::cpp2::ErrorCode::SUCCEEDED) { + stats::StatsManager::addValue(kCommitLogLatencyUs, execTime_); std::lock_guard g(raftLock_); committedLogId_ = lastLogId; firstLogId = lastLogId_ + 1; @@ -988,22 +1007,22 @@ bool RaftPart::prepareElectionRequest(cpp2::AskForVoteRequest& req, return false; } - req.set_space(spaceId_); - req.set_part(partId_); - req.set_candidate_addr(addr_.host); - req.set_candidate_port(addr_.port); + req.space_ref() = spaceId_; + req.part_ref() = partId_; + req.candidate_addr_ref() = addr_.host; + req.candidate_port_ref() = addr_.port; // Use term_ + 1 to check if peers would vote for me in prevote. // Only increase the term when prevote succeeeded. if (isPreVote) { - req.set_term(term_ + 1); + req.term_ref() = term_ + 1; } else { - req.set_term(++term_); + req.term_ref() = ++term_; // vote for myself votedAddr_ = addr_; votedTerm_ = term_; } - req.set_last_log_id(lastLogId_); - req.set_last_log_term(lastLogTerm_); + req.last_log_id_ref() = lastLogId_; + req.last_log_term_ref() = lastLogTerm_; hosts = followers(); @@ -1012,14 +1031,14 @@ bool RaftPart::prepareElectionRequest(cpp2::AskForVoteRequest& req, void RaftPart::getState(cpp2::GetStateResponse& resp) { std::lock_guard g(raftLock_); - resp.set_term(term_); - resp.set_role(role_); - resp.set_is_leader(role_ == Role::LEADER); - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); - resp.set_committed_log_id(committedLogId_); - resp.set_last_log_id(lastLogId_); - resp.set_last_log_term(lastLogTerm_); - resp.set_status(status_); + resp.term_ref() = term_; + resp.role_ref() = role_; + resp.is_leader_ref() = role_ == Role::LEADER; + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; + resp.committed_log_id_ref() = committedLogId_; + resp.last_log_id_ref() = lastLogId_; + resp.last_log_term_ref() = lastLogTerm_; + resp.status_ref() = status_; } bool RaftPart::processElectionResponses(const RaftPart::ElectionResponses& results, @@ -1270,19 +1289,19 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, // Make sure the partition is running if (UNLIKELY(status_ == Status::STOPPED)) { LOG(INFO) << idStr_ << "The part has been stopped, skip the request"; - resp.set_error_code(cpp2::ErrorCode::E_BAD_STATE); + resp.error_code_ref() = cpp2::ErrorCode::E_BAD_STATE; return; } if (UNLIKELY(status_ == Status::STARTING)) { LOG(INFO) << idStr_ << "The partition is still starting"; - resp.set_error_code(cpp2::ErrorCode::E_NOT_READY); + resp.error_code_ref() = cpp2::ErrorCode::E_NOT_READY; return; } if (UNLIKELY(status_ == Status::WAITING_SNAPSHOT)) { LOG(INFO) << idStr_ << "The partition is still waiting snapshot"; - resp.set_error_code(cpp2::ErrorCode::E_WAITING_SNAPSHOT); + resp.error_code_ref() = cpp2::ErrorCode::E_WAITING_SNAPSHOT; return; } @@ -1290,14 +1309,14 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, << lastLogId_ << ", lastLogTerm " << lastLogTerm_ << ", committedLogId " << committedLogId_ << ", term " << term_; if (role_ == Role::LEARNER) { - resp.set_error_code(cpp2::ErrorCode::E_BAD_ROLE); + resp.error_code_ref() = cpp2::ErrorCode::E_BAD_ROLE; return; } auto candidate = HostAddr(req.get_candidate_addr(), req.get_candidate_port()); auto code = checkPeer(candidate); if (code != cpp2::ErrorCode::SUCCEEDED) { - resp.set_error_code(code); + resp.error_code_ref() = code; return; } @@ -1306,7 +1325,7 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, LOG(INFO) << idStr_ << "The partition currently is on term " << term_ << ", the term proposed by the candidate is " << req.get_term() << ", so it will be rejected"; - resp.set_error_code(cpp2::ErrorCode::E_TERM_OUT_OF_DATE); + resp.error_code_ref() = cpp2::ErrorCode::E_TERM_OUT_OF_DATE; return; } @@ -1324,7 +1343,7 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, LOG(INFO) << idStr_ << "The partition's last term to receive a log is " << lastLogTerm_ << ", which is newer than the candidate's log " << req.get_last_log_term() << ". So the candidate will be rejected"; - resp.set_error_code(cpp2::ErrorCode::E_TERM_OUT_OF_DATE); + resp.error_code_ref() = cpp2::ErrorCode::E_TERM_OUT_OF_DATE; return; } @@ -1334,7 +1353,7 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, LOG(INFO) << idStr_ << "The partition's last log id is " << lastLogId_ << ". The candidate's last log id " << req.get_last_log_id() << " is smaller, so it will be rejected, candidate is " << candidate; - resp.set_error_code(cpp2::ErrorCode::E_LOG_STALE); + resp.error_code_ref() = cpp2::ErrorCode::E_LOG_STALE; return; } } @@ -1352,7 +1371,7 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, LOG(INFO) << idStr_ << "We have voted " << votedAddr_ << " on term " << votedTerm_ << ", so we should reject the candidate " << candidate << " request on term " << req.get_term(); - resp.set_error_code(cpp2::ErrorCode::E_TERM_OUT_OF_DATE); + resp.error_code_ref() = cpp2::ErrorCode::E_TERM_OUT_OF_DATE; return; } @@ -1362,7 +1381,7 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, if (req.get_is_pre_vote()) { // return succeed if it is prevote, do not change any state - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; return; } @@ -1382,11 +1401,12 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, leader_ = HostAddr("", 0); votedAddr_ = candidate; votedTerm_ = req.get_term(); - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; // Reset the last message time lastMsgRecvDur_.reset(); isBlindFollower_ = false; + stats::StatsManager::addValue(kNumRaftVotes); return; } @@ -1411,27 +1431,27 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, << ", wal lastLogId = " << wal_->lastLogId(); std::lock_guard g(raftLock_); - resp.set_current_term(term_); - resp.set_leader_addr(leader_.host); - resp.set_leader_port(leader_.port); - resp.set_committed_log_id(committedLogId_); - resp.set_last_log_id(lastLogId_ < committedLogId_ ? committedLogId_ : lastLogId_); - resp.set_last_log_term(lastLogTerm_); + resp.current_term_ref() = term_; + resp.leader_addr_ref() = leader_.host; + resp.leader_port_ref() = leader_.port; + resp.committed_log_id_ref() = committedLogId_; + resp.last_log_id_ref() = lastLogId_ < committedLogId_ ? committedLogId_ : lastLogId_; + resp.last_log_term_ref() = lastLogTerm_; // Check status if (UNLIKELY(status_ == Status::STOPPED)) { VLOG(2) << idStr_ << "The part has been stopped, skip the request"; - resp.set_error_code(cpp2::ErrorCode::E_BAD_STATE); + resp.error_code_ref() = cpp2::ErrorCode::E_BAD_STATE; return; } if (UNLIKELY(status_ == Status::STARTING)) { VLOG(2) << idStr_ << "The partition is still starting"; - resp.set_error_code(cpp2::ErrorCode::E_NOT_READY); + resp.error_code_ref() = cpp2::ErrorCode::E_NOT_READY; return; } if (UNLIKELY(status_ == Status::WAITING_SNAPSHOT)) { VLOG(2) << idStr_ << "The partition is waiting for snapshot"; - resp.set_error_code(cpp2::ErrorCode::E_WAITING_SNAPSHOT); + resp.error_code_ref() = cpp2::ErrorCode::E_WAITING_SNAPSHOT; return; } // Check leadership @@ -1439,7 +1459,7 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, if (err != cpp2::ErrorCode::SUCCEEDED) { // Wrong leadership VLOG(2) << idStr_ << "Will not follow the leader"; - resp.set_error_code(err); + resp.error_code_ref() = err; return; } @@ -1450,7 +1470,7 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, LOG(INFO) << idStr_ << "Stale log! The log " << req.get_last_log_id_sent() << ", term " << req.get_last_log_term_sent() << " i had committed yet. My committedLogId is " << committedLogId_ << ", term is " << term_; - resp.set_error_code(cpp2::ErrorCode::E_LOG_STALE); + resp.error_code_ref() = cpp2::ErrorCode::E_LOG_STALE; return; } else if (req.get_last_log_id_sent() < committedLogId_) { LOG(INFO) << idStr_ << "What?? How it happens! The log id is " << req.get_last_log_id_sent() @@ -1459,9 +1479,9 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, << ", to make the cluster stable i will follow the high term" << " candidate and cleanup my data"; reset(); - resp.set_committed_log_id(committedLogId_); - resp.set_last_log_id(lastLogId_); - resp.set_last_log_term(lastLogTerm_); + resp.committed_log_id_ref() = committedLogId_; + resp.last_log_id_ref() = lastLogId_; + resp.last_log_term_ref() = lastLogTerm_; return; } @@ -1472,7 +1492,7 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, } else if (req.get_last_log_id_sent() > lastLogId_) { // There is a gap LOG(INFO) << idStr_ << "Local is missing logs from id " << lastLogId_ << ". Need to catch up"; - resp.set_error_code(cpp2::ErrorCode::E_LOG_GAP); + resp.error_code_ref() = cpp2::ErrorCode::E_LOG_GAP; return; } else { // check the last log term is matched or not @@ -1485,10 +1505,10 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, << committedLogId_; TermID committedLogTerm = wal_->getLogTerm(committedLogId_); if (committedLogTerm > 0) { - resp.set_last_log_id(committedLogId_); - resp.set_last_log_term(committedLogTerm); + resp.last_log_id_ref() = committedLogId_; + resp.last_log_term_ref() = committedLogTerm; } - resp.set_error_code(cpp2::ErrorCode::E_LOG_GAP); + resp.error_code_ref() = cpp2::ErrorCode::E_LOG_GAP; return; } } @@ -1516,8 +1536,8 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, // stale log if (diffIndex == numLogs) { // All logs have been received before - resp.set_last_log_id(firstId + numLogs - 1); - resp.set_last_log_term(req.get_log_term()); + resp.last_log_id_ref() = firstId + numLogs - 1; + resp.last_log_term_ref() = req.get_log_term(); // nothing to append, goto commit break; } @@ -1534,7 +1554,7 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, LOG(ERROR) << idStr_ << "Rollback fail! lastLogId is" << lastLogId_ << ", logLogTerm is " << lastLogTerm_ << ", committedLogId is " << committedLogId_ << ", rollback id is " << firstId + diffIndex - 1; - resp.set_error_code(cpp2::ErrorCode::E_WAL_FAIL); + resp.error_code_ref() = cpp2::ErrorCode::E_WAL_FAIL; return; } @@ -1554,10 +1574,10 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, } lastLogId_ = wal_->lastLogId(); lastLogTerm_ = wal_->lastLogTerm(); - resp.set_last_log_id(lastLogId_); - resp.set_last_log_term(lastLogTerm_); + resp.last_log_id_ref() = lastLogId_; + resp.last_log_term_ref() = lastLogTerm_; } else { - resp.set_error_code(cpp2::ErrorCode::E_WAL_FAIL); + resp.error_code_ref() = cpp2::ErrorCode::E_WAL_FAIL; return; } } while (false); @@ -1570,26 +1590,27 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, // lack of log auto code = commitLogs(wal_->iterator(committedLogId_ + 1, lastLogIdCanCommit), false); if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { + stats::StatsManager::addValue(kCommitLogLatencyUs, execTime_); VLOG(1) << idStr_ << "Follower succeeded committing log " << committedLogId_ + 1 << " to " << lastLogIdCanCommit; committedLogId_ = lastLogIdCanCommit; - resp.set_committed_log_id(lastLogIdCanCommit); - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.committed_log_id_ref() = lastLogIdCanCommit; + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; } else if (code == nebula::cpp2::ErrorCode::E_WRITE_STALLED) { VLOG(1) << idStr_ << "Follower delay committing log " << committedLogId_ + 1 << " to " << lastLogIdCanCommit; // Even if log is not applied to state machine, still regard as succeeded: // 1. As a follower, upcoming request will try to commit them // 2. If it is elected as leader later, it will try to commit them as well - resp.set_committed_log_id(committedLogId_); - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.committed_log_id_ref() = committedLogId_; + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; } else { LOG(ERROR) << idStr_ << "Failed to commit log " << committedLogId_ + 1 << " to " << req.get_committed_log_id(); - resp.set_error_code(cpp2::ErrorCode::E_WAL_FAIL); + resp.error_code_ref() = cpp2::ErrorCode::E_WAL_FAIL; } } else { - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; } // Reset the timeout timer again in case wal and commit takes longer time than @@ -1678,22 +1699,22 @@ void RaftPart::processHeartbeatRequest(const cpp2::HeartbeatRequest& req, << ", local current term = " << term_; std::lock_guard g(raftLock_); - resp.set_current_term(term_); - resp.set_leader_addr(leader_.host); - resp.set_leader_port(leader_.port); - resp.set_committed_log_id(committedLogId_); - resp.set_last_log_id(lastLogId_ < committedLogId_ ? committedLogId_ : lastLogId_); - resp.set_last_log_term(lastLogTerm_); + resp.current_term_ref() = term_; + resp.leader_addr_ref() = leader_.host; + resp.leader_port_ref() = leader_.port; + resp.committed_log_id_ref() = committedLogId_; + resp.last_log_id_ref() = lastLogId_ < committedLogId_ ? committedLogId_ : lastLogId_; + resp.last_log_term_ref() = lastLogTerm_; // Check status if (UNLIKELY(status_ == Status::STOPPED)) { VLOG(2) << idStr_ << "The part has been stopped, skip the request"; - resp.set_error_code(cpp2::ErrorCode::E_BAD_STATE); + resp.error_code_ref() = cpp2::ErrorCode::E_BAD_STATE; return; } if (UNLIKELY(status_ == Status::STARTING)) { VLOG(2) << idStr_ << "The partition is still starting"; - resp.set_error_code(cpp2::ErrorCode::E_NOT_READY); + resp.error_code_ref() = cpp2::ErrorCode::E_NOT_READY; return; } // Check leadership @@ -1701,7 +1722,7 @@ void RaftPart::processHeartbeatRequest(const cpp2::HeartbeatRequest& req, if (err != cpp2::ErrorCode::SUCCEEDED) { // Wrong leadership VLOG(2) << idStr_ << "Will not follow the leader"; - resp.set_error_code(err); + resp.error_code_ref() = err; return; } @@ -1709,7 +1730,7 @@ void RaftPart::processHeartbeatRequest(const cpp2::HeartbeatRequest& req, lastMsgRecvDur_.reset(); // As for heartbeat, return ok after verifyLeader - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; return; } @@ -1722,24 +1743,24 @@ void RaftPart::processSendSnapshotRequest(const cpp2::SendSnapshotRequest& req, // Check status if (UNLIKELY(status_ == Status::STOPPED)) { LOG(ERROR) << idStr_ << "The part has been stopped, skip the request"; - resp.set_error_code(cpp2::ErrorCode::E_BAD_STATE); + resp.error_code_ref() = cpp2::ErrorCode::E_BAD_STATE; return; } if (UNLIKELY(status_ == Status::STARTING)) { LOG(ERROR) << idStr_ << "The partition is still starting"; - resp.set_error_code(cpp2::ErrorCode::E_NOT_READY); + resp.error_code_ref() = cpp2::ErrorCode::E_NOT_READY; return; } if (UNLIKELY(role_ != Role::FOLLOWER && role_ != Role::LEARNER)) { LOG(ERROR) << idStr_ << "Bad role " << roleStr(role_); - resp.set_error_code(cpp2::ErrorCode::E_BAD_STATE); + resp.error_code_ref() = cpp2::ErrorCode::E_BAD_STATE; return; } if (UNLIKELY(leader_ != HostAddr(req.get_leader_addr(), req.get_leader_port()) || term_ != req.get_term())) { LOG(ERROR) << idStr_ << "Term out of date, current term " << term_ << ", received term " << req.get_term(); - resp.set_error_code(cpp2::ErrorCode::E_TERM_OUT_OF_DATE); + resp.error_code_ref() = cpp2::ErrorCode::E_TERM_OUT_OF_DATE; return; } if (status_ != Status::WAITING_SNAPSHOT) { @@ -1751,13 +1772,14 @@ void RaftPart::processSendSnapshotRequest(const cpp2::SendSnapshotRequest& req, // TODO(heng): Maybe we should save them into one sst firstly? auto ret = commitSnapshot( req.get_rows(), req.get_committed_log_id(), req.get_committed_log_term(), req.get_done()); + stats::StatsManager::addValue(kCommitSnapshotLatencyUs, execTime_); lastTotalCount_ += ret.first; lastTotalSize_ += ret.second; if (lastTotalCount_ != req.get_total_count() || lastTotalSize_ != req.get_total_size()) { LOG(ERROR) << idStr_ << "Bad snapshot, total rows received " << lastTotalCount_ << ", total rows sended " << req.get_total_count() << ", total size received " << lastTotalSize_ << ", total size sended " << req.get_total_size(); - resp.set_error_code(cpp2::ErrorCode::E_PERSIST_SNAPSHOT_FAILED); + resp.error_code_ref() = cpp2::ErrorCode::E_PERSIST_SNAPSHOT_FAILED; return; } if (req.get_done()) { @@ -1772,7 +1794,7 @@ void RaftPart::processSendSnapshotRequest(const cpp2::SendSnapshotRequest& req, LOG(INFO) << idStr_ << "Receive all snapshot, committedLogId_ " << committedLogId_ << ", lastLodId " << lastLogId_ << ", lastLogTermId " << lastLogTerm_; } - resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.error_code_ref() = cpp2::ErrorCode::SUCCEEDED; return; } diff --git a/src/kvstore/raftex/RaftPart.h b/src/kvstore/raftex/RaftPart.h index 346ab53cee4..b1604cafc70 100644 --- a/src/kvstore/raftex/RaftPart.h +++ b/src/kvstore/raftex/RaftPart.h @@ -108,22 +108,34 @@ class RaftPart : public std::enable_shared_from_this { return role_ == Role::LEARNER; } - ClusterID clusterId() const { return clusterId_; } + ClusterID clusterId() const { + return clusterId_; + } - GraphSpaceID spaceId() const { return spaceId_; } + GraphSpaceID spaceId() const { + return spaceId_; + } - PartitionID partitionId() const { return partId_; } + PartitionID partitionId() const { + return partId_; + } - const HostAddr& address() const { return addr_; } + const HostAddr& address() const { + return addr_; + } HostAddr leader() const { std::lock_guard g(raftLock_); return leader_; } - TermID termId() const { return term_; } + TermID termId() const { + return term_; + } - std::shared_ptr wal() const { return wal_; } + std::shared_ptr wal() const { + return wal_; + } void addLearner(const HostAddr& learner); @@ -224,6 +236,10 @@ class RaftPart : public std::enable_shared_from_this { // Reset the part, clean up all data and WALs. void reset(); + uint64_t execTime() const { + return execTime_; + } + protected: // Protected constructor to prevent from instantiating directly RaftPart(ClusterID clusterId, @@ -241,7 +257,9 @@ class RaftPart : public std::enable_shared_from_this { using Status = cpp2::Status; using Role = cpp2::Role; - const char* idStr() const { return idStr_.c_str(); } + const char* idStr() const { + return idStr_.c_str(); + } // The method will be invoked by start() // @@ -563,6 +581,9 @@ class RaftPart : public std::enable_shared_from_this { int64_t startTimeMs_ = 0; std::atomic blocking_{false}; + + // For stats info + uint64_t execTime_{0}; }; } // namespace raftex diff --git a/src/kvstore/raftex/RaftexService.cpp b/src/kvstore/raftex/RaftexService.cpp index b1a26f8763c..622d61edd32 100644 --- a/src/kvstore/raftex/RaftexService.cpp +++ b/src/kvstore/raftex/RaftexService.cpp @@ -8,6 +8,7 @@ #include #include "common/base/Base.h" +#include "common/base/ErrorOr.h" #include "common/ssl/SSLConfig.h" #include "kvstore/raftex/RaftPart.h" @@ -97,7 +98,9 @@ void RaftexService::serve() { return; } - SCOPE_EXIT { server_->cleanUp(); }; + SCOPE_EXIT { + server_->cleanUp(); + }; status_.store(STATUS_RUNNING); LOG(INFO) << "Start the Raftex Service successfully"; @@ -177,8 +180,8 @@ void RaftexService::getState(cpp2::GetStateResponse& resp, const cpp2::GetStateR if (part != nullptr) { part->getState(resp); } else { - resp.set_term(-1); - resp.set_error_code(cpp2::ErrorCode::E_UNKNOWN_PART); + resp.term_ref() = -1; + resp.error_code_ref() = cpp2::ErrorCode::E_UNKNOWN_PART; } } @@ -186,7 +189,7 @@ void RaftexService::askForVote(cpp2::AskForVoteResponse& resp, const cpp2::AskFo auto part = findPart(req.get_space(), req.get_part()); if (!part) { // Not found - resp.set_error_code(cpp2::ErrorCode::E_UNKNOWN_PART); + resp.error_code_ref() = cpp2::ErrorCode::E_UNKNOWN_PART; return; } @@ -197,7 +200,7 @@ void RaftexService::appendLog(cpp2::AppendLogResponse& resp, const cpp2::AppendL auto part = findPart(req.get_space(), req.get_part()); if (!part) { // Not found - resp.set_error_code(cpp2::ErrorCode::E_UNKNOWN_PART); + resp.error_code_ref() = cpp2::ErrorCode::E_UNKNOWN_PART; return; } @@ -209,7 +212,7 @@ void RaftexService::sendSnapshot(cpp2::SendSnapshotResponse& resp, auto part = findPart(req.get_space(), req.get_part()); if (!part) { // Not found - resp.set_error_code(cpp2::ErrorCode::E_UNKNOWN_PART); + resp.error_code_ref() = cpp2::ErrorCode::E_UNKNOWN_PART; return; } @@ -223,7 +226,7 @@ void RaftexService::async_eb_heartbeat( auto part = findPart(req.get_space(), req.get_part()); if (!part) { // Not found - resp.set_error_code(cpp2::ErrorCode::E_UNKNOWN_PART); + resp.error_code_ref() = cpp2::ErrorCode::E_UNKNOWN_PART; callback->result(resp); return; } diff --git a/src/kvstore/raftex/RaftexService.h b/src/kvstore/raftex/RaftexService.h index 664a11c3347..888da5caddd 100644 --- a/src/kvstore/raftex/RaftexService.h +++ b/src/kvstore/raftex/RaftexService.h @@ -26,7 +26,9 @@ class RaftexService : public cpp2::RaftexServiceSvIf { uint16_t port = 0); virtual ~RaftexService(); - uint32_t getServerPort() const { return serverPort_; } + uint32_t getServerPort() const { + return serverPort_; + } std::shared_ptr getIOThreadPool() const; diff --git a/src/kvstore/raftex/SnapshotManager.cpp b/src/kvstore/raftex/SnapshotManager.cpp index b6a3adc268f..559f58377a1 100644 --- a/src/kvstore/raftex/SnapshotManager.cpp +++ b/src/kvstore/raftex/SnapshotManager.cpp @@ -116,17 +116,17 @@ folly::Future SnapshotManager::send( bool finished) { VLOG(2) << "Send snapshot request to " << addr; raftex::cpp2::SendSnapshotRequest req; - req.set_space(spaceId); - req.set_part(partId); - req.set_term(termId); - req.set_committed_log_id(committedLogId); - req.set_committed_log_term(committedLogTerm); - req.set_leader_addr(localhost.host); - req.set_leader_port(localhost.port); - req.set_rows(data); - req.set_total_size(totalSize); - req.set_total_count(totalCount); - req.set_done(finished); + req.space_ref() = spaceId; + req.part_ref() = partId; + req.term_ref() = termId; + req.committed_log_id_ref() = committedLogId; + req.committed_log_term_ref() = committedLogTerm; + req.leader_addr_ref() = localhost.host; + req.leader_port_ref() = localhost.port; + req.rows_ref() = data; + req.total_size_ref() = totalSize; + req.total_count_ref() = totalCount; + req.done_ref() = finished; auto* evb = ioThreadPool_->getEventBase(); return folly::via(evb, [this, addr, evb, req = std::move(req)]() mutable { auto client = connManager_.client(addr, evb, false, FLAGS_snapshot_send_timeout_ms); diff --git a/src/kvstore/raftex/test/CMakeLists.txt b/src/kvstore/raftex/test/CMakeLists.txt index 40982da8a59..738560fbfac 100644 --- a/src/kvstore/raftex/test/CMakeLists.txt +++ b/src/kvstore/raftex/test/CMakeLists.txt @@ -2,8 +2,9 @@ set(RAFTEX_TEST_LIBS $ $ $ - $ $ + $ + $ $ $ $ @@ -14,6 +15,10 @@ set(RAFTEX_TEST_LIBS $ $ $ + $ + $ + $ + $ ) diff --git a/src/kvstore/raftex/test/TestShard.cpp b/src/kvstore/raftex/test/TestShard.cpp index 8113a866428..66d419ad915 100644 --- a/src/kvstore/raftex/test/TestShard.cpp +++ b/src/kvstore/raftex/test/TestShard.cpp @@ -161,7 +161,9 @@ void TestShard::onElected(TermID term) { } } -void TestShard::onLeaderReady(TermID term) { UNUSED(term); } +void TestShard::onLeaderReady(TermID term) { + UNUSED(term); +} nebula::cpp2::ErrorCode TestShard::commitLogs(std::unique_ptr iter, bool) { LogID firstId = -1; @@ -240,7 +242,9 @@ void TestShard::cleanup() { lastCommittedLogId_ = 0; } -size_t TestShard::getNumLogs() const { return data_.size(); } +size_t TestShard::getNumLogs() const { + return data_.size(); +} bool TestShard::getLogMsg(size_t index, folly::StringPiece& msg) { folly::RWSpinLock::ReadHolder rh(&lock_); diff --git a/src/kvstore/raftex/test/TestShard.h b/src/kvstore/raftex/test/TestShard.h index a9ffded8560..58860429634 100644 --- a/src/kvstore/raftex/test/TestShard.h +++ b/src/kvstore/raftex/test/TestShard.h @@ -65,9 +65,13 @@ class TestShard : public RaftPart { return std::make_pair(committedLogId_, term_); } - std::shared_ptr getService() const { return service_; } + std::shared_ptr getService() const { + return service_; + } - size_t index() const { return idx_; } + size_t index() const { + return idx_; + } void onLostLeadership(TermID term) override; void onElected(TermID term) override; @@ -143,7 +147,9 @@ class NebulaSnapshotManager : public SnapshotManager { CHECK_NOTNULL(service); } - ~NebulaSnapshotManager() { LOG(INFO) << "~NebulaSnapshotManager()"; } + ~NebulaSnapshotManager() { + LOG(INFO) << "~NebulaSnapshotManager()"; + } void accessAllRowsInSnapshot(GraphSpaceID spaceId, PartitionID partId, diff --git a/src/kvstore/stats/CMakeLists.txt b/src/kvstore/stats/CMakeLists.txt new file mode 100644 index 00000000000..ff585725728 --- /dev/null +++ b/src/kvstore/stats/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2021 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. + +nebula_add_library( + kv_stats_obj + OBJECT + KVStats.cpp + ) diff --git a/src/kvstore/stats/KVStats.cpp b/src/kvstore/stats/KVStats.cpp new file mode 100644 index 00000000000..6b8996f9b58 --- /dev/null +++ b/src/kvstore/stats/KVStats.cpp @@ -0,0 +1,28 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "kvstore/stats/KVStats.h" + +#include "common/base/Base.h" +#include "common/stats/StatsManager.h" + +namespace nebula { + +stats::CounterId kCommitLogLatencyUs; +stats::CounterId kCommitSnapshotLatencyUs; +stats::CounterId kTransferLeaderLatencyUs; +stats::CounterId kNumRaftVotes; + +void initKVStats() { + kCommitLogLatencyUs = stats::StatsManager::registerHisto( + "commit_log_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kCommitSnapshotLatencyUs = stats::StatsManager::registerHisto( + "commit_snapshot_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kTransferLeaderLatencyUs = stats::StatsManager::registerHisto( + "transfer_leader_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kNumRaftVotes = stats::StatsManager::registerStats("num_raft_votes", "rate, sum"); +} + +} // namespace nebula diff --git a/src/kvstore/stats/KVStats.h b/src/kvstore/stats/KVStats.h new file mode 100644 index 00000000000..90da33a5f2a --- /dev/null +++ b/src/kvstore/stats/KVStats.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include "common/base/Base.h" +#include "common/stats/StatsManager.h" + +namespace nebula { + +extern stats::CounterId kCommitLogLatencyUs; +extern stats::CounterId kCommitSnapshotLatencyUs; +extern stats::CounterId kTransferLeaderLatencyUs; +extern stats::CounterId kNumRaftVotes; + +void initKVStats(); + +} // namespace nebula diff --git a/src/kvstore/test/CMakeLists.txt b/src/kvstore/test/CMakeLists.txt index cdcb719cf33..97eb868396c 100644 --- a/src/kvstore/test/CMakeLists.txt +++ b/src/kvstore/test/CMakeLists.txt @@ -38,6 +38,10 @@ set(KVSTORE_TEST_LIBS $ $ $ + $ + $ + $ + $ ) nebula_add_test( diff --git a/src/kvstore/test/MultiVersionBenchmark.cpp b/src/kvstore/test/MultiVersionBenchmark.cpp index 0c9a453d51f..17cb3065838 100644 --- a/src/kvstore/test/MultiVersionBenchmark.cpp +++ b/src/kvstore/test/MultiVersionBenchmark.cpp @@ -70,9 +70,13 @@ void testFn(bool withVersion) { } } -BENCHMARK(WithVersionTest) { testFn(true); } +BENCHMARK(WithVersionTest) { + testFn(true); +} -BENCHMARK(WithOutVersionTest) { testFn(false); } +BENCHMARK(WithOutVersionTest) { + testFn(false); +} } // namespace kvstore } // namespace nebula diff --git a/src/kvstore/test/NebulaListenerTest.cpp b/src/kvstore/test/NebulaListenerTest.cpp index 7cfe56cb4bd..143b89385a8 100644 --- a/src/kvstore/test/NebulaListenerTest.cpp +++ b/src/kvstore/test/NebulaListenerTest.cpp @@ -54,7 +54,9 @@ class DummyListener : public Listener { nullptr, schemaMan) {} - std::vector data() { return data_; } + std::vector data() { + return data_; + } std::pair commitSnapshot(const std::vector& data, LogID committedLogId, @@ -71,11 +73,17 @@ class DummyListener : public Listener { return result; } - std::pair committedSnapshot() { return committedSnapshot_; } + std::pair committedSnapshot() { + return committedSnapshot_; + } - std::pair committedId() { return lastCommittedLogId(); } + std::pair committedId() { + return lastCommittedLogId(); + } - int32_t snapshotBatchCount() { return snapshotBatchCount_; } + int32_t snapshotBatchCount() { + return snapshotBatchCount_; + } protected: void init() override {} @@ -87,13 +95,17 @@ class DummyListener : public Listener { return true; } - bool persist(LogID, TermID, LogID) override { return true; } + bool persist(LogID, TermID, LogID) override { + return true; + } std::pair lastCommittedLogId() override { return std::make_pair(committedLogId_, lastLogTerm_); } - LogID lastApplyLogId() override { return lastApplyLogId_; } + LogID lastApplyLogId() override { + return lastApplyLogId_; + } void cleanup() override { data_.clear(); @@ -232,8 +244,7 @@ class ListenerBasicTest : public ::testing::TestWithParam getWorkers() { - auto worker = - apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager(1, true); + auto worker = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager(1); worker->setNamePrefix("executor"); worker->start(); return worker; diff --git a/src/kvstore/test/NebulaStoreTest.cpp b/src/kvstore/test/NebulaStoreTest.cpp index f189b66449e..3bff012cdca 100644 --- a/src/kvstore/test/NebulaStoreTest.cpp +++ b/src/kvstore/test/NebulaStoreTest.cpp @@ -39,8 +39,8 @@ void dump(const std::vector& v) { } std::shared_ptr getHandlers() { - auto handlersPool = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager( - 1, true /*stats*/); + auto handlersPool = + apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager(1); handlersPool->setNamePrefix("executor"); handlersPool->start(); return handlersPool; diff --git a/src/kvstore/test/PartPerformanceTest.cpp b/src/kvstore/test/PartPerformanceTest.cpp index cf70e075a92..cb906ae8f4d 100644 --- a/src/kvstore/test/PartPerformanceTest.cpp +++ b/src/kvstore/test/PartPerformanceTest.cpp @@ -121,7 +121,9 @@ void multiThreadTest(bool useCache) { threads.emplace_back([db, i]() { range(i, db); }); } - FOR_EACH(t, threads) { t->join(); } + FOR_EACH(t, threads) { + t->join(); + } BENCHMARK_SUSPEND { db->Close(); @@ -150,7 +152,9 @@ void singleThreadTest(bool useCache, int32_t partnum) { genData(db); } - FOR_EACH_RANGE(i, 0, partnum) { range(i, db); } + FOR_EACH_RANGE(i, 0, partnum) { + range(i, db); + } BENCHMARK_SUSPEND { db->Close(); @@ -158,19 +162,29 @@ void singleThreadTest(bool useCache, int32_t partnum) { } } -BENCHMARK(ParallelMultiplePartNoCache) { multiThreadTest(true); } +BENCHMARK(ParallelMultiplePartNoCache) { + multiThreadTest(true); +} BENCHMARK(SerialMultiplePartNoCache) { singleThreadTest(true, FLAGS_part_performance_test_partnum); } -BENCHMARK(SerialSinglePartNocache) { singleThreadTest(true, 1); } +BENCHMARK(SerialSinglePartNocache) { + singleThreadTest(true, 1); +} -BENCHMARK(ParallelMultiplePartCache) { multiThreadTest(false); } +BENCHMARK(ParallelMultiplePartCache) { + multiThreadTest(false); +} -BENCHMARK(SerialMultiplePartCache) { singleThreadTest(false, FLAGS_part_performance_test_partnum); } +BENCHMARK(SerialMultiplePartCache) { + singleThreadTest(false, FLAGS_part_performance_test_partnum); +} -BENCHMARK(SerialSinglePartCache) { singleThreadTest(false, 1); } +BENCHMARK(SerialSinglePartCache) { + singleThreadTest(false, 1); +} } // namespace kvstore } // namespace nebula diff --git a/src/kvstore/test/RocksEngineConfigTest.cpp b/src/kvstore/test/RocksEngineConfigTest.cpp index c79b6cc8181..178d392ae6c 100644 --- a/src/kvstore/test/RocksEngineConfigTest.cpp +++ b/src/kvstore/test/RocksEngineConfigTest.cpp @@ -126,7 +126,9 @@ TEST(RocksEngineConfigTest, CompressionConfigTest) { ASSERT_EQ(rocksdb::kLZ4Compression, options.compression_per_level[6]); rocksdb::DB* db = nullptr; - SCOPE_EXIT { delete db; }; + SCOPE_EXIT { + delete db; + }; options.create_if_missing = true; fs::TempDir rootPath("/tmp/RocksDBCompressionConfigTest.XXXXXX"); status = rocksdb::DB::Open(options, rootPath.path(), &db); @@ -149,7 +151,9 @@ TEST(RocksEngineConfigTest, CompressionConfigTest) { ASSERT_EQ(rocksdb::kBZip2Compression, options.compression_per_level[6]); rocksdb::DB* db = nullptr; - SCOPE_EXIT { delete db; }; + SCOPE_EXIT { + delete db; + }; options.create_if_missing = true; fs::TempDir rootPath("/tmp/RocksDBCompressionConfigTest.XXXXXX"); status = rocksdb::DB::Open(options, rootPath.path(), &db); @@ -165,7 +169,9 @@ TEST(RocksEngineConfigTest, KeyValueSeparationTest) { ASSERT_TRUE(status.ok()) << status.ToString(); rocksdb::DB* db = nullptr; - SCOPE_EXIT { delete db; }; + SCOPE_EXIT { + delete db; + }; options.create_if_missing = true; fs::TempDir rootPath("/tmp/RocksDBCompressionConfigTest.XXXXXX"); status = rocksdb::DB::Open(options, rootPath.path(), &db); diff --git a/src/kvstore/wal/AtomicLogBuffer.h b/src/kvstore/wal/AtomicLogBuffer.h index 46477cf2c49..98fe8ee3ceb 100644 --- a/src/kvstore/wal/AtomicLogBuffer.h +++ b/src/kvstore/wal/AtomicLogBuffer.h @@ -26,7 +26,9 @@ struct Record { Record(ClusterID clusterId, TermID termId, std::string msg) : clusterId_(clusterId), termId_(termId), msg_(std::move(msg)) {} - int32_t size() const { return sizeof(ClusterID) + sizeof(TermID) + msg_.size(); } + int32_t size() const { + return sizeof(ClusterID) + sizeof(TermID) + msg_.size(); + } ClusterID clusterId_; TermID termId_; @@ -36,7 +38,9 @@ struct Record { struct Node { Node() = default; - bool isFull() { return pos_.load(std::memory_order_acquire) == kMaxLength; } + bool isFull() { + return pos_.load(std::memory_order_acquire) == kMaxLength; + } bool push_back(Record&& rec) { if (isFull()) { @@ -57,7 +61,9 @@ struct Node { return &(*records_)[index]; } - LogID lastLogId() const { return firstLogId_ + pos_.load(std::memory_order_relaxed); } + LogID lastLogId() const { + return firstLogId_ + pos_.load(std::memory_order_relaxed); + } LogID firstLogId_{0}; // total size for current Node. @@ -98,7 +104,9 @@ class AtomicLogBuffer : public std::enable_shared_from_this { FRIEND_TEST(AtomicLogBufferTest, SingleWriterMultiReadersTest); public: - ~Iterator() { logBuffer_->releaseRef(); } + ~Iterator() { + logBuffer_->releaseRef(); + } LogIterator& operator++() override { currIndex_++; @@ -127,18 +135,26 @@ class AtomicLogBuffer : public std::enable_shared_from_this { return *this; } - bool valid() const override { return valid_; } + bool valid() const override { + return valid_; + } LogID logId() const override { DCHECK(valid_); return currLogId_; } - TermID logTerm() const override { return record()->termId_; } + TermID logTerm() const override { + return record()->termId_; + } - ClusterID logSource() const override { return record()->clusterId_; } + ClusterID logSource() const override { + return record()->clusterId_; + } - folly::StringPiece logMsg() const override { return record()->msg_; } + folly::StringPiece logMsg() const override { + return record()->msg_; + } private: // Iterator could only be acquired by AtomicLogBuffer::iterator interface. @@ -167,9 +183,13 @@ class AtomicLogBuffer : public std::enable_shared_from_this { } } - Node* currNode() const { return currNode_; } + Node* currNode() const { + return currNode_; + } - int32_t currIndex() const { return currIndex_; } + int32_t currIndex() const { + return currIndex_; + } private: std::shared_ptr logBuffer_; @@ -257,7 +277,9 @@ class AtomicLogBuffer : public std::enable_shared_from_this { head->push_back(std::move(record)); } - LogID firstLogId() const { return firstLogId_.load(std::memory_order_relaxed); } + LogID firstLogId() const { + return firstLogId_.load(std::memory_order_relaxed); + } LogID lastLogId() const { auto* p = head_.load(std::memory_order_relaxed); @@ -333,7 +355,9 @@ class AtomicLogBuffer : public std::enable_shared_from_this { return p->markDeleted_ ? nullptr : p; } - int32_t addRef() { return refs_.fetch_add(1, std::memory_order_relaxed); } + int32_t addRef() { + return refs_.fetch_add(1, std::memory_order_relaxed); + } void releaseRef() { // All operations following SHOULD NOT reordered before tail.load() diff --git a/src/kvstore/wal/FileBasedWal.h b/src/kvstore/wal/FileBasedWal.h index 57d9439a5d3..881edfc91fb 100644 --- a/src/kvstore/wal/FileBasedWal.h +++ b/src/kvstore/wal/FileBasedWal.h @@ -60,17 +60,27 @@ class FileBasedWal final : public Wal, public std::enable_shared_from_this fn) const; - std::shared_ptr buffer() { return logBuffer_; } + std::shared_ptr buffer() { + return logBuffer_; + } private: /*************************************** diff --git a/src/kvstore/wal/WalFileInfo.h b/src/kvstore/wal/WalFileInfo.h index ef0abb2ce6f..3fcd048e5f4 100644 --- a/src/kvstore/wal/WalFileInfo.h +++ b/src/kvstore/wal/WalFileInfo.h @@ -23,21 +23,41 @@ class WalFileInfo final { mtime_(0), size_(0) {} - const char* path() const { return fullpath_.c_str(); } + const char* path() const { + return fullpath_.c_str(); + } - LogID firstId() const { return firstLogId_; } + LogID firstId() const { + return firstLogId_; + } - LogID lastId() const { return lastLogId_; } - void setLastId(LogID id) { lastLogId_ = id; } + LogID lastId() const { + return lastLogId_; + } + void setLastId(LogID id) { + lastLogId_ = id; + } - TermID lastTerm() const { return lastLogTerm_; } - void setLastTerm(TermID term) { lastLogTerm_ = term; } + TermID lastTerm() const { + return lastLogTerm_; + } + void setLastTerm(TermID term) { + lastLogTerm_ = term; + } - time_t mtime() const { return mtime_; } - void setMTime(time_t time) { mtime_ = time; } + time_t mtime() const { + return mtime_; + } + void setMTime(time_t time) { + mtime_ = time; + } - size_t size() const { return size_; } - void setSize(size_t size) { size_ = size; } + size_t size() const { + return size_; + } + void setSize(size_t size) { + size_ = size; + } private: const std::string fullpath_; diff --git a/src/kvstore/wal/WalFileIterator.cpp b/src/kvstore/wal/WalFileIterator.cpp index 3031a381c02..98021a1b452 100644 --- a/src/kvstore/wal/WalFileIterator.cpp +++ b/src/kvstore/wal/WalFileIterator.cpp @@ -155,11 +155,17 @@ LogIterator& WalFileIterator::operator++() { return *this; } -bool WalFileIterator::valid() const { return currId_ <= lastId_; } +bool WalFileIterator::valid() const { + return currId_ <= lastId_; +} -LogID WalFileIterator::logId() const { return currId_; } +LogID WalFileIterator::logId() const { + return currId_; +} -TermID WalFileIterator::logTerm() const { return currTerm_; } +TermID WalFileIterator::logTerm() const { + return currTerm_; +} ClusterID WalFileIterator::logSource() const { // Retrieve from the file diff --git a/src/kvstore/wal/test/CMakeLists.txt b/src/kvstore/wal/test/CMakeLists.txt index fb3e4383f4b..6cfd8ee1730 100644 --- a/src/kvstore/wal/test/CMakeLists.txt +++ b/src/kvstore/wal/test/CMakeLists.txt @@ -1,17 +1,26 @@ +set(WAL_TEST_LIBS + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ +) + nebula_add_test( NAME file_based_wal_test SOURCES FileBasedWalTest.cpp OBJECTS - $ - $ - $ - $ - $ - $ - $ + ${WAL_TEST_LIBS} LIBRARIES + ${THRIFT_LIBRARIES} gtest ) @@ -22,13 +31,9 @@ nebula_add_test( InMemoryLogBufferTest.cpp InMemoryLogBuffer.cpp OBJECTS - $ - $ - $ - $ - $ - $ + ${WAL_TEST_LIBS} LIBRARIES + ${THRIFT_LIBRARIES} gtest ) @@ -62,13 +67,8 @@ nebula_add_test( SOURCES WalFileIterTest.cpp OBJECTS - $ - $ - $ - $ - $ - $ - $ + ${WAL_TEST_LIBS} LIBRARIES + ${THRIFT_LIBRARIES} gtest ) diff --git a/src/kvstore/wal/test/InMemoryLogBufferList.h b/src/kvstore/wal/test/InMemoryLogBufferList.h index 12c2359e137..247326a5ad4 100644 --- a/src/kvstore/wal/test/InMemoryLogBufferList.h +++ b/src/kvstore/wal/test/InMemoryLogBufferList.h @@ -47,7 +47,9 @@ class InMemoryBufferList : public std::enable_shared_from_this>> +ActiveHostsMan::getServicesInHost(kvstore::KVStore* kv, std::string hostname) { + const auto& prefix = MetaKeyUtils::hostPrefix(); + std::unique_ptr iter; + auto retCode = kv->prefix(kDefaultSpaceId, kDefaultPartId, prefix, &iter); + if (retCode != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << "Failed to get services in the host: " << hostname << ", error " + << apache::thrift::util::enumNameSafe(retCode); + return retCode; + } + + std::vector> hosts; + while (iter->valid()) { + auto addr = MetaKeyUtils::parseHostKey(iter->key()); + HostInfo info = HostInfo::decode(iter->val()); + + if (addr.host == hostname) { + hosts.emplace_back(addr, info.role_); + } + iter->next(); + } + + return hosts; +} + ErrorOr> ActiveHostsMan::getActiveHosts( kvstore::KVStore* kv, int32_t expiredTTL, cpp2::HostRole role) { const auto& machinePrefix = MetaKeyUtils::machinePrefix(); diff --git a/src/meta/ActiveHostsMan.h b/src/meta/ActiveHostsMan.h index 97b70d35577..3cd5326d874 100644 --- a/src/meta/ActiveHostsMan.h +++ b/src/meta/ActiveHostsMan.h @@ -28,7 +28,9 @@ struct HostInfo { return this->lastHBTimeInMilliSec_ == that.lastHBTimeInMilliSec_; } - bool operator!=(const HostInfo& that) const { return !(*this == that); } + bool operator!=(const HostInfo& that) const { + return !(*this == that); + } int64_t lastHBTimeInMilliSec_ = 0; cpp2::HostRole role_{cpp2::HostRole::UNKNOWN}; @@ -115,6 +117,9 @@ class ActiveHostsMan final { static ErrorOr> getActiveHosts( kvstore::KVStore* kv, int32_t expiredTTL = 0, cpp2::HostRole role = cpp2::HostRole::STORAGE); + static ErrorOr>> + getServicesInHost(kvstore::KVStore* kv, std::string hostname); + static ErrorOr> getActiveHostsInZone( kvstore::KVStore* kv, const std::string& zoneName, int32_t expiredTTL = 0); diff --git a/src/meta/CMakeLists.txt b/src/meta/CMakeLists.txt index 77449574b61..b883f939959 100644 --- a/src/meta/CMakeLists.txt +++ b/src/meta/CMakeLists.txt @@ -43,6 +43,7 @@ nebula_add_library( processors/kv/RemoveRangeProcessor.cpp processors/kv/ScanProcessor.cpp processors/admin/HBProcessor.cpp + processors/admin/AgentHBProcessor.cpp processors/user/AuthenticationProcessor.cpp processors/admin/CreateSnapshotProcessor.cpp processors/admin/DropSnapshotProcessor.cpp @@ -160,8 +161,14 @@ set(meta_test_deps $ $ $ + $ + $ + $ + $ + $ ) nebula_add_subdirectory(http) nebula_add_subdirectory(test) nebula_add_subdirectory(upgrade) +nebula_add_subdirectory(stats) diff --git a/src/meta/MetaServiceHandler.cpp b/src/meta/MetaServiceHandler.cpp index cc78fcbf2c6..9293e4634d2 100644 --- a/src/meta/MetaServiceHandler.cpp +++ b/src/meta/MetaServiceHandler.cpp @@ -6,6 +6,7 @@ #include "meta/MetaServiceHandler.h" #include "common/utils/MetaKeyUtils.h" +#include "meta/processors/admin/AgentHBProcessor.h" #include "meta/processors/admin/CreateBackupProcessor.h" #include "meta/processors/admin/CreateSnapshotProcessor.h" #include "meta/processors/admin/DropSnapshotProcessor.h" @@ -334,6 +335,12 @@ folly::Future MetaServiceHandler::future_heartBeat(const cpp2::HBR RETURN_FUTURE(processor); } +folly::Future MetaServiceHandler::future_agentHeartbeat( + const cpp2::AgentHBReq& req) { + auto* processor = AgentHBProcessor::instance(kvstore_); + RETURN_FUTURE(processor); +} + folly::Future MetaServiceHandler::future_createUser( const cpp2::CreateUserReq& req) { auto* processor = CreateUserProcessor::instance(kvstore_); @@ -501,7 +508,7 @@ folly::Future MetaServiceHandler::future_getStats( folly::Future MetaServiceHandler::future_listCluster( const cpp2::ListClusterInfoReq& req) { - auto* processor = ListClusterInfoProcessor::instance(kvstore_, adminClient_.get()); + auto* processor = ListClusterInfoProcessor::instance(kvstore_); RETURN_FUTURE(processor); } diff --git a/src/meta/MetaServiceHandler.h b/src/meta/MetaServiceHandler.h index a1d7332fbf8..e1afb3c18bd 100644 --- a/src/meta/MetaServiceHandler.h +++ b/src/meta/MetaServiceHandler.h @@ -10,7 +10,10 @@ #include "interface/gen-cpp2/MetaService.h" #include "kvstore/KVStore.h" #include "meta/processors/admin/AdminClient.h" +#include "meta/processors/admin/AgentHBProcessor.h" #include "meta/processors/admin/HBProcessor.h" +#include "meta/processors/job/AdminJobProcessor.h" +#include "meta/processors/job/JobManager.h" namespace nebula { namespace meta { @@ -23,6 +26,7 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf { // Initialize counters kHBCounters.init(); + kAgentHBCounters.init(); } /** @@ -158,6 +162,8 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf { * */ folly::Future future_heartBeat(const cpp2::HBReq& req) override; + folly::Future future_agentHeartbeat(const cpp2::AgentHBReq& req) override; + folly::Future future_regConfig(const cpp2::RegConfigReq& req) override; folly::Future future_getConfig(const cpp2::GetConfigReq& req) override; diff --git a/src/meta/MetaServiceUtils.cpp b/src/meta/MetaServiceUtils.cpp index 96a5bb857a9..a6367dff496 100644 --- a/src/meta/MetaServiceUtils.cpp +++ b/src/meta/MetaServiceUtils.cpp @@ -17,18 +17,19 @@ nebula::cpp2::ErrorCode backupTable(kvstore::KVStore* kvstore, const std::string& tableName, std::vector& files, std::function filter) { - auto backupFilePath = kvstore->backupTable(kDefaultSpaceId, backupName, tableName, filter); - if (!ok(backupFilePath)) { - auto result = error(backupFilePath); - if (result == nebula::cpp2::ErrorCode::E_BACKUP_EMPTY_TABLE) { + auto backupRet = kvstore->backupTable(kDefaultSpaceId, backupName, tableName, filter); + if (!ok(backupRet)) { + auto code = error(backupRet); + if (code == nebula::cpp2::ErrorCode::E_BACKUP_EMPTY_TABLE) { return nebula::cpp2::ErrorCode::SUCCEEDED; } - return result; + return code; } + auto backupTableFiles = std::move(value(backupRet)); files.insert(files.end(), - std::make_move_iterator(value(backupFilePath).begin()), - std::make_move_iterator(value(backupFilePath).end())); + std::make_move_iterator(backupTableFiles.begin()), + std::make_move_iterator(backupTableFiles.end())); return nebula::cpp2::ErrorCode::SUCCEEDED; } } // namespace @@ -71,8 +72,8 @@ nebula::cpp2::ErrorCode MetaServiceUtils::alterColumnDefs(std::vectorget_name()) { if (prop.get_ttl_col() && (*prop.get_ttl_col() == colName)) { - prop.set_ttl_duration(0); - prop.set_ttl_col(""); + prop.ttl_duration_ref() = 0; + prop.ttl_col_ref() = ""; } cols.erase(it); return nebula::cpp2::ErrorCode::SUCCEEDED; @@ -101,14 +102,14 @@ nebula::cpp2::ErrorCode MetaServiceUtils::alterSchemaProp(std::vector MetaServiceUtils::spaceFilter ErrorOr> MetaServiceUtils::backupIndex( kvstore::KVStore* kvstore, - const std::unordered_set& spaces, + const std::unordered_set& spaceIds, const std::string& backupName, - const std::vector* spaceName) { + const std::vector* spaceNames) { auto indexTable = MetaKeyUtils::getIndexTable(); - return kvstore->backupTable( - kDefaultSpaceId, - backupName, - indexTable, - [spaces, spaceName, indexTable](const folly::StringPiece& key) -> bool { - if (spaces.empty()) { - return false; - } + return kvstore->backupTable(kDefaultSpaceId, + backupName, + indexTable, + // will filter out the index table when this function returns true + [spaceIds, spaceNames](const folly::StringPiece& key) -> bool { + if (spaceIds.empty()) { + return false; + } - auto type = *reinterpret_cast(key.data() + indexTable.size()); - if (type == EntryType::SPACE) { - if (spaceName == nullptr) { - return false; - } - auto sn = key.subpiece(indexTable.size() + sizeof(EntryType), - key.size() - indexTable.size() - sizeof(EntryType)) - .str(); - LOG(INFO) << "sn was " << sn; - auto it = std::find_if( - spaceName->cbegin(), spaceName->cend(), [&sn](auto& name) { return sn == name; }); + // space index: space name -> space id + auto type = MetaKeyUtils::parseIndexType(key); + if (type == EntryType::SPACE) { + if (spaceNames == nullptr || spaceNames->empty()) { + return false; + } - if (it == spaceName->cend()) { - return true; - } - return false; - } - - auto id = MetaKeyUtils::parseIndexKeySpaceID(key); - auto it = spaces.find(id); - if (it == spaces.end()) { - return true; - } + auto spaceName = MetaKeyUtils::parseIndexSpaceKey(key); + LOG(INFO) << "Space name was " << spaceName; + auto it = std::find_if( + spaceNames->cbegin(), + spaceNames->cend(), + [&spaceName](auto& name) { return spaceName == name; }); + if (it == spaceNames->cend()) { + return true; + } + return false; + } - return false; - }); + // other index: space id -> values + auto id = MetaKeyUtils::parseIndexKeySpaceID(key); + auto it = spaceIds.find(id); + if (it == spaceIds.end()) { + return true; + } + return false; + }); } -ErrorOr> MetaServiceUtils::backupSpaces( +ErrorOr> MetaServiceUtils::backupTables( kvstore::KVStore* kvstore, - const std::unordered_set& spaces, + const std::unordered_set& spaceIds, const std::string& backupName, const std::vector* spaceNames) { std::vector files; - auto tables = MetaKeyUtils::getTableMaps(); - files.reserve(tables.size()); + // backup space relative tables + auto tables = MetaKeyUtils::getTableMaps(); for (const auto& table : tables) { if (table.second.second == nullptr) { LOG(INFO) << table.first << " table skipped"; continue; } auto result = backupTable( - kvstore, backupName, table.second.first, files, spaceFilter(spaces, table.second.second)); + kvstore, backupName, table.second.first, files, spaceFilter(spaceIds, table.second.second)); if (result != nebula::cpp2::ErrorCode::SUCCEEDED) { return result; } LOG(INFO) << table.first << " table backup succeeded"; } - if (spaceNames == nullptr) { + // backup system tables if backup all spaces + bool allSpaces = spaceNames == nullptr || spaceNames->empty(); + if (allSpaces) { auto sysTables = MetaKeyUtils::getSystemTableMaps(); for (const auto& table : sysTables) { if (!table.second.second) { @@ -252,6 +256,7 @@ ErrorOr> MetaServiceUtils::bac } } + // backup system info tables auto sysInfos = MetaKeyUtils::getSystemInfoMaps(); for (const auto& table : sysInfos) { if (!table.second.second) { @@ -265,8 +270,9 @@ ErrorOr> MetaServiceUtils::bac LOG(INFO) << table.first << " table backup succeeded"; } - // The mapping of space name and space id needs to be handled separately. - auto ret = backupIndex(kvstore, spaces, backupName, spaceNames); + // backup the mapping of space name and space id separately, + // which skipped in space relative tables + auto ret = backupIndex(kvstore, spaceIds, backupName, spaceNames); if (!ok(ret)) { auto result = error(ret); if (result == nebula::cpp2::ErrorCode::E_BACKUP_EMPTY_TABLE) { diff --git a/src/meta/MetaServiceUtils.h b/src/meta/MetaServiceUtils.h index f6e9d2e17f7..e70091e27eb 100644 --- a/src/meta/MetaServiceUtils.h +++ b/src/meta/MetaServiceUtils.h @@ -43,11 +43,11 @@ class MetaServiceUtils final { const std::unordered_set& spaces, std::function parseSpace); - static ErrorOr> backupSpaces( + static ErrorOr> backupTables( kvstore::KVStore* kvstore, - const std::unordered_set& spaces, + const std::unordered_set& spaceIds, const std::string& backupName, - const std::vector* spaceName); + const std::vector* spaceNames); }; } // namespace meta diff --git a/src/meta/http/MetaHttpDownloadHandler.cpp b/src/meta/http/MetaHttpDownloadHandler.cpp index cee62941813..03167f1b1cd 100644 --- a/src/meta/http/MetaHttpDownloadHandler.cpp +++ b/src/meta/http/MetaHttpDownloadHandler.cpp @@ -112,7 +112,9 @@ void MetaHttpDownloadHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void MetaHttpDownloadHandler::requestComplete() noexcept { delete this; } +void MetaHttpDownloadHandler::requestComplete() noexcept { + delete this; +} void MetaHttpDownloadHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web Service MetaHttpDownloadHandler got error : " diff --git a/src/meta/http/MetaHttpIngestHandler.cpp b/src/meta/http/MetaHttpIngestHandler.cpp index e15f9dbedec..a11f8675fc8 100644 --- a/src/meta/http/MetaHttpIngestHandler.cpp +++ b/src/meta/http/MetaHttpIngestHandler.cpp @@ -97,7 +97,9 @@ void MetaHttpIngestHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void MetaHttpIngestHandler::requestComplete() noexcept { delete this; } +void MetaHttpIngestHandler::requestComplete() noexcept { + delete this; +} void MetaHttpIngestHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web Service MetaHttpIngestHandler got error : " << proxygen::getErrorString(error); diff --git a/src/meta/http/MetaHttpReplaceHostHandler.cpp b/src/meta/http/MetaHttpReplaceHostHandler.cpp index b3892a76f1c..23fa54fcf39 100644 --- a/src/meta/http/MetaHttpReplaceHostHandler.cpp +++ b/src/meta/http/MetaHttpReplaceHostHandler.cpp @@ -97,7 +97,9 @@ void MetaHttpReplaceHostHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void MetaHttpReplaceHostHandler::requestComplete() noexcept { delete this; } +void MetaHttpReplaceHostHandler::requestComplete() noexcept { + delete this; +} void MetaHttpReplaceHostHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web Service MetaHttpReplaceHostHandler got error : " diff --git a/src/meta/processors/BaseProcessor-inl.h b/src/meta/processors/BaseProcessor-inl.h index 04bcb80b232..2851ac50e28 100644 --- a/src/meta/processors/BaseProcessor-inl.h +++ b/src/meta/processors/BaseProcessor-inl.h @@ -116,27 +116,6 @@ ErrorOr> BaseProcessor:: return values; } -template -ErrorOr> BaseProcessor::allHosts() { - std::vector hosts; - const auto& prefix = MetaKeyUtils::hostPrefix(); - std::unique_ptr iter; - auto code = kvstore_->prefix(kDefaultSpaceId, kDefaultPartId, prefix, &iter); - if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { - VLOG(2) << "Can't find any hosts"; - return code; - } - - while (iter->valid()) { - HostAddr h; - auto hostAddrPiece = iter->key().subpiece(prefix.size()); - memcpy(&h, hostAddrPiece.data(), hostAddrPiece.size()); - hosts.emplace_back(std::move(h)); - iter->next(); - } - return hosts; -} - template ErrorOr BaseProcessor::autoIncrementId() { folly::SharedMutex::WriteHolder holder(LockUtils::idLock()); diff --git a/src/meta/processors/BaseProcessor.h b/src/meta/processors/BaseProcessor.h index d09f4d73327..c968f03f497 100644 --- a/src/meta/processors/BaseProcessor.h +++ b/src/meta/processors/BaseProcessor.h @@ -55,7 +55,9 @@ class BaseProcessor { virtual ~BaseProcessor() = default; - folly::Future getFuture() { return promise_.getFuture(); } + folly::Future getFuture() { + return promise_.getFuture(); + } protected: /** @@ -69,7 +71,7 @@ class BaseProcessor { void handleErrorCode(nebula::cpp2::ErrorCode code, GraphSpaceID spaceId = kDefaultSpaceId, PartitionID partId = kDefaultPartId) { - resp_.set_code(code); + resp_.code_ref() = code; if (code == nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { handleLeaderChanged(spaceId, partId); } @@ -78,9 +80,9 @@ class BaseProcessor { void handleLeaderChanged(GraphSpaceID spaceId, PartitionID partId) { auto leaderRet = kvstore_->partLeader(spaceId, partId); if (ok(leaderRet)) { - resp_.set_leader(toThriftHost(nebula::value(leaderRet))); + resp_.leader_ref() = toThriftHost(nebula::value(leaderRet)); } else { - resp_.set_code(nebula::error(leaderRet)); + resp_.code_ref() = nebula::error(leaderRet); } } @@ -89,16 +91,16 @@ class BaseProcessor { cpp2::ID thriftID; switch (type) { case EntryType::SPACE: - thriftID.set_space_id(static_cast(id)); + thriftID.space_id_ref() = static_cast(id); break; case EntryType::TAG: - thriftID.set_tag_id(static_cast(id)); + thriftID.tag_id_ref() = static_cast(id); break; case EntryType::EDGE: - thriftID.set_edge_type(static_cast(id)); + thriftID.edge_type_ref() = static_cast(id); break; case EntryType::INDEX: - thriftID.set_index_id(static_cast(id)); + thriftID.index_id_ref() = static_cast(id); break; case EntryType::CONFIG: case EntryType::GROUP: @@ -108,7 +110,9 @@ class BaseProcessor { return thriftID; } - HostAddr toThriftHost(const HostAddr& host) { return host; } + HostAddr toThriftHost(const HostAddr& host) { + return host; + } /** * General put function. @@ -149,11 +153,6 @@ class BaseProcessor { **/ void doMultiRemove(std::vector keys); - /** - * Get all hosts - * */ - ErrorOr> allHosts(); - /** * Get one auto-increment Id. * */ diff --git a/src/meta/processors/admin/AdminClient.cpp b/src/meta/processors/admin/AdminClient.cpp index 61fe5cf001e..3decaf0b314 100644 --- a/src/meta/processors/admin/AdminClient.cpp +++ b/src/meta/processors/admin/AdminClient.cpp @@ -24,8 +24,8 @@ folly::Future AdminClient::transLeader(GraphSpaceID spaceId, const HostAddr& leader, const HostAddr& dst) { storage::cpp2::TransLeaderReq req; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; auto ret = getPeers(spaceId, partId); if (!nebula::ok(ret)) { LOG(ERROR) << "Get peers failed: " << static_cast(nebula::error(ret)); @@ -53,7 +53,7 @@ folly::Future AdminClient::transLeader(GraphSpaceID spaceId, } } } - req.set_new_leader(std::move(target)); + req.new_leader_ref() = std::move(target); return getResponse( Utils::getAdminAddrFromStoreAddr(leader), std::move(req), @@ -78,16 +78,16 @@ folly::Future AdminClient::addPart(GraphSpaceID spaceId, const HostAddr& host, bool asLearner) { storage::cpp2::AddPartReq req; - req.set_space_id(spaceId); - req.set_part_id(partId); - req.set_as_learner(asLearner); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; + req.as_learner_ref() = asLearner; auto ret = getPeers(spaceId, partId); if (!nebula::ok(ret)) { LOG(ERROR) << "Get peers failed: " << static_cast(nebula::error(ret)); return Status::Error("Get peers failed"); } - req.set_peers(std::move(nebula::value(ret))); + req.peers_ref() = std::move(nebula::value(ret)); return getResponse( Utils::getAdminAddrFromStoreAddr(host), std::move(req), @@ -105,9 +105,9 @@ folly::Future AdminClient::addLearner(GraphSpaceID spaceId, PartitionID partId, const HostAddr& learner) { storage::cpp2::AddLearnerReq req; - req.set_space_id(spaceId); - req.set_part_id(partId); - req.set_learner(learner); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; + req.learner_ref() = learner; auto ret = getPeers(spaceId, partId); if (!nebula::ok(ret)) { LOG(ERROR) << "Get peers failed: " << static_cast(nebula::error(ret)); @@ -132,9 +132,9 @@ folly::Future AdminClient::waitingForCatchUpData(GraphSpaceID spaceId, PartitionID partId, const HostAddr& target) { storage::cpp2::CatchUpDataReq req; - req.set_space_id(spaceId); - req.set_part_id(partId); - req.set_target(target); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; + req.target_ref() = target; auto ret = getPeers(spaceId, partId); if (!nebula::ok(ret)) { LOG(ERROR) << "Get peers failed: " << static_cast(nebula::error(ret)); @@ -160,10 +160,10 @@ folly::Future AdminClient::memberChange(GraphSpaceID spaceId, const HostAddr& peer, bool added) { storage::cpp2::MemberChangeReq req; - req.set_space_id(spaceId); - req.set_part_id(partId); - req.set_add(added); - req.set_peer(peer); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; + req.add_ref() = added; + req.peer_ref() = peer; auto ret = getPeers(spaceId, partId); if (!nebula::ok(ret)) { LOG(ERROR) << "Get peers failed: " << static_cast(nebula::error(ret)); @@ -245,8 +245,8 @@ folly::Future AdminClient::removePart(GraphSpaceID spaceId, PartitionID partId, const HostAddr& host) { storage::cpp2::RemovePartReq req; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; return getResponse( Utils::getAdminAddrFromStoreAddr(host), std::move(req), @@ -263,8 +263,8 @@ folly::Future AdminClient::removePart(GraphSpaceID spaceId, folly::Future AdminClient::checkPeers(GraphSpaceID spaceId, PartitionID partId) { storage::cpp2::CheckPeersReq req; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; auto peerRet = getPeers(spaceId, partId); if (!nebula::ok(peerRet)) { LOG(ERROR) << "Get peers failed: " << static_cast(nebula::error(peerRet)); @@ -272,7 +272,7 @@ folly::Future AdminClient::checkPeers(GraphSpaceID spaceId, PartitionID } auto peers = std::move(nebula::value(peerRet)); - req.set_peers(peers); + req.peers_ref() = peers; folly::Promise pro; auto fut = pro.getFuture(); std::vector> futures; @@ -360,8 +360,8 @@ folly::Future AdminClient::getResponse(const HostAddr& host, auto&& result = std::move(t).value().get_result(); if (result.get_failed_parts().empty()) { storage::cpp2::PartitionResult resultCode; - resultCode.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); - resultCode.set_part_id(partId); + resultCode.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; + resultCode.part_id_ref() = partId; p.setValue(respGen(resultCode)); } else { auto resp = result.get_failed_parts().front(); @@ -618,19 +618,20 @@ folly::Future AdminClient::getLeaderDist(HostLeaderMap* result) { return future; } -folly::Future> AdminClient::createSnapshot(GraphSpaceID spaceId, - const std::string& name, - const HostAddr& host) { - folly::Promise> pro; +folly::Future> AdminClient::createSnapshot( + const std::set& spaceIds, const std::string& name, const HostAddr& host) { + folly::Promise> pro; auto f = pro.getFuture(); auto* evb = ioThreadPool_->getEventBase(); auto storageHost = Utils::getAdminAddrFromStoreAddr(host); - folly::via(evb, [evb, storageHost, host, pro = std::move(pro), spaceId, name, this]() mutable { + folly::via(evb, [evb, storageHost, host, pro = std::move(pro), spaceIds, name, this]() mutable { auto client = clientsMan_->client(storageHost, evb); storage::cpp2::CreateCPRequest req; - req.set_space_id(spaceId); - req.set_name(name); + std::vector idList; + idList.insert(idList.end(), spaceIds.begin(), spaceIds.end()); + req.space_ids_ref() = idList; + req.name_ref() = name; client->future_createCheckpoint(std::move(req)) .via(evb) .then([p = std::move(pro), storageHost, host]( @@ -644,10 +645,10 @@ folly::Future> AdminClient::createSnapshot(GraphSpace auto&& resp = std::move(t).value(); auto&& result = resp.get_result(); if (result.get_failed_parts().empty()) { - cpp2::BackupInfo backupInfo; - backupInfo.set_host(host); - backupInfo.set_info(std::move(resp.get_info())); - p.setValue(std::move(backupInfo)); + cpp2::HostBackupInfo hostBackupInfo; + hostBackupInfo.host_ref() = host; + hostBackupInfo.checkpoints_ref() = std::move(resp.get_info()); + p.setValue(std::move(hostBackupInfo)); return; } p.setValue(Status::Error("create checkpoint failed")); @@ -657,12 +658,14 @@ folly::Future> AdminClient::createSnapshot(GraphSpace return f; } -folly::Future AdminClient::dropSnapshot(GraphSpaceID spaceId, +folly::Future AdminClient::dropSnapshot(const std::set& spaceIds, const std::string& name, const HostAddr& host) { storage::cpp2::DropCPRequest req; - req.set_space_id(spaceId); - req.set_name(name); + std::vector idList; + idList.insert(idList.end(), spaceIds.begin(), spaceIds.end()); + req.space_ids_ref() = idList; + req.name_ref() = name; folly::Promise pro; auto f = pro.getFuture(); getResponse( @@ -676,12 +679,14 @@ folly::Future AdminClient::dropSnapshot(GraphSpaceID spaceId, return f; } -folly::Future AdminClient::blockingWrites(GraphSpaceID spaceId, +folly::Future AdminClient::blockingWrites(const std::set& spaceIds, storage::cpp2::EngineSignType sign, const HostAddr& host) { storage::cpp2::BlockingSignRequest req; - req.set_space_id(spaceId); - req.set_sign(sign); + std::vector idList; + idList.insert(idList.end(), spaceIds.begin(), spaceIds.end()); + req.space_ids_ref() = idList; + req.sign_ref() = sign; folly::Promise pro; auto f = pro.getFuture(); getResponse( @@ -700,7 +705,7 @@ folly::Future AdminClient::addTask(cpp2::AdminCmd cmd, int32_t taskId, GraphSpaceID spaceId, const std::vector& targetHost, - const std::vector& taskSpecficParas, + const std::vector& taskSpecificParas, std::vector parts, int concurrency, cpp2::StatsItem* statsResult) { @@ -720,16 +725,16 @@ folly::Future AdminClient::addTask(cpp2::AdminCmd cmd, } storage::cpp2::AddAdminTaskRequest req; - req.set_cmd(cmd); - req.set_job_id(jobId); - req.set_task_id(taskId); - req.set_concurrency(concurrency); + req.cmd_ref() = cmd; + req.job_id_ref() = jobId; + req.task_id_ref() = taskId; + req.concurrency_ref() = concurrency; storage::cpp2::TaskPara para; - para.set_space_id(spaceId); - para.set_parts(std::move(parts)); - para.set_task_specific_paras(taskSpecficParas); - req.set_para(std::move(para)); + para.space_id_ref() = spaceId; + para.parts_ref() = std::move(parts); + para.task_specific_paras_ref() = taskSpecificParas; + req.para_ref() = std::move(para); std::function respGen = [statsResult](storage::cpp2::AdminExecResp&& resp) -> void { @@ -769,8 +774,8 @@ folly::Future AdminClient::stopTask(const std::vector& target, } storage::cpp2::StopAdminTaskRequest req; - req.set_job_id(jobId); - req.set_task_id(taskId); + req.job_id_ref() = jobId; + req.task_id_ref() = taskId; getResponse( hosts, @@ -783,37 +788,5 @@ folly::Future AdminClient::stopTask(const std::vector& target, return f; } -folly::Future> AdminClient::listClusterInfo(const HostAddr& host) { - folly::Promise> pro; - auto f = pro.getFuture(); - - auto* evb = ioThreadPool_->getEventBase(); - auto storageHost = Utils::getAdminAddrFromStoreAddr(host); - folly::via(evb, [evb, storageHost, pro = std::move(pro), this]() mutable { - auto client = clientsMan_->client(storageHost, evb); - storage::cpp2::ListClusterInfoReq req; - client->future_listClusterInfo(std::move(req)) - .via(evb) - .then([p = std::move(pro), - storageHost](folly::Try&& t) mutable { - if (t.hasException()) { - LOG(ERROR) << folly::stringPrintf("RPC failure in AdminClient: %s", - t.exception().what().c_str()); - p.setValue(Status::Error("RPC failure in listClusterInfo")); - return; - } - auto&& resp = std::move(t).value(); - auto&& result = resp.get_result(); - if (result.get_failed_parts().empty()) { - p.setValue(resp.get_dir()); - return; - } - p.setValue(Status::Error("list clusterInfo failed")); - }); - }); - - return f; -} - } // namespace meta } // namespace nebula diff --git a/src/meta/processors/admin/AdminClient.h b/src/meta/processors/admin/AdminClient.h index e43394560e2..88527c5c54c 100644 --- a/src/meta/processors/admin/AdminClient.h +++ b/src/meta/processors/admin/AdminClient.h @@ -39,7 +39,9 @@ class AdminClient { virtual ~AdminClient() = default; - folly::Executor* executor() const { return ioThreadPool_.get(); } + folly::Executor* executor() const { + return ioThreadPool_.get(); + } virtual folly::Future transLeader(GraphSpaceID spaceId, PartitionID partId, @@ -81,15 +83,14 @@ class AdminClient { virtual folly::Future getLeaderDist(HostLeaderMap* result); - virtual folly::Future> createSnapshot(GraphSpaceID spaceId, - const std::string& name, - const HostAddr& host); + virtual folly::Future> createSnapshot( + const std::set& spaceIds, const std::string& name, const HostAddr& host); - virtual folly::Future dropSnapshot(GraphSpaceID spaceId, + virtual folly::Future dropSnapshot(const std::set& spaceIds, const std::string& name, const HostAddr& host); - virtual folly::Future blockingWrites(GraphSpaceID spaceId, + virtual folly::Future blockingWrites(const std::set& spaceIds, storage::cpp2::EngineSignType sign, const HostAddr& host); @@ -107,8 +108,6 @@ class AdminClient { int32_t jobId, int32_t taskId); - virtual folly::Future> listClusterInfo(const HostAddr& host); - private: template folly::Future getResponse(const HostAddr& host, diff --git a/src/meta/processors/admin/AgentHBProcessor.cpp b/src/meta/processors/admin/AgentHBProcessor.cpp new file mode 100644 index 00000000000..1df56fdab0e --- /dev/null +++ b/src/meta/processors/admin/AgentHBProcessor.cpp @@ -0,0 +1,137 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "meta/processors/admin/AgentHBProcessor.h" + +#include "common/time/WallClock.h" +#include "meta/ActiveHostsMan.h" +#include "meta/KVBasedClusterIdMan.h" +#include "meta/MetaVersionMan.h" + +namespace nebula { +namespace meta { + +AgentHBCounters kAgentHBCounters; + +void AgentHBProcessor::onFinished() { + if (counters_) { + stats::StatsManager::addValue(counters_->numCalls_); + stats::StatsManager::addValue(counters_->latency_, this->duration_.elapsedInUSec()); + } + + Base::onFinished(); +} + +// Agent heartbeat register agent to meta and pull all services info in agent's host +void AgentHBProcessor::process(const cpp2::AgentHBReq& req) { + HostAddr agentAddr((*req.host_ref()).host, (*req.host_ref()).port); + LOG(INFO) << "Receive heartbeat from " << agentAddr << ", role = AGENT"; + + nebula::cpp2::ErrorCode ret = nebula::cpp2::ErrorCode::SUCCEEDED; + do { + // update agent host info + HostInfo info( + time::WallClock::fastNowInMilliSec(), cpp2::HostRole::AGENT, req.get_git_info_sha()); + ret = ActiveHostsMan::updateHostInfo(kvstore_, agentAddr, info); + if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << folly::sformat("Put agent {} info failed: {}", + agentAddr.toString(), + apache::thrift::util::enumNameSafe(ret)); + break; + } + + // get services in the agent host + auto servicesRet = ActiveHostsMan::getServicesInHost(kvstore_, agentAddr.host); + if (!nebula::ok(servicesRet)) { + ret = nebula::error(servicesRet); + LOG(ERROR) << folly::sformat("Get active services for {} failed: {}", + agentAddr.host, + apache::thrift::util::enumNameSafe(ret)); + break; + } + + // get dir info for the services in agent host + std::unordered_map serviceDirinfo; + std::string hostDirHostPrefix = MetaKeyUtils::hostDirHostPrefix(agentAddr.host); + auto dirIterRet = doPrefix(hostDirHostPrefix); + if (!nebula::ok(dirIterRet)) { + ret = nebula::error(dirIterRet); + LOG(ERROR) << folly::sformat("Get host {} dir prefix iterator failed: {}", + agentAddr.host, + apache::thrift::util::enumNameSafe(ret)); + break; + } + auto dirIter = std::move(nebula::value(dirIterRet)); + for (; dirIter->valid(); dirIter->next()) { + HostAddr addr = MetaKeyUtils::parseHostDirKey(dirIter->key()); + nebula::cpp2::DirInfo dir = MetaKeyUtils::parseHostDir(dirIter->val()); + serviceDirinfo[addr] = dir; + } + + // join the service host info and dir info + auto services = std::move(nebula::value(servicesRet)); + std::vector serviceList; + for (const auto& [addr, role] : services) { + if (addr == agentAddr) { + // skip iteself + continue; + } + + if (role == cpp2::HostRole::AGENT) { + LOG(INFO) << folly::sformat("there is another agent: {} in the host", addr.toString()); + continue; + } + + auto it = serviceDirinfo.find(addr); + if (it == serviceDirinfo.end()) { + LOG(ERROR) << folly::sformat("{} dir info not found", addr.toString()); + break; + } + + cpp2::ServiceInfo serviceInfo; + serviceInfo.addr_ref() = addr; + serviceInfo.dir_ref() = it->second; + serviceInfo.role_ref() = role; + serviceList.emplace_back(serviceInfo); + } + if (serviceList.size() != services.size() - 1) { + ret = nebula::cpp2::ErrorCode::E_AGENT_HB_FAILUE; + // missing some services' dir info + LOG(ERROR) << folly::sformat( + "Missing some services's dir info, excepted service {}, but only got {}", + services.size() - 1, + serviceList.size()); + break; + } + + // add meta service if have, agent should get meta dir info in separate rpc + // because follower metad can't report it's dir info to the leader metad + auto partRet = kvstore_->part(kDefaultSpaceId, kDefaultPartId); + if (!nebula::ok(partRet)) { + ret = nebula::error(partRet); + LOG(ERROR) << "Get meta part store failed, error: " + << apache::thrift::util::enumNameSafe(ret); + return; + } + auto raftPeers = nebula::value(partRet)->peers(); + for (auto& raftAddr : raftPeers) { + auto metaAddr = Utils::getStoreAddrFromRaftAddr(raftAddr); + if (metaAddr.host == agentAddr.host) { + cpp2::ServiceInfo serviceInfo; + serviceInfo.addr_ref() = metaAddr; + serviceInfo.role_ref() = cpp2::HostRole::META; + serviceList.emplace_back(serviceInfo); + } + } + + resp_.service_list_ref() = serviceList; + } while (false); + + handleErrorCode(ret); + onFinished(); +} + +} // namespace meta +} // namespace nebula diff --git a/src/meta/processors/admin/AgentHBProcessor.h b/src/meta/processors/admin/AgentHBProcessor.h new file mode 100644 index 00000000000..0119bb730fb --- /dev/null +++ b/src/meta/processors/admin/AgentHBProcessor.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include + +#include "common/stats/StatsManager.h" +#include "meta/processors/BaseProcessor.h" + +namespace nebula { +namespace meta { + +struct AgentHBCounters final { + stats::CounterId numCalls_; + stats::CounterId latency_; + + void init() { + if (!numCalls_.valid()) { + numCalls_ = stats::StatsManager::registerStats("num_agent_heartbeats", "rate, sum"); + latency_ = stats::StatsManager::registerHisto( + "agent_heartbeat_latency_us", 1000, 0, 20000, "avg, p75, p95, p99"); + VLOG(1) << "Succeeded in initializing the AgentHBCounters"; + } else { + VLOG(1) << "AgentHBCounters has been initialized"; + } + } +}; +extern AgentHBCounters kAgentHBCounters; + +class AgentHBProcessor : public BaseProcessor { + FRIEND_TEST(AgentHBProcessorTest, AgentHBTest); + + using Base = BaseProcessor; + + public: + static AgentHBProcessor* instance(kvstore::KVStore* kvstore, + const AgentHBCounters* counters = &kAgentHBCounters) { + return new AgentHBProcessor(kvstore, counters); + } + + void process(const cpp2::AgentHBReq& req); + + protected: + void onFinished() override; + + private: + explicit AgentHBProcessor(kvstore::KVStore* kvstore, const AgentHBCounters* counters) + : BaseProcessor(kvstore), counters_(counters) {} + + const AgentHBCounters* counters_{nullptr}; +}; + +} // namespace meta +} // namespace nebula diff --git a/src/meta/processors/admin/CreateBackupProcessor.cpp b/src/meta/processors/admin/CreateBackupProcessor.cpp index e2454366a5e..afa8541a687 100644 --- a/src/meta/processors/admin/CreateBackupProcessor.cpp +++ b/src/meta/processors/admin/CreateBackupProcessor.cpp @@ -18,11 +18,10 @@ CreateBackupProcessor::spaceNameToId(const std::vector* backupSpace folly::SharedMutex::ReadHolder rHolder(LockUtils::spaceLock()); std::unordered_set spaces; - if (backupSpaces != nullptr) { - DCHECK(!backupSpaces->empty()); + bool allSpaces = backupSpaces == nullptr || backupSpaces->empty(); + if (!allSpaces) { std::vector keys; keys.reserve(backupSpaces->size()); - std::transform( backupSpaces->begin(), backupSpaces->end(), std::back_inserter(keys), [](auto& name) { return MetaKeyUtils::indexSpaceKey(name); @@ -84,6 +83,7 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { } JobManager* jobMgr = JobManager::getInstance(); + // make sure there is no index job auto result = jobMgr->checkIndexJobRunning(); if (!nebula::ok(result)) { LOG(ERROR) << "get Index status failed, not allowed to create backup."; @@ -91,7 +91,6 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { onFinished(); return; } - if (nebula::value(result)) { LOG(ERROR) << "Index is rebuilding, not allowed to create backup."; handleErrorCode(nebula::cpp2::ErrorCode::E_BACKUP_BUILDING_INDEX); @@ -101,6 +100,7 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { folly::SharedMutex::WriteHolder wHolder(LockUtils::snapshotLock()); + // get active storage host list auto activeHostsRet = ActiveHostsMan::getActiveHosts(kvstore_); if (!nebula::ok(activeHostsRet)) { handleErrorCode(nebula::error(activeHostsRet)); @@ -108,7 +108,6 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { return; } auto hosts = std::move(nebula::value(activeHostsRet)); - if (hosts.empty()) { LOG(ERROR) << "There has some offline hosts"; handleErrorCode(nebula::cpp2::ErrorCode::E_NO_HOSTS); @@ -116,25 +115,32 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { return; } + // transform space names to id list auto spaceIdRet = spaceNameToId(backupSpaces); if (!nebula::ok(spaceIdRet)) { handleErrorCode(nebula::error(spaceIdRet)); onFinished(); return; } - auto spaces = nebula::value(spaceIdRet); // The entire process follows mostly snapshot logic. + // step 1 : write a flag key to handle backup failed std::vector data; auto backupName = folly::format("BACKUP_{}", MetaKeyUtils::genTimestampStr()).str(); - data.emplace_back( MetaKeyUtils::snapshotKey(backupName), MetaKeyUtils::snapshotVal(cpp2::SnapshotStatus::INVALID, NetworkUtils::toHostsStr(hosts))); - Snapshot::instance(kvstore_, client_)->setSpaces(spaces); + auto putRet = doSyncPut(data); + if (putRet != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << "Write backup meta error"; + handleErrorCode(putRet); + onFinished(); + return; + } - // step 1 : Blocking all writes action for storage engines. + Snapshot::instance(kvstore_, client_)->setSpaces(spaces); + // step 2 : Blocking all writes action for storage engines. auto ret = Snapshot::instance(kvstore_, client_)->blockingWrites(SignType::BLOCK_ON); if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { LOG(ERROR) << "Send blocking sign to storage engine error"; @@ -150,7 +156,8 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { // step 3 : Create checkpoint for all storage engines. auto sret = Snapshot::instance(kvstore_, client_)->createSnapshot(backupName); if (!nebula::ok(sret)) { - LOG(ERROR) << "Checkpoint create error on storage engine"; + LOG(ERROR) << "Checkpoint create error on storage engine: " + << apache::thrift::util::enumNameSafe(nebula::error(sret)); handleErrorCode(nebula::error(sret)); ret = Snapshot::instance(kvstore_, client_)->blockingWrites(SignType::BLOCK_OFF); if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { @@ -161,7 +168,7 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { } // step 4 created backup for meta(export sst). - auto backupFiles = MetaServiceUtils::backupSpaces(kvstore_, spaces, backupName, backupSpaces); + auto backupFiles = MetaServiceUtils::backupTables(kvstore_, spaces, backupName, backupSpaces); if (!nebula::ok(backupFiles)) { LOG(ERROR) << "Failed backup meta"; handleErrorCode(nebula::cpp2::ErrorCode::E_BACKUP_FAILED); @@ -178,12 +185,12 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { return; } - // step 6 : update snapshot status from INVALID to VALID. + // step 6 : update backup status from INVALID to VALID. + data.clear(); data.emplace_back( MetaKeyUtils::snapshotKey(backupName), MetaKeyUtils::snapshotVal(cpp2::SnapshotStatus::VALID, NetworkUtils::toHostsStr(hosts))); - - auto putRet = doSyncPut(std::move(data)); + putRet = doSyncPut(std::move(data)); if (putRet != nebula::cpp2::ErrorCode::SUCCEEDED) { LOG(ERROR) << "All checkpoint creations are done, " "but update checkpoint status error. " @@ -194,13 +201,20 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { return; } - std::unordered_map backupInfo; - - // set backup info + // space backup info: + // - space desc + // - backup info list: + // - backup info: + // - host + // - checkpoint info: + // - space id + // - parts + // - path + std::unordered_map backups; auto snapshotInfo = std::move(nebula::value(sret)); for (auto id : spaces) { LOG(INFO) << "backup space " << id; - cpp2::SpaceBackupInfo spaceInfo; + cpp2::SpaceBackupInfo spaceBackup; auto spaceKey = MetaKeyUtils::spaceKey(id); auto spaceRet = doGet(spaceKey); if (!nebula::ok(spaceRet)) { @@ -208,29 +222,32 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) { onFinished(); return; } - auto properties = MetaKeyUtils::parseSpace(nebula::value(spaceRet)); + auto spaceDesc = MetaKeyUtils::parseSpace(nebula::value(spaceRet)); // todo we should save partition info. auto it = snapshotInfo.find(id); DCHECK(it != snapshotInfo.end()); - spaceInfo.set_info(std::move(it->second)); - spaceInfo.set_space(std::move(properties)); - backupInfo.emplace(id, std::move(spaceInfo)); + + spaceBackup.host_backups_ref() = std::move(it->second); + spaceBackup.space_ref() = std::move(spaceDesc); + backups.emplace(id, std::move(spaceBackup)); } + cpp2::BackupMeta backup; LOG(INFO) << "sst files count was:" << nebula::value(backupFiles).size(); - backup.set_meta_files(std::move(nebula::value(backupFiles))); - backup.set_backup_info(std::move(backupInfo)); - backup.set_backup_name(std::move(backupName)); - backup.set_full(true); - if (backupSpaces == nullptr) { - backup.set_include_system_space(true); + backup.meta_files_ref() = std::move(nebula::value(backupFiles)); + backup.space_backups_ref() = std::move(backups); + backup.backup_name_ref() = std::move(backupName); + backup.full_ref() = true; + bool allSpaces = backupSpaces == nullptr || backupSpaces->empty(); + if (allSpaces) { + backup.all_spaces_ref() = true; } else { - backup.set_include_system_space(false); + backup.all_spaces_ref() = false; } - backup.set_create_time(time::WallClock::fastNowInMilliSec()); + backup.create_time_ref() = time::WallClock::fastNowInMilliSec(); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_meta(std::move(backup)); + resp_.meta_ref() = std::move(backup); LOG(INFO) << "backup done"; onFinished(); diff --git a/src/meta/processors/admin/DropSnapshotProcessor.cpp b/src/meta/processors/admin/DropSnapshotProcessor.cpp index a4d05a4d4b3..140ae8c4bfe 100644 --- a/src/meta/processors/admin/DropSnapshotProcessor.cpp +++ b/src/meta/processors/admin/DropSnapshotProcessor.cpp @@ -17,9 +17,14 @@ void DropSnapshotProcessor::process(const cpp2::DropSnapshotReq& req) { // Check snapshot is exists auto key = MetaKeyUtils::snapshotKey(snapshot); - auto ret = doGet(std::move(key)); + auto ret = doGet(key); if (!nebula::ok(ret)) { auto retCode = nebula::error(ret); + if (retCode == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) { + LOG(INFO) << "Snapshot " << snapshot << " does not exist or already dropped."; + onFinished(); + return; + } LOG(ERROR) << "Get snapshot " << snapshot << " failed, error " << apache::thrift::util::enumNameSafe(retCode); handleErrorCode(retCode); @@ -76,7 +81,7 @@ void DropSnapshotProcessor::process(const cpp2::DropSnapshotReq& req) { return; } // Delete metadata of checkpoint - doRemove(MetaKeyUtils::snapshotKey(snapshot)); + doRemove(key); LOG(INFO) << "Drop snapshot " << snapshot << " successfully"; } diff --git a/src/meta/processors/admin/GetMetaDirInfoProcessor.cpp b/src/meta/processors/admin/GetMetaDirInfoProcessor.cpp index cc16d2679b5..0d96ed730f6 100644 --- a/src/meta/processors/admin/GetMetaDirInfoProcessor.cpp +++ b/src/meta/processors/admin/GetMetaDirInfoProcessor.cpp @@ -15,37 +15,13 @@ namespace meta { void GetMetaDirInfoProcessor::process(const cpp2::GetMetaDirInfoReq& req) { UNUSED(req); - auto data_root = kvstore_->getDataRoot(); - - std::vector realpaths; - bool failed = false; - std::transform(std::make_move_iterator(data_root.begin()), - std::make_move_iterator(data_root.end()), - std::back_inserter(realpaths), - [&failed](auto f) { - if (f[0] == '/') { - return f; - } else { - auto result = nebula::fs::FileUtils::realPath(f.c_str()); - if (!result.ok()) { - failed = true; - LOG(ERROR) << "Failed to get the absolute path of file: " << f; - return f; - } - return std::string(result.value()); - } - }); - if (failed) { - resp_.set_code(nebula::cpp2::ErrorCode::E_GET_META_DIR_FAILURE); - onFinished(); - return; - } + auto datapaths = kvstore_->getDataRoot(); nebula::cpp2::DirInfo dir; - dir.set_data(realpaths); - dir.set_root(boost::filesystem::current_path().string()); - resp_.set_dir(std::move(dir)); + dir.data_ref() = datapaths; + dir.root_ref() = boost::filesystem::current_path().string(); + resp_.dir_ref() = std::move(dir); - resp_.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); + resp_.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; onFinished(); } } // namespace meta diff --git a/src/meta/processors/admin/HBProcessor.cpp b/src/meta/processors/admin/HBProcessor.cpp index ef2e05c5e6c..7e78aba9732 100644 --- a/src/meta/processors/admin/HBProcessor.cpp +++ b/src/meta/processors/admin/HBProcessor.cpp @@ -41,10 +41,11 @@ void HBProcessor::process(const cpp2::HBReq& req) { return; } + // set or check storaged's cluster id ClusterID peerClusterId = req.get_cluster_id(); if (peerClusterId == 0) { LOG(INFO) << "Set clusterId for new host " << host << "!"; - resp_.set_cluster_id(clusterId_); + resp_.cluster_id_ref() = clusterId_; } else if (peerClusterId != clusterId_) { LOG(ERROR) << "Reject wrong cluster host " << host << "!"; handleErrorCode(nebula::cpp2::ErrorCode::E_WRONGCLUSTER); @@ -52,6 +53,7 @@ void HBProcessor::process(const cpp2::HBReq& req) { return; } + // set disk parts map if (req.disk_parts_ref().has_value()) { for (const auto& [spaceId, partDiskMap] : *req.get_disk_parts()) { for (const auto& [path, partList] : partDiskMap) { @@ -74,24 +76,39 @@ void HBProcessor::process(const cpp2::HBReq& req) { } } + // update host info HostInfo info(time::WallClock::fastNowInMilliSec(), role, req.get_git_info_sha()); if (req.leader_partIds_ref().has_value()) { ret = ActiveHostsMan::updateHostInfo(kvstore_, host, info, &*req.leader_partIds_ref()); } else { ret = ActiveHostsMan::updateHostInfo(kvstore_, host, info); } - if (ret == nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { - auto leaderRet = kvstore_->partLeader(kDefaultSpaceId, kDefaultPartId); - if (nebula::ok(leaderRet)) { - resp_.set_leader(toThriftHost(nebula::value(leaderRet))); + if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { + handleErrorCode(ret); + onFinished(); + return; + } + + // update host dir info + if (req.get_role() == cpp2::HostRole::STORAGE || req.get_role() == cpp2::HostRole::GRAPH) { + if (req.dir_ref().has_value()) { + std::vector data; + LOG(INFO) << folly::sformat("Update host {} dir info, root path: {}, data path size: {}", + host.toString(), + req.get_dir()->get_root(), + req.get_dir()->get_data().size()); + data.emplace_back(std::make_pair(MetaKeyUtils::hostDirKey(host.host, host.port), + MetaKeyUtils::hostDirVal(*req.get_dir()))); + ret = doSyncPut(data); } } + // set update time and meta version auto lastUpdateTimeRet = LastUpdateTimeMan::get(kvstore_); if (nebula::ok(lastUpdateTimeRet)) { - resp_.set_last_update_time_in_ms(nebula::value(lastUpdateTimeRet)); + resp_.last_update_time_in_ms_ref() = nebula::value(lastUpdateTimeRet); } else if (nebula::error(lastUpdateTimeRet) == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) { - resp_.set_last_update_time_in_ms(0); + resp_.last_update_time_in_ms_ref() = 0; } auto version = metaVersion_.load(); @@ -99,7 +116,7 @@ void HBProcessor::process(const cpp2::HBReq& req) { metaVersion_.store(static_cast(MetaVersionMan::getMetaVersionFromKV(kvstore_))); } - resp_.set_meta_version(metaVersion_.load()); + resp_.meta_version_ref() = metaVersion_.load(); handleErrorCode(ret); onFinished(); diff --git a/src/meta/processors/admin/ListClusterInfoProcessor.cpp b/src/meta/processors/admin/ListClusterInfoProcessor.cpp index 3776ef2cd7b..ce5215e2f98 100644 --- a/src/meta/processors/admin/ListClusterInfoProcessor.cpp +++ b/src/meta/processors/admin/ListClusterInfoProcessor.cpp @@ -22,52 +22,96 @@ void ListClusterInfoProcessor::process(const cpp2::ListClusterInfoReq& req) { return; } - const auto& prefix = MetaKeyUtils::hostPrefix(); - std::unique_ptr iter; - auto ret = kvstore_->prefix(kDefaultSpaceId, kDefaultPartId, prefix, &iter, true); - if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { - LOG(ERROR) << "prefix failed:" << apache::thrift::util::enumNameSafe(ret); + // services(include agent service) group by ip/hostname + std::unordered_map> hostServices; + + // non-meta services, may include inactive services + const auto& hostPrefix = MetaKeyUtils::hostPrefix(); + auto iterRet = doPrefix(hostPrefix); + if (!nebula::ok(iterRet)) { + LOG(ERROR) << "get host prefix failed:" + << apache::thrift::util::enumNameSafe(nebula::error(iterRet)); handleErrorCode(nebula::cpp2::ErrorCode::E_LIST_CLUSTER_FAILURE); onFinished(); return; } - - std::vector storages; - while (iter->valid()) { - auto host = MetaKeyUtils::parseHostKey(iter->key()); + auto iter = nebula::value(iterRet).get(); + for (; iter->valid(); iter->next()) { + HostAddr addr = MetaKeyUtils::parseHostKey(iter->key()); HostInfo info = HostInfo::decode(iter->val()); - if (info.role_ != cpp2::HostRole::STORAGE) { - iter->next(); - continue; - } + cpp2::ServiceInfo service; + service.role_ref() = info.role_; + service.addr_ref() = addr; - auto status = client_->listClusterInfo(host).get(); - if (!status.ok()) { - LOG(ERROR) << "listcluster info from storage failed, host: " << host; - handleErrorCode(nebula::cpp2::ErrorCode::E_LIST_CLUSTER_FAILURE); - onFinished(); - return; + // fill the dir info + if (info.role_ == meta::cpp2::HostRole::GRAPH || info.role_ == meta::cpp2::HostRole::STORAGE) { + auto dirKey = MetaKeyUtils::hostDirKey(addr.host, addr.port); + auto dirRet = doGet(dirKey); + if (!nebula::ok(dirRet)) { + LOG(ERROR) << folly::sformat("Get host {} dir info for {} failed: {}", + addr.toString(), + apache::thrift::util::enumNameSafe(info.role_), + apache::thrift::util::enumNameSafe(nebula::error(dirRet))); + handleErrorCode(nebula::error(dirRet)); + onFinished(); + return; + } + auto dir = MetaKeyUtils::parseHostDir(std::move(nebula::value(dirRet))); + service.dir_ref() = std::move(dir); } - storages.emplace_back(apache::thrift::FragileConstructor(), std::move(host), status.value()); - iter->next(); + if (hostServices.find(addr.host) == hostServices.end()) { + hostServices[addr.host] = std::vector(); + } + hostServices[addr.host].emplace_back(std::move(service)); } - auto* pm = store->partManager(); - auto* mpm = dynamic_cast(pm); - if (mpm == nullptr) { - resp_.set_code(nebula::cpp2::ErrorCode::E_LIST_CLUSTER_FAILURE); + // meta service + auto partRet = kvstore_->part(kDefaultSpaceId, kDefaultPartId); + if (!nebula::ok(partRet)) { + auto code = nebula::error(partRet); + LOG(ERROR) << "get meta part store failed, error: " << apache::thrift::util::enumNameSafe(code); + handleErrorCode(nebula::cpp2::ErrorCode::E_LIST_CLUSTER_FAILURE); onFinished(); return; } - auto& map = mpm->partsMap(); - auto hosts = map[kDefaultSpaceId][kDefaultPartId].hosts_; - LOG(INFO) << "meta servers count: " << hosts.size(); - resp_.set_meta_servers(std::move(hosts)); + auto raftPeers = nebula::value(partRet)->peers(); + for (auto& raftAddr : raftPeers) { + auto metaAddr = Utils::getStoreAddrFromRaftAddr(raftAddr); + cpp2::ServiceInfo service; + service.role_ref() = cpp2::HostRole::META; + service.addr_ref() = metaAddr; + + if (hostServices.find(metaAddr.host) == hostServices.end()) { + hostServices[metaAddr.host] = std::vector(); + } + hostServices[metaAddr.host].push_back(service); + } + + // check: there should be only one agent in each host + for (const auto& [host, services] : hostServices) { + int agentCount = 0; + for (auto& s : services) { + if (s.get_role() == cpp2::HostRole::AGENT) { + agentCount++; + } + } + if (agentCount != 1) { + LOG(ERROR) << folly::sformat("There are {} agent count is host {}", agentCount, host); + handleErrorCode(nebula::cpp2::ErrorCode::E_LIST_CLUSTER_FAILURE); + onFinished(); + return; + } + + if (services.size() <= 1) { + LOG(ERROR) << "There is no other service than agent in host: " << host; + continue; + } + } - resp_.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_storage_servers(std::move(storages)); + resp_.host_services_ref() = hostServices; + resp_.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; onFinished(); } } // namespace meta diff --git a/src/meta/processors/admin/ListClusterInfoProcessor.h b/src/meta/processors/admin/ListClusterInfoProcessor.h index 1b754c192de..a62b098905d 100644 --- a/src/meta/processors/admin/ListClusterInfoProcessor.h +++ b/src/meta/processors/admin/ListClusterInfoProcessor.h @@ -14,15 +14,14 @@ namespace meta { class ListClusterInfoProcessor : public BaseProcessor { public: - static ListClusterInfoProcessor* instance(kvstore::KVStore* kvstore, AdminClient* client) { - return new ListClusterInfoProcessor(kvstore, client); + static ListClusterInfoProcessor* instance(kvstore::KVStore* kvstore) { + return new ListClusterInfoProcessor(kvstore); } void process(const cpp2::ListClusterInfoReq& req); private: - explicit ListClusterInfoProcessor(kvstore::KVStore* kvstore, AdminClient* client) - : BaseProcessor(kvstore), client_(client) {} - AdminClient* client_; + explicit ListClusterInfoProcessor(kvstore::KVStore* kvstore) + : BaseProcessor(kvstore) {} }; } // namespace meta } // namespace nebula diff --git a/src/meta/processors/admin/ListSnapshotsProcessor.cpp b/src/meta/processors/admin/ListSnapshotsProcessor.cpp index 4f63e11dc83..c1a14400737 100644 --- a/src/meta/processors/admin/ListSnapshotsProcessor.cpp +++ b/src/meta/processors/admin/ListSnapshotsProcessor.cpp @@ -29,15 +29,15 @@ void ListSnapshotsProcessor::process(const cpp2::ListSnapshotsReq&) { auto status = MetaKeyUtils::parseSnapshotStatus(val); auto hosts = MetaKeyUtils::parseSnapshotHosts(val); cpp2::Snapshot snapshot; - snapshot.set_name(std::move(name)); - snapshot.set_status(std::move(status)); - snapshot.set_hosts(std::move(hosts)); + snapshot.name_ref() = std::move(name); + snapshot.status_ref() = std::move(status); + snapshot.hosts_ref() = std::move(hosts); snapshots.emplace_back(std::move(snapshot)); iter->next(); } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_snapshots(std::move(snapshots)); + resp_.snapshots_ref() = std::move(snapshots); onFinished(); } diff --git a/src/meta/processors/admin/SnapShot.cpp b/src/meta/processors/admin/SnapShot.cpp index 3c0c90f8872..49452bd83d5 100644 --- a/src/meta/processors/admin/SnapShot.cpp +++ b/src/meta/processors/admin/SnapShot.cpp @@ -15,11 +15,12 @@ namespace nebula { namespace meta { -ErrorOr>> +ErrorOr>> Snapshot::createSnapshot(const std::string& name) { - auto retSpacesHostsRet = getSpacesHosts(); - if (!nebula::ok(retSpacesHostsRet)) { - auto retcode = nebula::error(retSpacesHostsRet); + auto hostSpacesRet = getHostSpaces(); + if (!nebula::ok(hostSpacesRet)) { + auto retcode = nebula::error(hostSpacesRet); if (retcode != nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { retcode = nebula::cpp2::ErrorCode::E_STORE_FAILURE; } @@ -27,21 +28,37 @@ Snapshot::createSnapshot(const std::string& name) { } // This structure is used for the subsequent construction of the // common.PartitionBackupInfo - std::unordered_map> info; - - auto spacesHosts = nebula::value(retSpacesHostsRet); - for (const auto& spaceHosts : spacesHosts) { - for (const auto& host : spaceHosts.second) { - auto status = client_->createSnapshot(spaceHosts.first, name, host).get(); - if (!status.ok()) { - return nebula::cpp2::ErrorCode::E_RPC_FAILURE; + std::unordered_map> info; + + auto hostSpaces = nebula::value(hostSpacesRet); + for (auto const& [host, spaces] : hostSpaces) { + auto snapshotRet = client_->createSnapshot(spaces, name, host).get(); + if (!snapshotRet.ok()) { + return nebula::cpp2::ErrorCode::E_RPC_FAILURE; + } + auto backupInfo = snapshotRet.value(); + + // split backup info by space id + std::unordered_map spaceBackup; + for (auto& ck : backupInfo.get_checkpoints()) { + auto it = spaceBackup.find(ck.get_space_id()); + if (it == spaceBackup.cend()) { + cpp2::HostBackupInfo hostBackup; + hostBackup.host_ref() = host; + hostBackup.checkpoints_ref().value().push_back(ck); + spaceBackup[ck.get_space_id()] = std::move(hostBackup); + } else { + it->second.checkpoints_ref().value().push_back(ck); } - auto backupInfo = status.value(); - auto it = info.find(spaceHosts.first); - if (it != info.cend()) { - it->second.emplace_back(backupInfo); + } + + // insert to global result + for (auto& [spaceId, binfo] : spaceBackup) { + auto it = info.find(spaceId); + if (it == info.cend()) { + info[spaceId] = {std::move(binfo)}; } else { - info[spaceHosts.first] = {std::move(backupInfo)}; + it->second.emplace_back(binfo); } } } @@ -50,62 +67,61 @@ Snapshot::createSnapshot(const std::string& name) { nebula::cpp2::ErrorCode Snapshot::dropSnapshot(const std::string& name, const std::vector& hosts) { - auto retSpacesHostsRet = getSpacesHosts(); - if (!nebula::ok(retSpacesHostsRet)) { - auto retcode = nebula::error(retSpacesHostsRet); + auto hostSpacesRet = getHostSpaces(); + if (!nebula::ok(hostSpacesRet)) { + auto retcode = nebula::error(hostSpacesRet); if (retcode != nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { retcode = nebula::cpp2::ErrorCode::E_STORE_FAILURE; } return retcode; } - auto spacesHosts = nebula::value(retSpacesHostsRet); - for (const auto& spaceHosts : spacesHosts) { - for (const auto& host : spaceHosts.second) { - if (std::find(hosts.begin(), hosts.end(), host) != hosts.end()) { - auto status = client_->dropSnapshot(spaceHosts.first, name, host).get(); - if (!status.ok()) { - auto msg = "failed drop checkpoint : \"%s\". on host %s. error %s"; - auto error = folly::stringPrintf( - msg, name.c_str(), host.toString().c_str(), status.toString().c_str()); - LOG(ERROR) << error; - } - } + auto hostSpaces = nebula::value(hostSpacesRet); + for (const auto& [host, spaces] : hostSpaces) { + if (std::find(hosts.begin(), hosts.end(), host) == hosts.end()) { + continue; + } + + auto status = client_->dropSnapshot(spaces, name, host).get(); + if (!status.ok()) { + auto msg = "failed drop checkpoint : \"%s\". on host %s. error %s"; + auto error = folly::stringPrintf( + msg, name.c_str(), host.toString().c_str(), status.toString().c_str()); + LOG(ERROR) << error; } } return nebula::cpp2::ErrorCode::SUCCEEDED; } nebula::cpp2::ErrorCode Snapshot::blockingWrites(storage::cpp2::EngineSignType sign) { - auto retSpacesHostsRet = getSpacesHosts(); - if (!nebula::ok(retSpacesHostsRet)) { - auto retcode = nebula::error(retSpacesHostsRet); + auto hostSpacesRet = getHostSpaces(); + if (!nebula::ok(hostSpacesRet)) { + auto retcode = nebula::error(hostSpacesRet); if (retcode != nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { retcode = nebula::cpp2::ErrorCode::E_STORE_FAILURE; } return retcode; } - auto spacesHosts = nebula::value(retSpacesHostsRet); + auto hostSpaces = nebula::value(hostSpacesRet); auto ret = nebula::cpp2::ErrorCode::SUCCEEDED; - for (const auto& spaceHosts : spacesHosts) { - for (const auto& host : spaceHosts.second) { - LOG(INFO) << "will block write host: " << host; - auto status = client_->blockingWrites(spaceHosts.first, sign, host).get(); - if (!status.ok()) { - LOG(ERROR) << "Send blocking sign error on host : " << host; - ret = nebula::cpp2::ErrorCode::E_BLOCK_WRITE_FAILURE; - if (sign == storage::cpp2::EngineSignType::BLOCK_ON) { - break; - } + for (const auto& [host, spaces] : hostSpaces) { + LOG(INFO) << "will block write host: " << host; + auto status = client_->blockingWrites(spaces, sign, host).get(); + if (!status.ok()) { + LOG(ERROR) << "Send blocking sign error on host " << host + << ", errorcode: " << status.message(); + ret = nebula::cpp2::ErrorCode::E_BLOCK_WRITE_FAILURE; + if (sign == storage::cpp2::EngineSignType::BLOCK_ON) { + break; } } } return ret; } -ErrorOr>> -Snapshot::getSpacesHosts() { +ErrorOr>> +Snapshot::getHostSpaces() { folly::SharedMutex::ReadHolder rHolder(LockUtils::spaceLock()); const auto& prefix = MetaKeyUtils::partPrefix(); std::unique_ptr iter; @@ -116,23 +132,24 @@ Snapshot::getSpacesHosts() { return retCode; } - std::map> hostsByspaces; - + std::map> hostSpaces; for (; iter->valid(); iter->next()) { auto partHosts = MetaKeyUtils::parsePartVal(iter->val()); - auto space = MetaKeyUtils::parsePartKeySpaceId(iter->key()); - if (!spaces_.empty()) { - auto it = spaces_.find(space); + auto spaceId = MetaKeyUtils::parsePartKeySpaceId(iter->key()); + + bool allSpaces = spaces_.empty(); + if (!allSpaces) { + auto it = spaces_.find(spaceId); if (it == spaces_.end()) { continue; } } - for (auto& ph : partHosts) { - hostsByspaces[space].emplace(std::move(ph)); + for (auto& host : partHosts) { + hostSpaces[host].emplace(spaceId); } } - return hostsByspaces; + return hostSpaces; } } // namespace meta diff --git a/src/meta/processors/admin/SnapShot.h b/src/meta/processors/admin/SnapShot.h index 82e9ef5bf47..0c1d9e7b124 100644 --- a/src/meta/processors/admin/SnapShot.h +++ b/src/meta/processors/admin/SnapShot.h @@ -26,9 +26,12 @@ class Snapshot { ~Snapshot() = default; - inline void setSpaces(std::unordered_set spaces) { spaces_ = std::move(spaces); } + inline void setSpaces(std::unordered_set spaces) { + spaces_ = std::move(spaces); + } - ErrorOr>> + ErrorOr>> createSnapshot(const std::string& name); nebula::cpp2::ErrorCode dropSnapshot(const std::string& name, const std::vector& hosts); @@ -40,7 +43,7 @@ class Snapshot { executor_.reset(new folly::CPUThreadPoolExecutor(1)); } - ErrorOr>> getSpacesHosts(); + ErrorOr>> getHostSpaces(); private: kvstore::KVStore* kv_{nullptr}; diff --git a/src/meta/processors/admin/VerifyClientVersionProcessor.cpp b/src/meta/processors/admin/VerifyClientVersionProcessor.cpp index 84b84141fff..3678c717a47 100644 --- a/src/meta/processors/admin/VerifyClientVersionProcessor.cpp +++ b/src/meta/processors/admin/VerifyClientVersionProcessor.cpp @@ -20,11 +20,11 @@ void VerifyClientVersionProcessor::process(const cpp2::VerifyClientVersionReq& r ":", FLAGS_client_white_list, std::inserter(whiteList, whiteList.begin())); if (FLAGS_enable_client_white_list && whiteList.find(req.get_client_version()) == whiteList.end()) { - resp_.set_code(nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE); - resp_.set_error_msg(folly::stringPrintf( + resp_.code_ref() = nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE; + resp_.error_msg_ref() = folly::stringPrintf( "Meta client version(%s) is not accepted, current meta client white list: %s.", req.get_client_version().c_str(), - FLAGS_client_white_list.c_str())); + FLAGS_client_white_list.c_str()); } else { const auto& host = req.get_host(); auto versionKey = MetaKeyUtils::versionKey(host); @@ -32,7 +32,7 @@ void VerifyClientVersionProcessor::process(const cpp2::VerifyClientVersionReq& r std::vector versionData; versionData.emplace_back(std::move(versionKey), std::move(versionVal)); doSyncPut(versionData); - resp_.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); + resp_.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; } onFinished(); } diff --git a/src/meta/processors/config/GetConfigProcessor.cpp b/src/meta/processors/config/GetConfigProcessor.cpp index 8adb08a122c..1b1d45fb0d9 100644 --- a/src/meta/processors/config/GetConfigProcessor.cpp +++ b/src/meta/processors/config/GetConfigProcessor.cpp @@ -34,7 +34,7 @@ void GetConfigProcessor::process(const cpp2::GetConfigReq& req) { } while (false); if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { - resp_.set_items(std::move(items)); + resp_.items_ref() = std::move(items); } handleErrorCode(code); onFinished(); @@ -56,8 +56,8 @@ nebula::cpp2::ErrorCode GetConfigProcessor::getOneConfig(const cpp2::ConfigModul } cpp2::ConfigItem item = MetaKeyUtils::parseConfigValue(nebula::value(ret)); - item.set_module(module); - item.set_name(name); + item.module_ref() = module; + item.name_ref() = name; items.emplace_back(std::move(item)); return nebula::cpp2::ErrorCode::SUCCEEDED; } diff --git a/src/meta/processors/config/ListConfigsProcessor.cpp b/src/meta/processors/config/ListConfigsProcessor.cpp index 16a237276c4..cc7056601c8 100644 --- a/src/meta/processors/config/ListConfigsProcessor.cpp +++ b/src/meta/processors/config/ListConfigsProcessor.cpp @@ -28,13 +28,13 @@ void ListConfigsProcessor::process(const cpp2::ListConfigsReq& req) { auto value = iter->val(); auto item = MetaKeyUtils::parseConfigValue(value); auto configName = MetaKeyUtils::parseConfigKey(key); - item.set_module(configName.first); - item.set_name(configName.second); + item.module_ref() = configName.first; + item.name_ref() = configName.second; items.emplace_back(std::move(item)); iter->next(); } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_items(std::move(items)); + resp_.items_ref() = std::move(items); onFinished(); } diff --git a/src/meta/processors/index/CreateEdgeIndexProcessor.cpp b/src/meta/processors/index/CreateEdgeIndexProcessor.cpp index b8a3451d57c..b38626ccf7f 100644 --- a/src/meta/processors/index/CreateEdgeIndexProcessor.cpp +++ b/src/meta/processors/index/CreateEdgeIndexProcessor.cpp @@ -46,7 +46,7 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) { LOG(ERROR) << "Create Edge Index Failed: " << indexName << " has existed"; handleErrorCode(nebula::cpp2::ErrorCode::E_EXISTED); } - resp_.set_id(to(nebula::value(ret), EntryType::INDEX)); + resp_.id_ref() = to(nebula::value(ret), EntryType::INDEX); onFinished(); return; } else { @@ -94,7 +94,7 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) { } if (checkIndexExist(fields, item)) { - resp_.set_code(nebula::cpp2::ErrorCode::E_EXISTED); + resp_.code_ref() = nebula::cpp2::ErrorCode::E_EXISTED; onFinished(); return; } @@ -155,8 +155,8 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) { onFinished(); return; } - col.type.set_type(nebula::cpp2::PropertyType::FIXED_STRING); - col.type.set_type_length(*field.get_type_length()); + col.type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING; + col.type.type_length_ref() = *field.get_type_length(); } else if (field.type_length_ref().has_value()) { LOG(ERROR) << "No need to set type length : " << field.get_name(); handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM); @@ -183,24 +183,24 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) { auto edgeIndex = nebula::value(edgeIndexRet); cpp2::IndexItem item; - item.set_index_id(edgeIndex); - item.set_index_name(indexName); + item.index_id_ref() = edgeIndex; + item.index_name_ref() = indexName; nebula::cpp2::SchemaID schemaID; - schemaID.set_edge_type(edgeType); - item.set_schema_id(schemaID); - item.set_schema_name(edgeName); - item.set_fields(std::move(columns)); + schemaID.edge_type_ref() = edgeType; + item.schema_id_ref() = schemaID; + item.schema_name_ref() = edgeName; + item.fields_ref() = std::move(columns); if (req.index_params_ref().has_value()) { - item.set_index_params(*req.index_params_ref()); + item.index_params_ref() = *req.index_params_ref(); } if (req.comment_ref().has_value()) { - item.set_comment(*req.comment_ref()); + item.comment_ref() = *req.comment_ref(); } data.emplace_back(MetaKeyUtils::indexIndexKey(space, indexName), std::string(reinterpret_cast(&edgeIndex), sizeof(IndexID))); data.emplace_back(MetaKeyUtils::indexKey(space, edgeIndex), MetaKeyUtils::indexVal(item)); LOG(INFO) << "Create Edge Index " << indexName << ", edgeIndex " << edgeIndex; - resp_.set_id(to(edgeIndex, EntryType::INDEX)); + resp_.id_ref() = to(edgeIndex, EntryType::INDEX); doSyncPutAndUpdate(std::move(data)); } diff --git a/src/meta/processors/index/CreateTagIndexProcessor.cpp b/src/meta/processors/index/CreateTagIndexProcessor.cpp index 6c094d0cfff..68edfdbbfc5 100644 --- a/src/meta/processors/index/CreateTagIndexProcessor.cpp +++ b/src/meta/processors/index/CreateTagIndexProcessor.cpp @@ -46,7 +46,7 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) { LOG(ERROR) << "Create Tag Index Failed: " << indexName << " has existed"; handleErrorCode(nebula::cpp2::ErrorCode::E_EXISTED); } - resp_.set_id(to(nebula::value(ret), EntryType::INDEX)); + resp_.id_ref() = to(nebula::value(ret), EntryType::INDEX); onFinished(); return; } else { @@ -93,7 +93,7 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) { } if (checkIndexExist(fields, item)) { - resp_.set_code(nebula::cpp2::ErrorCode::E_EXISTED); + resp_.code_ref() = nebula::cpp2::ErrorCode::E_EXISTED; onFinished(); return; } @@ -153,8 +153,8 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) { onFinished(); return; } - col.type.set_type(nebula::cpp2::PropertyType::FIXED_STRING); - col.type.set_type_length(*field.get_type_length()); + col.type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING; + col.type.type_length_ref() = *field.get_type_length(); } else if (field.type_length_ref().has_value()) { LOG(ERROR) << "No need to set type length : " << field.get_name(); handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM); @@ -181,25 +181,25 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) { auto tagIndex = nebula::value(tagIndexRet); cpp2::IndexItem item; - item.set_index_id(tagIndex); - item.set_index_name(indexName); + item.index_id_ref() = tagIndex; + item.index_name_ref() = indexName; nebula::cpp2::SchemaID schemaID; - schemaID.set_tag_id(tagID); - item.set_schema_id(schemaID); - item.set_schema_name(tagName); - item.set_fields(std::move(columns)); + schemaID.tag_id_ref() = tagID; + item.schema_id_ref() = schemaID; + item.schema_name_ref() = tagName; + item.fields_ref() = std::move(columns); if (req.index_params_ref().has_value()) { - item.set_index_params(*req.index_params_ref()); + item.index_params_ref() = *req.index_params_ref(); } if (req.comment_ref().has_value()) { - item.set_comment(*req.comment_ref()); + item.comment_ref() = *req.comment_ref(); } data.emplace_back(MetaKeyUtils::indexIndexKey(space, indexName), std::string(reinterpret_cast(&tagIndex), sizeof(IndexID))); data.emplace_back(MetaKeyUtils::indexKey(space, tagIndex), MetaKeyUtils::indexVal(item)); LOG(INFO) << "Create Tag Index " << indexName << ", tagIndex " << tagIndex; - resp_.set_id(to(tagIndex, EntryType::INDEX)); + resp_.id_ref() = to(tagIndex, EntryType::INDEX); doSyncPutAndUpdate(std::move(data)); } diff --git a/src/meta/processors/index/DropEdgeIndexProcessor.cpp b/src/meta/processors/index/DropEdgeIndexProcessor.cpp index 02f8aa9d661..580969f9c08 100644 --- a/src/meta/processors/index/DropEdgeIndexProcessor.cpp +++ b/src/meta/processors/index/DropEdgeIndexProcessor.cpp @@ -55,13 +55,13 @@ void DropEdgeIndexProcessor::process(const cpp2::DropEdgeIndexReq& req) { auto item = MetaKeyUtils::parseIndex(nebula::value(indexItemRet)); if (item.get_schema_id().getType() != nebula::cpp2::SchemaID::Type::edge_type) { LOG(ERROR) << "Drop Edge Index Failed: Index Name " << indexName << " is not EdgeIndex"; - resp_.set_code(nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND); + resp_.code_ref() = nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND; onFinished(); return; } LOG(INFO) << "Drop Edge Index " << indexName; - resp_.set_id(to(edgeIndexID, EntryType::INDEX)); + resp_.id_ref() = to(edgeIndexID, EntryType::INDEX); doSyncMultiRemoveAndUpdate(std::move(keys)); } diff --git a/src/meta/processors/index/DropTagIndexProcessor.cpp b/src/meta/processors/index/DropTagIndexProcessor.cpp index b079a69aa71..0f9755b0411 100644 --- a/src/meta/processors/index/DropTagIndexProcessor.cpp +++ b/src/meta/processors/index/DropTagIndexProcessor.cpp @@ -54,13 +54,13 @@ void DropTagIndexProcessor::process(const cpp2::DropTagIndexReq& req) { auto item = MetaKeyUtils::parseIndex(nebula::value(indexItemRet)); if (item.get_schema_id().getType() != nebula::cpp2::SchemaID::Type::tag_id) { LOG(ERROR) << "Drop Tag Index Failed: Index Name " << indexName << " is not TagIndex"; - resp_.set_code(nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND); + resp_.code_ref() = nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND; onFinished(); return; } LOG(INFO) << "Drop Tag Index " << indexName; - resp_.set_id(to(tagIndexID, EntryType::INDEX)); + resp_.id_ref() = to(tagIndexID, EntryType::INDEX); doSyncMultiRemoveAndUpdate(std::move(keys)); } diff --git a/src/meta/processors/index/FTIndexProcessor.cpp b/src/meta/processors/index/FTIndexProcessor.cpp index 544be2a73a1..2df5241d791 100644 --- a/src/meta/processors/index/FTIndexProcessor.cpp +++ b/src/meta/processors/index/FTIndexProcessor.cpp @@ -156,7 +156,7 @@ void ListFTIndexesProcessor::process(const cpp2::ListFTIndexesReq&) { indexes.emplace(std::move(name), std::move(index)); iter->next(); } - resp_.set_indexes(std::move(indexes)); + resp_.indexes_ref() = std::move(indexes); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/index/FTServiceProcessor.cpp b/src/meta/processors/index/FTServiceProcessor.cpp index 9f0cbe0fbb8..af3fbaf720b 100644 --- a/src/meta/processors/index/FTServiceProcessor.cpp +++ b/src/meta/processors/index/FTServiceProcessor.cpp @@ -71,7 +71,7 @@ void ListFTClientsProcessor::process(const cpp2::ListFTClientsReq&) { if (iter->valid()) { clients = MetaKeyUtils::parseFTClients(iter->val()); } - resp_.set_clients(std::move(clients)); + resp_.clients_ref() = std::move(clients); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/index/GetEdgeIndexProcessor.cpp b/src/meta/processors/index/GetEdgeIndexProcessor.cpp index d69e1213815..ede1aa7353e 100644 --- a/src/meta/processors/index/GetEdgeIndexProcessor.cpp +++ b/src/meta/processors/index/GetEdgeIndexProcessor.cpp @@ -42,13 +42,13 @@ void GetEdgeIndexProcessor::process(const cpp2::GetEdgeIndexReq& req) { auto item = MetaKeyUtils::parseIndex(nebula::value(indexItemRet)); if (item.get_schema_id().getType() != nebula::cpp2::SchemaID::Type::edge_type) { LOG(ERROR) << "Get Edge Index Failed: Index Name " << indexName << " is not EdgeIndex"; - resp_.set_code(nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND); + resp_.code_ref() = nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND; onFinished(); return; } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_item(std::move(item)); + resp_.item_ref() = std::move(item); onFinished(); } diff --git a/src/meta/processors/index/GetTagIndexProcessor.cpp b/src/meta/processors/index/GetTagIndexProcessor.cpp index 8f7c416375c..63b98de6457 100644 --- a/src/meta/processors/index/GetTagIndexProcessor.cpp +++ b/src/meta/processors/index/GetTagIndexProcessor.cpp @@ -43,13 +43,13 @@ void GetTagIndexProcessor::process(const cpp2::GetTagIndexReq& req) { auto item = MetaKeyUtils::parseIndex(nebula::value(indexItemRet)); if (item.get_schema_id().getType() != nebula::cpp2::SchemaID::Type::tag_id) { LOG(ERROR) << "Get Tag Index Failed: Index Name " << indexName << " is not TagIndex"; - resp_.set_code(nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND); + resp_.code_ref() = nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND; onFinished(); return; } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_item(std::move(item)); + resp_.item_ref() = std::move(item); onFinished(); } diff --git a/src/meta/processors/index/ListEdgeIndexesProcessor.cpp b/src/meta/processors/index/ListEdgeIndexesProcessor.cpp index f2b93784285..a1865b6671d 100644 --- a/src/meta/processors/index/ListEdgeIndexesProcessor.cpp +++ b/src/meta/processors/index/ListEdgeIndexesProcessor.cpp @@ -35,7 +35,7 @@ void ListEdgeIndexesProcessor::process(const cpp2::ListEdgeIndexesReq& req) { iter->next(); } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_items(std::move(items)); + resp_.items_ref() = std::move(items); onFinished(); } diff --git a/src/meta/processors/index/ListTagIndexesProcessor.cpp b/src/meta/processors/index/ListTagIndexesProcessor.cpp index a255d9fa1b4..2cbebf9b709 100644 --- a/src/meta/processors/index/ListTagIndexesProcessor.cpp +++ b/src/meta/processors/index/ListTagIndexesProcessor.cpp @@ -35,7 +35,7 @@ void ListTagIndexesProcessor::process(const cpp2::ListTagIndexesReq& req) { iter->next(); } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_items(std::move(items)); + resp_.items_ref() = std::move(items); onFinished(); } diff --git a/src/meta/processors/job/AdminJobProcessor.cpp b/src/meta/processors/job/AdminJobProcessor.cpp index 950a34d18dc..755179ae7a8 100644 --- a/src/meta/processors/job/AdminJobProcessor.cpp +++ b/src/meta/processors/job/AdminJobProcessor.cpp @@ -6,6 +6,7 @@ #include "meta/processors/job/AdminJobProcessor.h" #include "common/base/StatusOr.h" +#include "common/stats/StatsManager.h" #include "meta/processors/job/JobDescription.h" #include "meta/processors/job/JobManager.h" @@ -44,7 +45,7 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { auto jobExist = jobMgr->checkJobExist(cmd, paras, jId); if (jobExist) { LOG(INFO) << "Job has already exists: " << jId; - result.set_job_id(jId); + result.job_id_ref() = jId; break; } @@ -58,14 +59,14 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { JobDescription jobDesc(nebula::value(jobId), cmd, paras); errorCode = jobMgr->addJob(jobDesc, adminClient_); if (errorCode == nebula::cpp2::ErrorCode::SUCCEEDED) { - result.set_job_id(nebula::value(jobId)); + result.job_id_ref() = nebula::value(jobId); } break; } case nebula::meta::cpp2::AdminJobOp::SHOW_All: { auto ret = jobMgr->showJobs(req.get_paras().back()); if (nebula::ok(ret)) { - result.set_job_desc(nebula::value(ret)); + result.job_desc_ref() = nebula::value(ret); } else { errorCode = nebula::error(ret); } @@ -87,8 +88,8 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { } auto ret = jobMgr->showJob(iJob, req.get_paras().back()); if (nebula::ok(ret)) { - result.set_job_desc(std::vector{nebula::value(ret).first}); - result.set_task_desc(nebula::value(ret).second); + result.job_desc_ref() = std::vector{nebula::value(ret).first}; + result.task_desc_ref() = nebula::value(ret).second; } else { errorCode = nebula::error(ret); } @@ -120,7 +121,7 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { } auto ret = jobMgr->recoverJob(spaceName, adminClient_, jobIds); if (nebula::ok(ret)) { - result.set_recovered_job_num(nebula::value(ret)); + result.recovered_job_num_ref() = nebula::value(ret); } else { errorCode = nebula::error(ret); } @@ -136,7 +137,7 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { onFinished(); return; } - resp_.set_result(std::move(result)); + resp_.result_ref() = std::move(result); onFinished(); } diff --git a/src/meta/processors/job/AdminJobProcessor.h b/src/meta/processors/job/AdminJobProcessor.h index 589e81a7fa4..21ab6fac3a9 100644 --- a/src/meta/processors/job/AdminJobProcessor.h +++ b/src/meta/processors/job/AdminJobProcessor.h @@ -6,6 +6,7 @@ #ifndef META_ADMINJOBPROCESSOR_H_ #define META_ADMINJOBPROCESSOR_H_ +#include "common/stats/StatsManager.h" #include "meta/processors/BaseProcessor.h" #include "meta/processors/admin/AdminClient.h" diff --git a/src/meta/processors/job/BalanceJobExecutor.cpp b/src/meta/processors/job/BalanceJobExecutor.cpp index ae38d659d92..d2d74400c39 100644 --- a/src/meta/processors/job/BalanceJobExecutor.cpp +++ b/src/meta/processors/job/BalanceJobExecutor.cpp @@ -31,9 +31,13 @@ BalanceJobExecutor::BalanceJobExecutor(JobID jobId, toHost_ = TargetHosts::NONE; } -bool BalanceJobExecutor::check() { return !paras_.empty(); } +bool BalanceJobExecutor::check() { + return !paras_.empty(); +} -nebula::cpp2::ErrorCode BalanceJobExecutor::prepare() { return nebula::cpp2::ErrorCode::SUCCEEDED; } +nebula::cpp2::ErrorCode BalanceJobExecutor::prepare() { + return nebula::cpp2::ErrorCode::SUCCEEDED; +} nebula::cpp2::ErrorCode BalanceJobExecutor::stop() { stopped_ = true; @@ -47,7 +51,9 @@ folly::Future BalanceJobExecutor::executeInternal(HostAddr&& address, return Status::OK(); } -bool BalanceJobExecutor::runInMeta() { return true; } +bool BalanceJobExecutor::runInMeta() { + return true; +} nebula::cpp2::ErrorCode BalanceJobExecutor::recovery() { return nebula::cpp2::ErrorCode::SUCCEEDED; diff --git a/src/meta/processors/job/BalanceJobExecutor.h b/src/meta/processors/job/BalanceJobExecutor.h index 3832122fce1..e7f1653d6a5 100644 --- a/src/meta/processors/job/BalanceJobExecutor.h +++ b/src/meta/processors/job/BalanceJobExecutor.h @@ -91,12 +91,12 @@ class DataBalanceJobExecutor : public BalanceJobExecutor { FRIEND_TEST(BalanceTest, ManyHostsLeaderBalancePlanTest); FRIEND_TEST(BalanceTest, LeaderBalanceWithZoneTest); FRIEND_TEST(BalanceTest, LeaderBalanceWithLargerZoneTest); - FRIEND_TEST(BalanceTest, LeaderBalanceWithComplexZoneTest); + FRIEND_TEST(BalanceTest, DISABLED_LeaderBalanceWithComplexZoneTest); FRIEND_TEST(BalanceTest, ExpansionZoneTest); FRIEND_TEST(BalanceTest, ExpansionHostIntoZoneTest); FRIEND_TEST(BalanceTest, ShrinkZoneTest); FRIEND_TEST(BalanceTest, ShrinkHostFromZoneTest); - FRIEND_TEST(BalanceTest, BalanceWithComplexZoneTest); + FRIEND_TEST(BalanceTest, DISABLED_BalanceWithComplexZoneTest); FRIEND_TEST(BalanceIntegrationTest, LeaderBalanceTest); FRIEND_TEST(BalanceIntegrationTest, BalanceTest); friend void testRestBlancer(); @@ -181,12 +181,12 @@ class LeaderBalanceJobExecutor : public BalanceJobExecutor { FRIEND_TEST(BalanceTest, ManyHostsLeaderBalancePlanTest); FRIEND_TEST(BalanceTest, LeaderBalanceWithZoneTest); FRIEND_TEST(BalanceTest, LeaderBalanceWithLargerZoneTest); - FRIEND_TEST(BalanceTest, LeaderBalanceWithComplexZoneTest); + FRIEND_TEST(BalanceTest, DISABLED_LeaderBalanceWithComplexZoneTest); FRIEND_TEST(BalanceTest, ExpansionZoneTest); FRIEND_TEST(BalanceTest, ExpansionHostIntoZoneTest); FRIEND_TEST(BalanceTest, ShrinkZoneTest); FRIEND_TEST(BalanceTest, ShrinkHostFromZoneTest); - FRIEND_TEST(BalanceTest, BalanceWithComplexZoneTest); + FRIEND_TEST(BalanceTest, DISABLED_BalanceWithComplexZoneTest); FRIEND_TEST(BalanceIntegrationTest, LeaderBalanceTest); FRIEND_TEST(BalanceIntegrationTest, BalanceTest); friend void testRestBlancer(); diff --git a/src/meta/processors/job/BalancePlan.cpp b/src/meta/processors/job/BalancePlan.cpp index db1533f0f31..397e142a82a 100644 --- a/src/meta/processors/job/BalancePlan.cpp +++ b/src/meta/processors/job/BalancePlan.cpp @@ -157,24 +157,24 @@ ErrorOr> BalancePlan::sh std::vector thriftTasks; for (auto& task : tasks) { cpp2::BalanceTask t; - t.set_id(task.taskIdStr()); - t.set_command(task.taskCommandStr()); + t.id_ref() = task.taskIdStr(); + t.command_ref() = task.taskCommandStr(); switch (task.result()) { case BalanceTaskResult::SUCCEEDED: - t.set_result(cpp2::TaskResult::SUCCEEDED); + t.result_ref() = cpp2::TaskResult::SUCCEEDED; break; case BalanceTaskResult::FAILED: - t.set_result(cpp2::TaskResult::FAILED); + t.result_ref() = cpp2::TaskResult::FAILED; break; case BalanceTaskResult::IN_PROGRESS: - t.set_result(cpp2::TaskResult::IN_PROGRESS); + t.result_ref() = cpp2::TaskResult::IN_PROGRESS; break; case BalanceTaskResult::INVALID: - t.set_result(cpp2::TaskResult::INVALID); + t.result_ref() = cpp2::TaskResult::INVALID; break; } - t.set_start_time(task.startTime()); - t.set_stop_time(task.endTime()); + t.start_time_ref() = task.startTime(); + t.stop_time_ref() = task.endTime(); thriftTasks.emplace_back(std::move(t)); } return thriftTasks; diff --git a/src/meta/processors/job/BalancePlan.h b/src/meta/processors/job/BalancePlan.h index 2dc9b969e52..6f506600e52 100644 --- a/src/meta/processors/job/BalancePlan.h +++ b/src/meta/processors/job/BalancePlan.h @@ -41,7 +41,9 @@ class BalancePlan { tasks_(plan.tasks_), finishedTaskNum_(plan.finishedTaskNum_) {} - void addTask(BalanceTask task) { tasks_.emplace_back(std::move(task)); } + void addTask(BalanceTask task) { + tasks_.emplace_back(std::move(task)); + } void invoke(); @@ -54,17 +56,27 @@ class BalancePlan { * */ void rollback() {} - meta::cpp2::JobStatus status() { return jobDescription_.getStatus(); } + meta::cpp2::JobStatus status() { + return jobDescription_.getStatus(); + } - void setStatus(meta::cpp2::JobStatus status) { jobDescription_.setStatus(status); } + void setStatus(meta::cpp2::JobStatus status) { + jobDescription_.setStatus(status); + } nebula::cpp2::ErrorCode saveInStore(bool onlyPlan = false); - JobID id() const { return jobDescription_.getJobId(); } + JobID id() const { + return jobDescription_.getJobId(); + } - const std::vector& tasks() const { return tasks_; } + const std::vector& tasks() const { + return tasks_; + } - int32_t taskSize() const { return tasks_.size(); } + int32_t taskSize() const { + return tasks_.size(); + } void stop() { std::lock_guard lg(lock_); diff --git a/src/meta/processors/job/BalanceTask.h b/src/meta/processors/job/BalanceTask.h index 5add8dc1c45..84be7b33ae3 100644 --- a/src/meta/processors/job/BalanceTask.h +++ b/src/meta/processors/job/BalanceTask.h @@ -50,18 +50,26 @@ class BalanceTask { kv_(kv), client_(client) {} - const std::string& taskIdStr() const { return taskIdStr_; } + const std::string& taskIdStr() const { + return taskIdStr_; + } - const std::string& taskCommandStr() const { return commandStr_; } + const std::string& taskCommandStr() const { + return commandStr_; + } void invoke(); void rollback(); - BalanceTaskResult result() const { return ret_; } + BalanceTaskResult result() const { + return ret_; + } private: - std::string buildTaskId() { return folly::stringPrintf("%d, %d:%d", jobId_, spaceId_, partId_); } + std::string buildTaskId() { + return folly::stringPrintf("%d, %d:%d", jobId_, spaceId_, partId_); + } std::string buildCommand() { return folly::stringPrintf( @@ -70,9 +78,13 @@ class BalanceTask { bool saveInStore(); - int64_t startTime() const { return startTimeMs_; } + int64_t startTime() const { + return startTimeMs_; + } - int64_t endTime() const { return endTimeMs_; } + int64_t endTime() const { + return endTimeMs_; + } private: JobID jobId_; diff --git a/src/meta/processors/job/GetStatsProcessor.cpp b/src/meta/processors/job/GetStatsProcessor.cpp index 094d018cc7d..355f0d67600 100644 --- a/src/meta/processors/job/GetStatsProcessor.cpp +++ b/src/meta/processors/job/GetStatsProcessor.cpp @@ -40,7 +40,7 @@ void GetStatsProcessor::process(const cpp2::GetStatsReq& req) { } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_stats(std::move(statsItem)); + resp_.stats_ref() = std::move(statsItem); onFinished(); } diff --git a/src/meta/processors/job/JobDescription.cpp b/src/meta/processors/job/JobDescription.cpp index d87a4c396e0..2586168dbfd 100644 --- a/src/meta/processors/job/JobDescription.cpp +++ b/src/meta/processors/job/JobDescription.cpp @@ -66,7 +66,9 @@ ErrorOr JobDescription::makeJobDescript return nebula::cpp2::ErrorCode::E_INVALID_JOB; } -std::string JobDescription::jobKey() const { return makeJobKey(id_); } +std::string JobDescription::jobKey() const { + return makeJobKey(id_); +} std::string JobDescription::makeJobKey(JobID iJob) { std::string str; @@ -131,12 +133,12 @@ JobDescription::decodeValV1(const folly::StringPiece& rawVal) { cpp2::JobDesc JobDescription::toJobDesc() { cpp2::JobDesc ret; - ret.set_id(id_); - ret.set_cmd(cmd_); - ret.set_paras(paras_); - ret.set_status(status_); - ret.set_start_time(startTime_); - ret.set_stop_time(stopTime_); + ret.id_ref() = id_; + ret.cmd_ref() = cmd_; + ret.paras_ref() = paras_; + ret.status_ref() = status_; + ret.start_time_ref() = startTime_; + ret.stop_time_ref() = stopTime_; return ret; } diff --git a/src/meta/processors/job/JobDescription.h b/src/meta/processors/job/JobDescription.h index 5532a7949d6..0e09ec554d6 100644 --- a/src/meta/processors/job/JobDescription.h +++ b/src/meta/processors/job/JobDescription.h @@ -51,22 +51,30 @@ class JobDescription { static ErrorOr makeJobDescription( folly::StringPiece key, folly::StringPiece val); - JobID getJobId() const { return id_; } + JobID getJobId() const { + return id_; + } /* * return the command for this job. (e.g. compact, flush ...) * */ - cpp2::AdminCmd getCmd() const { return cmd_; } + cpp2::AdminCmd getCmd() const { + return cmd_; + } /* * return the paras for this job. (e.g. space name for compact/flush) * */ - std::vector getParas() const { return paras_; } + std::vector getParas() const { + return paras_; + } /* * return the status (e.g. Queue, running, finished, failed, stopped); * */ - Status getStatus() const { return status_; } + Status getStatus() const { + return status_; + } /* * return the key write to kv store @@ -140,7 +148,9 @@ class JobDescription { return this->cmd_ == that.cmd_ && this->paras_ == that.paras_ && this->status_ == that.status_; } - bool operator!=(const JobDescription& that) const { return !(*this == that); } + bool operator!=(const JobDescription& that) const { + return !(*this == that); + } private: static bool isSupportedValue(const folly::StringPiece& val); diff --git a/src/meta/processors/job/JobManager.cpp b/src/meta/processors/job/JobManager.cpp index ca2c116e719..69247726e0b 100644 --- a/src/meta/processors/job/JobManager.cpp +++ b/src/meta/processors/job/JobManager.cpp @@ -12,6 +12,7 @@ #include #include "common/http/HttpClient.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "common/utils/MetaKeyUtils.h" #include "interface/gen-cpp2/common_types.h" @@ -33,6 +34,7 @@ using nebula::kvstore::KVIterator; namespace nebula { namespace meta { +stats::CounterId kNumRunningJobs; JobManager* JobManager::getInstance() { static JobManager inst; @@ -61,7 +63,9 @@ bool JobManager::init(nebula::kvstore::KVStore* store) { return true; } -JobManager::~JobManager() { shutDown(); } +JobManager::~JobManager() { + shutDown(); +} nebula::cpp2::ErrorCode JobManager::handleRemainingJobs() { std::unique_ptr iter; @@ -174,7 +178,9 @@ bool JobManager::runJobInternal(const JobDescription& jobDesc, JbOp op) { } if (jobExec->runInMeta()) { jobExec->setFinishCallBack([this, &jobDesc](bool ret) { - SCOPE_EXIT { cleanJob(jobDesc.getJobId()); }; + SCOPE_EXIT { + cleanJob(jobDesc.getJobId()); + }; if (ret) { JobDescription jd = jobDesc; if (!jd.setStatus(cpp2::JobStatus::FINISHED)) { @@ -212,7 +218,9 @@ nebula::cpp2::ErrorCode JobManager::jobFinished(JobID jobId, cpp2::JobStatus job "{}, jobId={}, result={}", __func__, jobId, apache::thrift::util::enumNameSafe(jobStatus)); // normal job finish may race to job stop std::lock_guard lk(muJobFinished_); - SCOPE_EXIT { cleanJob(jobId); }; + SCOPE_EXIT { + cleanJob(jobId); + }; auto optJobDescRet = JobDescription::loadJobDescription(jobId, kvStore_); if (!nebula::ok(optJobDescRet)) { LOG(WARNING) << folly::sformat("can't load job, jobId={}", jobId); diff --git a/src/meta/processors/job/JobManager.h b/src/meta/processors/job/JobManager.h index 8d9a2e8d188..59eac5d2dff 100644 --- a/src/meta/processors/job/JobManager.h +++ b/src/meta/processors/job/JobManager.h @@ -14,6 +14,7 @@ #include "common/base/Base.h" #include "common/base/ErrorOr.h" +#include "common/stats/StatsManager.h" #include "interface/gen-cpp2/meta_types.h" #include "kvstore/NebulaStore.h" #include "meta/processors/job/JobDescription.h" @@ -23,6 +24,7 @@ namespace nebula { namespace meta { +extern stats::CounterId kNumRunningJobs; class JobManager : public nebula::cpp::NonCopyable, public nebula::cpp::NonMovable { friend class JobManagerTest; diff --git a/src/meta/processors/job/JobStatus.cpp b/src/meta/processors/job/JobStatus.cpp index 898dd09e5fd..67b90fe16b4 100644 --- a/src/meta/processors/job/JobStatus.cpp +++ b/src/meta/processors/job/JobStatus.cpp @@ -26,7 +26,9 @@ int JobStatus::phaseNumber(Status st) { return INT_MIN; } -bool JobStatus::laterThan(Status lhs, Status rhs) { return phaseNumber(lhs) > phaseNumber(rhs); } +bool JobStatus::laterThan(Status lhs, Status rhs) { + return phaseNumber(lhs) > phaseNumber(rhs); +} std::string JobStatus::toString(Status st) { switch (st) { diff --git a/src/meta/processors/job/JobUtils.cpp b/src/meta/processors/job/JobUtils.cpp index e9a9eb40779..0cf484c14fa 100644 --- a/src/meta/processors/job/JobUtils.cpp +++ b/src/meta/processors/job/JobUtils.cpp @@ -41,11 +41,17 @@ const std::string kJob = "__job_mgr_"; // NOLINT * */ const std::string kJobArchive = "__job_mgr_archive_"; // NOLINT -const std::string& JobUtil::jobPrefix() { return kJob; } +const std::string& JobUtil::jobPrefix() { + return kJob; +} -const std::string& JobUtil::currJobKey() { return kCurrJob; } +const std::string& JobUtil::currJobKey() { + return kCurrJob; +} -const std::string& JobUtil::archivePrefix() { return kJobArchive; } +const std::string& JobUtil::archivePrefix() { + return kJobArchive; +} std::string JobUtil::parseString(folly::StringPiece rawVal, size_t offset) { if (rawVal.size() < offset + sizeof(size_t)) { diff --git a/src/meta/processors/job/ListEdgeIndexStatusProcessor.cpp b/src/meta/processors/job/ListEdgeIndexStatusProcessor.cpp index 5caf4bfa2b7..0e2b5daa2bc 100644 --- a/src/meta/processors/job/ListEdgeIndexStatusProcessor.cpp +++ b/src/meta/processors/job/ListEdgeIndexStatusProcessor.cpp @@ -68,11 +68,11 @@ void ListEdgeIndexStatusProcessor::process(const cpp2::ListIndexStatusReq& req) } for (auto& kv : tmp) { cpp2::IndexStatus status; - status.set_name(std::move(kv.first)); - status.set_status(apache::thrift::util::enumNameSafe(kv.second)); + status.name_ref() = std::move(kv.first); + status.status_ref() = apache::thrift::util::enumNameSafe(kv.second); statuses.emplace_back(std::move(status)); } - resp_.set_statuses(std::move(statuses)); + resp_.statuses_ref() = std::move(statuses); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/job/ListTagIndexStatusProcessor.cpp b/src/meta/processors/job/ListTagIndexStatusProcessor.cpp index b8ba0479f92..860b1a4c51a 100644 --- a/src/meta/processors/job/ListTagIndexStatusProcessor.cpp +++ b/src/meta/processors/job/ListTagIndexStatusProcessor.cpp @@ -69,11 +69,11 @@ void ListTagIndexStatusProcessor::process(const cpp2::ListIndexStatusReq& req) { } for (auto& kv : tmp) { cpp2::IndexStatus status; - status.set_name(std::move(kv.first)); - status.set_status(apache::thrift::util::enumNameSafe(kv.second)); + status.name_ref() = std::move(kv.first); + status.status_ref() = apache::thrift::util::enumNameSafe(kv.second); statuses.emplace_back(std::move(status)); } - resp_.set_statuses(std::move(statuses)); + resp_.statuses_ref() = std::move(statuses); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/job/MetaJobExecutor.h b/src/meta/processors/job/MetaJobExecutor.h index bd10d0af110..8b75c51c0a5 100644 --- a/src/meta/processors/job/MetaJobExecutor.h +++ b/src/meta/processors/job/MetaJobExecutor.h @@ -48,17 +48,25 @@ class MetaJobExecutor { // Stop the job when the user cancel it. virtual nebula::cpp2::ErrorCode stop() = 0; - virtual nebula::cpp2::ErrorCode finish(bool) { return nebula::cpp2::ErrorCode::SUCCEEDED; } + virtual nebula::cpp2::ErrorCode finish(bool) { + return nebula::cpp2::ErrorCode::SUCCEEDED; + } - void setSpaceId(GraphSpaceID spaceId) { space_ = spaceId; } + void setSpaceId(GraphSpaceID spaceId) { + space_ = spaceId; + } virtual nebula::cpp2::ErrorCode saveSpecialTaskStatus(const cpp2::ReportTaskReq&) { return nebula::cpp2::ErrorCode::SUCCEEDED; } - virtual bool runInMeta() { return false; } + virtual bool runInMeta() { + return false; + } - virtual nebula::cpp2::ErrorCode recovery() { return nebula::cpp2::ErrorCode::SUCCEEDED; } + virtual nebula::cpp2::ErrorCode recovery() { + return nebula::cpp2::ErrorCode::SUCCEEDED; + } void setFinishCallBack(std::function func) { onFinished_ = func; diff --git a/src/meta/processors/job/RebuildJobExecutor.cpp b/src/meta/processors/job/RebuildJobExecutor.cpp index beecb6e4555..cd80e043633 100644 --- a/src/meta/processors/job/RebuildJobExecutor.cpp +++ b/src/meta/processors/job/RebuildJobExecutor.cpp @@ -17,7 +17,9 @@ DECLARE_int32(heartbeat_interval_secs); namespace nebula { namespace meta { -bool RebuildJobExecutor::check() { return paras_.size() >= 1; } +bool RebuildJobExecutor::check() { + return paras_.size() >= 1; +} nebula::cpp2::ErrorCode RebuildJobExecutor::prepare() { // the last value of paras_ is the space name, others are index name diff --git a/src/meta/processors/job/StatsJobExecutor.cpp b/src/meta/processors/job/StatsJobExecutor.cpp index ceab9a7b085..ef45e303211 100644 --- a/src/meta/processors/job/StatsJobExecutor.cpp +++ b/src/meta/processors/job/StatsJobExecutor.cpp @@ -52,7 +52,7 @@ nebula::cpp2::ErrorCode StatsJobExecutor::prepare() { // Set the status of the stats job to running cpp2::StatsItem statsItem; - statsItem.set_status(cpp2::JobStatus::RUNNING); + statsItem.status_ref() = cpp2::JobStatus::RUNNING; auto statsKey = MetaKeyUtils::statsKey(space_); auto statsVal = MetaKeyUtils::statsVal(statsItem); return save(statsKey, statsVal); @@ -163,9 +163,9 @@ nebula::cpp2::ErrorCode StatsJobExecutor::finish(bool exeSuccessed) { } auto statsItem = MetaKeyUtils::parseStatsVal(val); if (exeSuccessed) { - statsItem.set_status(cpp2::JobStatus::FINISHED); + statsItem.status_ref() = cpp2::JobStatus::FINISHED; } else { - statsItem.set_status(cpp2::JobStatus::FAILED); + statsItem.status_ref() = cpp2::JobStatus::FAILED; } auto statsVal = MetaKeyUtils::statsVal(statsItem); auto retCode = save(statsKey, statsVal); diff --git a/src/meta/processors/job/TaskDescription.cpp b/src/meta/processors/job/TaskDescription.cpp index 04907c69e7f..66fde77a510 100644 --- a/src/meta/processors/job/TaskDescription.cpp +++ b/src/meta/processors/job/TaskDescription.cpp @@ -125,12 +125,12 @@ std::tuple TaskDescription::parseVal( * */ cpp2::TaskDesc TaskDescription::toTaskDesc() { cpp2::TaskDesc ret; - ret.set_job_id(iJob_); - ret.set_task_id(iTask_); - ret.set_host(dest_); - ret.set_status(status_); - ret.set_start_time(startTime_); - ret.set_stop_time(stopTime_); + ret.job_id_ref() = iJob_; + ret.task_id_ref() = iTask_; + ret.host_ref() = dest_; + ret.status_ref() = status_; + ret.start_time_ref() = startTime_; + ret.stop_time_ref() = stopTime_; return ret; } diff --git a/src/meta/processors/job/TaskDescription.h b/src/meta/processors/job/TaskDescription.h index dd51f2fb070..f9f05a77950 100644 --- a/src/meta/processors/job/TaskDescription.h +++ b/src/meta/processors/job/TaskDescription.h @@ -99,9 +99,13 @@ class TaskDescription { * */ bool setStatus(cpp2::JobStatus newStatus); - JobID getJobId() { return iJob_; } + JobID getJobId() { + return iJob_; + } - TaskID getTaskId() { return iTask_; } + TaskID getTaskId() { + return iTask_; + } private: JobID iJob_; diff --git a/src/meta/processors/kv/GetProcessor.cpp b/src/meta/processors/kv/GetProcessor.cpp index f6c17b0710f..bed3a344cad 100644 --- a/src/meta/processors/kv/GetProcessor.cpp +++ b/src/meta/processors/kv/GetProcessor.cpp @@ -21,7 +21,7 @@ void GetProcessor::process(const cpp2::GetReq& req) { } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_value(std::move(nebula::value(result))); + resp_.value_ref() = std::move(nebula::value(result)); onFinished(); } diff --git a/src/meta/processors/kv/GetProcessor.h b/src/meta/processors/kv/GetProcessor.h index 66cab62c815..f555044d09e 100644 --- a/src/meta/processors/kv/GetProcessor.h +++ b/src/meta/processors/kv/GetProcessor.h @@ -13,7 +13,9 @@ namespace meta { class GetProcessor : public BaseProcessor { public: - static GetProcessor* instance(kvstore::KVStore* kvstore) { return new GetProcessor(kvstore); } + static GetProcessor* instance(kvstore::KVStore* kvstore) { + return new GetProcessor(kvstore); + } void process(const cpp2::GetReq& req); diff --git a/src/meta/processors/kv/MultiGetProcessor.cpp b/src/meta/processors/kv/MultiGetProcessor.cpp index 503fe03744d..ef50ff56337 100644 --- a/src/meta/processors/kv/MultiGetProcessor.cpp +++ b/src/meta/processors/kv/MultiGetProcessor.cpp @@ -24,7 +24,7 @@ void MultiGetProcessor::process(const cpp2::MultiGetReq& req) { } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_values(std::move(nebula::value(result))); + resp_.values_ref() = std::move(nebula::value(result)); onFinished(); } diff --git a/src/meta/processors/kv/ScanProcessor.cpp b/src/meta/processors/kv/ScanProcessor.cpp index 62d54cb638e..1b14f1a5b8a 100644 --- a/src/meta/processors/kv/ScanProcessor.cpp +++ b/src/meta/processors/kv/ScanProcessor.cpp @@ -21,7 +21,7 @@ void ScanProcessor::process(const cpp2::ScanReq& req) { } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_values(std::move(nebula::value(result))); + resp_.values_ref() = std::move(nebula::value(result)); onFinished(); } diff --git a/src/meta/processors/kv/ScanProcessor.h b/src/meta/processors/kv/ScanProcessor.h index 7ee83fd2c71..1d127af59fb 100644 --- a/src/meta/processors/kv/ScanProcessor.h +++ b/src/meta/processors/kv/ScanProcessor.h @@ -13,7 +13,9 @@ namespace meta { class ScanProcessor : public BaseProcessor { public: - static ScanProcessor* instance(kvstore::KVStore* kvstore) { return new ScanProcessor(kvstore); } + static ScanProcessor* instance(kvstore::KVStore* kvstore) { + return new ScanProcessor(kvstore); + } void process(const cpp2::ScanReq& req); diff --git a/src/meta/processors/listener/ListenerProcessor.cpp b/src/meta/processors/listener/ListenerProcessor.cpp index 528a1f35a77..52c6daa90be 100644 --- a/src/meta/processors/listener/ListenerProcessor.cpp +++ b/src/meta/processors/listener/ListenerProcessor.cpp @@ -123,19 +123,19 @@ void ListListenerProcessor::process(const cpp2::ListListenerReq& req) { auto iter = nebula::value(iterRet).get(); while (iter->valid()) { cpp2::ListenerInfo listener; - listener.set_type(MetaKeyUtils::parseListenerType(iter->key())); - listener.set_host(MetaKeyUtils::deserializeHostAddr(iter->val())); - listener.set_part_id(MetaKeyUtils::parseListenerPart(iter->key())); + listener.type_ref() = MetaKeyUtils::parseListenerType(iter->key()); + listener.host_ref() = MetaKeyUtils::deserializeHostAddr(iter->val()); + listener.part_id_ref() = MetaKeyUtils::parseListenerPart(iter->key()); if (std::find(activeHosts.begin(), activeHosts.end(), *listener.host_ref()) != activeHosts.end()) { - listener.set_status(cpp2::HostStatus::ONLINE); + listener.status_ref() = cpp2::HostStatus::ONLINE; } else { - listener.set_status(cpp2::HostStatus::OFFLINE); + listener.status_ref() = cpp2::HostStatus::OFFLINE; } listeners.emplace_back(std::move(listener)); iter->next(); } - resp_.set_listeners(std::move(listeners)); + resp_.listeners_ref() = std::move(listeners); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/parts/CreateSpaceAsProcessor.cpp b/src/meta/processors/parts/CreateSpaceAsProcessor.cpp index 2533539e75c..b61ab6fd7c7 100644 --- a/src/meta/processors/parts/CreateSpaceAsProcessor.cpp +++ b/src/meta/processors/parts/CreateSpaceAsProcessor.cpp @@ -84,7 +84,7 @@ void CreateSpaceAsProcessor::process(const cpp2::CreateSpaceAsReq &req) { return; } - resp_.set_id(to(nebula::value(newSpaceId), EntryType::SPACE)); + resp_.id_ref() = to(nebula::value(newSpaceId), EntryType::SPACE); rc_ = doSyncPut(std::move(data)); if (rc_ != nebula::cpp2::ErrorCode::SUCCEEDED) { LOG(ERROR) << "put data error, " << apache::thrift::util::enumNameSafe(rc_); @@ -113,7 +113,7 @@ ErrorOr> CreateSpaceAsProcesso data.emplace_back(MetaKeyUtils::indexSpaceKey(spaceName), std::string(reinterpret_cast(&newSpaceId), sizeof(newSpaceId))); cpp2::SpaceDesc spaceDesc = MetaKeyUtils::parseSpace(nebula::value(oldSpaceVal)); - spaceDesc.set_space_name(spaceName); + spaceDesc.space_name_ref() = spaceName; data.emplace_back(MetaKeyUtils::spaceKey(newSpaceId), MetaKeyUtils::spaceVal(spaceDesc)); auto prefix = MetaKeyUtils::partPrefix(oldSpaceId); diff --git a/src/meta/processors/parts/CreateSpaceProcessor.cpp b/src/meta/processors/parts/CreateSpaceProcessor.cpp index ecaf159b58a..c4b76ad936b 100644 --- a/src/meta/processors/parts/CreateSpaceProcessor.cpp +++ b/src/meta/processors/parts/CreateSpaceProcessor.cpp @@ -25,7 +25,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { LOG(ERROR) << "Create Space Failed : Space " << spaceName << " have existed!"; ret = nebula::cpp2::ErrorCode::E_EXISTED; } - resp_.set_id(to(nebula::value(spaceRet), EntryType::SPACE)); + resp_.id_ref() = to(nebula::value(spaceRet), EntryType::SPACE); handleErrorCode(ret); onFinished(); return; @@ -59,7 +59,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { } // Set the default value back to the struct, which will be written to // storage - properties.set_partition_num(partitionNum); + properties.partition_num_ref() = partitionNum; } if (replicaFactor == 0) { @@ -72,7 +72,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { } // Set the default value back to the struct, which will be written to // storage - properties.set_replica_factor(replicaFactor); + properties.replica_factor_ref() = replicaFactor; } if (vidSize == 0) { @@ -98,7 +98,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { return; } - properties.vid_type_ref().value().set_type_length(vidSize); + properties.vid_type_ref().value().type_length_ref() = vidSize; auto idRet = autoIncrementId(); if (!nebula::ok(idRet)) { LOG(ERROR) << "Create Space Failed : Get space id failed"; @@ -129,7 +129,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { zoneIter->next(); } - properties.set_zone_names(zones); + properties.zone_names_ref() = zones; } else { zones = properties.get_zone_names(); } @@ -251,7 +251,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { return; } - resp_.set_id(to(spaceId, EntryType::SPACE)); + resp_.id_ref() = to(spaceId, EntryType::SPACE); doSyncPutAndUpdate(std::move(data)); LOG(INFO) << "Create space " << spaceName; } diff --git a/src/meta/processors/parts/GetPartsAllocProcessor.cpp b/src/meta/processors/parts/GetPartsAllocProcessor.cpp index 722b87df438..2a5d81e2a20 100644 --- a/src/meta/processors/parts/GetPartsAllocProcessor.cpp +++ b/src/meta/processors/parts/GetPartsAllocProcessor.cpp @@ -32,10 +32,10 @@ void GetPartsAllocProcessor::process(const cpp2::GetPartsAllocReq& req) { iter->next(); } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_parts(std::move(parts)); + resp_.parts_ref() = std::move(parts); auto terms = getTerm(spaceId); if (!terms.empty()) { - resp_.set_terms(std::move(terms)); + resp_.terms_ref() = std::move(terms); } onFinished(); } diff --git a/src/meta/processors/parts/GetSpaceProcessor.cpp b/src/meta/processors/parts/GetSpaceProcessor.cpp index 883ed36c144..72ba8b8ee5c 100644 --- a/src/meta/processors/parts/GetSpaceProcessor.cpp +++ b/src/meta/processors/parts/GetSpaceProcessor.cpp @@ -41,9 +41,9 @@ void GetSpaceProcessor::process(const cpp2::GetSpaceReq& req) { << folly::join(",", properties.get_zone_names()); cpp2::SpaceItem item; - item.set_space_id(spaceId); - item.set_properties(std::move(properties)); - resp_.set_item(std::move(item)); + item.space_id_ref() = spaceId; + item.properties_ref() = std::move(properties); + resp_.item_ref() = std::move(item); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/parts/ListHostsProcessor.cpp b/src/meta/processors/parts/ListHostsProcessor.cpp index a2c425203bb..6294ced8fee 100644 --- a/src/meta/processors/parts/ListHostsProcessor.cpp +++ b/src/meta/processors/parts/ListHostsProcessor.cpp @@ -58,7 +58,7 @@ void ListHostsProcessor::process(const cpp2::ListHostsReq& req) { } } if (retCode == nebula::cpp2::ErrorCode::SUCCEEDED) { - resp_.set_hosts(std::move(hostItems_)); + resp_.hosts_ref() = std::move(hostItems_); } handleErrorCode(retCode); onFinished(); @@ -85,11 +85,11 @@ nebula::cpp2::ErrorCode ListHostsProcessor::allMetaHostsStatus() { } for (auto& host : metaPeers) { cpp2::HostItem item; - item.set_hostAddr(std::move(host)); - item.set_role(cpp2::HostRole::META); - item.set_git_info_sha(gitInfoSha()); - item.set_status(cpp2::HostStatus::ONLINE); - item.set_version(getOriginVersion()); + item.hostAddr_ref() = std::move(host); + item.role_ref() = cpp2::HostRole::META; + item.git_info_sha_ref() = gitInfoSha(); + item.status_ref() = cpp2::HostStatus::ONLINE; + item.version_ref() = getOriginVersion(); hostItems_.emplace_back(item); } return nebula::cpp2::ErrorCode::SUCCEEDED; @@ -120,16 +120,16 @@ nebula::cpp2::ErrorCode ListHostsProcessor::allHostsWithStatus(cpp2::HostRole ro cpp2::HostItem item; auto host = MetaKeyUtils::parseHostKey(iter->key()); - item.set_hostAddr(std::move(host)); + item.hostAddr_ref() = std::move(host); - item.set_role(info.role_); - item.set_git_info_sha(info.gitInfoSha_); + item.role_ref() = info.role_; + item.git_info_sha_ref() = info.gitInfoSha_; auto versionKey = MetaKeyUtils::versionKey(item.get_hostAddr()); auto versionRet = doGet(versionKey); if (nebula::ok(versionRet)) { auto versionVal = MetaKeyUtils::parseVersion(value(versionRet)); - item.set_version(versionVal); + item.version_ref() = versionVal; } if (now - info.lastHBTimeInMilliSec_ < FLAGS_removed_threshold_sec * 1000) { @@ -137,9 +137,9 @@ nebula::cpp2::ErrorCode ListHostsProcessor::allHostsWithStatus(cpp2::HostRole ro // offline. Same as ActiveHostsMan::getActiveHosts if (now - info.lastHBTimeInMilliSec_ < FLAGS_heartbeat_interval_secs * FLAGS_expired_time_factor * 1000) { - item.set_status(cpp2::HostStatus::ONLINE); + item.status_ref() = cpp2::HostStatus::ONLINE; } else { - item.set_status(cpp2::HostStatus::OFFLINE); + item.status_ref() = cpp2::HostStatus::OFFLINE; } hostItems_.emplace_back(item); } else { @@ -261,7 +261,7 @@ nebula::cpp2::ErrorCode ListHostsProcessor::fillAllParts() { return item.get_hostAddr() == hostAddr; }); if (it != hostItems_.end()) { - it->set_all_parts(std::move(hostEntry.second)); + it->all_parts_ref() = std::move(hostEntry.second); } } diff --git a/src/meta/processors/parts/ListPartsProcessor.cpp b/src/meta/processors/parts/ListPartsProcessor.cpp index a13b8ad1307..5ebbaa84377 100644 --- a/src/meta/processors/parts/ListPartsProcessor.cpp +++ b/src/meta/processors/parts/ListPartsProcessor.cpp @@ -58,8 +58,8 @@ void ListPartsProcessor::process(const cpp2::ListPartsReq& req) { for (auto& partEntry : partHostsMap) { cpp2::PartItem partItem; - partItem.set_part_id(partEntry.first); - partItem.set_peers(std::move(partEntry.second)); + partItem.part_id_ref() = partEntry.first; + partItem.peers_ref() = std::move(partEntry.second); std::vector losts; for (auto& host : partItem.get_peers()) { if (std::find(activeHosts.begin(), activeHosts.end(), HostAddr(host.host, host.port)) == @@ -67,7 +67,7 @@ void ListPartsProcessor::process(const cpp2::ListPartsReq& req) { losts.emplace_back(host.host, host.port); } } - partItem.set_losts(std::move(losts)); + partItem.losts_ref() = std::move(losts); partItems.emplace_back(std::move(partItem)); } if (partItems.size() != partHostsMap.size()) { @@ -75,7 +75,7 @@ void ListPartsProcessor::process(const cpp2::ListPartsReq& req) { } auto retCode = getLeaderDist(partItems); if (retCode == nebula::cpp2::ErrorCode::SUCCEEDED) { - resp_.set_parts(std::move(partItems)); + resp_.parts_ref() = std::move(partItems); } handleErrorCode(retCode); onFinished(); @@ -144,7 +144,7 @@ nebula::cpp2::ErrorCode ListPartsProcessor::getLeaderDist(std::vectorval()); VLOG(3) << "List spaces " << spaceId << ", name " << spaceName; cpp2::IdName space; - space.set_id(to(spaceId, EntryType::SPACE)); - space.set_name(std::move(spaceName)); + space.id_ref() = to(spaceId, EntryType::SPACE); + space.name_ref() = std::move(spaceName); spaces.emplace_back(std::move(space)); iter->next(); } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_spaces(std::move(spaces)); + resp_.spaces_ref() = std::move(spaces); onFinished(); } diff --git a/src/meta/processors/schema/AlterEdgeProcessor.cpp b/src/meta/processors/schema/AlterEdgeProcessor.cpp index df3f21fd47f..e2a552f1fdf 100644 --- a/src/meta/processors/schema/AlterEdgeProcessor.cpp +++ b/src/meta/processors/schema/AlterEdgeProcessor.cpp @@ -140,14 +140,14 @@ void AlterEdgeProcessor::process(const cpp2::AlterEdgeReq& req) { return; } - schema.set_schema_prop(std::move(prop)); - schema.set_columns(std::move(columns)); + schema.schema_prop_ref() = std::move(prop); + schema.columns_ref() = std::move(columns); std::vector data; LOG(INFO) << "Alter edge " << edgeName << ", edgeType " << edgeType; data.emplace_back(MetaKeyUtils::schemaEdgeKey(spaceId, edgeType, version), MetaKeyUtils::schemaVal(edgeName, schema)); - resp_.set_id(to(edgeType, EntryType::EDGE)); + resp_.id_ref() = to(edgeType, EntryType::EDGE); doSyncPutAndUpdate(std::move(data)); } diff --git a/src/meta/processors/schema/AlterTagProcessor.cpp b/src/meta/processors/schema/AlterTagProcessor.cpp index 11d7f31d3f2..31f0ea41173 100644 --- a/src/meta/processors/schema/AlterTagProcessor.cpp +++ b/src/meta/processors/schema/AlterTagProcessor.cpp @@ -139,14 +139,14 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) { return; } - schema.set_schema_prop(std::move(prop)); - schema.set_columns(std::move(columns)); + schema.schema_prop_ref() = std::move(prop); + schema.columns_ref() = std::move(columns); std::vector data; LOG(INFO) << "Alter Tag " << tagName << ", tagId " << tagId; data.emplace_back(MetaKeyUtils::schemaTagKey(spaceId, tagId, version), MetaKeyUtils::schemaVal(tagName, schema)); - resp_.set_id(to(tagId, EntryType::TAG)); + resp_.id_ref() = to(tagId, EntryType::TAG); doSyncPutAndUpdate(std::move(data)); } diff --git a/src/meta/processors/schema/CreateEdgeProcessor.cpp b/src/meta/processors/schema/CreateEdgeProcessor.cpp index ad232348b2c..671d5ddab16 100644 --- a/src/meta/processors/schema/CreateEdgeProcessor.cpp +++ b/src/meta/processors/schema/CreateEdgeProcessor.cpp @@ -22,7 +22,7 @@ void CreateEdgeProcessor::process(const cpp2::CreateEdgeReq& req) { if (nebula::ok(conflictRet)) { LOG(ERROR) << "Failed to create edge `" << edgeName << "': some tag with the same name already exists."; - resp_.set_id(to(nebula::value(conflictRet), EntryType::EDGE)); + resp_.id_ref() = to(nebula::value(conflictRet), EntryType::EDGE); handleErrorCode(nebula::cpp2::ErrorCode::E_CONFLICT); onFinished(); return; @@ -46,8 +46,8 @@ void CreateEdgeProcessor::process(const cpp2::CreateEdgeReq& req) { } cpp2::Schema schema; - schema.set_columns(std::move(columns)); - schema.set_schema_prop(req.get_schema().get_schema_prop()); + schema.columns_ref() = std::move(columns); + schema.schema_prop_ref() = req.get_schema().get_schema_prop(); folly::SharedMutex::WriteHolder wHolder(LockUtils::edgeLock()); auto ret = getEdgeType(spaceId, edgeName); @@ -58,7 +58,7 @@ void CreateEdgeProcessor::process(const cpp2::CreateEdgeReq& req) { LOG(ERROR) << "Create Edge Failed :" << edgeName << " has existed"; handleErrorCode(nebula::cpp2::ErrorCode::E_EXISTED); } - resp_.set_id(to(nebula::value(ret), EntryType::EDGE)); + resp_.id_ref() = to(nebula::value(ret), EntryType::EDGE); onFinished(); return; } else { @@ -88,7 +88,7 @@ void CreateEdgeProcessor::process(const cpp2::CreateEdgeReq& req) { MetaKeyUtils::schemaVal(edgeName, schema)); LOG(INFO) << "Create Edge " << edgeName << ", edgeType " << edgeType; - resp_.set_id(to(edgeType, EntryType::EDGE)); + resp_.id_ref() = to(edgeType, EntryType::EDGE); doSyncPutAndUpdate(std::move(data)); } diff --git a/src/meta/processors/schema/CreateTagProcessor.cpp b/src/meta/processors/schema/CreateTagProcessor.cpp index 3578863737b..b5f3d39124b 100644 --- a/src/meta/processors/schema/CreateTagProcessor.cpp +++ b/src/meta/processors/schema/CreateTagProcessor.cpp @@ -22,7 +22,7 @@ void CreateTagProcessor::process(const cpp2::CreateTagReq& req) { if (nebula::ok(conflictRet)) { LOG(ERROR) << "Failed to create tag `" << tagName << "': some edge with the same name already exists."; - resp_.set_id(to(nebula::value(conflictRet), EntryType::TAG)); + resp_.id_ref() = to(nebula::value(conflictRet), EntryType::TAG); handleErrorCode(nebula::cpp2::ErrorCode::E_CONFLICT); onFinished(); return; @@ -46,8 +46,8 @@ void CreateTagProcessor::process(const cpp2::CreateTagReq& req) { } cpp2::Schema schema; - schema.set_columns(std::move(columns)); - schema.set_schema_prop(req.get_schema().get_schema_prop()); + schema.columns_ref() = std::move(columns); + schema.schema_prop_ref() = req.get_schema().get_schema_prop(); folly::SharedMutex::WriteHolder wHolder(LockUtils::tagLock()); auto ret = getTagId(spaceId, tagName); @@ -58,7 +58,7 @@ void CreateTagProcessor::process(const cpp2::CreateTagReq& req) { LOG(ERROR) << "Create Tag Failed :" << tagName << " has existed"; handleErrorCode(nebula::cpp2::ErrorCode::E_EXISTED); } - resp_.set_id(to(nebula::value(ret), EntryType::TAG)); + resp_.id_ref() = to(nebula::value(ret), EntryType::TAG); onFinished(); return; } else { @@ -89,7 +89,7 @@ void CreateTagProcessor::process(const cpp2::CreateTagReq& req) { LOG(INFO) << "Create Tag " << tagName << ", TagID " << tagId; - resp_.set_id(to(tagId, EntryType::TAG)); + resp_.id_ref() = to(tagId, EntryType::TAG); doSyncPutAndUpdate(std::move(data)); } diff --git a/src/meta/processors/schema/DropEdgeProcessor.cpp b/src/meta/processors/schema/DropEdgeProcessor.cpp index fa48fc04f84..1315681bbb3 100644 --- a/src/meta/processors/schema/DropEdgeProcessor.cpp +++ b/src/meta/processors/schema/DropEdgeProcessor.cpp @@ -21,7 +21,7 @@ void DropEdgeProcessor::process(const cpp2::DropEdgeReq& req) { auto iRet = doGet(indexKey); if (nebula::ok(iRet)) { edgeType = *reinterpret_cast(nebula::value(iRet).c_str()); - resp_.set_id(to(edgeType, EntryType::EDGE)); + resp_.id_ref() = to(edgeType, EntryType::EDGE); } else { auto retCode = nebula::error(iRet); if (retCode == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) { diff --git a/src/meta/processors/schema/DropTagProcessor.cpp b/src/meta/processors/schema/DropTagProcessor.cpp index 4f0d508acf8..08cc3ff5331 100644 --- a/src/meta/processors/schema/DropTagProcessor.cpp +++ b/src/meta/processors/schema/DropTagProcessor.cpp @@ -21,7 +21,7 @@ void DropTagProcessor::process(const cpp2::DropTagReq& req) { auto iRet = doGet(indexKey); if (nebula::ok(iRet)) { tagId = *reinterpret_cast(nebula::value(iRet).c_str()); - resp_.set_id(to(tagId, EntryType::TAG)); + resp_.id_ref() = to(tagId, EntryType::TAG); } else { auto retCode = nebula::error(iRet); if (retCode == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) { diff --git a/src/meta/processors/schema/GetEdgeProcessor.cpp b/src/meta/processors/schema/GetEdgeProcessor.cpp index da8c371ab3f..0ae0e3a5443 100644 --- a/src/meta/processors/schema/GetEdgeProcessor.cpp +++ b/src/meta/processors/schema/GetEdgeProcessor.cpp @@ -61,7 +61,7 @@ void GetEdgeProcessor::process(const cpp2::GetEdgeReq& req) { VLOG(3) << "Get Edge SpaceID: " << spaceId << ", edgeName: " << edgeName << ", version " << ver; handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_schema(MetaKeyUtils::parseSchema(schemaValue)); + resp_.schema_ref() = MetaKeyUtils::parseSchema(schemaValue); onFinished(); } diff --git a/src/meta/processors/schema/GetTagProcessor.cpp b/src/meta/processors/schema/GetTagProcessor.cpp index 16af1b78f2e..82e726e34ad 100644 --- a/src/meta/processors/schema/GetTagProcessor.cpp +++ b/src/meta/processors/schema/GetTagProcessor.cpp @@ -62,7 +62,7 @@ void GetTagProcessor::process(const cpp2::GetTagReq& req) { VLOG(3) << "Get Tag SpaceID: " << spaceId << ", tagName: " << tagName << ", version " << ver; handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_schema(MetaKeyUtils::parseSchema(schemaValue)); + resp_.schema_ref() = MetaKeyUtils::parseSchema(schemaValue); onFinished(); } diff --git a/src/meta/processors/schema/ListEdgesProcessor.cpp b/src/meta/processors/schema/ListEdgesProcessor.cpp index c35fa286769..3e5e2691762 100644 --- a/src/meta/processors/schema/ListEdgesProcessor.cpp +++ b/src/meta/processors/schema/ListEdgesProcessor.cpp @@ -33,14 +33,14 @@ void ListEdgesProcessor::process(const cpp2::ListEdgesReq &req) { auto edgeName = val.subpiece(sizeof(int32_t), nameLen).str(); auto schema = MetaKeyUtils::parseSchema(val); cpp2::EdgeItem edge; - edge.set_edge_type(edgeType); - edge.set_edge_name(std::move(edgeName)); - edge.set_version(version); - edge.set_schema(std::move(schema)); + edge.edge_type_ref() = edgeType; + edge.edge_name_ref() = std::move(edgeName); + edge.version_ref() = version; + edge.schema_ref() = std::move(schema); edges.emplace_back(std::move(edge)); iter->next(); } - resp_.set_edges(std::move(edges)); + resp_.edges_ref() = std::move(edges); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/schema/ListTagsProcessor.cpp b/src/meta/processors/schema/ListTagsProcessor.cpp index 4a7d5928261..26da7cd41d6 100644 --- a/src/meta/processors/schema/ListTagsProcessor.cpp +++ b/src/meta/processors/schema/ListTagsProcessor.cpp @@ -33,14 +33,14 @@ void ListTagsProcessor::process(const cpp2::ListTagsReq &req) { auto tagName = val.subpiece(sizeof(int32_t), nameLen).str(); auto schema = MetaKeyUtils::parseSchema(val); cpp2::TagItem item; - item.set_tag_id(tagID); - item.set_tag_name(std::move(tagName)); - item.set_version(version); - item.set_schema(std::move(schema)); + item.tag_id_ref() = tagID; + item.tag_name_ref() = std::move(tagName); + item.version_ref() = version; + item.schema_ref() = std::move(schema); tags.emplace_back(std::move(item)); iter->next(); } - resp_.set_tags(std::move(tags)); + resp_.tags_ref() = std::move(tags); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/schema/SchemaUtil.cpp b/src/meta/processors/schema/SchemaUtil.cpp index 0b4c8dd8c72..80568a8c523 100644 --- a/src/meta/processors/schema/SchemaUtil.cpp +++ b/src/meta/processors/schema/SchemaUtil.cpp @@ -122,7 +122,7 @@ bool SchemaUtil::checkType(std::vector& columns) { const auto trimStr = value.getStr().substr(0, typeLen); value.setStr(trimStr); const auto& fixedValue = *ConstantExpression::make(pool, value); - column.set_default_value(Expression::encode(fixedValue)); + column.default_value_ref() = Expression::encode(fixedValue); } break; } diff --git a/src/meta/processors/session/SessionManagerProcessor.cpp b/src/meta/processors/session/SessionManagerProcessor.cpp index cb2ab2675c3..76bb7285b22 100644 --- a/src/meta/processors/session/SessionManagerProcessor.cpp +++ b/src/meta/processors/session/SessionManagerProcessor.cpp @@ -21,17 +21,17 @@ void CreateSessionProcessor::process(const cpp2::CreateSessionReq& req) { cpp2::Session session; // The sessionId is generated by microsecond timestamp - session.set_session_id(time::WallClock::fastNowInMicroSec()); - session.set_create_time(session.get_session_id()); - session.set_update_time(0); - session.set_user_name(user); - session.set_graph_addr(req.get_graph_addr()); - session.set_client_ip(req.get_client_ip()); + session.session_id_ref() = time::WallClock::fastNowInMicroSec(); + session.create_time_ref() = session.get_session_id(); + session.update_time_ref() = 0; + session.user_name_ref() = user; + session.graph_addr_ref() = req.get_graph_addr(); + session.client_ip_ref() = req.get_client_ip(); std::vector data; data.emplace_back(MetaKeyUtils::sessionKey(session.get_session_id()), MetaKeyUtils::sessionVal(session)); - resp_.set_session(session); + resp_.session_ref() = session; ret = doSyncPut(std::move(data)); if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { LOG(ERROR) << "Put data error on meta server, errorCode: " @@ -75,7 +75,7 @@ void UpdateSessionsProcessor::process(const cpp2::UpdateSessionsReq& req) { } auto& desc = savedQuery.second; if (desc.get_status() == cpp2::QueryStatus::KILLING) { - const_cast(newQuery->second).set_status(cpp2::QueryStatus::KILLING); + const_cast(newQuery->second).status_ref() = cpp2::QueryStatus::KILLING; killedQueriesInCurrentSession.emplace(epId, desc); } } @@ -102,7 +102,7 @@ void UpdateSessionsProcessor::process(const cpp2::UpdateSessionsReq& req) { return; } - resp_.set_killed_queries(std::move(killedQueries)); + resp_.killed_queries_ref() = std::move(killedQueries); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } @@ -125,7 +125,7 @@ void ListSessionsProcessor::process(const cpp2::ListSessionsReq&) { sessions.emplace_back(std::move(session)); iter->next(); } - resp_.set_sessions(std::move(sessions)); + resp_.sessions_ref() = std::move(sessions); for (auto& session : resp_.get_sessions()) { LOG(INFO) << "resp list session: " << session.get_session_id(); } @@ -150,7 +150,7 @@ void GetSessionProcessor::process(const cpp2::GetSessionReq& req) { } auto session = MetaKeyUtils::parseSessionVal(nebula::value(ret)); - resp_.set_session(std::move(session)); + resp_.session_ref() = std::move(session); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } @@ -203,7 +203,7 @@ void KillQueryProcessor::process(const cpp2::KillQueryReq& req) { onFinished(); return; } - query->second.set_status(cpp2::QueryStatus::KILLING); + query->second.status_ref() = cpp2::QueryStatus::KILLING; } data.emplace_back(MetaKeyUtils::sessionKey(sessionId), MetaKeyUtils::sessionVal(session)); diff --git a/src/meta/processors/user/AuthenticationProcessor.cpp b/src/meta/processors/user/AuthenticationProcessor.cpp index c2e6a70a223..ac09be9844c 100644 --- a/src/meta/processors/user/AuthenticationProcessor.cpp +++ b/src/meta/processors/user/AuthenticationProcessor.cpp @@ -247,7 +247,7 @@ void ListUsersProcessor::process(const cpp2::ListUsersReq& req) { users.emplace(std::move(account), std::move(password)); iter->next(); } - resp_.set_users(std::move(users)); + resp_.users_ref() = std::move(users); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } @@ -273,13 +273,13 @@ void ListRolesProcessor::process(const cpp2::ListRolesReq& req) { auto account = MetaKeyUtils::parseRoleUser(iter->key()); auto val = iter->val(); cpp2::RoleItem role; - role.set_user_id(std::move(account)); - role.set_space_id(spaceId); - role.set_role_type(*reinterpret_cast(val.begin())); + role.user_id_ref() = std::move(account); + role.space_id_ref() = spaceId; + role.role_type_ref() = *reinterpret_cast(val.begin()); roles.emplace_back(std::move(role)); iter->next(); } - resp_.set_roles(std::move(roles)); + resp_.roles_ref() = std::move(roles); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } @@ -306,14 +306,14 @@ void GetUserRolesProcessor::process(const cpp2::GetUserRolesReq& req) { if (account == act) { auto val = iter->val(); cpp2::RoleItem role; - role.set_user_id(std::move(account)); - role.set_space_id(spaceId); - role.set_role_type(*reinterpret_cast(val.begin())); + role.user_id_ref() = std::move(account); + role.space_id_ref() = spaceId; + role.role_type_ref() = *reinterpret_cast(val.begin()); roles.emplace_back(std::move(role)); } iter->next(); } - resp_.set_roles(std::move(roles)); + resp_.roles_ref() = std::move(roles); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/user/AuthenticationProcessor.h b/src/meta/processors/user/AuthenticationProcessor.h index a4be35dc4c5..79fd01a4945 100644 --- a/src/meta/processors/user/AuthenticationProcessor.h +++ b/src/meta/processors/user/AuthenticationProcessor.h @@ -50,7 +50,9 @@ class DropUserProcessor : public BaseProcessor { class GrantProcessor : public BaseProcessor { public: - static GrantProcessor* instance(kvstore::KVStore* kvstore) { return new GrantProcessor(kvstore); } + static GrantProcessor* instance(kvstore::KVStore* kvstore) { + return new GrantProcessor(kvstore); + } void process(const cpp2::GrantRoleReq& req); diff --git a/src/meta/processors/zone/DropHostsProcessor.cpp b/src/meta/processors/zone/DropHostsProcessor.cpp index 607e6f80042..d822b420327 100644 --- a/src/meta/processors/zone/DropHostsProcessor.cpp +++ b/src/meta/processors/zone/DropHostsProcessor.cpp @@ -141,7 +141,7 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) { return; } - resp_.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); + resp_.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; folly::Baton baton; kvstore_->asyncMultiRemove(kDefaultSpaceId, kDefaultPartId, @@ -178,7 +178,7 @@ DropHostsProcessor::checkRelatedSpaceAndCollect(const std::string& zoneName) { return nebula::cpp2::ErrorCode::E_CONFLICT; } else { zones.erase(it); - properties.set_zone_names(zones); + properties.zone_names_ref() = zones; auto spaceKey = iter->key().data(); auto spaceVal = MetaKeyUtils::spaceVal(properties); diff --git a/src/meta/processors/zone/GetZoneProcessor.cpp b/src/meta/processors/zone/GetZoneProcessor.cpp index 2e71b19489c..882424055de 100644 --- a/src/meta/processors/zone/GetZoneProcessor.cpp +++ b/src/meta/processors/zone/GetZoneProcessor.cpp @@ -40,7 +40,7 @@ void GetZoneProcessor::process(const cpp2::GetZoneReq& req) { auto hosts = MetaKeyUtils::parseZoneHosts(std::move(nebula::value(zoneValueRet))); LOG(INFO) << "Get Zone: " << zoneName << " node size: " << hosts.size(); - resp_.set_hosts(std::move(hosts)); + resp_.hosts_ref() = std::move(hosts); handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); onFinished(); } diff --git a/src/meta/processors/zone/ListZonesProcessor.cpp b/src/meta/processors/zone/ListZonesProcessor.cpp index b2f94b98be0..61a1b07d2ff 100644 --- a/src/meta/processors/zone/ListZonesProcessor.cpp +++ b/src/meta/processors/zone/ListZonesProcessor.cpp @@ -26,18 +26,18 @@ void ListZonesProcessor::process(const cpp2::ListZonesReq&) { auto zoneName = MetaKeyUtils::parseZoneName(iter->key()); auto hosts = MetaKeyUtils::parseZoneHosts(iter->val()); cpp2::Zone zone; - zone.set_zone_name(std::move(zoneName)); + zone.zone_name_ref() = std::move(zoneName); if (hosts.size() != 0) { - zone.set_nodes(std::move(hosts)); + zone.nodes_ref() = std::move(hosts); } else { - zone.set_nodes({HostAddr("", 0)}); + zone.nodes_ref() = {HostAddr("", 0)}; } zones.emplace_back(std::move(zone)); iter->next(); } handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); - resp_.set_zones(std::move(zones)); + resp_.zones_ref() = std::move(zones); onFinished(); } diff --git a/src/meta/processors/zone/MergeZoneProcessor.cpp b/src/meta/processors/zone/MergeZoneProcessor.cpp index c8d3b011942..379fcbf7857 100644 --- a/src/meta/processors/zone/MergeZoneProcessor.cpp +++ b/src/meta/processors/zone/MergeZoneProcessor.cpp @@ -8,7 +8,9 @@ namespace nebula { namespace meta { -void MergeZoneProcessor::process(const cpp2::MergeZoneReq& req) { UNUSED(req); } +void MergeZoneProcessor::process(const cpp2::MergeZoneReq& req) { + UNUSED(req); +} } // namespace meta } // namespace nebula diff --git a/src/meta/processors/zone/RenameZoneProcessor.cpp b/src/meta/processors/zone/RenameZoneProcessor.cpp index 56493689072..6939a802373 100644 --- a/src/meta/processors/zone/RenameZoneProcessor.cpp +++ b/src/meta/processors/zone/RenameZoneProcessor.cpp @@ -50,7 +50,7 @@ void RenameZoneProcessor::process(const cpp2::RenameZoneReq& req) { auto it = std::find(zones.begin(), zones.end(), originalZoneName); if (it != zones.end()) { std::replace(zones.begin(), zones.end(), originalZoneName, zoneName); - properties.set_zone_names(zones); + properties.zone_names_ref() = zones; auto spaceVal = MetaKeyUtils::spaceVal(properties); data.emplace_back(spaceKey, std::move(spaceVal)); } diff --git a/src/meta/processors/zone/SplitZoneProcessor.cpp b/src/meta/processors/zone/SplitZoneProcessor.cpp index 8205e83d34e..6286e026bea 100644 --- a/src/meta/processors/zone/SplitZoneProcessor.cpp +++ b/src/meta/processors/zone/SplitZoneProcessor.cpp @@ -8,7 +8,9 @@ namespace nebula { namespace meta { -void SplitZoneProcessor::process(const cpp2::SplitZoneReq& req) { UNUSED(req); } +void SplitZoneProcessor::process(const cpp2::SplitZoneReq& req) { + UNUSED(req); +} } // namespace meta } // namespace nebula diff --git a/src/meta/stats/CMakeLists.txt b/src/meta/stats/CMakeLists.txt new file mode 100644 index 00000000000..91bcf68755d --- /dev/null +++ b/src/meta/stats/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2021 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. + +nebula_add_library( + meta_stats_obj + OBJECT + MetaStats.cpp + ) diff --git a/src/meta/stats/MetaStats.cpp b/src/meta/stats/MetaStats.cpp new file mode 100644 index 00000000000..990289fea53 --- /dev/null +++ b/src/meta/stats/MetaStats.cpp @@ -0,0 +1,14 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "kvstore/stats/KVStats.h" + +namespace nebula { + +void initMetaStats() { + initKVStats(); +} + +} // namespace nebula diff --git a/src/meta/stats/MetaStats.h b/src/meta/stats/MetaStats.h new file mode 100644 index 00000000000..a8a5fba750e --- /dev/null +++ b/src/meta/stats/MetaStats.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include "common/stats/StatsManager.h" + +namespace nebula { + +void initMetaStats(); + +} // namespace nebula diff --git a/src/meta/test/ActiveHostsManTest.cpp b/src/meta/test/ActiveHostsManTest.cpp index b88eea278b4..b927e6ed720 100644 --- a/src/meta/test/ActiveHostsManTest.cpp +++ b/src/meta/test/ActiveHostsManTest.cpp @@ -129,8 +129,8 @@ TEST(ActiveHostsManTest, LeaderTest) { auto makePartInfo = [](int partId) { cpp2::LeaderInfo part; - part.set_part_id(partId); - part.set_term(partId * 1024); + part.part_id_ref() = partId; + part.term_ref() = partId * 1024; return part; }; diff --git a/src/meta/test/AdminClientTest.cpp b/src/meta/test/AdminClientTest.cpp index 3a4ac07c134..cae27355f21 100644 --- a/src/meta/test/AdminClientTest.cpp +++ b/src/meta/test/AdminClientTest.cpp @@ -21,28 +21,28 @@ storage::cpp2::AdminExecResp resp; \ storage::cpp2::ResponseCommon result; \ std::vector partRetCode; \ - result.set_failed_parts(partRetCode); \ - resp.set_result(result); \ + result.failed_parts_ref() = partRetCode; \ + resp.result_ref() = result; \ pro.setValue(std::move(resp)); \ return f; \ } while (false) -#define RETURN_LEADER_CHANGED(req, leader) \ - UNUSED(req); \ - do { \ - folly::Promise pro; \ - auto f = pro.getFuture(); \ - storage::cpp2::AdminExecResp resp; \ - storage::cpp2::ResponseCommon result; \ - std::vector partRetCode; \ - storage::cpp2::PartitionResult thriftRet; \ - thriftRet.set_code(nebula::cpp2::ErrorCode::E_LEADER_CHANGED); \ - thriftRet.set_leader(leader); \ - partRetCode.emplace_back(std::move(thriftRet)); \ - result.set_failed_parts(partRetCode); \ - resp.set_result(result); \ - pro.setValue(std::move(resp)); \ - return f; \ +#define RETURN_LEADER_CHANGED(req, leader) \ + UNUSED(req); \ + do { \ + folly::Promise pro; \ + auto f = pro.getFuture(); \ + storage::cpp2::AdminExecResp resp; \ + storage::cpp2::ResponseCommon result; \ + std::vector partRetCode; \ + storage::cpp2::PartitionResult thriftRet; \ + thriftRet.code_ref() = nebula::cpp2::ErrorCode::E_LEADER_CHANGED; \ + thriftRet.leader_ref() = leader; \ + partRetCode.emplace_back(std::move(thriftRet)); \ + result.failed_parts_ref() = partRetCode; \ + resp.result_ref() = result; \ + pro.setValue(std::move(resp)); \ + return f; \ } while (false) DECLARE_int32(max_retry_times_admin_op); @@ -91,11 +91,11 @@ class TestStorageService : public storage::cpp2::StorageAdminServiceSvIf { storage::cpp2::CreateCPResp resp; storage::cpp2::ResponseCommon result; std::vector partRetCode; - result.set_failed_parts(partRetCode); - resp.set_result(result); + result.failed_parts_ref() = partRetCode; + resp.result_ref() = result; nebula::cpp2::CheckpointInfo cpInfo; - cpInfo.set_path("snapshot_path"); - resp.set_info({cpInfo}); + cpInfo.path_ref() = "snapshot_path"; + resp.info_ref() = {cpInfo}; pro.setValue(std::move(resp)); return f; } @@ -318,24 +318,28 @@ TEST(AdminClientTest, SnapshotTest) { auto client = std::make_unique(kv.get()); { LOG(INFO) << "Test Blocking Writes On..."; + std::set ids{1}; auto status = - client->blockingWrites(1, storage::cpp2::EngineSignType::BLOCK_ON, storageHost).get(); + client->blockingWrites(ids, storage::cpp2::EngineSignType::BLOCK_ON, storageHost).get(); ASSERT_TRUE(status.ok()); } { LOG(INFO) << "Test Create Snapshot..."; - auto status = client->createSnapshot(1, "test_snapshot", storageHost).get(); + std::set ids{1}; + auto status = client->createSnapshot(ids, "test_snapshot", storageHost).get(); ASSERT_TRUE(status.ok()); } { LOG(INFO) << "Test Drop Snapshot..."; - auto status = client->dropSnapshot(1, "test_snapshot", storageHost).get(); + std::set ids{1}; + auto status = client->dropSnapshot(ids, "test_snapshot", storageHost).get(); ASSERT_TRUE(status.ok()); } { LOG(INFO) << "Test Blocking Writes Off..."; + std::set ids{1}; auto status = - client->blockingWrites(1, storage::cpp2::EngineSignType::BLOCK_OFF, storageHost).get(); + client->blockingWrites(ids, storage::cpp2::EngineSignType::BLOCK_OFF, storageHost).get(); ASSERT_TRUE(status.ok()); } } diff --git a/src/meta/test/AgentHBProcessorTest.cpp b/src/meta/test/AgentHBProcessorTest.cpp new file mode 100644 index 00000000000..2a344037dcd --- /dev/null +++ b/src/meta/test/AgentHBProcessorTest.cpp @@ -0,0 +1,97 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include + +#include "common/base/Base.h" +#include "common/fs/TempDir.h" +#include "common/utils/MetaKeyUtils.h" +#include "meta/processors/admin/AgentHBProcessor.h" +#include "meta/test/TestUtils.h" + +namespace nebula { +namespace meta { + +TEST(AgentHBProcessorTest, AgentHBTest) { + fs::TempDir rootPath("/tmp/AgentHBTest.XXXXXX"); + std::unique_ptr kv(MockCluster::initMetaKV(rootPath.path())); + + // mock 5 storage service in 5 hosts + { + // register storage machines so their heartbeat can be accepted + std::vector machines; + for (auto i = 0; i < 5; i++) { + machines.emplace_back(nebula::MetaKeyUtils::machineKey(std::to_string(i), i), ""); + } + folly::Baton baton; + kv->asyncMultiPut( + kDefaultSpaceId, kDefaultPartId, std::move(machines), [&](auto) { baton.post(); }); + baton.wait(); + + // mock one heartbeat for each storage service + const ClusterID kClusterId = 10; + for (auto i = 0; i < 5; i++) { + cpp2::HBReq req; + req.host_ref() = HostAddr(std::to_string(i), i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; + nebula::cpp2::DirInfo dir; + dir.root_ref() = "/tmp/nebula"; + std::vector ds; + ds.push_back("/tmp/nebula/data"); + dir.data_ref() = ds; + req.dir_ref() = dir; + + auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); + auto f = processor->getFuture(); + processor->process(req); + auto resp = std::move(f).get(); + ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); + } + } + + // mock an agent in each host + for (auto i = 0; i < 5; i++) { + cpp2::AgentHBReq req; + req.host_ref() = HostAddr(std::to_string(i), 10 + i); + auto* processor = AgentHBProcessor::instance(kv.get(), nullptr); + auto f = processor->getFuture(); + processor->process(req); + auto resp = std::move(f).get(); + ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); + ASSERT_EQ(1, resp.get_service_list().size()); + + auto s = resp.get_service_list()[0]; + ASSERT_EQ(cpp2::HostRole::STORAGE, s.get_role()); + ASSERT_EQ(HostAddr(std::to_string(i), i), s.get_addr()); + ASSERT_EQ(1, s.get_dir().get_data().size()); + } + + auto hostsRet = ActiveHostsMan::getActiveHosts(kv.get(), 1, cpp2::HostRole::STORAGE); + ASSERT_TRUE(nebula::ok(hostsRet)); + ASSERT_EQ(5, nebula::value(hostsRet).size()); + + hostsRet = ActiveHostsMan::getActiveHosts(kv.get(), 1, cpp2::HostRole::AGENT); + ASSERT_TRUE(nebula::ok(hostsRet)); + ASSERT_EQ(5, nebula::value(hostsRet).size()); + + sleep(3); + hostsRet = ActiveHostsMan::getActiveHosts(kv.get(), 1, cpp2::HostRole::STORAGE); + ASSERT_TRUE(nebula::ok(hostsRet)); + ASSERT_EQ(0, nebula::value(hostsRet).size()); + hostsRet = ActiveHostsMan::getActiveHosts(kv.get(), 1, cpp2::HostRole::AGENT); + ASSERT_TRUE(nebula::ok(hostsRet)); + ASSERT_EQ(0, nebula::value(hostsRet).size()); +} + +} // namespace meta +} // namespace nebula + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + folly::init(&argc, &argv, true); + google::SetStderrLogging(google::INFO); + return RUN_ALL_TESTS(); +} diff --git a/src/meta/test/AuthProcessorTest.cpp b/src/meta/test/AuthProcessorTest.cpp index f1a7a7a32bc..b80fdd35e5d 100644 --- a/src/meta/test/AuthProcessorTest.cpp +++ b/src/meta/test/AuthProcessorTest.cpp @@ -21,9 +21,9 @@ TEST(AuthProcessorTest, CreateUserTest) { std::unique_ptr kv(MockCluster::initMetaKV(rootPath.path())); { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user1"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -40,9 +40,9 @@ TEST(AuthProcessorTest, CreateUserTest) { // Test user exists and param 'if_not_exists' == false; { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user1"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -52,9 +52,9 @@ TEST(AuthProcessorTest, CreateUserTest) { // Test user exists and param 'if_not_exists' == true; { cpp2::CreateUserReq req; - req.set_if_not_exists(true); - req.set_account("user1"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = true; + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -69,9 +69,9 @@ TEST(AuthProcessorTest, AlterUserTest) { // create a user. { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user1"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -81,8 +81,8 @@ TEST(AuthProcessorTest, AlterUserTest) { // Simple alter user. { cpp2::AlterUserReq req; - req.set_account("user1"); - req.set_encoded_pwd("password_1"); + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password_1"; auto* processor = AlterUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -92,8 +92,8 @@ TEST(AuthProcessorTest, AlterUserTest) { // If user not exists { cpp2::AlterUserReq req; - req.set_account("user2"); - req.set_encoded_pwd("user3"); + req.account_ref() = "user2"; + req.encoded_pwd_ref() = "user3"; auto* processor = AlterUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -108,9 +108,9 @@ TEST(AuthProcessorTest, DropUserTest) { // create a user. { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user1"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -120,8 +120,8 @@ TEST(AuthProcessorTest, DropUserTest) { // User not exists and 'if_exists' = false. { cpp2::DropUserReq req; - req.set_account("user2"); - req.set_if_exists(false); + req.account_ref() = "user2"; + req.if_exists_ref() = false; auto* processor = DropUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -131,8 +131,8 @@ TEST(AuthProcessorTest, DropUserTest) { // User not exists and 'if_exists' = true. { cpp2::DropUserReq req; - req.set_account("user2"); - req.set_if_exists(true); + req.account_ref() = "user2"; + req.if_exists_ref() = true; auto* processor = DropUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -142,8 +142,8 @@ TEST(AuthProcessorTest, DropUserTest) { // User exists. { cpp2::DropUserReq req; - req.set_account("user1"); - req.set_if_exists(false); + req.account_ref() = "user1"; + req.if_exists_ref() = false; auto* processor = DropUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -165,7 +165,7 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -176,13 +176,13 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // create space1 { cpp2::SpaceDesc properties; - properties.set_space_name("space1"); - properties.set_partition_num(1); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "space1"; + properties.partition_num_ref() = 1; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -193,13 +193,13 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // create space2 { cpp2::SpaceDesc properties; - properties.set_space_name("space2"); - properties.set_partition_num(1); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "space2"; + properties.partition_num_ref() = 1; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -210,9 +210,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // create a user1. { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user1"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -222,9 +222,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // create a user2. { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user2"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user2"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -234,9 +234,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // create a user3. { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user3"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user3"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -247,10 +247,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::GrantRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user"); - role.set_space_id(space1); - role.set_role_type(cpp2::RoleType::GUEST); - req.set_role_item(role); + role.user_id_ref() = "user"; + role.space_id_ref() = space1; + role.role_type_ref() = cpp2::RoleType::GUEST; + req.role_item_ref() = role; auto* processor = GrantProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -261,10 +261,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::GrantRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(-1); - role.set_role_type(cpp2::RoleType::GUEST); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = -1; + role.role_type_ref() = cpp2::RoleType::GUEST; + req.role_item_ref() = role; auto* processor = GrantProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -275,10 +275,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::GrantRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(space1); - role.set_role_type(cpp2::RoleType::GUEST); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = space1; + role.role_type_ref() = cpp2::RoleType::GUEST; + req.role_item_ref() = role; auto* processor = GrantProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -289,10 +289,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::GrantRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user2"); - role.set_space_id(space1); - role.set_role_type(cpp2::RoleType::ADMIN); - req.set_role_item(role); + role.user_id_ref() = "user2"; + role.space_id_ref() = space1; + role.role_type_ref() = cpp2::RoleType::ADMIN; + req.role_item_ref() = role; auto* processor = GrantProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -303,10 +303,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::GrantRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user2"); - role.set_space_id(space2); - role.set_role_type(cpp2::RoleType::DBA); - req.set_role_item(role); + role.user_id_ref() = "user2"; + role.space_id_ref() = space2; + role.role_type_ref() = cpp2::RoleType::DBA; + req.role_item_ref() = role; auto* processor = GrantProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -316,7 +316,7 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // list roles. { cpp2::ListRolesReq req; - req.set_space_id(space1); + req.space_id_ref() = space1; auto* processor = ListRolesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -324,20 +324,20 @@ TEST(AuthProcessorTest, GrantRevokeTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); std::vector expectRoles; cpp2::RoleItem role; - role.set_space_id(space1); - role.set_user_id("user1"); - role.set_role_type(cpp2::RoleType::GUEST); + role.space_id_ref() = space1; + role.user_id_ref() = "user1"; + role.role_type_ref() = cpp2::RoleType::GUEST; expectRoles.emplace_back(std::move(role)); - role.set_space_id(space1); - role.set_user_id("user2"); - role.set_role_type(cpp2::RoleType::ADMIN); + role.space_id_ref() = space1; + role.user_id_ref() = "user2"; + role.role_type_ref() = cpp2::RoleType::ADMIN; expectRoles.emplace_back(std::move(role)); ASSERT_EQ(expectRoles, resp.get_roles()); } // list roles. { cpp2::ListRolesReq req; - req.set_space_id(space2); + req.space_id_ref() = space2; auto* processor = ListRolesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -345,9 +345,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); std::vector expectRoles; cpp2::RoleItem role; - role.set_space_id(space2); - role.set_user_id("user2"); - role.set_role_type(cpp2::RoleType::DBA); + role.space_id_ref() = space2; + role.user_id_ref() = "user2"; + role.role_type_ref() = cpp2::RoleType::DBA; expectRoles.emplace_back(std::move(role)); ASSERT_EQ(expectRoles, resp.get_roles()); } @@ -355,9 +355,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::RevokeRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user"); - role.set_space_id(space2); - req.set_role_item(role); + role.user_id_ref() = "user"; + role.space_id_ref() = space2; + req.role_item_ref() = role; auto* processor = RevokeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -368,9 +368,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::RevokeRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(-1); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = -1; + req.role_item_ref() = role; auto* processor = RevokeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -381,10 +381,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::RevokeRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(space1); - role.set_role_type(cpp2::RoleType::ADMIN); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = space1; + role.role_type_ref() = cpp2::RoleType::ADMIN; + req.role_item_ref() = role; auto* processor = RevokeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -395,9 +395,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::RevokeRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(space1); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = space1; + req.role_item_ref() = role; auto* processor = RevokeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -408,10 +408,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::RevokeRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(space1); - role.set_role_type(cpp2::RoleType::GUEST); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = space1; + role.role_type_ref() = cpp2::RoleType::GUEST; + req.role_item_ref() = role; auto* processor = RevokeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -421,7 +421,7 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // list roles. { cpp2::ListRolesReq req; - req.set_space_id(space1); + req.space_id_ref() = space1; auto* processor = ListRolesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -429,16 +429,16 @@ TEST(AuthProcessorTest, GrantRevokeTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); std::vector expectRoles; cpp2::RoleItem role; - role.set_space_id(space1); - role.set_user_id("user2"); - role.set_role_type(cpp2::RoleType::ADMIN); + role.space_id_ref() = space1; + role.user_id_ref() = "user2"; + role.role_type_ref() = cpp2::RoleType::ADMIN; expectRoles.emplace_back(std::move(role)); ASSERT_EQ(expectRoles, resp.get_roles()); } // list roles. { cpp2::ListRolesReq req; - req.set_space_id(space2); + req.space_id_ref() = space2; auto* processor = ListRolesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -446,9 +446,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); std::vector expectRoles; cpp2::RoleItem role; - role.set_space_id(space2); - role.set_user_id("user2"); - role.set_role_type(cpp2::RoleType::DBA); + role.space_id_ref() = space2; + role.user_id_ref() = "user2"; + role.role_type_ref() = cpp2::RoleType::DBA; expectRoles.emplace_back(std::move(role)); ASSERT_EQ(expectRoles, resp.get_roles()); } @@ -456,9 +456,9 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::RevokeRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(space1); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = space1; + req.role_item_ref() = role; auto* processor = RevokeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -478,8 +478,8 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // role deleted after drop user { cpp2::DropUserReq req; - req.set_account("user2"); - req.set_if_exists(false); + req.account_ref() = "user2"; + req.if_exists_ref() = false; auto* processor = DropUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -489,7 +489,7 @@ TEST(AuthProcessorTest, GrantRevokeTest) { // list roles. { cpp2::ListRolesReq req; - req.set_space_id(space2); + req.space_id_ref() = space2; auto* processor = ListRolesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -501,10 +501,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { { cpp2::GrantRoleReq req; nebula::meta::cpp2::RoleItem role; - role.set_user_id("user1"); - role.set_space_id(space1); - role.set_role_type(cpp2::RoleType::ADMIN); - req.set_role_item(role); + role.user_id_ref() = "user1"; + role.space_id_ref() = space1; + role.role_type_ref() = cpp2::RoleType::ADMIN; + req.role_item_ref() = role; auto* processor = GrantProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -513,7 +513,7 @@ TEST(AuthProcessorTest, GrantRevokeTest) { } { cpp2::ListRolesReq req; - req.set_space_id(space1); + req.space_id_ref() = space1; auto* processor = ListRolesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -523,8 +523,8 @@ TEST(AuthProcessorTest, GrantRevokeTest) { } { cpp2::DropSpaceReq req; - req.set_space_name("space1"); - req.set_if_exists(false); + req.space_name_ref() = "space1"; + req.if_exists_ref() = false; auto* processor = DropSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -551,9 +551,9 @@ TEST(AuthProcessorTest, ChangePasswordTest) { // create a user. { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("user1"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "user1"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -563,9 +563,9 @@ TEST(AuthProcessorTest, ChangePasswordTest) { // change password, user dose not exists. { cpp2::ChangePasswordReq req; - req.set_account("user"); - req.set_new_encoded_pwd("pwd1"); - req.set_old_encoded_pwd("pwd1"); + req.account_ref() = "user"; + req.new_encoded_pwd_ref() = "pwd1"; + req.old_encoded_pwd_ref() = "pwd1"; auto* processor = ChangePasswordProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -575,9 +575,9 @@ TEST(AuthProcessorTest, ChangePasswordTest) { // change password, old password is not valid. { cpp2::ChangePasswordReq req; - req.set_account("user1"); - req.set_new_encoded_pwd("pwd1"); - req.set_old_encoded_pwd("pwd1"); + req.account_ref() = "user1"; + req.new_encoded_pwd_ref() = "pwd1"; + req.old_encoded_pwd_ref() = "pwd1"; auto* processor = ChangePasswordProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -587,9 +587,9 @@ TEST(AuthProcessorTest, ChangePasswordTest) { // change password, old password is valid. { cpp2::ChangePasswordReq req; - req.set_account("user1"); - req.set_new_encoded_pwd("pwd1"); - req.set_old_encoded_pwd("password"); + req.account_ref() = "user1"; + req.new_encoded_pwd_ref() = "pwd1"; + req.old_encoded_pwd_ref() = "password"; auto* processor = ChangePasswordProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -599,8 +599,8 @@ TEST(AuthProcessorTest, ChangePasswordTest) { // change password, old password is not need check. { cpp2::ChangePasswordReq req; - req.set_account("user1"); - req.set_new_encoded_pwd("pwdpwd"); + req.account_ref() = "user1"; + req.new_encoded_pwd_ref() = "pwdpwd"; auto* processor = ChangePasswordProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/BalancerTest.cpp b/src/meta/test/BalancerTest.cpp index 3ddbc6a5544..abdc886a1ea 100644 --- a/src/meta/test/BalancerTest.cpp +++ b/src/meta/test/BalancerTest.cpp @@ -163,13 +163,13 @@ TEST(BalanceTest, SimpleTestWithZone) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(4); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 4; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2", "zone_3"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -221,13 +221,13 @@ TEST(BalanceTest, ExpansionZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(4); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 4; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -259,11 +259,11 @@ TEST(BalanceTest, ExpansionZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(4); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 4; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2", "zone_3"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); std::vector data; data.emplace_back(MetaKeyUtils::spaceKey(1), MetaKeyUtils::spaceVal(properties)); folly::Baton baton; @@ -308,13 +308,13 @@ TEST(BalanceTest, ExpansionHostIntoZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(4); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 4; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -385,13 +385,13 @@ TEST(BalanceTest, ShrinkZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(4); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 4; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2", "zone_3"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -435,13 +435,13 @@ TEST(BalanceTest, ShrinkHostFromZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(4); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 4; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -470,7 +470,7 @@ TEST(BalanceTest, ShrinkHostFromZoneTest) { ASSERT_EQ(Status::OK(), ret.value()); } -TEST(BalanceTest, BalanceWithComplexZoneTest) { +TEST(BalanceTest, DISABLED_BalanceWithComplexZoneTest) { fs::TempDir rootPath("/tmp/LeaderBalanceWithComplexZoneTest.XXXXXX"); auto store = MockCluster::initMetaKV(rootPath.path()); auto* kv = dynamic_cast(store.get()); @@ -499,11 +499,11 @@ TEST(BalanceTest, BalanceWithComplexZoneTest) { { { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(18); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 18; + properties.replica_factor_ref() = 3; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -515,13 +515,13 @@ TEST(BalanceTest, BalanceWithComplexZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("space_on_group_0"); - properties.set_partition_num(64); - properties.set_replica_factor(3); + properties.space_name_ref() = "space_on_group_0"; + properties.partition_num_ref() = 64; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2", "zone_3", "zone_4"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -533,14 +533,14 @@ TEST(BalanceTest, BalanceWithComplexZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("space_on_group_1"); - properties.set_partition_num(81); - properties.set_replica_factor(3); + properties.space_name_ref() = "space_on_group_1"; + properties.partition_num_ref() = 81; + properties.replica_factor_ref() = 3; std::vector zones = { "zone_0", "zone_1", "zone_2", "zone_3", "zone_4", "zone_5", "zone_6", "zone_7", "zone_8"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -1626,7 +1626,8 @@ TEST(BalanceTest, LeaderBalanceTest) { dist[HostAddr("1", 1)][1] = {6, 7, 8}; dist[HostAddr("2", 2)][1] = {9}; EXPECT_CALL(client, getLeaderDist(_)) - .WillOnce(DoAll(SetArgPointee<0>(dist), Return(ByMove(folly::Future(Status::OK()))))); + .WillOnce(testing::DoAll(SetArgPointee<0>(dist), + Return(ByMove(folly::Future(Status::OK()))))); LeaderBalanceJobExecutor balancer( testJobId.fetch_add(1, std::memory_order_relaxed), kv, &client, {}); @@ -1655,13 +1656,13 @@ TEST(BalanceTest, LeaderBalanceWithZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(8); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 8; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -1733,13 +1734,13 @@ TEST(BalanceTest, LeaderBalanceWithLargerZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(8); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 8; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2", "zone_3", "zone_4"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -1774,7 +1775,7 @@ TEST(BalanceTest, LeaderBalanceWithLargerZoneTest) { } } -TEST(BalanceTest, LeaderBalanceWithComplexZoneTest) { +TEST(BalanceTest, DISABLED_LeaderBalanceWithComplexZoneTest) { fs::TempDir rootPath("/tmp/LeaderBalanceWithComplexZoneTest.XXXXXX"); auto store = MockCluster::initMetaKV(rootPath.path()); auto* kv = dynamic_cast(store.get()); @@ -1803,11 +1804,11 @@ TEST(BalanceTest, LeaderBalanceWithComplexZoneTest) { { { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(9); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -1818,13 +1819,13 @@ TEST(BalanceTest, LeaderBalanceWithComplexZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("space_on_group_0"); - properties.set_partition_num(64); - properties.set_replica_factor(3); + properties.space_name_ref() = "space_on_group_0"; + properties.partition_num_ref() = 64; + properties.replica_factor_ref() = 3; std::vector zones = {"zone_0", "zone_1", "zone_2", "zone_3", "zone_4"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -1835,14 +1836,14 @@ TEST(BalanceTest, LeaderBalanceWithComplexZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("space_on_group_1"); - properties.set_partition_num(81); - properties.set_replica_factor(3); + properties.space_name_ref() = "space_on_group_1"; + properties.partition_num_ref() = 81; + properties.replica_factor_ref() = 3; std::vector zones = { "zone_0", "zone_1", "zone_2", "zone_3", "zone_4", "zone_5", "zone_6", "zone_7", "zone_8"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/CMakeLists.txt b/src/meta/test/CMakeLists.txt index 83c2851bff8..958cba2a3b9 100644 --- a/src/meta/test/CMakeLists.txt +++ b/src/meta/test/CMakeLists.txt @@ -47,6 +47,21 @@ nebula_add_test( gtest ) +nebula_add_test( + NAME + agent_hb_processor_test + SOURCES + AgentHBProcessorTest.cpp + OBJECTS + ${meta_test_deps} + LIBRARIES + ${ROCKSDB_LIBRARIES} + ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} + wangle + gtest +) + nebula_add_test( NAME meta_client_test diff --git a/src/meta/test/CreateBackupProcessorTest.cpp b/src/meta/test/CreateBackupProcessorTest.cpp index b06341894d3..f81f1e583d9 100644 --- a/src/meta/test/CreateBackupProcessorTest.cpp +++ b/src/meta/test/CreateBackupProcessorTest.cpp @@ -23,8 +23,8 @@ namespace meta { storage::cpp2::AdminExecResp resp; \ storage::cpp2::ResponseCommon result; \ std::vector partRetCode; \ - result.set_failed_parts(partRetCode); \ - resp.set_result(result); \ + result.failed_parts_ref() = partRetCode; \ + resp.result_ref() = result; \ pro.setValue(std::move(resp)); \ return f; \ } while (false) @@ -47,19 +47,18 @@ class TestStorageService : public storage::cpp2::StorageAdminServiceSvIf { storage::cpp2::CreateCPResp resp; storage::cpp2::ResponseCommon result; std::vector partRetCode; - nebula::cpp2::PartitionBackupInfo partitionInfo; std::unordered_map info; nebula::cpp2::LogInfo logInfo; - logInfo.set_log_id(logId); - logInfo.set_term_id(termId); + logInfo.log_id_ref() = logId; + logInfo.term_id_ref() = termId; info.emplace(1, std::move(logInfo)); - partitionInfo.set_info(std::move(info)); - result.set_failed_parts(partRetCode); - resp.set_result(result); + result.failed_parts_ref() = partRetCode; + resp.result_ref() = result; nebula::cpp2::CheckpointInfo cpInfo; - cpInfo.set_path("snapshot_path"); - cpInfo.set_partition_info(std::move(partitionInfo)); - resp.set_info({cpInfo}); + cpInfo.path_ref() = "snapshot_path"; + cpInfo.parts_ref() = std::move(info); + cpInfo.space_id_ref() = req.get_space_ids()[0]; + resp.info_ref() = {cpInfo}; pro.setValue(std::move(resp)); return f; } @@ -81,73 +80,67 @@ TEST(ProcessorTest, CreateBackupTest) { rpcServer->start("storage-admin", 0, handler); LOG(INFO) << "Start storage server on " << rpcServer->port_; - std::string localIp("127.0.0.1"); - LOG(INFO) << "Now test interfaces with retry to leader!"; - fs::TempDir rootPath("/tmp/create_backup_test.XXXXXX"); std::unique_ptr kv(MockCluster::initMetaKV(rootPath.path())); + // register machines std::vector machines; + std::string localIp("127.0.0.1"); machines.emplace_back(nebula::MetaKeyUtils::machineKey(localIp, rpcServer->port_), ""); - folly::Baton b; kv->asyncMultiPut(kDefaultSpaceId, kDefaultPartId, std::move(machines), [&](auto) { b.post(); }); b.wait(); + // resgister active hosts, same with heartbeat auto now = time::WallClock::fastNowInMilliSec(); HostAddr host(localIp, rpcServer->port_); ActiveHostsMan::updateHostInfo(kv.get(), host, HostInfo(now, meta::cpp2::HostRole::STORAGE, "")); - HostAddr storageHost = Utils::getStoreAddrFromAdminAddr(host); - - auto client = std::make_unique(kv.get()); - std::vector hosts; - hosts.emplace_back(host); - meta::TestUtils::registerHB(kv.get(), hosts); - - // mock admin client + // mock space 1: test_space bool ret = false; cpp2::SpaceDesc properties; GraphSpaceID id = 1; - properties.set_space_name("test_space"); - properties.set_partition_num(1); - properties.set_replica_factor(1); + properties.space_name_ref() = "test_space"; + properties.partition_num_ref() = 1; + properties.replica_factor_ref() = 1; auto spaceVal = MetaKeyUtils::spaceVal(properties); std::vector data; data.emplace_back(MetaKeyUtils::indexSpaceKey("test_space"), std::string(reinterpret_cast(&id), sizeof(GraphSpaceID))); data.emplace_back(MetaKeyUtils::spaceKey(id), MetaKeyUtils::spaceVal(properties)); + // mock space 2: test_space2 cpp2::SpaceDesc properties2; GraphSpaceID id2 = 2; - properties2.set_space_name("test_space2"); - properties2.set_partition_num(1); - properties2.set_replica_factor(1); + properties2.space_name_ref() = "test_space2"; + properties2.partition_num_ref() = 1; + properties2.replica_factor_ref() = 1; spaceVal = MetaKeyUtils::spaceVal(properties2); data.emplace_back(MetaKeyUtils::indexSpaceKey("test_space2"), - std::string(reinterpret_cast(&id), sizeof(GraphSpaceID))); + std::string(reinterpret_cast(&id2), sizeof(GraphSpaceID))); data.emplace_back(MetaKeyUtils::spaceKey(id2), MetaKeyUtils::spaceVal(properties2)); + // mock index data std::string indexName = "test_space_index"; int32_t tagIndex = 2; - cpp2::IndexItem item; - item.set_index_id(tagIndex); - item.set_index_name(indexName); + item.index_id_ref() = tagIndex; + item.index_name_ref() = indexName; nebula::cpp2::SchemaID schemaID; TagID tagID = 3; std::string tagName = "test_space_tag1"; - schemaID.set_tag_id(tagID); - item.set_schema_id(schemaID); - item.set_schema_name(tagName); + schemaID.tag_id_ref() = tagID; + item.schema_id_ref() = schemaID; + item.schema_name_ref() = tagName; data.emplace_back(MetaKeyUtils::indexIndexKey(id, indexName), std::string(reinterpret_cast(&tagIndex), sizeof(IndexID))); data.emplace_back(MetaKeyUtils::indexKey(id, tagIndex), MetaKeyUtils::indexVal(item)); + // mock partition data std::vector allHosts; + HostAddr storageHost = Utils::getStoreAddrFromAdminAddr(host); allHosts.emplace_back(storageHost); - for (auto partId = 1; partId <= 1; partId++) { std::vector hosts2; size_t idx = partId; @@ -164,10 +157,11 @@ TEST(ProcessorTest, CreateBackupTest) { }); baton.wait(); + auto client = std::make_unique(kv.get()); { cpp2::CreateBackupReq req; std::vector spaces = {"test_space"}; - req.set_spaces(std::move(spaces)); + req.spaces_ref() = std::move(spaces); JobManager* jobMgr = JobManager::getInstance(); ASSERT_TRUE(jobMgr->init(kv.get())); auto* processor = CreateBackupProcessor::instance(kv.get(), client.get()); @@ -204,19 +198,19 @@ TEST(ProcessorTest, CreateBackupTest) { }); ASSERT_EQ(it, metaFiles.cend()); - ASSERT_EQ(1, meta.get_backup_info().size()); - for (auto s : meta.get_backup_info()) { - ASSERT_EQ(1, s.first); - ASSERT_EQ(1, s.second.get_info().size()); - ASSERT_EQ(1, s.second.get_info()[0].get_info().size()); + ASSERT_EQ(1, meta.get_space_backups().size()); + for (auto s : meta.get_space_backups()) { + auto spaceBackup = s.second; + ASSERT_EQ(1, spaceBackup.get_host_backups().size()); + ASSERT_EQ(1, spaceBackup.get_host_backups()[0].get_checkpoints().size()); - auto checkInfo = s.second.get_info()[0].get_info()[0]; + auto checkInfo = spaceBackup.get_host_backups()[0].get_checkpoints()[0]; ASSERT_EQ("snapshot_path", checkInfo.get_path()); ASSERT_TRUE(meta.get_full()); - ASSERT_FALSE(meta.get_include_system_space()); - auto partitionInfo = checkInfo.get_partition_info().get_info(); - ASSERT_EQ(partitionInfo.size(), 1); - for (auto p : partitionInfo) { + ASSERT_FALSE(meta.get_all_spaces()); + auto parts = checkInfo.get_parts(); + ASSERT_EQ(parts.size(), 1); + for (auto p : parts) { ASSERT_EQ(p.first, 1); auto logInfo = p.second; ASSERT_EQ(logInfo.get_log_id(), logId); diff --git a/src/meta/test/GetStatsTest.cpp b/src/meta/test/GetStatsTest.cpp index bc10498acb8..a58e001c365 100644 --- a/src/meta/test/GetStatsTest.cpp +++ b/src/meta/test/GetStatsTest.cpp @@ -57,16 +57,16 @@ struct JobCallBack { folly::Future operator()() { cpp2::ReportTaskReq req; - req.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); - req.set_job_id(jobId_); - req.set_task_id(taskId_); + req.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; + req.job_id_ref() = jobId_; + req.task_id_ref() = taskId_; cpp2::StatsItem item; - item.set_tag_vertices({{"t1", n_}, {"t2", n_}}); - item.set_edges({{"e1", n_}, {"e2", n_}}); - item.set_space_vertices(2 * n_); - item.set_space_edges(2 * n_); - req.set_stats(item); + item.tag_vertices_ref() = {{"t1", n_}, {"t2", n_}}; + item.edges_ref() = {{"e1", n_}, {"e2", n_}}; + item.space_vertices_ref() = 2 * n_; + item.space_edges_ref() = 2 * n_; + req.stats_ref() = item; jobMgr_->reportTaskFinish(req); return folly::Future(Status::OK()); } @@ -106,8 +106,8 @@ class GetStatsTest : public ::testing::Test { ActiveHostsMan::AllLeaders leaders; for (auto i = 0U; i != parts.size(); ++i) { leaders[space].emplace_back(); - leaders[space].back().set_part_id(parts[i]); - leaders[space].back().set_term(9999); + leaders[space].back().part_id_ref() = parts[i]; + leaders[space].back().term_ref() = 9999; } return std::make_pair(host, leaders); } @@ -138,7 +138,7 @@ TEST_F(GetStatsTest, StatsJob) { ASSERT_EQ(cpp2::JobStatus::QUEUE, job1.status_); cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); @@ -181,7 +181,7 @@ TEST_F(GetStatsTest, StatsJob) { ASSERT_EQ(cpp2::JobStatus::FINISHED, job2.status_); cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); @@ -229,7 +229,7 @@ TEST_F(GetStatsTest, StatsJob) { // Success, but stats data is the result of the last stats job. cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); @@ -283,7 +283,7 @@ TEST_F(GetStatsTest, StatsJob) { ASSERT_NE(nebula::cpp2::ErrorCode::SUCCEEDED, ret); cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); @@ -318,7 +318,7 @@ TEST_F(GetStatsTest, StatsJob) { ASSERT_EQ(cpp2::JobStatus::FINISHED, job2.status_); cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); @@ -392,7 +392,7 @@ TEST_F(GetStatsTest, MockSingleMachineTest) { ASSERT_EQ(cpp2::JobStatus::FINISHED, desc.status_); cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); @@ -432,7 +432,7 @@ TEST_F(GetStatsTest, MockSingleMachineTest) { ASSERT_EQ(cpp2::JobStatus::FINISHED, desc.status_); cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); @@ -509,7 +509,7 @@ TEST_F(GetStatsTest, MockMultiMachineTest) { ASSERT_EQ(cpp2::JobStatus::FINISHED, desc.status_); cpp2::GetStatsReq req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto* processor = GetStatsProcessor::instance(kv_.get()); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/HBProcessorTest.cpp b/src/meta/test/HBProcessorTest.cpp index 77a4d515e44..bbd619d579a 100644 --- a/src/meta/test/HBProcessorTest.cpp +++ b/src/meta/test/HBProcessorTest.cpp @@ -32,10 +32,9 @@ TEST(HBProcessorTest, HBTest) { { for (auto i = 0; i < 5; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr(std::to_string(i), i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.host_ref() = HostAddr(std::to_string(i), i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -53,9 +52,9 @@ TEST(HBProcessorTest, HBTest) { LOG(INFO) << "Test for invalid host!"; cpp2::HBReq req; - req.set_host(HostAddr(std::to_string(11), 11)); - req.set_cluster_id(1); - req.set_role(cpp2::HostRole::STORAGE); + req.host_ref() = HostAddr(std::to_string(11), 11); + req.cluster_id_ref() = 1; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/IndexProcessorTest.cpp b/src/meta/test/IndexProcessorTest.cpp index 89d82d6ba78..379e563e15a 100644 --- a/src/meta/test/IndexProcessorTest.cpp +++ b/src/meta/test/IndexProcessorTest.cpp @@ -42,15 +42,15 @@ TEST(IndexProcessorTest, AlterEdgeWithTTLTest) { cpp2::SchemaProp schemaProp; std::vector cols; cols.emplace_back(TestUtils::columnDef(0, PropertyType::INT64)); - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("col_0"); - schema.set_schema_prop(std::move(schemaProp)); - schema.set_columns(std::move(cols)); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "col_0"; + schema.schema_prop_ref() = std::move(schemaProp); + schema.columns_ref() = std::move(cols); cpp2::CreateEdgeReq req; - req.set_space_id(1); - req.set_edge_name("ttl"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.edge_name_ref() = "ttl"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -59,12 +59,12 @@ TEST(IndexProcessorTest, AlterEdgeWithTTLTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("ttl"); + req.space_id_ref() = 1; + req.edge_name_ref() = "ttl"; cpp2::IndexFieldDef field; - field.set_name("col_0"); - req.set_fields({field}); - req.set_index_name("ttl_index"); + field.name_ref() = "col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "ttl_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -74,11 +74,11 @@ TEST(IndexProcessorTest, AlterEdgeWithTTLTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(1000); - schemaProp.set_ttl_col("col_0"); - req.set_space_id(1); - req.set_edge_name("ttl"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 1000; + schemaProp.ttl_col_ref() = "col_0"; + req.space_id_ref() = 1; + req.edge_name_ref() = "ttl"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -98,15 +98,15 @@ TEST(IndexProcessorTest, AlterTagWithTTLTest) { cpp2::SchemaProp schemaProp; std::vector cols; cols.emplace_back(TestUtils::columnDef(0, PropertyType::INT64)); - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("col_0"); - schema.set_schema_prop(std::move(schemaProp)); - schema.set_columns(std::move(cols)); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "col_0"; + schema.schema_prop_ref() = std::move(schemaProp); + schema.columns_ref() = std::move(cols); cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("ttl"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "ttl"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -115,12 +115,12 @@ TEST(IndexProcessorTest, AlterTagWithTTLTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("ttl"); + req.space_id_ref() = 1; + req.tag_name_ref() = "ttl"; cpp2::IndexFieldDef field; - field.set_name("col_0"); - req.set_fields({field}); - req.set_index_name("ttl_index"); + field.name_ref() = "col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "ttl_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -130,11 +130,11 @@ TEST(IndexProcessorTest, AlterTagWithTTLTest) { { cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(1000); - schemaProp.set_ttl_col("col_0"); - req.set_space_id(1); - req.set_tag_name("ttl"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 1000; + schemaProp.ttl_col_ref() = "col_0"; + req.space_id_ref() = 1; + req.tag_name_ref() = "ttl"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -152,11 +152,11 @@ TEST(IndexProcessorTest, TagIndexTest) { { // Allow to create tag index on no fields cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; std::vector fields{}; - req.set_fields(std::move(fields)); - req.set_index_name("no_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "no_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -166,11 +166,11 @@ TEST(IndexProcessorTest, TagIndexTest) { { // Duplicate tag index on no fields cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; std::vector fields{}; - req.set_fields(std::move(fields)); - req.set_index_name("no_field_index_1"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "no_field_index_1"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -179,12 +179,12 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -193,12 +193,12 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("duplicate_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "duplicate_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -207,8 +207,8 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::DropTagIndexReq req; - req.set_space_id(1); - req.set_index_name("no_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "no_field_index"; auto* processor = DropTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -217,16 +217,16 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_0"); - field2.set_name("tag_0_col_1"); + field1.name_ref() = "tag_0_col_0"; + field2.name_ref() = "tag_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("multi_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "multi_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -235,16 +235,16 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_0"); - field2.set_name("tag_0_col_1"); + field1.name_ref() = "tag_0_col_0"; + field2.name_ref() = "tag_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("duplicate_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "duplicate_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -253,12 +253,12 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("duplicate_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "duplicate_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -267,16 +267,16 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_1"); - field2.set_name("tag_0_col_0"); + field1.name_ref() = "tag_0_col_1"; + field2.name_ref() = "tag_0_col_0"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("disorder_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "disorder_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -285,16 +285,16 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_0"); - field2.set_name("tag_0_col_0"); + field1.name_ref() = "tag_0_col_0"; + field2.name_ref() = "tag_0_col_0"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("conflict_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "conflict_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -303,12 +303,12 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_not_exist"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_not_exist"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("tag_not_exist_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "tag_not_exist_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -317,12 +317,12 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("field_not_exist"); - req.set_fields({field}); - req.set_index_name("field_not_exist_index"); + field.name_ref() = "field_not_exist"; + req.fields_ref() = {field}; + req.index_name_ref() = "field_not_exist_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -332,12 +332,12 @@ TEST(IndexProcessorTest, TagIndexTest) { { // Test index have exist cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -346,7 +346,7 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::ListTagIndexesReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListTagIndexesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -357,8 +357,8 @@ TEST(IndexProcessorTest, TagIndexTest) { ASSERT_EQ(3, items.size()); { cpp2::ColumnDef column; - column.set_name("tag_0_col_0"); - column.type.set_type(PropertyType::INT64); + column.name_ref() = "tag_0_col_0"; + column.type.type_ref() = PropertyType::INT64; std::vector columns; columns.emplace_back(std::move(column)); @@ -371,14 +371,14 @@ TEST(IndexProcessorTest, TagIndexTest) { { std::vector columns; cpp2::ColumnDef intColumn; - intColumn.set_name("tag_0_col_0"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "tag_0_col_0"; + intColumn.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(intColumn)); cpp2::ColumnDef stringColumn; - stringColumn.set_name("tag_0_col_1"); - stringColumn.type.set_type(PropertyType::FIXED_STRING); - stringColumn.type.set_type_length(MAX_INDEX_TYPE_LENGTH); + stringColumn.name_ref() = "tag_0_col_1"; + stringColumn.type.type_ref() = PropertyType::FIXED_STRING; + stringColumn.type.type_length_ref() = MAX_INDEX_TYPE_LENGTH; columns.emplace_back(std::move(stringColumn)); auto multiItem = items[1]; @@ -389,13 +389,13 @@ TEST(IndexProcessorTest, TagIndexTest) { { std::vector columns; cpp2::ColumnDef stringColumn; - stringColumn.set_name("tag_0_col_1"); - stringColumn.type.set_type(PropertyType::FIXED_STRING); - stringColumn.type.set_type_length(MAX_INDEX_TYPE_LENGTH); + stringColumn.name_ref() = "tag_0_col_1"; + stringColumn.type.type_ref() = PropertyType::FIXED_STRING; + stringColumn.type.type_length_ref() = MAX_INDEX_TYPE_LENGTH; columns.emplace_back(std::move(stringColumn)); cpp2::ColumnDef intColumn; - intColumn.set_name("tag_0_col_0"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "tag_0_col_0"; + intColumn.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(intColumn)); auto disorderItem = items[2]; @@ -406,8 +406,8 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::GetTagIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = GetTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -419,8 +419,8 @@ TEST(IndexProcessorTest, TagIndexTest) { ASSERT_EQ(2, item.get_index_id()); cpp2::ColumnDef column; - column.set_name("tag_0_col_0"); - column.type.set_type(PropertyType::INT64); + column.name_ref() = "tag_0_col_0"; + column.type.type_ref() = PropertyType::INT64; std::vector columns; columns.emplace_back(std::move(column)); @@ -428,8 +428,8 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::DropTagIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = DropTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -439,8 +439,8 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::GetTagIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = GetTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -450,8 +450,8 @@ TEST(IndexProcessorTest, TagIndexTest) { } { cpp2::DropTagIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = DropTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -469,12 +469,12 @@ TEST(IndexProcessorTest, TagIndexTestV2) { TestUtils::mockTag(kv.get(), 2, 0, true); { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -483,8 +483,8 @@ TEST(IndexProcessorTest, TagIndexTestV2) { } { cpp2::GetTagIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = GetTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -496,9 +496,9 @@ TEST(IndexProcessorTest, TagIndexTestV2) { ASSERT_EQ(1, item.get_index_id()); cpp2::ColumnDef column; - column.set_name("tag_0_col_0"); - column.type.set_type(PropertyType::INT64); - column.set_nullable(true); + column.name_ref() = "tag_0_col_0"; + column.type.type_ref() = PropertyType::INT64; + column.nullable_ref() = true; std::vector columns; columns.emplace_back(std::move(column)); @@ -515,11 +515,11 @@ TEST(IndexProcessorTest, EdgeIndexTest) { { // Allow to create edge index on no fields cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; std::vector fields{}; - req.set_fields(std::move(fields)); - req.set_index_name("no_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "no_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -529,11 +529,11 @@ TEST(IndexProcessorTest, EdgeIndexTest) { { // Duplicate edge index on no fields cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; std::vector fields{}; - req.set_fields(std::move(fields)); - req.set_index_name("no_field_index_1"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "no_field_index_1"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -542,12 +542,12 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -556,12 +556,12 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("duplicate_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "duplicate_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -570,8 +570,8 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::DropEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("no_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "no_field_index"; auto* processor = DropEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -580,16 +580,16 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_0"); - field2.set_name("edge_0_col_1"); + field1.name_ref() = "edge_0_col_0"; + field2.name_ref() = "edge_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("multi_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "multi_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -598,16 +598,16 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_0"); - field2.set_name("edge_0_col_1"); + field1.name_ref() = "edge_0_col_0"; + field2.name_ref() = "edge_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("duplicate_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "duplicate_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -616,12 +616,12 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("duplicate_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "duplicate_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -630,16 +630,16 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_1"); - field2.set_name("edge_0_col_0"); + field1.name_ref() = "edge_0_col_1"; + field2.name_ref() = "edge_0_col_0"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("disorder_field_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "disorder_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -648,16 +648,16 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_0"); - field2.set_name("edge_0_col_0"); + field1.name_ref() = "edge_0_col_0"; + field2.name_ref() = "edge_0_col_0"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); - req.set_fields(std::move(fields)); - req.set_index_name("conflict_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "conflict_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -666,12 +666,12 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_not_exist"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_not_exist"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("edge_not_exist_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "edge_not_exist_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -680,12 +680,12 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_field_not_exist"); - req.set_fields({field}); - req.set_index_name("field_not_exist_index"); + field.name_ref() = "edge_field_not_exist"; + req.fields_ref() = {field}; + req.index_name_ref() = "field_not_exist_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -694,12 +694,12 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -708,7 +708,7 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::ListEdgeIndexesReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListEdgeIndexesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -718,8 +718,8 @@ TEST(IndexProcessorTest, EdgeIndexTest) { ASSERT_EQ(3, items.size()); { cpp2::ColumnDef column; - column.set_name("edge_0_col_0"); - column.type.set_type(PropertyType::INT64); + column.name_ref() = "edge_0_col_0"; + column.type.type_ref() = PropertyType::INT64; std::vector columns; columns.emplace_back(std::move(column)); @@ -731,14 +731,14 @@ TEST(IndexProcessorTest, EdgeIndexTest) { { std::vector columns; cpp2::ColumnDef intColumn; - intColumn.set_name("edge_0_col_0"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "edge_0_col_0"; + intColumn.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(intColumn)); cpp2::ColumnDef stringColumn; - stringColumn.set_name("edge_0_col_1"); - stringColumn.type.set_type(PropertyType::FIXED_STRING); - stringColumn.type.set_type_length(MAX_INDEX_TYPE_LENGTH); + stringColumn.name_ref() = "edge_0_col_1"; + stringColumn.type.type_ref() = PropertyType::FIXED_STRING; + stringColumn.type.type_length_ref() = MAX_INDEX_TYPE_LENGTH; columns.emplace_back(std::move(stringColumn)); auto multiItem = items[1]; @@ -749,13 +749,13 @@ TEST(IndexProcessorTest, EdgeIndexTest) { { std::vector columns; cpp2::ColumnDef stringColumn; - stringColumn.set_name("edge_0_col_1"); - stringColumn.type.set_type(PropertyType::FIXED_STRING); - stringColumn.type.set_type_length(MAX_INDEX_TYPE_LENGTH); + stringColumn.name_ref() = "edge_0_col_1"; + stringColumn.type.type_ref() = PropertyType::FIXED_STRING; + stringColumn.type.type_length_ref() = MAX_INDEX_TYPE_LENGTH; columns.emplace_back(std::move(stringColumn)); cpp2::ColumnDef intColumn; - intColumn.set_name("edge_0_col_0"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "edge_0_col_0"; + intColumn.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(intColumn)); auto disorderItem = items[2]; @@ -766,8 +766,8 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::GetEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = GetEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -780,8 +780,8 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::DropEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = DropEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -791,8 +791,8 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::GetEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = GetEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -802,8 +802,8 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::DropEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = DropEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -816,16 +816,16 @@ TEST(IndexProcessorTest, EdgeIndexTest) { { for (auto i = 1; i < 18; i++) { cpp2::IndexFieldDef field; - field.set_name(folly::stringPrintf("col-%d", i)); + field.name_ref() = folly::stringPrintf("col-%d", i); bigFields.emplace_back(std::move(field)); } } { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_fields(bigFields); - req.set_index_name("index_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.fields_ref() = bigFields; + req.index_name_ref() = "index_0"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -834,10 +834,10 @@ TEST(IndexProcessorTest, EdgeIndexTest) { } { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_fields(std::move(bigFields)); - req.set_index_name("index_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.fields_ref() = std::move(bigFields); + req.index_name_ref() = "index_0"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -854,12 +854,12 @@ TEST(IndexProcessorTest, EdgeIndexTestV2) { TestUtils::mockEdge(kv.get(), 2, 0, true); { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -868,8 +868,8 @@ TEST(IndexProcessorTest, EdgeIndexTestV2) { } { cpp2::GetEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = GetEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -880,9 +880,9 @@ TEST(IndexProcessorTest, EdgeIndexTestV2) { ASSERT_EQ(1, item.get_index_id()); cpp2::ColumnDef column; - column.set_name("edge_0_col_0"); - column.type.set_type(PropertyType::INT64); - column.set_nullable(true); + column.name_ref() = "edge_0_col_0"; + column.type.type_ref() = PropertyType::INT64; + column.nullable_ref() = true; std::vector columns; columns.emplace_back(std::move(column)); ASSERT_TRUE(TestUtils::verifyResult(columns, fields)); @@ -897,12 +897,12 @@ TEST(IndexProcessorTest, IndexCheckAlterEdgeTest) { TestUtils::mockEdge(kv.get(), 2); { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -920,11 +920,11 @@ TEST(IndexProcessorTest, IndexCheckAlterEdgeTest) { } items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -937,16 +937,16 @@ TEST(IndexProcessorTest, IndexCheckAlterEdgeTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "edge_0_col_2"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -960,16 +960,16 @@ TEST(IndexProcessorTest, IndexCheckAlterEdgeTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "edge_0_col_3"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -983,16 +983,16 @@ TEST(IndexProcessorTest, IndexCheckAlterEdgeTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "edge_0_col_0"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1006,16 +1006,16 @@ TEST(IndexProcessorTest, IndexCheckAlterEdgeTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "edge_0_col_0"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1032,12 +1032,12 @@ TEST(IndexProcessorTest, IndexCheckAlterTagTest) { TestUtils::mockTag(kv.get(), 2); { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1050,15 +1050,15 @@ TEST(IndexProcessorTest, IndexCheckAlterTagTest) { cpp2::Schema addSch; cpp2::ColumnDef column; column.name = "tag_0_col_2"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*addSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1071,14 +1071,14 @@ TEST(IndexProcessorTest, IndexCheckAlterTagTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "tag_0_col_2"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1091,15 +1091,15 @@ TEST(IndexProcessorTest, IndexCheckAlterTagTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "tag_0_col_2"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1112,14 +1112,14 @@ TEST(IndexProcessorTest, IndexCheckAlterTagTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "tag_0_col_0"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1132,15 +1132,15 @@ TEST(IndexProcessorTest, IndexCheckAlterTagTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "tag_0_col_0"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1157,12 +1157,12 @@ TEST(IndexProcessorTest, IndexCheckDropEdgeTest) { TestUtils::mockEdge(kv.get(), 2); { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1171,8 +1171,8 @@ TEST(IndexProcessorTest, IndexCheckDropEdgeTest) { } { cpp2::DropEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; auto* processor = DropEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1189,12 +1189,12 @@ TEST(IndexProcessorTest, IndexCheckDropTagTest) { TestUtils::mockTag(kv.get(), 2); { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1203,8 +1203,8 @@ TEST(IndexProcessorTest, IndexCheckDropTagTest) { } { cpp2::DropTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; auto* processor = DropTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1221,12 +1221,12 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { TestUtils::mockTag(kv.get(), 1); { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1241,15 +1241,15 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { for (auto i = 0; i < 2; i++) { cpp2::ColumnDef column; column.name = folly::stringPrintf("tag_0_col_%d", i + 10); - column.type.set_type(i < 1 ? PropertyType::INT64 : PropertyType::STRING); + column.type.type_ref() = (i < 1 ? PropertyType::INT64 : PropertyType::STRING); (*addSch.columns_ref()).emplace_back(std::move(column)); } items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1261,11 +1261,11 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { { cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_col("tag_0_col_0"); - schemaProp.set_ttl_duration(100); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_col_ref() = "tag_0_col_0"; + schemaProp.ttl_duration_ref() = 100; + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1277,11 +1277,11 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { { cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_col("tag_0_col_10"); - schemaProp.set_ttl_duration(100); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_col_ref() = "tag_0_col_10"; + schemaProp.ttl_duration_ref() = 100; + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1292,8 +1292,8 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { // Drop index { cpp2::DropTagIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = DropTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1305,11 +1305,11 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { { cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_col("tag_0_col_0"); - schemaProp.set_ttl_duration(100); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_col_ref() = "tag_0_col_0"; + schemaProp.ttl_duration_ref() = 100; + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1320,12 +1320,12 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { // Tag with ttl to creat index on ttl col { cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); - req.set_fields({field}); - req.set_index_name("ttl_with_index"); + field.name_ref() = "tag_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "ttl_with_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1337,11 +1337,11 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { { cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(0); - schemaProp.set_ttl_col(""); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 0; + schemaProp.ttl_col_ref() = ""; + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1351,8 +1351,8 @@ TEST(IndexProcessorTest, IndexTTLTagTest) { } { cpp2::DropTagIndexReq req; - req.set_space_id(1); - req.set_index_name("ttl_with_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "ttl_with_index"; auto* processor = DropTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1370,12 +1370,12 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { TestUtils::mockEdge(kv.get(), 1); { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("single_field_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "single_field_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1390,16 +1390,16 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { for (auto i = 0; i < 2; i++) { cpp2::ColumnDef column; column.name = folly::stringPrintf("edge_0_col_%d", i + 10); - column.type.set_type(i < 1 ? PropertyType::INT64 : PropertyType::STRING); + column.type.type_ref() = (i < 1 ? PropertyType::INT64 : PropertyType::STRING); (*addSch.columns_ref()).emplace_back(std::move(column)); } items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1410,11 +1410,11 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_col("edge_0_col_0"); - schemaProp.set_ttl_duration(100); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_col_ref() = "edge_0_col_0"; + schemaProp.ttl_duration_ref() = 100; + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1426,11 +1426,11 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_col("edge_0_col_10"); - schemaProp.set_ttl_duration(100); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_col_ref() = "edge_0_col_10"; + schemaProp.ttl_duration_ref() = 100; + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1441,8 +1441,8 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { // Drop index { cpp2::DropEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("single_field_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "single_field_index"; auto* processor = DropEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1454,11 +1454,11 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_col("edge_0_col_0"); - schemaProp.set_ttl_duration(100); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_col_ref() = "edge_0_col_0"; + schemaProp.ttl_duration_ref() = 100; + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1469,12 +1469,12 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { // Edge with ttl to create index on ttl col { cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); - req.set_fields({field}); - req.set_index_name("ttl_with_index"); + field.name_ref() = "edge_0_col_0"; + req.fields_ref() = {field}; + req.index_name_ref() = "ttl_with_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1486,11 +1486,11 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(0); - schemaProp.set_ttl_col(""); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 0; + schemaProp.ttl_col_ref() = ""; + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1500,8 +1500,8 @@ TEST(IndexProcessorTest, IndexTTLEdgeTest) { } { cpp2::DropEdgeIndexReq req; - req.set_space_id(1); - req.set_index_name("ttl_with_index"); + req.space_id_ref() = 1; + req.index_name_ref() = "ttl_with_index"; auto* processor = DropEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1521,31 +1521,31 @@ void mockSchemas(kvstore::KVStore* kv) { // data type is string { cpp2::ColumnDef col; - col.set_name("col_string"); - col.type.set_type(PropertyType::STRING); + col.name_ref() = "col_string"; + col.type.type_ref() = PropertyType::STRING; (*srcsch.columns_ref()).emplace_back(std::move(col)); } // non-string type { cpp2::ColumnDef col; - col.set_name("col_int"); - col.type.set_type(PropertyType::INT64); + col.name_ref() = "col_int"; + col.type.type_ref() = PropertyType::INT64; (*srcsch.columns_ref()).emplace_back(std::move(col)); } // data type is fixed_string, length <= MAX_INDEX_TYPE_LENGTH { cpp2::ColumnDef col; - col.set_name("col_fixed_string_1"); - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(MAX_INDEX_TYPE_LENGTH); + col.name_ref() = "col_fixed_string_1"; + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = MAX_INDEX_TYPE_LENGTH; (*srcsch.columns_ref()).emplace_back(std::move(col)); } // data type is fixed_string, length > MAX_INDEX_TYPE_LENGTH { cpp2::ColumnDef col; - col.set_name("col_fixed_string_2"); - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(257); + col.name_ref() = "col_fixed_string_2"; + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 257; (*srcsch.columns_ref()).emplace_back(std::move(col)); } auto tagIdVal = std::string(reinterpret_cast(&tagId), sizeof(tagId)); @@ -1579,15 +1579,15 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; if (id == 5) { - schemaId.set_tag_id(5); + schemaId.tag_id_ref() = 5; } else { - schemaId.set_edge_type(6); + schemaId.edge_type_ref() = 6; } - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string", "col_fixed_string_2"}); - req.set_fulltext_index_name("test_ft_index"); - req.set_index(std::move(index)); + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string", "col_fixed_string_2"}; + req.fulltext_index_name_ref() = "test_ft_index"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1601,15 +1601,15 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; if (id == 5) { - schemaId.set_tag_id(5); + schemaId.tag_id_ref() = 5; } else { - schemaId.set_edge_type(6); + schemaId.edge_type_ref() = 6; } - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string", "col_int"}); - req.set_fulltext_index_name("test_ft_index"); - req.set_index(std::move(index)); + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string", "col_int"}; + req.fulltext_index_name_ref() = "test_ft_index"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1623,15 +1623,15 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; if (id == 5) { - schemaId.set_tag_id(5); + schemaId.tag_id_ref() = 5; } else { - schemaId.set_edge_type(6); + schemaId.edge_type_ref() = 6; } - index.set_space_id(2); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string"}); - req.set_fulltext_index_name("test_ft_index"); - req.set_index(std::move(index)); + index.space_id_ref() = 2; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string"}; + req.fulltext_index_name_ref() = "test_ft_index"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1645,15 +1645,15 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; if (id == 5) { - schemaId.set_tag_id(55); + schemaId.tag_id_ref() = 55; } else { - schemaId.set_edge_type(66); + schemaId.edge_type_ref() = 66; } - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string"}); - req.set_fulltext_index_name("test_ft_index"); - req.set_index(std::move(index)); + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string"}; + req.fulltext_index_name_ref() = "test_ft_index"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1669,15 +1669,15 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; if (id == 5) { - schemaId.set_tag_id(5); + schemaId.tag_id_ref() = 5; } else { - schemaId.set_edge_type(6); + schemaId.edge_type_ref() = 6; } - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_bool"}); - req.set_fulltext_index_name("test_ft_index"); - req.set_index(std::move(index)); + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_bool"}; + req.fulltext_index_name_ref() = "test_ft_index"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1693,12 +1693,12 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::CreateFTIndexReq req; cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(5); - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string", "col_fixed_string_1"}); - req.set_fulltext_index_name("ft_tag_index"); - req.set_index(std::move(index)); + schemaId.tag_id_ref() = 5; + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string", "col_fixed_string_1"}; + req.fulltext_index_name_ref() = "ft_tag_index"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1711,12 +1711,12 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::CreateFTIndexReq req; cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(5); - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string", "col_fixed_string_1"}); - req.set_fulltext_index_name("ft_tag_index"); - req.set_index(std::move(index)); + schemaId.tag_id_ref() = 5; + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string", "col_fixed_string_1"}; + req.fulltext_index_name_ref() = "ft_tag_index"; + req.index_ref() = (std::move(index)); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1729,12 +1729,12 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::CreateFTIndexReq req; cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(5); - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string", "col_fixed_string_1"}); - req.set_fulltext_index_name("ft_tag_index_re"); - req.set_index(std::move(index)); + schemaId.tag_id_ref() = 5; + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string", "col_fixed_string_1"}; + req.fulltext_index_name_ref() = "ft_tag_index_re"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1747,12 +1747,12 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::CreateFTIndexReq req; cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(5); - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string"}); - req.set_fulltext_index_name("ft_tag_index_re"); - req.set_index(std::move(index)); + schemaId.tag_id_ref() = 5; + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string"}; + req.fulltext_index_name_ref() = "ft_tag_index_re"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1765,12 +1765,12 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { cpp2::CreateFTIndexReq req; cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(6); - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string"}); - req.set_fulltext_index_name("ft_tag_index"); - req.set_index(std::move(index)); + schemaId.edge_type_ref() = 6; + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string"}; + req.fulltext_index_name_ref() = "ft_tag_index"; + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1792,13 +1792,13 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { ASSERT_EQ(fields, index->second.get_fields()); ASSERT_EQ(1, index->second.get_space_id()); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(5); + schemaId.tag_id_ref() = 5; ASSERT_EQ(schemaId, index->second.get_depend_schema()); } { cpp2::DropFTIndexReq req; - req.set_space_id(1); - req.set_fulltext_index_name("ft_tag_index"); + req.space_id_ref() = 1; + req.fulltext_index_name_ref() = "ft_tag_index"; auto* processor = DropFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1817,8 +1817,8 @@ TEST(IndexProcessorTest, CreateFTIndexTest) { // expected error. fulltext index not found. { cpp2::DropFTIndexReq req; - req.set_space_id(1); - req.set_fulltext_index_name("ft_tag_index"); + req.space_id_ref() = 1; + req.fulltext_index_name_ref() = "ft_tag_index"; auto* processor = DropFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1839,15 +1839,15 @@ TEST(IndexProcessorTest, DropWithFTIndexTest) { cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; if (id == 5) { - schemaId.set_tag_id(5); + schemaId.tag_id_ref() = 5; } else { - schemaId.set_edge_type(6); + schemaId.edge_type_ref() = 6; } - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string", "col_fixed_string_1"}); - req.set_fulltext_index_name(folly::stringPrintf("test_ft_index_%d", id)); - req.set_index(std::move(index)); + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string", "col_fixed_string_1"}; + req.fulltext_index_name_ref() = folly::stringPrintf("test_ft_index_%d", id); + req.index_ref() = (std::move(index)); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1858,8 +1858,8 @@ TEST(IndexProcessorTest, DropWithFTIndexTest) { } { cpp2::DropTagReq req; - req.set_space_id(1); - req.set_tag_name("test_tag"); + req.space_id_ref() = 1; + req.tag_name_ref() = "test_tag"; auto* processor = DropTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1868,8 +1868,8 @@ TEST(IndexProcessorTest, DropWithFTIndexTest) { } { cpp2::DropEdgeReq req; - req.set_space_id(1); - req.set_edge_name("test_edge"); + req.space_id_ref() = 1; + req.edge_name_ref() = "test_edge"; auto* processor = DropEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1890,15 +1890,15 @@ TEST(IndexProcessorTest, AlterWithFTIndexTest) { cpp2::FTIndex index; nebula::cpp2::SchemaID schemaId; if (id == 5) { - schemaId.set_tag_id(5); + schemaId.tag_id_ref() = 5; } else { - schemaId.set_edge_type(6); + schemaId.edge_type_ref() = 6; } - index.set_space_id(1); - index.set_depend_schema(std::move(schemaId)); - index.set_fields({"col_string", "col_fixed_string_1"}); - req.set_fulltext_index_name(folly::stringPrintf("test_ft_index_%d", id)); - req.set_index(std::move(index)); + index.space_id_ref() = 1; + index.depend_schema_ref() = std::move(schemaId); + index.fields_ref() = {"col_string", "col_fixed_string_1"}; + req.fulltext_index_name_ref() = folly::stringPrintf("test_ft_index_%d", id); + req.index_ref() = std::move(index); auto* processor = CreateFTIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1913,14 +1913,14 @@ TEST(IndexProcessorTest, AlterWithFTIndexTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "col_string"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); - req.set_space_id(1); - req.set_tag_name("test_tag"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "test_tag"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1933,15 +1933,15 @@ TEST(IndexProcessorTest, AlterWithFTIndexTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "col_string"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_tag_name("test_tag"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "test_tag"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1954,15 +1954,15 @@ TEST(IndexProcessorTest, AlterWithFTIndexTest) { cpp2::Schema addSch; cpp2::ColumnDef column; column.name = "col_bool"; - column.type.set_type(PropertyType::BOOL); + column.type.type_ref() = PropertyType::BOOL; (*addSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); - req.set_space_id(1); - req.set_tag_name("test_tag"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "test_tag"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1976,14 +1976,14 @@ TEST(IndexProcessorTest, AlterWithFTIndexTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "col_string"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); - req.set_space_id(1); - req.set_edge_name("test_edge"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); + req.space_id_ref() = 1; + req.edge_name_ref() = "test_edge"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1996,15 +1996,15 @@ TEST(IndexProcessorTest, AlterWithFTIndexTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "col_string"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_edge_name("test_edge"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.edge_name_ref() = "test_edge"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2017,15 +2017,15 @@ TEST(IndexProcessorTest, AlterWithFTIndexTest) { cpp2::Schema addSch; cpp2::ColumnDef column; column.name = "col_bool"; - column.type.set_type(PropertyType::BOOL); + column.type.type_ref() = PropertyType::BOOL; (*addSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); - req.set_space_id(1); - req.set_edge_name("test_edge"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); + req.space_id_ref() = 1; + req.edge_name_ref() = "test_edge"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2040,7 +2040,7 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2113,16 +2113,16 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { cols.emplace_back(TestUtils::columnDef(0, PropertyType::INT64)); cols.emplace_back(TestUtils::columnDef(1, PropertyType::FLOAT)); cols.emplace_back(TestUtils::columnDef(2, PropertyType::STRING)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); // create space, use global id { cpp2::SpaceDesc properties; - properties.set_space_name("my_space"); - properties.set_partition_num(9); - properties.set_replica_factor(1); + properties.space_name_ref() = "my_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2135,9 +2135,9 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { { // Succeeded cpp2::CreateTagReq req; - req.set_space_id(6); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 6; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2148,14 +2148,14 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { // create tag index in my_space, because there is local_id key, use local_id + 1 { cpp2::CreateTagIndexReq req; - req.set_space_id(6); - req.set_tag_name("default_tag"); + req.space_id_ref() = 6; + req.tag_name_ref() = "default_tag"; std::vector fields; cpp2::IndexFieldDef field1; - field1.set_name("col_0"); + field1.name_ref() = "col_0"; fields.emplace_back(std::move(field1)); - req.set_fields(std::move(fields)); - req.set_index_name("default_tag_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "default_tag_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2167,9 +2167,9 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { { // Succeeded cpp2::CreateEdgeReq req; - req.set_space_id(6); - req.set_edge_name("default_edge"); - req.set_schema(schema); + req.space_id_ref() = 6; + req.edge_name_ref() = "default_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2180,14 +2180,14 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { // create edge index in my_space, because there is local_id key, use local_id + 1 { cpp2::CreateEdgeIndexReq req; - req.set_space_id(6); - req.set_edge_name("default_edge"); + req.space_id_ref() = 6; + req.edge_name_ref() = "default_edge"; std::vector fields; cpp2::IndexFieldDef field1; - field1.set_name("col_0"); + field1.name_ref() = "col_0"; fields.emplace_back(std::move(field1)); - req.set_fields(std::move(fields)); - req.set_index_name("default_edge_index"); + req.fields_ref() = (std::move(fields)); + req.index_name_ref() = ("default_edge_index"); auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2199,11 +2199,11 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { // create space, space Id is global id + 1 { cpp2::SpaceDesc properties; - properties.set_space_name("last_space"); - properties.set_partition_num(9); - properties.set_replica_factor(1); + properties.space_name_ref() = "last_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2216,9 +2216,9 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { { // Succeeded cpp2::CreateTagReq req; - req.set_space_id(6); - req.set_tag_name("my_tag"); - req.set_schema(schema); + req.space_id_ref() = (6); + req.tag_name_ref() = ("my_tag"); + req.schema_ref() = (schema); auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2229,14 +2229,14 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { // create tag index in my_space, because there is local_id key, use local_id + 1 { cpp2::CreateTagIndexReq req; - req.set_space_id(6); - req.set_tag_name("my_tag"); + req.space_id_ref() = 6; + req.tag_name_ref() = "my_tag"; std::vector fields; cpp2::IndexFieldDef field1; - field1.set_name("col_0"); + field1.name_ref() = "col_0"; fields.emplace_back(std::move(field1)); - req.set_fields(std::move(fields)); - req.set_index_name("my_tag_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "my_tag_index"; auto* processor = CreateTagIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2248,9 +2248,9 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { { // Succeeded cpp2::CreateEdgeReq req; - req.set_space_id(6); - req.set_edge_name("my_edge"); - req.set_schema(schema); + req.space_id_ref() = 6; + req.edge_name_ref() = "my_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2262,14 +2262,14 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { { // Allow to create edge index on no fields cpp2::CreateEdgeIndexReq req; - req.set_space_id(6); - req.set_edge_name("my_edge"); + req.space_id_ref() = 6; + req.edge_name_ref() = "my_edge"; std::vector fields; cpp2::IndexFieldDef field1; - field1.set_name("col_0"); + field1.name_ref() = "col_0"; fields.emplace_back(std::move(field1)); - req.set_fields(std::move(fields)); - req.set_index_name("my_edge_index"); + req.fields_ref() = std::move(fields); + req.index_name_ref() = "my_edge_index"; auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/JobManagerTest.cpp b/src/meta/test/JobManagerTest.cpp index 9c910486c5c..55ae1b5a155 100644 --- a/src/meta/test/JobManagerTest.cpp +++ b/src/meta/test/JobManagerTest.cpp @@ -300,7 +300,9 @@ TEST_F(JobManagerTest, showJobsFromMultiSpace) { ASSERT_EQ(jobs[0].get_stop_time(), jd2.stopTime_); } -HostAddr toHost(std::string strIp) { return HostAddr(strIp, 0); } +HostAddr toHost(std::string strIp) { + return HostAddr(strIp, 0); +} TEST_F(JobManagerTest, showJob) { std::vector paras{"test_space"}; diff --git a/src/meta/test/ListClusterInfoTest.cpp b/src/meta/test/ListClusterInfoTest.cpp index 3ba124f2626..a804f57076f 100644 --- a/src/meta/test/ListClusterInfoTest.cpp +++ b/src/meta/test/ListClusterInfoTest.cpp @@ -19,26 +19,7 @@ const char root_dir[] = "/tmp/create_backup_test.XXXXXX"; const char data_dir[] = "/tmp/create_backup_test.XXXXXX/data"; } // namespace -class TestStorageService : public storage::cpp2::StorageAdminServiceSvIf { - public: - folly::Future future_listClusterInfo( - const storage::cpp2::ListClusterInfoReq& req) override { - UNUSED(req); - folly::Promise pro; - auto f = pro.getFuture(); - storage::cpp2::ListClusterInfoResp resp; - storage::cpp2::ResponseCommon result; - std::vector partRetCode; - result.set_failed_parts(partRetCode); - resp.set_result(result); - nebula::cpp2::DirInfo dir; - dir.set_root(root_dir); - dir.set_data({data_dir}); - resp.set_dir(std::move(dir)); - pro.setValue(std::move(resp)); - return f; - } -}; +class TestStorageService : public storage::cpp2::StorageAdminServiceSvIf {}; TEST(ProcessorTest, ListClusterInfoTest) { auto rpcServer = std::make_unique(); @@ -46,33 +27,61 @@ TEST(ProcessorTest, ListClusterInfoTest) { rpcServer->start("storage-admin", 0, handler); LOG(INFO) << "Start storage server on " << rpcServer->port_; - std::string localIp("127.0.0.1"); - LOG(INFO) << "Now test interfaces with retry to leader!"; - + std::string localIp("127.0.0.1"); fs::TempDir rootPath(root_dir); - std::unique_ptr kv(MockCluster::initMetaKV(rootPath.path())); - HostAddr host(localIp, rpcServer->port_); - HostAddr storageHost = Utils::getStoreAddrFromAdminAddr(host); + HostAddr kvAddr(localIp, 10079); + std::unique_ptr kv(MockCluster::initMetaKV(rootPath.path(), kvAddr)); + HostAddr rpcHost(localIp, rpcServer->port_); - auto client = std::make_unique(kv.get()); + // register storage and save its dir info + HostAddr storageHost = Utils::getStoreAddrFromAdminAddr(rpcHost); std::vector hosts; hosts.emplace_back(storageHost); meta::TestUtils::registerHB(kv.get(), hosts); + std::vector dirs; + nebula::cpp2::DirInfo dir; + dir.root_ref() = std::string(root_dir); + std::vector ds; + ds.push_back(std::string(data_dir)); + dir.data_ref() = ds; + dirs.emplace_back(std::make_pair(MetaKeyUtils::hostDirKey(storageHost.host, storageHost.port), + MetaKeyUtils::hostDirVal(dir))); + folly::Baton b; + kv->asyncMultiPut(kDefaultSpaceId, kDefaultPartId, std::move(dirs), [&](auto) { b.post(); }); + b.wait(); + + // register agent + Port randomPort = 10080; + HostAddr agentHost(localIp, randomPort); + hosts.clear(); + hosts.emplace_back(agentHost); + meta::TestUtils::setupHB(kv.get(), hosts, cpp2::HostRole::AGENT, gitInfoSha()); + { cpp2::ListClusterInfoReq req; - auto* processor = ListClusterInfoProcessor::instance(kv.get(), client.get()); + auto* processor = ListClusterInfoProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); auto resp = std::move(f).get(); LOG(INFO) << folly::to(resp.get_code()); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); - for (auto s : resp.get_storage_servers()) { - ASSERT_EQ(storageHost, s.get_host()); - ASSERT_EQ(s.get_dir().get_root(), root_dir); - ASSERT_EQ(s.get_dir().get_data()[0], data_dir); + ASSERT_EQ(resp.get_host_services().size(), 1); + for (auto iter : resp.get_host_services()) { + auto host = iter.first; + auto services = iter.second; + + ASSERT_EQ(services.size(), 3); + + std::unordered_map m; + for (auto s : services) { + m[s.get_role()] = s; + } + ASSERT_NE(m.find(cpp2::HostRole::META), m.end()); + ASSERT_NE(m.find(cpp2::HostRole::STORAGE), m.end()); + ASSERT_NE(m.find(cpp2::HostRole::AGENT), m.end()); } } } diff --git a/src/meta/test/MetaClientTest.cpp b/src/meta/test/MetaClientTest.cpp index ef563bfed78..b0d2ed3ffa6 100644 --- a/src/meta/test/MetaClientTest.cpp +++ b/src/meta/test/MetaClientTest.cpp @@ -52,11 +52,11 @@ TEST(MetaClientTest, InterfacesTest) { // Test createSpace, listSpaces, getPartsAlloc. { meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space"); - spaceDesc.set_partition_num(8); - spaceDesc.set_replica_factor(3); - spaceDesc.set_charset_name("utf8"); - spaceDesc.set_collate_name("utf8_bin"); + spaceDesc.space_name_ref() = "default_space"; + spaceDesc.partition_num_ref() = 8; + spaceDesc.replica_factor_ref() = 3; + spaceDesc.charset_name_ref() = "utf8"; + spaceDesc.collate_name_ref() = "utf8_bin"; auto ret = client->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); spaceId = ret.value(); @@ -66,9 +66,9 @@ TEST(MetaClientTest, InterfacesTest) { } { meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space"); - spaceDesc.set_partition_num(8); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default_space"; + spaceDesc.partition_num_ref() = 8; + spaceDesc.replica_factor_ref() = 3; auto ret = client->createSpace(spaceDesc).get(); ASSERT_FALSE(ret.ok()); } @@ -103,7 +103,7 @@ TEST(MetaClientTest, InterfacesTest) { for (auto i = 0; i < 5; i++) { cpp2::ColumnDef column; column.name = "tagItem" + std::to_string(i); - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; (*schema.columns_ref()).emplace_back(std::move(column)); } auto ret = client->createTagSchema(spaceId, "tagName", schema).get(); @@ -118,9 +118,9 @@ TEST(MetaClientTest, InterfacesTest) { for (auto i = 0; i < 5; i++) { cpp2::ColumnDef column; column.name = "tagItem" + std::to_string(i); - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; const auto& defaultValue = *ConstantExpression::make(metaPool, std::to_string(i)); - column.set_default_value(Expression::encode(defaultValue)); + column.default_value_ref() = Expression::encode(defaultValue); (*schema.columns_ref()).emplace_back(std::move(column)); } auto ret = client->createTagSchema(spaceId, "tagWithDefault", schema).get(); @@ -131,11 +131,11 @@ TEST(MetaClientTest, InterfacesTest) { cpp2::Schema schema; cpp2::ColumnDef column; column.name = "tagItem"; - column.type.set_type(PropertyType::STRING); - column.set_nullable(true); + column.type.type_ref() = PropertyType::STRING; + column.nullable_ref() = true; const auto& defaultValue = *ArithmeticExpression::makeDivision( metaPool, ConstantExpression::make(metaPool, 1), ConstantExpression::make(metaPool, 0)); - column.set_default_value(Expression::encode(defaultValue)); + column.default_value_ref() = Expression::encode(defaultValue); (*schema.columns_ref()).emplace_back(std::move(column)); auto ret = client->createTagSchema(spaceId, "tagWithWrongDefault", schema).get(); ASSERT_FALSE(ret.ok()) << ret.status(); @@ -146,7 +146,7 @@ TEST(MetaClientTest, InterfacesTest) { for (auto i = 0; i < 5; i++) { cpp2::ColumnDef column; column.name = "edgeItem" + std::to_string(i); - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; (*schema.columns_ref()).emplace_back(std::move(column)); } auto ret = client->createEdgeSchema(spaceId, "edgeName", schema).get(); @@ -160,9 +160,9 @@ TEST(MetaClientTest, InterfacesTest) { for (auto i = 0; i < 5; i++) { cpp2::ColumnDef column; column.name = "edgeItem" + std::to_string(i); - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; const auto& defaultValue = *ConstantExpression::make(metaPool, std::to_string(i)); - column.set_default_value(Expression::encode(defaultValue)); + column.default_value_ref() = Expression::encode(defaultValue); (*schema.columns_ref()).emplace_back(std::move(column)); } auto ret = client->createEdgeSchema(spaceId, "edgeWithDefault", schema).get(); @@ -359,9 +359,9 @@ TEST(MetaClientTest, TagTest) { EXPECT_TRUE(result.ok()); } meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default"); - spaceDesc.set_partition_num(9); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default"; + spaceDesc.partition_num_ref() = 9; + spaceDesc.replica_factor_ref() = 3; auto ret = client->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); GraphSpaceID spaceId = ret.value(); @@ -371,25 +371,25 @@ TEST(MetaClientTest, TagTest) { { std::vector columns; columns.emplace_back(); - columns.back().set_name("column_i"); + columns.back().name_ref() = "column_i"; const auto& intValue = *ConstantExpression::make(metaPool, Value(0L)); - columns.back().set_default_value(Expression::encode(intValue)); - columns.back().type.set_type(PropertyType::INT64); + columns.back().default_value_ref() = Expression::encode(intValue); + columns.back().type.type_ref() = PropertyType::INT64; columns.emplace_back(); const auto& floatValue = *ConstantExpression::make(metaPool, Value(3.14)); - columns.back().set_default_value(Expression::encode(floatValue)); - columns.back().set_name("column_d"); - columns.back().type.set_type(PropertyType::DOUBLE); + columns.back().default_value_ref() = Expression::encode(floatValue); + columns.back().name_ref() = "column_d"; + columns.back().type.type_ref() = PropertyType::DOUBLE; columns.emplace_back(); const auto& strValue = *ConstantExpression::make(metaPool, "test"); - columns.back().set_default_value(Expression::encode(strValue)); - columns.back().set_name("column_s"); - columns.back().type.set_type(PropertyType::STRING); + columns.back().default_value_ref() = Expression::encode(strValue); + columns.back().name_ref() = "column_s"; + columns.back().type.type_ref() = PropertyType::STRING; cpp2::Schema schema; - schema.set_columns(std::move(columns)); + schema.columns_ref() = std::move(columns); auto result = client->createTagSchema(spaceId, "test_tag", std::move(schema)).get(); ASSERT_TRUE(result.ok()); id = result.value(); @@ -397,21 +397,21 @@ TEST(MetaClientTest, TagTest) { { std::vector columns; cpp2::ColumnDef intColumn; - intColumn.set_name("column_i"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "column_i"; + intColumn.type.type_ref() = PropertyType::INT64; const auto& intValue = *ConstantExpression::make(metaPool, Value(0L)); - intColumn.set_default_value(Expression::encode(intValue)); + intColumn.default_value_ref() = Expression::encode(intValue); columns.emplace_back(std::move(intColumn)); cpp2::ColumnDef doubleColumn; - doubleColumn.set_name("column_d"); - doubleColumn.type.set_type(PropertyType::STRING); + doubleColumn.name_ref() = "column_d"; + doubleColumn.type.type_ref() = PropertyType::STRING; const auto& floatValue = *ConstantExpression::make(metaPool, Value(3.14)); - doubleColumn.set_default_value(Expression::encode(floatValue)); + doubleColumn.default_value_ref() = Expression::encode(floatValue); columns.emplace_back(std::move(doubleColumn)); cpp2::Schema schema; - schema.set_columns(columns); + schema.columns_ref() = columns; auto result = client->createTagSchema(spaceId, "test_tag_type_mismatch", schema).get(); ASSERT_FALSE(result.ok()); @@ -453,20 +453,20 @@ TEST(MetaClientTest, TagTest) { auto genSchema = [](Value value, PropertyType type, bool isFunction = false) -> auto { std::vector columns; columns.emplace_back(); - columns.back().set_name("colName"); + columns.back().name_ref() = "colName"; auto valueExpr = ConstantExpression::make(metaPool, std::move(value)); if (isFunction) { ArgumentList* argList = ArgumentList::make(metaPool); argList->addArgument(valueExpr); auto fExpr = FunctionCallExpression::make(metaPool, "timestamp", argList); - columns.back().set_default_value(Expression::encode(*fExpr)); + columns.back().default_value_ref() = Expression::encode(*fExpr); } else { - columns.back().set_default_value(Expression::encode(*valueExpr)); + columns.back().default_value_ref() = Expression::encode(*valueExpr); } - columns.back().type.set_type(type); + columns.back().type.type_ref() = type; cpp2::Schema schema; - schema.set_columns(std::move(columns)); + schema.columns_ref() = std::move(columns); return schema; }; // Test wrong format timestamp in default value @@ -594,9 +594,9 @@ TEST(MetaClientTest, EdgeTest) { EXPECT_TRUE(result.ok()); } meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space"); - spaceDesc.set_partition_num(9); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default_space"; + spaceDesc.partition_num_ref() = 9; + spaceDesc.replica_factor_ref() = 3; auto ret = client->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); GraphSpaceID space = ret.value(); @@ -607,49 +607,49 @@ TEST(MetaClientTest, EdgeTest) { std::vector columns; cpp2::ColumnDef intColumn; - intColumn.set_name("column_i"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "column_i"; + intColumn.type.type_ref() = PropertyType::INT64; const auto& intValue = *ConstantExpression::make(metaPool, Value(0L)); - intColumn.set_default_value(Expression::encode(intValue)); + intColumn.default_value_ref() = Expression::encode(intValue); columns.emplace_back(std::move(intColumn)); cpp2::ColumnDef doubleColumn; - doubleColumn.set_name("column_d"); - doubleColumn.type.set_type(PropertyType::DOUBLE); + doubleColumn.name_ref() = "column_d"; + doubleColumn.type.type_ref() = PropertyType::DOUBLE; const auto& floatValue = *ConstantExpression::make(metaPool, Value(3.14)); - doubleColumn.set_default_value(Expression::encode(floatValue)); + doubleColumn.default_value_ref() = Expression::encode(floatValue); columns.emplace_back(std::move(doubleColumn)); cpp2::ColumnDef stringColumn; - stringColumn.set_name("column_s"); - stringColumn.type.set_type(PropertyType::STRING); + stringColumn.name_ref() = "column_s"; + stringColumn.type.type_ref() = PropertyType::STRING; const auto& strValue = *ConstantExpression::make(metaPool, "test"); - stringColumn.set_default_value(Expression::encode(strValue)); + stringColumn.default_value_ref() = Expression::encode(strValue); columns.emplace_back(std::move(stringColumn)); expectedColumns = columns; cpp2::Schema schema; - schema.set_columns(std::move(columns)); + schema.columns_ref() = std::move(columns); auto result = client->createEdgeSchema(space, "test_edge", schema).get(); ASSERT_TRUE(result.ok()); } { std::vector columns; cpp2::ColumnDef intColumn; - intColumn.set_name("column_i"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "column_i"; + intColumn.type.type_ref() = PropertyType::INT64; const auto& intValue = *ConstantExpression::make(metaPool, Value(0L)); - intColumn.set_default_value(Expression::encode(intValue)); + intColumn.default_value_ref() = Expression::encode(intValue); columns.emplace_back(std::move(intColumn)); cpp2::ColumnDef doubleColumn; - doubleColumn.set_name("column_d"); - doubleColumn.type.set_type(PropertyType::STRING); + doubleColumn.name_ref() = "column_d"; + doubleColumn.type.type_ref() = PropertyType::STRING; const auto& floatValue = *ConstantExpression::make(metaPool, Value(3.14)); - doubleColumn.set_default_value(Expression::encode(floatValue)); + doubleColumn.default_value_ref() = Expression::encode(floatValue); columns.emplace_back(std::move(doubleColumn)); cpp2::Schema schema; - schema.set_columns(columns); + schema.columns_ref() = columns; auto result = client->createEdgeSchema(space, "test_edge_type_mismatch", schema).get(); ASSERT_FALSE(result.ok()); @@ -664,7 +664,7 @@ TEST(MetaClientTest, EdgeTest) { version = edges[0].get_version(); cpp2::Schema expected; - expected.set_columns(std::move(expectedColumns)); + expected.columns_ref() = std::move(expectedColumns); cpp2::Schema resultSchema = edges[0].get_schema(); ASSERT_TRUE(TestUtils::verifySchema(resultSchema, expected)); } @@ -704,9 +704,9 @@ TEST(MetaClientTest, TagIndexTest) { } meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space"); - spaceDesc.set_partition_num(8); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default_space"; + spaceDesc.partition_num_ref() = 8; + spaceDesc.replica_factor_ref() = 3; auto ret = client->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); GraphSpaceID space = ret.value(); @@ -716,25 +716,25 @@ TEST(MetaClientTest, TagIndexTest) { for (auto i = 0; i < 2; i++) { std::vector columns; cpp2::ColumnDef column0; - column0.set_name(folly::stringPrintf("tag_%d_col_0", i)); - column0.type.set_type(PropertyType::INT64); + column0.name_ref() = folly::stringPrintf("tag_%d_col_0", i); + column0.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(column0)); cpp2::ColumnDef column1; - column1.set_name(folly::stringPrintf("tag_%d_col_1", i)); - column1.type.set_type(PropertyType::FIXED_STRING); - column1.type.set_type_length(50); + column1.name_ref() = folly::stringPrintf("tag_%d_col_1", i); + column1.type.type_ref() = PropertyType::FIXED_STRING; + column1.type.type_length_ref() = 50; columns.emplace_back(std::move(column1)); cpp2::Schema schema; - schema.set_columns(std::move(columns)); + schema.columns_ref() = std::move(columns); auto result = client->createTagSchema(space, folly::stringPrintf("tag_%d", i), schema).get(); ASSERT_TRUE(result.ok()); } } { cpp2::IndexFieldDef field; - field.set_name("tag_0_col_0"); + field.name_ref() = "tag_0_col_0"; auto result = client->createTagIndex(space, "tag_single_field_index", "tag_0", {field}).get(); ASSERT_TRUE(result.ok()); singleFieldIndexID = result.value(); @@ -742,8 +742,8 @@ TEST(MetaClientTest, TagIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_0"); - field2.set_name("tag_0_col_1"); + field1.name_ref() = "tag_0_col_0"; + field2.name_ref() = "tag_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); auto result = @@ -754,8 +754,8 @@ TEST(MetaClientTest, TagIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_0"); - field2.set_name("not_exist_field"); + field1.name_ref() = "tag_0_col_0"; + field2.name_ref() = "not_exist_field"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); @@ -768,8 +768,8 @@ TEST(MetaClientTest, TagIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_0"); - field2.set_name("tag_0_col_1"); + field1.name_ref() = "tag_0_col_0"; + field2.name_ref() = "tag_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); @@ -782,8 +782,8 @@ TEST(MetaClientTest, TagIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("tag_0_col_0"); - field2.set_name("tag_0_col_0"); + field1.name_ref() = "tag_0_col_0"; + field2.name_ref() = "tag_0_col_0"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); @@ -799,8 +799,8 @@ TEST(MetaClientTest, TagIndexTest) { { cpp2::ColumnDef singleColumn; - singleColumn.set_name("tag_0_col_0"); - singleColumn.type.set_type(PropertyType::INT64); + singleColumn.name_ref() = "tag_0_col_0"; + singleColumn.type.type_ref() = PropertyType::INT64; std::vector columns; columns.emplace_back(std::move(singleColumn)); auto singleFieldResult = values[0].get_fields(); @@ -810,14 +810,14 @@ TEST(MetaClientTest, TagIndexTest) { { std::vector columns; cpp2::ColumnDef intColumn; - intColumn.set_name("tag_0_col_0"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "tag_0_col_0"; + intColumn.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(intColumn)); cpp2::ColumnDef stringColumn; - stringColumn.set_name("tag_0_col_1"); - stringColumn.type.set_type(PropertyType::FIXED_STRING); - stringColumn.type.set_type_length(50); + stringColumn.name_ref() = "tag_0_col_1"; + stringColumn.type.type_ref() = PropertyType::FIXED_STRING; + stringColumn.type.type_length_ref() = 50; columns.emplace_back(std::move(stringColumn)); auto multiFieldResult = values[1].get_fields(); @@ -883,9 +883,9 @@ TEST(MetaClientTest, EdgeIndexTest) { } meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space"); - spaceDesc.set_partition_num(8); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default_space"; + spaceDesc.partition_num_ref() = 8; + spaceDesc.replica_factor_ref() = 3; auto ret = client->createSpace(spaceDesc).get(); GraphSpaceID space = ret.value(); IndexID singleFieldIndexID; @@ -894,18 +894,18 @@ TEST(MetaClientTest, EdgeIndexTest) { for (auto i = 0; i < 2; i++) { std::vector columns; cpp2::ColumnDef column0; - column0.set_name(folly::stringPrintf("edge_%d_col_0", i)); - column0.type.set_type(PropertyType::INT64); + column0.name_ref() = folly::stringPrintf("edge_%d_col_0", i); + column0.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(column0)); cpp2::ColumnDef column1; - column1.set_name(folly::stringPrintf("edge_%d_col_1", i)); - column1.type.set_type(PropertyType::FIXED_STRING); - column1.type.set_type_length(50); + column1.name_ref() = folly::stringPrintf("edge_%d_col_1", i); + column1.type.type_ref() = PropertyType::FIXED_STRING; + column1.type.type_length_ref() = 50; columns.emplace_back(std::move(column1)); cpp2::Schema schema; - schema.set_columns(std::move(columns)); + schema.columns_ref() = std::move(columns); auto result = client->createEdgeSchema(space, folly::stringPrintf("edge_%d", i), schema).get(); ASSERT_TRUE(result.ok()); @@ -913,7 +913,7 @@ TEST(MetaClientTest, EdgeIndexTest) { } { cpp2::IndexFieldDef field; - field.set_name("edge_0_col_0"); + field.name_ref() = "edge_0_col_0"; auto result = client->createEdgeIndex(space, "edge_single_field_index", "edge_0", {field}).get(); ASSERT_TRUE(result.ok()); @@ -922,8 +922,8 @@ TEST(MetaClientTest, EdgeIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_0"); - field2.set_name("edge_0_col_1"); + field1.name_ref() = "edge_0_col_0"; + field2.name_ref() = "edge_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); auto result = @@ -934,8 +934,8 @@ TEST(MetaClientTest, EdgeIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_0"); - field2.set_name("edge_0_col_1"); + field1.name_ref() = "edge_0_col_0"; + field2.name_ref() = "edge_0_col_1"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); auto result = @@ -946,8 +946,8 @@ TEST(MetaClientTest, EdgeIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_0"); - field2.set_name("edge_0_col_0"); + field1.name_ref() = "edge_0_col_0"; + field2.name_ref() = "edge_0_col_0"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); auto result = @@ -958,8 +958,8 @@ TEST(MetaClientTest, EdgeIndexTest) { { std::vector fields; cpp2::IndexFieldDef field1, field2; - field1.set_name("edge_0_col_0"); - field2.set_name("not_exist_field"); + field1.name_ref() = "edge_0_col_0"; + field2.name_ref() = "not_exist_field"; fields.emplace_back(std::move(field1)); fields.emplace_back(std::move(field2)); auto result = @@ -975,8 +975,8 @@ TEST(MetaClientTest, EdgeIndexTest) { { cpp2::ColumnDef column; - column.set_name("edge_0_col_0"); - column.type.set_type(PropertyType::INT64); + column.name_ref() = "edge_0_col_0"; + column.type.type_ref() = PropertyType::INT64; std::vector columns; columns.emplace_back(std::move(column)); @@ -987,13 +987,13 @@ TEST(MetaClientTest, EdgeIndexTest) { { std::vector columns; cpp2::ColumnDef intColumn; - intColumn.set_name("edge_0_col_0"); - intColumn.type.set_type(PropertyType::INT64); + intColumn.name_ref() = "edge_0_col_0"; + intColumn.type.type_ref() = PropertyType::INT64; columns.emplace_back(std::move(intColumn)); cpp2::ColumnDef stringColumn; - stringColumn.set_name("edge_0_col_1"); - stringColumn.type.set_type(PropertyType::FIXED_STRING); - stringColumn.type.set_type_length(50); + stringColumn.name_ref() = "edge_0_col_1"; + stringColumn.type.type_ref() = PropertyType::FIXED_STRING; + stringColumn.type.type_length_ref() = 50; columns.emplace_back(std::move(stringColumn)); auto multiFieldResult = values[1].get_fields(); ASSERT_TRUE(TestUtils::verifyResult(columns, multiFieldResult)); @@ -1066,12 +1066,12 @@ TEST(MetaClientTest, FTServiceTest) { std::vector clients; cpp2::FTClient c1, c2; - c1.set_host({"0", 0}); - c1.set_user("u1"); - c1.set_pwd("pwd"); + c1.host_ref() = {"0", 0}; + c1.user_ref() = "u1"; + c1.pwd_ref() = "pwd"; clients.emplace_back(c1); - c2.set_host({"1", 1}); - c2.set_user("u2"); + c2.host_ref() = {"1", 1}; + c2.user_ref() = "u2"; clients.emplace_back(c2); { cpp2::FTServiceType type = cpp2::FTServiceType::ELASTICSEARCH; @@ -1190,7 +1190,7 @@ TEST(MetaClientTest, DiffTest) { std::vector hosts = {{"0", 0}}; { cpp2::AddHostsReq req; - req.set_hosts(hosts); + req.hosts_ref() = hosts; auto* processor = AddHostsProcessor::instance(kv); auto f = processor->getFuture(); processor->process(req); @@ -1222,9 +1222,9 @@ TEST(MetaClientTest, DiffTest) { { // Test Create Space and List Spaces meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space"); - spaceDesc.set_partition_num(9); - spaceDesc.set_replica_factor(1); + spaceDesc.space_name_ref() = "default_space"; + spaceDesc.partition_num_ref() = 9; + spaceDesc.replica_factor_ref() = 1; auto ret = client->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); } @@ -1233,9 +1233,9 @@ TEST(MetaClientTest, DiffTest) { ASSERT_EQ(9, listener->partNum); { meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space_1"); - spaceDesc.set_partition_num(5); - spaceDesc.set_replica_factor(1); + spaceDesc.space_name_ref() = "default_space_1"; + spaceDesc.partition_num_ref() = 5; + spaceDesc.replica_factor_ref() = 1; auto ret = client->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); } @@ -1288,14 +1288,14 @@ TEST(MetaClientTest, ListenerDiffTest) { { // create two space meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("listener_space"); - spaceDesc.set_partition_num(9); - spaceDesc.set_replica_factor(1); + spaceDesc.space_name_ref() = "listener_space"; + spaceDesc.partition_num_ref() = 9; + spaceDesc.replica_factor_ref() = 1; auto ret = console->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); auto spaceId = ret.value(); - spaceDesc.set_space_name("no_listener_space"); + spaceDesc.space_name_ref() = "no_listener_space"; ret = console->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); @@ -1399,7 +1399,7 @@ class TestMetaService : public cpp2::MetaServiceSvIf { folly::Promise pro; auto f = pro.getFuture(); cpp2::HBResp resp; - resp.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); + resp.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; pro.setValue(std::move(resp)); return f; } @@ -1407,9 +1407,13 @@ class TestMetaService : public cpp2::MetaServiceSvIf { class TestMetaServiceRetry : public cpp2::MetaServiceSvIf { public: - void setLeader(HostAddr leader) { leader_ = leader; } + void setLeader(HostAddr leader) { + leader_ = leader; + } - void setAddr(HostAddr addr) { addr_ = addr; } + void setAddr(HostAddr addr) { + addr_ = addr; + } folly::Future future_heartBeat(const cpp2::HBReq& req) override { UNUSED(req); @@ -1417,10 +1421,10 @@ class TestMetaServiceRetry : public cpp2::MetaServiceSvIf { auto f = pro.getFuture(); cpp2::HBResp resp; if (addr_ == leader_) { - resp.set_code(nebula::cpp2::ErrorCode::SUCCEEDED); + resp.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; } else { - resp.set_code(nebula::cpp2::ErrorCode::E_LEADER_CHANGED); - resp.set_leader(leader_); + resp.code_ref() = nebula::cpp2::ErrorCode::E_LEADER_CHANGED; + resp.leader_ref() = leader_; } pro.setValue(std::move(resp)); return f; @@ -1554,10 +1558,10 @@ cpp2::ConfigItem initConfigItem(cpp2::ConfigModule module, cpp2::ConfigMode mode, Value value) { cpp2::ConfigItem configItem; - configItem.set_module(module); - configItem.set_name(name); - configItem.set_mode(mode); - configItem.set_value(value); + configItem.module_ref() = module; + configItem.name_ref() = name; + configItem.mode_ref() = mode; + configItem.value_ref() = value; return configItem; } @@ -1692,9 +1696,9 @@ TEST(MetaClientTest, ListenerTest) { client->waitForMetadReady(); meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default"); - spaceDesc.set_partition_num(9); - spaceDesc.set_replica_factor(3); + spaceDesc.space_name_ref() = "default"; + spaceDesc.partition_num_ref() = 9; + spaceDesc.replica_factor_ref() = 3; auto ret = client->createSpace(spaceDesc).get(); ASSERT_TRUE(ret.ok()) << ret.status(); GraphSpaceID space = ret.value(); @@ -1713,10 +1717,10 @@ TEST(MetaClientTest, ListenerTest) { std::vector expected; for (size_t i = 0; i < 9; i++) { cpp2::ListenerInfo l; - l.set_type(cpp2::ListenerType::ELASTICSEARCH); - l.set_host(listenerHosts[i % 4]); - l.set_part_id(i + 1); - l.set_status(cpp2::HostStatus::ONLINE); + l.type_ref() = cpp2::ListenerType::ELASTICSEARCH; + l.host_ref() = listenerHosts[i % 4]; + l.part_id_ref() = i + 1; + l.status_ref() = cpp2::HostStatus::ONLINE; expected.emplace_back(std::move(l)); } ASSERT_EQ(expected, listeners); @@ -1978,11 +1982,11 @@ TEST(MetaClientTest, DropHostsTest) { { // Create Space on cluster, the replica number same with the zone size. meta::cpp2::SpaceDesc properties; - properties.set_space_name("default_space_0"); - properties.set_partition_num(9); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_0"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; auto ret = client->createSpace(properties).get(); ASSERT_TRUE(ret.ok()) << ret.status(); ASSERT_EQ(1, ret.value()); @@ -1990,11 +1994,11 @@ TEST(MetaClientTest, DropHostsTest) { { // Create Space on cluster, the replica number less than the zone size. cpp2::SpaceDesc properties; - properties.set_space_name("default_space_1"); - properties.set_partition_num(9); - properties.set_replica_factor(1); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_1"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; auto ret = client->createSpace(properties).get(); ASSERT_TRUE(ret.ok()) << ret.status(); ASSERT_EQ(2, ret.value()); @@ -2002,11 +2006,11 @@ TEST(MetaClientTest, DropHostsTest) { { // Create Space on cluster, the replica number greater than the zone size. cpp2::SpaceDesc properties; - properties.set_space_name("default_space_2"); - properties.set_partition_num(9); - properties.set_replica_factor(6); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_2"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 6; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; auto ret = client->createSpace(properties).get(); ASSERT_FALSE(ret.ok()) << ret.status(); } @@ -2042,13 +2046,13 @@ TEST(MetaClientTest, DropHostsTest) { { // Create Space on cluster, the replica number greater than the zone size. cpp2::SpaceDesc properties; - properties.set_space_name("default_space_on_zone_3"); - properties.set_partition_num(9); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_on_zone_3"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); auto ret = client->createSpace(properties).get(); ASSERT_TRUE(ret.ok()) << ret.status(); ASSERT_EQ(4, ret.value()); @@ -2056,13 +2060,13 @@ TEST(MetaClientTest, DropHostsTest) { { // Create Space on cluster, the replica number less than the zone size cpp2::SpaceDesc properties; - properties.set_space_name("default_space_on_zone_1"); - properties.set_partition_num(9); - properties.set_replica_factor(1); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_on_zone_1"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); auto ret = client->createSpace(properties).get(); ASSERT_TRUE(ret.ok()) << ret.status(); ASSERT_EQ(5, ret.value()); @@ -2070,13 +2074,13 @@ TEST(MetaClientTest, DropHostsTest) { { // Create Space on cluster, the replica number greater than the zone size cpp2::SpaceDesc properties; - properties.set_space_name("default_space_on_zone_6"); - properties.set_partition_num(9); - properties.set_replica_factor(6); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_on_zone_6"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 6; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); auto ret = client->createSpace(properties).get(); ASSERT_FALSE(ret.ok()) << ret.status(); } @@ -2170,13 +2174,13 @@ TEST(MetaClientTest, RenameZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default"); - properties.set_partition_num(9); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); auto ret = client->createSpace(properties).get(); ASSERT_TRUE(ret.ok()) << ret.status(); ASSERT_EQ(1, ret.value()); @@ -2271,9 +2275,9 @@ TEST(MetaClientTest, RocksdbOptionsTest) { std::vector hosts = {{"0", 0}}; TestUtils::registerHB(cluster.metaKV_.get(), hosts); meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("default_space"); - spaceDesc.set_partition_num(9); - spaceDesc.set_replica_factor(1); + spaceDesc.space_name_ref() = "default_space"; + spaceDesc.partition_num_ref() = 9; + spaceDesc.replica_factor_ref() = 1; client->createSpace(spaceDesc).get(); sleep(FLAGS_heartbeat_interval_secs + 1); } diff --git a/src/meta/test/MockAdminClient.h b/src/meta/test/MockAdminClient.h index 077b98f9f63..25715351004 100644 --- a/src/meta/test/MockAdminClient.h +++ b/src/meta/test/MockAdminClient.h @@ -29,13 +29,17 @@ class MockAdminClient : public AdminClient { MOCK_METHOD2(checkPeers, folly::Future(GraphSpaceID, PartitionID)); MOCK_METHOD1(getLeaderDist, folly::Future(HostLeaderMap*)); MOCK_METHOD3(createSnapshot, - folly::Future>(GraphSpaceID, - const std::string&, - const HostAddr&)); + folly::Future>(const std::set&, + const std::string&, + const HostAddr&)); MOCK_METHOD3(dropSnapshot, - folly::Future(GraphSpaceID, const std::string&, const HostAddr&)); + folly::Future(const std::set&, + const std::string&, + const HostAddr&)); MOCK_METHOD3(blockingWrites, - folly::Future(GraphSpaceID, storage::cpp2::EngineSignType, const HostAddr&)); + folly::Future(const std::set&, + storage::cpp2::EngineSignType, + const HostAddr&)); MOCK_METHOD9(addTask, folly::Future(cpp2::AdminCmd, int32_t, diff --git a/src/meta/test/MockHdfsHelper.h b/src/meta/test/MockHdfsHelper.h index 57c2c9f9a05..9d911466efc 100644 --- a/src/meta/test/MockHdfsHelper.h +++ b/src/meta/test/MockHdfsHelper.h @@ -35,7 +35,9 @@ class MockHdfsOKHelper : public nebula::hdfs::HdfsHelper { return ""; } - bool checkHadoopPath() override { return true; } + bool checkHadoopPath() override { + return true; + } }; class MockHdfsNotExistHelper : public nebula::hdfs::HdfsHelper { @@ -60,7 +62,9 @@ class MockHdfsNotExistHelper : public nebula::hdfs::HdfsHelper { return Status::Error(folly::stringPrintf("HDFS Path %s Not Exist", hdfsPath.c_str())); } - bool checkHadoopPath() override { return true; } + bool checkHadoopPath() override { + return true; + } }; } // namespace meta diff --git a/src/meta/test/ProcessorTest.cpp b/src/meta/test/ProcessorTest.cpp index 417e279f9ea..a4cd7763a05 100644 --- a/src/meta/test/ProcessorTest.cpp +++ b/src/meta/test/ProcessorTest.cpp @@ -58,7 +58,7 @@ TEST(ProcessorTest, ListHostsTest) { // after received heartbeat, host status will become online TestUtils::registerHB(kv.get(), hosts); cpp2::ListHostsReq req; - req.set_type(cpp2::ListHostType::STORAGE); + req.type_ref() = cpp2::ListHostType::STORAGE; auto* processor = ListHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -74,7 +74,7 @@ TEST(ProcessorTest, ListHostsTest) { // host info expired sleep(FLAGS_heartbeat_interval_secs * FLAGS_expired_time_factor + 1); cpp2::ListHostsReq req; - req.set_type(cpp2::ListHostType::STORAGE); + req.type_ref() = cpp2::ListHostType::STORAGE; auto* processor = ListHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -112,7 +112,7 @@ TEST(ProcessorTest, ListSpecficHostsTest) { meta::TestUtils::setupHB(kv.get(), storageHosts, roleVec[2], gitInfoShaVec[2]); { cpp2::ListHostsReq req; - req.set_type(cpp2::ListHostType::GRAPH); + req.type_ref() = cpp2::ListHostType::GRAPH; auto* processor = ListHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -129,7 +129,7 @@ TEST(ProcessorTest, ListSpecficHostsTest) { { cpp2::ListHostsReq req; - req.set_type(cpp2::ListHostType::STORAGE); + req.type_ref() = cpp2::ListHostType::STORAGE; auto* processor = ListHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -155,7 +155,7 @@ TEST(ProcessorTest, ListPartsTest) { TestUtils::assembleSpace(kv.get(), 1, 9, 3, 3); { cpp2::ListPartsReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListPartsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -180,8 +180,8 @@ TEST(ProcessorTest, ListPartsTest) { // List specified part, and part exists { cpp2::ListPartsReq req; - req.set_space_id(1); - req.set_part_ids({9}); + req.space_id_ref() = 1; + req.part_ids_ref() = {9}; auto* processor = ListPartsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -200,8 +200,8 @@ TEST(ProcessorTest, ListPartsTest) { // List specified part, and part not exist { cpp2::ListPartsReq req; - req.set_space_id(1); - req.set_part_ids({11}); + req.space_id_ref() = 1; + req.part_ids_ref() = {11}; auto* processor = ListPartsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -217,8 +217,8 @@ TEST(ProcessorTest, ListPartsTest) { int64_t term = 999; auto makeLeaderInfo = [&](PartitionID partId) { cpp2::LeaderInfo leaderInfo; - leaderInfo.set_part_id(partId); - leaderInfo.set_term(term); + leaderInfo.part_id_ref() = partId; + leaderInfo.term_ref() = term; return leaderInfo; }; @@ -245,7 +245,7 @@ TEST(ProcessorTest, ListPartsTest) { { cpp2::ListPartsReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListPartsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -313,7 +313,7 @@ TEST(ProcessorTest, SpaceTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -323,13 +323,13 @@ TEST(ProcessorTest, SpaceTest) { int32_t hostsNum = 4; { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(8); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 8; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -339,7 +339,7 @@ TEST(ProcessorTest, SpaceTest) { } { cpp2::GetSpaceReq req; - req.set_space_name("default_space"); + req.space_name_ref() = "default_space"; auto* processor = GetSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -369,7 +369,7 @@ TEST(ProcessorTest, SpaceTest) { // fashion. { cpp2::GetPartsAllocReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = GetPartsAllocProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -389,7 +389,7 @@ TEST(ProcessorTest, SpaceTest) { } { cpp2::DropSpaceReq req; - req.set_space_name("default_space"); + req.space_name_ref() = "default_space"; auto* processor = DropSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -408,8 +408,8 @@ TEST(ProcessorTest, SpaceTest) { // With IF EXISTS { cpp2::DropSpaceReq req; - req.set_space_name("not_exist_space"); - req.set_if_exists(true); + req.space_name_ref() = "not_exist_space"; + req.if_exists_ref() = true; auto* processor = DropSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -420,8 +420,8 @@ TEST(ProcessorTest, SpaceTest) { constexpr char spaceName[] = "exist_space"; cpp2::CreateSpaceReq req; cpp2::SpaceDesc properties; - properties.set_space_name(spaceName); - req.set_properties(std::move(properties)); + properties.space_name_ref() = spaceName; + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -429,8 +429,8 @@ TEST(ProcessorTest, SpaceTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); cpp2::DropSpaceReq req1; - req1.set_space_name(spaceName); - req1.set_if_exists(true); + req1.space_name_ref() = spaceName; + req1.if_exists_ref() = true; auto* processor1 = DropSpaceProcessor::instance(kv.get()); auto f1 = processor1->getFuture(); processor1->process(req1); @@ -440,9 +440,9 @@ TEST(ProcessorTest, SpaceTest) { // Test default value { cpp2::SpaceDesc properties; - properties.set_space_name("space_with_no_option"); + properties.space_name_ref() = "space_with_no_option"; cpp2::CreateSpaceReq creq; - creq.set_properties(std::move(properties)); + creq.properties_ref() = std::move(properties); auto* cprocessor = CreateSpaceProcessor::instance(kv.get()); auto cf = cprocessor->getFuture(); cprocessor->process(creq); @@ -450,7 +450,7 @@ TEST(ProcessorTest, SpaceTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, cresp.get_code()); cpp2::GetSpaceReq greq; - greq.set_space_name("space_with_no_option"); + greq.space_name_ref() = "space_with_no_option"; auto* gprocessor = GetSpaceProcessor::instance(kv.get()); auto gf = gprocessor->getFuture(); gprocessor->process(greq); @@ -464,7 +464,7 @@ TEST(ProcessorTest, SpaceTest) { ASSERT_EQ("", gresp.get_item().get_properties().get_collate_name()); cpp2::DropSpaceReq dreq; - dreq.set_space_name("space_with_no_option"); + dreq.space_name_ref() = "space_with_no_option"; auto* dprocessor = DropSpaceProcessor::instance(kv.get()); auto df = dprocessor->getFuture(); dprocessor->process(dreq); @@ -479,7 +479,7 @@ TEST(ProcessorTest, CreateTagTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -488,11 +488,11 @@ TEST(ProcessorTest, CreateTagTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("first_space"); - properties.set_partition_num(9); - properties.set_replica_factor(1); + properties.space_name_ref() = "first_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -503,11 +503,11 @@ TEST(ProcessorTest, CreateTagTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("second_space"); - properties.set_partition_num(9); - properties.set_replica_factor(1); + properties.space_name_ref() = "second_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -521,13 +521,13 @@ TEST(ProcessorTest, CreateTagTest) { cols.emplace_back(TestUtils::columnDef(0, PropertyType::INT64)); cols.emplace_back(TestUtils::columnDef(1, PropertyType::FLOAT)); cols.emplace_back(TestUtils::columnDef(2, PropertyType::STRING)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); { // Space not exist cpp2::CreateTagReq req; - req.set_space_id(0); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 0; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -537,9 +537,9 @@ TEST(ProcessorTest, CreateTagTest) { { // Succeeded cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -550,9 +550,9 @@ TEST(ProcessorTest, CreateTagTest) { { // Tag have existed cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -562,9 +562,9 @@ TEST(ProcessorTest, CreateTagTest) { { // Create same name tag in diff spaces cpp2::CreateTagReq req; - req.set_space_id(2); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 2; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -575,9 +575,9 @@ TEST(ProcessorTest, CreateTagTest) { { // Create same name edge in same spaces cpp2::CreateEdgeReq req; - req.set_space_id(1); - req.set_edge_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.edge_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -587,15 +587,15 @@ TEST(ProcessorTest, CreateTagTest) { { // Set schema ttl property cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("col_0"); - schema.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "col_0"; + schema.schema_prop_ref() = std::move(schemaProp); // Tag with TTL cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_ttl"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_ttl"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -609,18 +609,18 @@ TEST(ProcessorTest, CreateTagTest) { std::vector colsWithDefault; cpp2::ColumnDef columnWithDefault; - columnWithDefault.set_name(folly::stringPrintf("col_type_mismatch")); - columnWithDefault.type.set_type(PropertyType::BOOL); + columnWithDefault.name_ref() = folly::stringPrintf("col_type_mismatch"); + columnWithDefault.type.type_ref() = PropertyType::BOOL; const auto& strValue = *ConstantExpression::make(metaPool, "default value"); - columnWithDefault.set_default_value(Expression::encode(strValue)); + columnWithDefault.default_value_ref() = Expression::encode(strValue); colsWithDefault.push_back(std::move(columnWithDefault)); - schemaWithDefault.set_columns(std::move(colsWithDefault)); + schemaWithDefault.columns_ref() = std::move(colsWithDefault); cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_type_mismatch"); - req.set_schema(std::move(schemaWithDefault)); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_type_mismatche"; + req.schema_ref() = std::move(schemaWithDefault); auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -633,18 +633,18 @@ TEST(ProcessorTest, CreateTagTest) { std::vector colsWithDefault; cpp2::ColumnDef columnWithDefault; - columnWithDefault.set_name(folly::stringPrintf("col_value_mismatch")); - columnWithDefault.type.set_type(PropertyType::INT8); + columnWithDefault.name_ref() = folly::stringPrintf("col_value_mismatch"); + columnWithDefault.type.type_ref() = PropertyType::INT8; const auto& intValue = *ConstantExpression::make(metaPool, 256); - columnWithDefault.set_default_value(Expression::encode(intValue)); + columnWithDefault.default_value_ref() = Expression::encode(intValue); colsWithDefault.push_back(std::move(columnWithDefault)); - schemaWithDefault.set_columns(std::move(colsWithDefault)); + schemaWithDefault.columns_ref() = std::move(colsWithDefault); cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_value_mismatch"); - req.set_schema(std::move(schemaWithDefault)); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_value_mismatche"; + req.schema_ref() = std::move(schemaWithDefault); auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -653,10 +653,10 @@ TEST(ProcessorTest, CreateTagTest) { } { cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("all_tag_type"); + req.space_id_ref() = 1; + req.tag_name_ref() = "all_tag_type"; auto allSchema = TestUtils::mockSchemaWithAllType(); - req.set_schema(std::move(allSchema)); + req.schema_ref() = std::move(allSchema); auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -664,9 +664,9 @@ TEST(ProcessorTest, CreateTagTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); cpp2::GetTagReq getReq; - getReq.set_space_id(1); - getReq.set_tag_name("all_tag_type"); - getReq.set_version(0); + getReq.space_id_ref() = 1; + getReq.tag_name_ref() = "all_tag_type"; + getReq.version_ref() = 0; auto* getProcessor = GetTagProcessor::instance(kv.get()); auto getFut = getProcessor->getFuture(); getProcessor->process(getReq); @@ -682,7 +682,7 @@ TEST(ProcessorTest, CreateEdgeTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -691,11 +691,11 @@ TEST(ProcessorTest, CreateEdgeTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(9); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -707,11 +707,11 @@ TEST(ProcessorTest, CreateEdgeTest) { { // Create another space cpp2::SpaceDesc properties; - properties.set_space_name("another_space"); - properties.set_partition_num(9); - properties.set_replica_factor(3); + properties.space_name_ref() = "another_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -726,12 +726,12 @@ TEST(ProcessorTest, CreateEdgeTest) { cols.emplace_back(TestUtils::columnDef(0, PropertyType::INT64)); cols.emplace_back(TestUtils::columnDef(1, PropertyType::FLOAT)); cols.emplace_back(TestUtils::columnDef(2, PropertyType::STRING)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); { cpp2::CreateEdgeReq req; - req.set_space_id(0); - req.set_edge_name("default_edge"); - req.set_schema(schema); + req.space_id_ref() = 0; + req.edge_name_ref() = "default_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -741,9 +741,9 @@ TEST(ProcessorTest, CreateEdgeTest) { { // Succeeded cpp2::CreateEdgeReq req; - req.set_space_id(1); - req.set_edge_name("default_edge"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.edge_name_ref() = "default_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -754,9 +754,9 @@ TEST(ProcessorTest, CreateEdgeTest) { { // Existed cpp2::CreateEdgeReq req; - req.set_space_id(1); - req.set_edge_name("default_edge"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.edge_name_ref() = "default_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -766,9 +766,9 @@ TEST(ProcessorTest, CreateEdgeTest) { { // Create same name edge in diff spaces cpp2::CreateEdgeReq req; - req.set_space_id(2); - req.set_edge_name("default_edge"); - req.set_schema(schema); + req.space_id_ref() = 2; + req.edge_name_ref() = "default_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -779,9 +779,9 @@ TEST(ProcessorTest, CreateEdgeTest) { { // Create same name tag in same spaces cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("default_edge"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "default_edge"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -791,15 +791,15 @@ TEST(ProcessorTest, CreateEdgeTest) { // Set schema ttl property cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("col_0"); - schema.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "col_0"; + schema.schema_prop_ref() = std::move(schemaProp); { // Edge with TTL cpp2::CreateEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_ttl"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_ttl"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -814,12 +814,12 @@ TEST(ProcessorTest, CreateEdgeTest) { colsWithDefault.emplace_back(TestUtils::columnDef(1, PropertyType::INT64, Value(11))); colsWithDefault.emplace_back(TestUtils::columnDef(2, PropertyType::DOUBLE, Value(11.0))); colsWithDefault.emplace_back(TestUtils::columnDef(3, PropertyType::STRING, Value("test"))); - schemaWithDefault.set_columns(std::move(colsWithDefault)); + schemaWithDefault.columns_ref() = std::move(colsWithDefault); cpp2::CreateEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_with_default"); - req.set_schema(std::move(schemaWithDefault)); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_with_defaule"; + req.schema_ref() = std::move(schemaWithDefault); auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -831,12 +831,12 @@ TEST(ProcessorTest, CreateEdgeTest) { cpp2::Schema schemaWithDefault; std::vector colsWithDefault; colsWithDefault.push_back(TestUtils::columnDef(0, PropertyType::BOOL, Value("default value"))); - schemaWithDefault.set_columns(std::move(colsWithDefault)); + schemaWithDefault.columns_ref() = std::move(colsWithDefault); cpp2::CreateEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_type_mismatch"); - req.set_schema(std::move(schemaWithDefault)); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_type_mismatche"; + req.schema_ref() = std::move(schemaWithDefault); auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -845,10 +845,10 @@ TEST(ProcessorTest, CreateEdgeTest) { } { cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("all_edge_type"); + req.space_id_ref() = 1; + req.tag_name_ref() = "all_edge_type"; auto allSchema = TestUtils::mockSchemaWithAllType(); - req.set_schema(std::move(allSchema)); + req.schema_ref() = std::move(allSchema); auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -856,9 +856,9 @@ TEST(ProcessorTest, CreateEdgeTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); cpp2::GetTagReq getReq; - getReq.set_space_id(1); - getReq.set_tag_name("all_edge_type"); - getReq.set_version(0); + getReq.space_id_ref() = 1; + getReq.tag_name_ref() = "all_edge_type"; + getReq.version_ref() = 0; auto* getProcessor = GetTagProcessor::instance(kv.get()); auto getFut = getProcessor->getFuture(); getProcessor->process(getReq); @@ -874,7 +874,7 @@ TEST(ProcessorTest, KVOperationTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -883,11 +883,11 @@ TEST(ProcessorTest, KVOperationTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(9); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -905,8 +905,8 @@ TEST(ProcessorTest, KVOperationTest) { } cpp2::MultiPutReq req; - req.set_segment("test"); - req.set_pairs(std::move(pairs)); + req.segment_ref() = "test"; + req.pairs_ref() = std::move(pairs); auto* processor = MultiPutProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -917,8 +917,8 @@ TEST(ProcessorTest, KVOperationTest) { { // Get Test cpp2::GetReq req; - req.set_segment("test"); - req.set_key("key_0"); + req.segment_ref() = "test"; + req.key_ref() = "key_0"; auto* processor = GetProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -928,8 +928,8 @@ TEST(ProcessorTest, KVOperationTest) { ASSERT_EQ("value_0", resp.get_value()); cpp2::GetReq missedReq; - missedReq.set_segment("test"); - missedReq.set_key("missed_key"); + missedReq.segment_ref() = "test"; + missedReq.key_ref() = "missed_key"; auto* missedProcessor = GetProcessor::instance(kv.get()); auto missedFuture = missedProcessor->getFuture(); @@ -945,8 +945,8 @@ TEST(ProcessorTest, KVOperationTest) { } cpp2::MultiGetReq req; - req.set_segment("test"); - req.set_keys(std::move(keys)); + req.segment_ref() = "test"; + req.keys_ref() = std::move(keys); auto* processor = MultiGetProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -960,9 +960,9 @@ TEST(ProcessorTest, KVOperationTest) { { // Scan Test cpp2::ScanReq req; - req.set_segment("test"); - req.set_start("key_1"); - req.set_end("key_4"); + req.segment_ref() = "test"; + req.start_ref() = "key_1"; + req.end_ref() = "key_4"; auto* processor = ScanProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -977,8 +977,8 @@ TEST(ProcessorTest, KVOperationTest) { { // Remove Test cpp2::RemoveReq req; - req.set_segment("test"); - req.set_key("key_9"); + req.segment_ref() = "test"; + req.key_ref() = "key_9"; auto* processor = RemoveProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -989,9 +989,9 @@ TEST(ProcessorTest, KVOperationTest) { { // Remove Range Test cpp2::RemoveRangeReq req; - req.set_segment("test"); - req.set_start("key_0"); - req.set_end("key_4"); + req.segment_ref() = "test"; + req.start_ref() = "key_0"; + req.end_ref() = "key_4"; auto* processor = RemoveRangeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1010,7 +1010,7 @@ TEST(ProcessorTest, ListOrGetTagsTest) { // Test ListTagsProcessor { cpp2::ListTagsReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListTagsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1032,9 +1032,9 @@ TEST(ProcessorTest, ListOrGetTagsTest) { // Test GetTagProcessor with version { cpp2::GetTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_version(0); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.version_ref() = 0; auto* processor = GetTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1054,9 +1054,9 @@ TEST(ProcessorTest, ListOrGetTagsTest) { // Test GetTagProcessor without version { cpp2::GetTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_version(-1); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.version_ref() = -1; auto* processor = GetTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1076,8 +1076,8 @@ TEST(ProcessorTest, ListOrGetTagsTest) { // Test GetTagProcessor with not exist tagName { cpp2::GetTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_1"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_1"; auto* processor = GetTagProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1096,7 +1096,7 @@ TEST(ProcessorTest, ListOrGetEdgesTest) { // Test ListEdgesProcessor { cpp2::ListEdgesReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListEdgesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1119,9 +1119,9 @@ TEST(ProcessorTest, ListOrGetEdgesTest) { { for (auto t = 0; t < 10; t++) { cpp2::GetEdgeReq req; - req.set_space_id(1); - req.set_edge_name(folly::stringPrintf("edge_%d", t)); - req.set_version(t); + req.space_id_ref() = 1; + req.edge_name_ref() = folly::stringPrintf("edge_%d", t); + req.version_ref() = t; auto* processor = GetEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1142,9 +1142,9 @@ TEST(ProcessorTest, ListOrGetEdgesTest) { // Test GetEdgeProcessor without version { cpp2::GetEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_version(-1); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.version_ref() = -1; auto* processor = GetEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1164,8 +1164,8 @@ TEST(ProcessorTest, ListOrGetEdgesTest) { // Test GetEdgeProcessor with not exist edgeName { cpp2::GetEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_10"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_10"; auto* processor = GetEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -1184,8 +1184,8 @@ TEST(ProcessorTest, DropTagTest) { // Space not exist { cpp2::DropTagReq req; - req.set_space_id(0); - req.set_tag_name("tag_0"); + req.space_id_ref() = 0; + req.tag_name_ref() = "tag_0"; auto* processor = DropTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1195,8 +1195,8 @@ TEST(ProcessorTest, DropTagTest) { // Tag not exist { cpp2::DropTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_no"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_no"; auto* processor = DropTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1206,8 +1206,8 @@ TEST(ProcessorTest, DropTagTest) { // Succeeded { cpp2::DropTagReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; auto* processor = DropTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1230,9 +1230,9 @@ TEST(ProcessorTest, DropTagTest) { // With IF EXISTS { cpp2::DropTagReq req; - req.set_space_id(1); - req.set_tag_name("not_exist_tag"); - req.set_if_exists(true); + req.space_id_ref() = 1; + req.tag_name_ref() = "not_exist_tag"; + req.if_exists_ref() = true; auto* processor = DropTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1243,8 +1243,8 @@ TEST(ProcessorTest, DropTagTest) { constexpr GraphSpaceID spaceId = 1; constexpr char tagName[] = "exist_tag"; cpp2::CreateTagReq req; - req.set_space_id(spaceId); - req.set_tag_name(tagName); + req.space_id_ref() = spaceId; + req.tag_name_ref() = tagName; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1252,9 +1252,9 @@ TEST(ProcessorTest, DropTagTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); cpp2::DropTagReq req1; - req1.set_space_id(spaceId); - req1.set_tag_name(tagName); - req1.set_if_exists(true); + req1.space_id_ref() = spaceId; + req1.tag_name_ref() = tagName; + req1.if_exists_ref() = true; auto* processor1 = DropTagProcessor::instance(kv.get()); auto f1 = processor1->getFuture(); processor1->process(req1); @@ -1272,8 +1272,8 @@ TEST(ProcessorTest, DropEdgeTest) { // Space not exist { cpp2::DropEdgeReq req; - req.set_space_id(0); - req.set_edge_name("edge_0"); + req.space_id_ref() = 0; + req.edge_name_ref() = "edge_0"; auto* processor = DropEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1283,8 +1283,8 @@ TEST(ProcessorTest, DropEdgeTest) { // Edge not exist { cpp2::DropEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_no"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_no"; auto* processor = DropEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1294,8 +1294,8 @@ TEST(ProcessorTest, DropEdgeTest) { // Succeeded { cpp2::DropEdgeReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; auto* processor = DropEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1319,9 +1319,9 @@ TEST(ProcessorTest, DropEdgeTest) { // With IF EXISTS { cpp2::DropEdgeReq req; - req.set_space_id(1); - req.set_edge_name("not_exist_edge"); - req.set_if_exists(true); + req.space_id_ref() = 1; + req.edge_name_ref() = "not_exist_edge"; + req.if_exists_ref() = true; auto* processor = DropEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1332,8 +1332,8 @@ TEST(ProcessorTest, DropEdgeTest) { constexpr GraphSpaceID spaceId = 1; constexpr char edgeName[] = "exist_edge"; cpp2::CreateTagReq req; - req.set_space_id(spaceId); - req.set_tag_name(edgeName); + req.space_id_ref() = spaceId; + req.tag_name_ref() = edgeName; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1341,9 +1341,9 @@ TEST(ProcessorTest, DropEdgeTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); cpp2::DropEdgeReq req1; - req1.set_space_id(spaceId); - req1.set_edge_name(edgeName); - req1.set_if_exists(true); + req1.space_id_ref() = spaceId; + req1.edge_name_ref() = edgeName; + req1.if_exists_ref() = true; auto* processor1 = DropEdgeProcessor::instance(kv.get()); auto f1 = processor1->getFuture(); processor1->process(req1); @@ -1365,14 +1365,14 @@ TEST(ProcessorTest, AlterTagTest) { for (auto i = 0; i < 2; i++) { cpp2::ColumnDef column; column.name = folly::stringPrintf("tag_0_col_%d", i + 10); - column.type.set_type(i < 1 ? PropertyType::INT64 : PropertyType::STRING); + column.type.type_ref() = i < 1 ? PropertyType::INT64 : PropertyType::STRING; (*addSch.columns_ref()).emplace_back(std::move(column)); } cpp2::Schema changeSch; for (auto i = 0; i < 2; i++) { cpp2::ColumnDef column; column.name = folly::stringPrintf("tag_0_col_%d", i); - column.type.set_type(i < 1 ? PropertyType::BOOL : PropertyType::DOUBLE); + column.type.type_ref() = i < 1 ? PropertyType::BOOL : PropertyType::DOUBLE; (*changeSch.columns_ref()).emplace_back(std::move(column)); } cpp2::Schema dropSch; @@ -1380,19 +1380,19 @@ TEST(ProcessorTest, AlterTagTest) { column.name = "tag_0_col_0"; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1402,7 +1402,7 @@ TEST(ProcessorTest, AlterTagTest) { // Verify alter result. { cpp2::ListTagsReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListTagsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1422,18 +1422,18 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::ColumnDef column; column.name = "tag_0_col_1"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; cols.emplace_back(std::move(column)); column.name = "tag_0_col_10"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(column)); column.name = "tag_0_col_11"; - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; cols.emplace_back(std::move(column)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); EXPECT_EQ(schema, tag.get_schema()); } // Alter tag with ttl @@ -1441,11 +1441,11 @@ TEST(ProcessorTest, AlterTagTest) { // Only set ttl_duration cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); + schemaProp.ttl_duration_ref() = 100; - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1456,12 +1456,12 @@ TEST(ProcessorTest, AlterTagTest) { { cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("tag_0_col_10"); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "tag_0_col_10"; - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1471,7 +1471,7 @@ TEST(ProcessorTest, AlterTagTest) { // Verify alter result. { cpp2::ListTagsReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListTagsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1493,23 +1493,23 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::ColumnDef column; column.name = "tag_0_col_1"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; cols.emplace_back(std::move(column)); column.name = "tag_0_col_10"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(column)); column.name = "tag_0_col_11"; - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; cols.emplace_back(std::move(column)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("tag_0_col_10"); - schema.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "tag_0_col_10"; + schema.schema_prop_ref() = std::move(schemaProp); EXPECT_EQ(schema.get_columns(), tag.get_schema().get_columns()); EXPECT_EQ(*schema.get_schema_prop().get_ttl_duration(), *tag.get_schema().get_schema_prop().get_ttl_duration()); @@ -1523,16 +1523,16 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "tag_0_col_10"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1543,12 +1543,12 @@ TEST(ProcessorTest, AlterTagTest) { { cpp2::AlterTagReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("tag_0_col_11"); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "tag_0_col_11"; - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1565,11 +1565,11 @@ TEST(ProcessorTest, AlterTagTest) { (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1579,7 +1579,7 @@ TEST(ProcessorTest, AlterTagTest) { // Verify alter drop ttl col result. { cpp2::ListTagsReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListTagsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1607,19 +1607,19 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::ColumnDef column; column.name = "tag_0_col_1"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; cols.emplace_back(std::move(column)); column.name = "tag_0_col_11"; - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; cols.emplace_back(std::move(column)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(0); - schemaProp.set_ttl_col(""); - schema.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 0; + schemaProp.ttl_col_ref() = ""; + schema.schema_prop_ref() = std::move(schemaProp); EXPECT_EQ(schema.get_columns(), tag.get_schema().get_columns()); EXPECT_EQ(*schema.get_schema_prop().get_ttl_duration(), *tag.get_schema().get_schema_prop().get_ttl_duration()); @@ -1634,15 +1634,15 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::Schema addSch; cpp2::ColumnDef column; column.name = "tag_0_col_1"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*addSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1656,15 +1656,15 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "tag_0_col_2"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1678,15 +1678,15 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "tag_0_col_0"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1700,17 +1700,17 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::Schema schema; cpp2::ColumnDef column; column.name = "add_col_mismatch_type"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; const auto& strValue = *ConstantExpression::make(metaPool, "default value"); - column.set_default_value(Expression::encode(strValue)); + column.default_value_ref() = Expression::encode(strValue); (*schema.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(schema)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1724,18 +1724,18 @@ TEST(ProcessorTest, AlterTagTest) { cpp2::Schema schema; cpp2::ColumnDef column; column.name = "add_col_fixed_string_type"; - column.type.set_type(PropertyType::FIXED_STRING); - column.type.set_type_length(5); + column.type.type_ref() = PropertyType::FIXED_STRING; + column.type.type_length_ref() = 5; const auto& strValue = *ConstantExpression::make(metaPool, "Hello world!"); - column.set_default_value(Expression::encode(strValue)); + column.default_value_ref() = Expression::encode(strValue); (*schema.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(schema)); - req.set_space_id(1); - req.set_tag_name("tag_0"); - req.set_tag_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "tag_0"; + req.tag_items_ref() = items; auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1744,9 +1744,9 @@ TEST(ProcessorTest, AlterTagTest) { // check result cpp2::GetTagReq getReq; - getReq.set_space_id(1); - getReq.set_tag_name("tag_0"); - getReq.set_version(-1); + getReq.space_id_ref() = 1; + getReq.tag_name_ref() = "tag_0"; + getReq.version_ref() = -1; auto* getProcessor = GetTagProcessor::instance(kv.get()); auto getFut = getProcessor->getFuture(); @@ -1788,11 +1788,11 @@ TEST(ProcessorTest, AlterEdgeTest) { } items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1801,7 +1801,7 @@ TEST(ProcessorTest, AlterEdgeTest) { } { cpp2::ListEdgesReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListEdgesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1822,16 +1822,16 @@ TEST(ProcessorTest, AlterEdgeTest) { for (int32_t i = 0; i < 2; i++) { cpp2::ColumnDef column; column.name = folly::stringPrintf("edge_0_col_%d", i); - column.type.set_type(i < 1 ? PropertyType::INT64 : PropertyType::STRING); + column.type.type_ref() = i < 1 ? PropertyType::INT64 : PropertyType::STRING; (*addSch.columns_ref()).emplace_back(std::move(column)); } items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1845,14 +1845,14 @@ TEST(ProcessorTest, AlterEdgeTest) { for (auto i = 0; i < 2; i++) { cpp2::ColumnDef column; column.name = folly::stringPrintf("edge_%d_col_%d", 0, i + 10); - column.type.set_type(i < 1 ? PropertyType::INT64 : PropertyType::STRING); + column.type.type_ref() = i < 1 ? PropertyType::INT64 : PropertyType::STRING; (*addSch.columns_ref()).emplace_back(std::move(column)); } cpp2::Schema changeSch; for (auto i = 0; i < 2; i++) { cpp2::ColumnDef column; column.name = folly::stringPrintf("edge_%d_col_%d", 0, i); - column.type.set_type(i < 1 ? PropertyType::BOOL : PropertyType::DOUBLE); + column.type.type_ref() = i < 1 ? PropertyType::BOOL : PropertyType::DOUBLE; (*changeSch.columns_ref()).emplace_back(std::move(column)); } cpp2::Schema dropSch; @@ -1861,20 +1861,20 @@ TEST(ProcessorTest, AlterEdgeTest) { (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1884,7 +1884,7 @@ TEST(ProcessorTest, AlterEdgeTest) { // Verify alter result. { cpp2::ListEdgesReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListEdgesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1911,17 +1911,17 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::ColumnDef column; column.name = "edge_0_col_1"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; cols.emplace_back(std::move(column)); column.name = "edge_0_col_10"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(column)); column.name = "edge_0_col_11"; - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; cols.emplace_back(std::move(column)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); EXPECT_EQ(schema, edge.get_schema()); } @@ -1929,11 +1929,11 @@ TEST(ProcessorTest, AlterEdgeTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); + schemaProp.ttl_duration_ref() = 100; - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1944,12 +1944,12 @@ TEST(ProcessorTest, AlterEdgeTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("edge_0_col_10"); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "edge_0_col_10"; - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1959,7 +1959,7 @@ TEST(ProcessorTest, AlterEdgeTest) { // Verify alter result. { cpp2::ListEdgesReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListEdgesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1988,23 +1988,23 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::ColumnDef column; column.name = "edge_0_col_1"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; cols.emplace_back(std::move(column)); column.name = "edge_0_col_10"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(column)); column.name = "edge_0_col_11"; - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; cols.emplace_back(std::move(column)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("edge_0_col_10"); - schema.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "edge_0_col_10"; + schema.schema_prop_ref() = std::move(schemaProp); EXPECT_EQ(schema.get_columns(), edge.get_schema().get_columns()); EXPECT_EQ(*schema.get_schema_prop().get_ttl_duration(), *edge.get_schema().get_schema_prop().get_ttl_duration()); @@ -2018,16 +2018,16 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "edge_0_col_10"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2038,12 +2038,12 @@ TEST(ProcessorTest, AlterEdgeTest) { { cpp2::AlterEdgeReq req; cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(100); - schemaProp.set_ttl_col("edge_0_col_11"); + schemaProp.ttl_duration_ref() = 100; + schemaProp.ttl_col_ref() = "edge_0_col_11"; - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_schema_prop(std::move(schemaProp)); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.schema_prop_ref() = std::move(schemaProp); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2060,11 +2060,11 @@ TEST(ProcessorTest, AlterEdgeTest) { (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2074,7 +2074,7 @@ TEST(ProcessorTest, AlterEdgeTest) { // Verify alter drop ttl col result { cpp2::ListEdgesReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListEdgesProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2103,19 +2103,19 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::ColumnDef column; column.name = "edge_0_col_1"; - column.type.set_type(PropertyType::DOUBLE); + column.type.type_ref() = PropertyType::DOUBLE; cols.emplace_back(std::move(column)); column.name = "edge_0_col_11"; - column.type.set_type(PropertyType::STRING); + column.type.type_ref() = PropertyType::STRING; cols.emplace_back(std::move(column)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); cpp2::SchemaProp schemaProp; - schemaProp.set_ttl_duration(0); - schemaProp.set_ttl_col(""); - schema.set_schema_prop(std::move(schemaProp)); + schemaProp.ttl_duration_ref() = 0; + schemaProp.ttl_col_ref() = ""; + schema.schema_prop_ref() = std::move(schemaProp); EXPECT_EQ(schema.get_columns(), edge.get_schema().get_columns()); EXPECT_EQ(*schema.get_schema_prop().get_ttl_duration(), *edge.get_schema().get_schema_prop().get_ttl_duration()); @@ -2130,16 +2130,16 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::Schema addSch; cpp2::ColumnDef column; column.name = "edge_0_col_1"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*addSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(addSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(addSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2153,16 +2153,16 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::Schema changeSch; cpp2::ColumnDef column; column.name = "edge_0_col_2"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*changeSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::CHANGE); - items.back().set_schema(std::move(changeSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::CHANGE; + items.back().schema_ref() = std::move(changeSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2176,16 +2176,16 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::Schema dropSch; cpp2::ColumnDef column; column.name = "edge_0_col_2"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; (*dropSch.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::DROP); - items.back().set_schema(std::move(dropSch)); + items.back().op_ref() = cpp2::AlterSchemaOp::DROP; + items.back().schema_ref() = std::move(dropSch); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2199,17 +2199,17 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::Schema schema; cpp2::ColumnDef column; column.name = "add_col_mismatch_type"; - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; const auto& strValue = *ConstantExpression::make(metaPool, "default value"); - column.set_default_value(Expression::encode(strValue)); + column.default_value_ref() = Expression::encode(strValue); (*schema.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(schema)); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(schema); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2223,18 +2223,18 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::Schema schema; cpp2::ColumnDef column; column.name = "add_col_fixed_string_type"; - column.type.set_type(PropertyType::FIXED_STRING); - column.type.set_type_length(5); + column.type.type_ref() = PropertyType::FIXED_STRING; + column.type.type_length_ref() = 5; const auto& strValue = *ConstantExpression::make(metaPool, "Hello world!"); - column.set_default_value(Expression::encode(strValue)); + column.default_value_ref() = Expression::encode(strValue); (*schema.columns_ref()).emplace_back(std::move(column)); items.emplace_back(); - items.back().set_op(cpp2::AlterSchemaOp::ADD); - items.back().set_schema(std::move(schema)); - req.set_space_id(1); - req.set_edge_name("edge_0"); - req.set_edge_items(items); + items.back().op_ref() = cpp2::AlterSchemaOp::ADD; + items.back().schema_ref() = std::move(schema); + req.space_id_ref() = 1; + req.edge_name_ref() = "edge_0"; + req.edge_items_ref() = items; auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2243,9 +2243,9 @@ TEST(ProcessorTest, AlterEdgeTest) { // check result cpp2::GetEdgeReq getReq; - getReq.set_space_id(1); - getReq.set_edge_name("edge_0"); - getReq.set_version(-1); + getReq.space_id_ref() = 1; + getReq.edge_name_ref() = "edge_0"; + getReq.version_ref() = -1; auto* getProcessor = GetEdgeProcessor::instance(kv.get()); auto getFut = getProcessor->getFuture(); @@ -2275,7 +2275,7 @@ TEST(ProcessorTest, SameNameTagsTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2284,11 +2284,11 @@ TEST(ProcessorTest, SameNameTagsTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default_space"); - properties.set_partition_num(9); - properties.set_replica_factor(3); + properties.space_name_ref() = "default_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2298,11 +2298,11 @@ TEST(ProcessorTest, SameNameTagsTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("second_space"); - properties.set_partition_num(9); - properties.set_replica_factor(1); + properties.space_name_ref() = "second_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2317,12 +2317,12 @@ TEST(ProcessorTest, SameNameTagsTest) { cols.emplace_back(TestUtils::columnDef(0, PropertyType::INT64)); cols.emplace_back(TestUtils::columnDef(1, PropertyType::FLOAT)); cols.emplace_back(TestUtils::columnDef(2, PropertyType::STRING)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); { cpp2::CreateTagReq req; - req.set_space_id(1); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 1; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2332,9 +2332,9 @@ TEST(ProcessorTest, SameNameTagsTest) { } { cpp2::CreateTagReq req; - req.set_space_id(2); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 2; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2346,8 +2346,8 @@ TEST(ProcessorTest, SameNameTagsTest) { // Remove Test { cpp2::DropTagReq req; - req.set_space_id(1); - req.set_tag_name("default_tag"); + req.space_id_ref() = 1; + req.tag_name_ref() = "default_tag"; auto* processor = DropTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2358,7 +2358,7 @@ TEST(ProcessorTest, SameNameTagsTest) { // List Test { cpp2::ListTagsReq req; - req.set_space_id(1); + req.space_id_ref() = 1; auto* processor = ListTagsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2370,7 +2370,7 @@ TEST(ProcessorTest, SameNameTagsTest) { } { cpp2::ListTagsReq req; - req.set_space_id(2); + req.space_id_ref() = 2; auto* processor = ListTagsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2394,9 +2394,9 @@ TEST(ProcessorTest, SessionManagerTest) { ExecutionPlanID epId = 1; { cpp2::CreateUserReq req; - req.set_if_not_exists(false); - req.set_account("test_user"); - req.set_encoded_pwd("password"); + req.if_not_exists_ref() = false; + req.account_ref() = "test_user"; + req.encoded_pwd_ref() = "password"; auto* processor = CreateUserProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2406,8 +2406,8 @@ TEST(ProcessorTest, SessionManagerTest) { // create session { cpp2::CreateSessionReq req; - req.set_user("test_user"); - req.set_graph_addr(HostAddr("127.0.0.1", 3699)); + req.user_ref() = "test_user"; + req.graph_addr_ref() = HostAddr("127.0.0.1", 3699); auto* processor = CreateSessionProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2420,11 +2420,11 @@ TEST(ProcessorTest, SessionManagerTest) { { cpp2::UpdateSessionsReq req; meta::cpp2::Session session; - session.set_session_id(sessionId); - session.set_space_name("test"); - session.set_update_time(time::WallClock::fastNowInMicroSec()); + session.session_id_ref() = sessionId; + session.space_name_ref() = "test"; + session.update_time_ref() = time::WallClock::fastNowInMicroSec(); session.queries_ref()->emplace(epId, cpp2::QueryDesc()); - req.set_sessions({session}); + req.sessions_ref() = {session}; auto* processor = UpdateSessionsProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2448,7 +2448,7 @@ TEST(ProcessorTest, SessionManagerTest) { // get session { cpp2::GetSessionReq req; - req.set_session_id(sessionId); + req.session_id_ref() = sessionId; auto* processor = GetSessionProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2463,7 +2463,7 @@ TEST(ProcessorTest, SessionManagerTest) { std::unordered_map> killedQueries; std::unordered_set eps = {epId}; killedQueries.emplace(sessionId, std::move(eps)); - killReq.set_kill_queries(std::move(killedQueries)); + killReq.kill_queries_ref() = std::move(killedQueries); auto* processor = KillQueryProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2475,10 +2475,10 @@ TEST(ProcessorTest, SessionManagerTest) { { cpp2::UpdateSessionsReq req; meta::cpp2::Session session; - session.set_session_id(sessionId); - session.set_space_name("test"); + session.session_id_ref() = sessionId; + session.space_name_ref() = "test"; session.queries_ref()->emplace(epId, cpp2::QueryDesc()); - req.set_sessions({session}); + req.sessions_ref() = {session}; auto* processor = UpdateSessionsProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2497,7 +2497,7 @@ TEST(ProcessorTest, SessionManagerTest) { // delete session { cpp2::RemoveSessionReq delReq; - delReq.set_session_id(sessionId); + delReq.session_id_ref() = sessionId; auto* dProcessor = RemoveSessionProcessor::instance(kv.get()); auto delFut = dProcessor->getFuture(); @@ -2507,7 +2507,7 @@ TEST(ProcessorTest, SessionManagerTest) { // check result cpp2::GetSessionReq getReq; - getReq.set_session_id(sessionId); + getReq.session_id_ref() = sessionId; auto* gProcessor = GetSessionProcessor::instance(kv.get()); auto getFut = gProcessor->getFuture(); @@ -2523,7 +2523,7 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { { cpp2::AddHostsReq req; std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2583,16 +2583,16 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { cols.emplace_back(TestUtils::columnDef(0, PropertyType::INT64)); cols.emplace_back(TestUtils::columnDef(1, PropertyType::FLOAT)); cols.emplace_back(TestUtils::columnDef(2, PropertyType::STRING)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); // create space, use global id { cpp2::SpaceDesc properties; - properties.set_space_name("my_space"); - properties.set_partition_num(9); - properties.set_replica_factor(1); + properties.space_name_ref() = "my_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2605,9 +2605,9 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { { // Succeeded cpp2::CreateTagReq req; - req.set_space_id(22); - req.set_tag_name("default_tag"); - req.set_schema(schema); + req.space_id_ref() = 22; + req.tag_name_ref() = "default_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2619,9 +2619,9 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { { // Succeeded cpp2::CreateEdgeReq req; - req.set_space_id(22); - req.set_edge_name("default_edge"); - req.set_schema(schema); + req.space_id_ref() = 22; + req.edge_name_ref() = "default_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2633,11 +2633,11 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { // create space, space Id is global id + 1 { cpp2::SpaceDesc properties; - properties.set_space_name("last_space"); - properties.set_partition_num(9); - properties.set_replica_factor(1); + properties.space_name_ref() = "last_space"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); @@ -2650,9 +2650,9 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { { // Succeeded cpp2::CreateTagReq req; - req.set_space_id(22); - req.set_tag_name("my_tag"); - req.set_schema(schema); + req.space_id_ref() = 22; + req.tag_name_ref() = "my_tag"; + req.schema_ref() = schema; auto* processor = CreateTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2664,9 +2664,9 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { { // Succeeded cpp2::CreateEdgeReq req; - req.set_space_id(22); - req.set_edge_name("my_edge"); - req.set_schema(schema); + req.space_id_ref() = 22; + req.edge_name_ref() = "my_edge"; + req.schema_ref() = schema; auto* processor = CreateEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2684,10 +2684,10 @@ TEST(ProcessorTest, HostsTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -2700,7 +2700,7 @@ TEST(ProcessorTest, HostsTest) { cpp2::AddHostsReq req; std::vector hosts; hosts.emplace_back("127.0.0.1", 8989); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2713,7 +2713,7 @@ TEST(ProcessorTest, HostsTest) { std::vector hosts; hosts.emplace_back("127.0.0.1", 8987); hosts.emplace_back("127.0.0.1", 8988); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2725,10 +2725,10 @@ TEST(ProcessorTest, HostsTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -2742,7 +2742,7 @@ TEST(ProcessorTest, HostsTest) { std::vector hosts; hosts.emplace_back("127.0.0.1", 8986); hosts.emplace_back("127.0.0.1", 8986); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2753,7 +2753,7 @@ TEST(ProcessorTest, HostsTest) { // Add empty hosts cpp2::AddHostsReq req; std::vector hosts; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2765,7 +2765,7 @@ TEST(ProcessorTest, HostsTest) { cpp2::AddHostsReq req; std::vector hosts; hosts.emplace_back("127.0.0.1", 8988); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2778,7 +2778,7 @@ TEST(ProcessorTest, HostsTest) { std::vector hosts; hosts.emplace_back("127.0.0.1", 8986); hosts.emplace_back("127.0.0.1", 8988); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2804,7 +2804,7 @@ TEST(ProcessorTest, HostsTest) { std::vector hosts; hosts.emplace_back("127.0.0.1", 8987); hosts.emplace_back("127.0.0.1", 8987); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2815,7 +2815,7 @@ TEST(ProcessorTest, HostsTest) { // Drop hosts which is empty cpp2::DropHostsReq req; std::vector hosts; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2827,7 +2827,7 @@ TEST(ProcessorTest, HostsTest) { cpp2::DropHostsReq req; std::vector hosts; hosts.emplace_back("127.0.0.1", 8986); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2839,7 +2839,7 @@ TEST(ProcessorTest, HostsTest) { cpp2::DropHostsReq req; std::vector hosts; hosts.emplace_back("127.0.0.1", 8987); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2852,7 +2852,7 @@ TEST(ProcessorTest, HostsTest) { std::vector hosts; hosts.emplace_back("127.0.0.1", 8988); hosts.emplace_back("127.0.0.1", 8989); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2864,10 +2864,10 @@ TEST(ProcessorTest, HostsTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -2885,10 +2885,10 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -2899,10 +2899,10 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { { // Add host into new zone with duplicate hosts. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8988}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2912,9 +2912,9 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { { // Add host into new zone with empty hosts. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); - req.set_hosts({}); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; + req.hosts_ref() = {}; auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2924,10 +2924,10 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { { // Add host into new zone. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2939,10 +2939,10 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -2953,10 +2953,10 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { { // Add host into new zone with zone name conflict. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8977}, {"127.0.0.1", 8978}, {"127.0.0.1", 8979}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2966,10 +2966,10 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { { // the hosts have exist in another zones. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_1"); - req.set_is_new(true); + req.zone_name_ref() = "zone_1"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8977}, {"127.0.0.1", 8978}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -2986,10 +2986,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -3000,10 +3000,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { { // Add host into zone with duplicate hosts cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(false); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = false; std::vector hosts = {{"127.0.0.1", 8988}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3013,9 +3013,9 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { { // Add host into zone with empty hosts cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(false); - req.set_hosts({}); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = false; + req.hosts_ref() = {}; auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3025,10 +3025,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { { // Add host into zone which zone is not exist. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_not_existed"); - req.set_is_new(false); + req.zone_name_ref() = "zone_not_existed"; + req.is_new_ref() = false; std::vector hosts = {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3038,10 +3038,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { { // Add host into zone. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3051,10 +3051,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { { // Add host into zone with zone name conflict. cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8977}, {"127.0.0.1", 8978}, {"127.0.0.1", 8979}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3063,10 +3063,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { } { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_1"); - req.set_is_new(true); + req.zone_name_ref() = "zone_1"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8977}, {"127.0.0.1", 8978}, {"127.0.0.1", 8979}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3078,7 +3078,7 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { cpp2::AddHostsReq req; std::vector hosts; hosts.emplace_back("127.0.0.1", 8988); - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3087,10 +3087,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { } { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_1"); - req.set_is_new(false); + req.zone_name_ref() = "zone_1"; + req.is_new_ref() = false; std::vector hosts = {{"127.0.0.1", 8976}, {"127.0.0.1", 8988}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3101,7 +3101,7 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { // Drop hosts which is empty. cpp2::DropHostsReq req; std::vector hosts; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3112,7 +3112,7 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { // Drop hosts which have duplicate element. cpp2::DropHostsReq req; std::vector hosts = {{"127.0.0.1", 8988}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3123,7 +3123,7 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { // Drop hosts. cpp2::DropHostsReq req; std::vector hosts = {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3135,10 +3135,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -3156,10 +3156,10 @@ TEST(ProcessorTest, DropHostsTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -3171,7 +3171,7 @@ TEST(ProcessorTest, DropHostsTest) { // Add multi host cpp2::AddHostsReq req; std::vector hosts = {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3183,10 +3183,10 @@ TEST(ProcessorTest, DropHostsTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -3210,13 +3210,13 @@ TEST(ProcessorTest, DropHostsTest) { { // Create Space on cluster, the replica number same with the zone size. cpp2::SpaceDesc properties; - properties.set_space_name("default_space_0"); - properties.set_partition_num(9); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_0"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3227,13 +3227,13 @@ TEST(ProcessorTest, DropHostsTest) { { // Create Space on cluster, the replica number less than the zone size. cpp2::SpaceDesc properties; - properties.set_space_name("default_space_1"); - properties.set_partition_num(9); - properties.set_replica_factor(1); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_1"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3244,13 +3244,13 @@ TEST(ProcessorTest, DropHostsTest) { { // Create Space on cluster, the replica number greater than the zone size. cpp2::SpaceDesc properties; - properties.set_space_name("default_space_2"); - properties.set_partition_num(9); - properties.set_replica_factor(6); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_2"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 6; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3259,10 +3259,10 @@ TEST(ProcessorTest, DropHostsTest) { } { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8976}, {"127.0.0.1", 8977}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3271,10 +3271,10 @@ TEST(ProcessorTest, DropHostsTest) { } { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_1"); - req.set_is_new(true); + req.zone_name_ref() = "zone_1"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8978}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3283,10 +3283,10 @@ TEST(ProcessorTest, DropHostsTest) { } { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_2"); - req.set_is_new(true); + req.zone_name_ref() = "zone_2"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8979}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3318,15 +3318,15 @@ TEST(ProcessorTest, DropHostsTest) { { // Create Space on cluster, the replica number same with the zone size cpp2::SpaceDesc properties; - properties.set_space_name("default_space_on_zone_3"); - properties.set_partition_num(9); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_on_zone_3"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3337,15 +3337,15 @@ TEST(ProcessorTest, DropHostsTest) { { // Create Space on cluster, the replica number less than the zone size cpp2::SpaceDesc properties; - properties.set_space_name("default_space_on_zone_1"); - properties.set_partition_num(9); - properties.set_replica_factor(1); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_on_zone_1"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 1; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3356,15 +3356,15 @@ TEST(ProcessorTest, DropHostsTest) { { // Create Space on cluster, the replica number greater than the zone size cpp2::SpaceDesc properties; - properties.set_space_name("default_space_on_zone_6"); - properties.set_partition_num(9); - properties.set_replica_factor(6); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default_space_on_zone_6"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 6; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3375,7 +3375,7 @@ TEST(ProcessorTest, DropHostsTest) { // Drop hosts which hold partition. cpp2::DropHostsReq req; std::vector hosts = {{"127.0.0.1", 8987}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3386,7 +3386,7 @@ TEST(ProcessorTest, DropHostsTest) { // Drop hosts which hold partition. cpp2::DropHostsReq req; std::vector hosts = {{"127.0.0.1", 8977}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3395,7 +3395,7 @@ TEST(ProcessorTest, DropHostsTest) { } { cpp2::DropSpaceReq req; - req.set_space_name("default_space_on_zone_1"); + req.space_name_ref() = "default_space_on_zone_1"; auto* processor = DropSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3404,7 +3404,7 @@ TEST(ProcessorTest, DropHostsTest) { } { cpp2::DropSpaceReq req; - req.set_space_name("default_space_on_zone_3"); + req.space_name_ref() = "default_space_on_zone_3"; auto* processor = DropSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3413,7 +3413,7 @@ TEST(ProcessorTest, DropHostsTest) { } { cpp2::DropSpaceReq req; - req.set_space_name("default_space_0"); + req.space_name_ref() = "default_space_0"; auto* processor = DropSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3422,7 +3422,7 @@ TEST(ProcessorTest, DropHostsTest) { } { cpp2::DropSpaceReq req; - req.set_space_name("default_space_1"); + req.space_name_ref() = "default_space_1"; auto* processor = DropSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3433,7 +3433,7 @@ TEST(ProcessorTest, DropHostsTest) { // Drop hosts. cpp2::DropHostsReq req; std::vector hosts = {{"127.0.0.1", 8987}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3444,7 +3444,7 @@ TEST(ProcessorTest, DropHostsTest) { // Drop hosts. cpp2::DropHostsReq req; std::vector hosts = {{"127.0.0.1", 8976}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3455,7 +3455,7 @@ TEST(ProcessorTest, DropHostsTest) { // Drop hosts. cpp2::DropHostsReq req; std::vector hosts = {{"127.0.0.1", 8978}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = DropHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3487,10 +3487,10 @@ TEST(ProcessorTest, RenameZoneTest) { auto kv = MockCluster::initMetaKV(rootPath.path()); { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_0"); - req.set_is_new(true); + req.zone_name_ref() = "zone_0"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8987}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3499,10 +3499,10 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_1"); - req.set_is_new(true); + req.zone_name_ref() = "zone_1"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8988}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3511,10 +3511,10 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::AddHostsIntoZoneReq req; - req.set_zone_name("zone_2"); - req.set_is_new(true); + req.zone_name_ref() = "zone_2"; + req.is_new_ref() = true; std::vector hosts = {{"127.0.0.1", 8989}}; - req.set_hosts(std::move(hosts)); + req.hosts_ref() = std::move(hosts); auto* processor = AddHostsIntoZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3526,10 +3526,10 @@ TEST(ProcessorTest, RenameZoneTest) { const ClusterID kClusterId = 10; for (auto i = 8987; i < 8990; i++) { cpp2::HBReq req; - req.set_role(cpp2::HostRole::STORAGE); - req.set_host(HostAddr("127.0.0.1", i)); - req.set_cluster_id(kClusterId); - req.set_role(cpp2::HostRole::STORAGE); + req.role_ref() = cpp2::HostRole::STORAGE; + req.host_ref() = HostAddr("127.0.0.1", i); + req.cluster_id_ref() = kClusterId; + req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -3552,15 +3552,15 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::SpaceDesc properties; - properties.set_space_name("default"); - properties.set_partition_num(9); - properties.set_replica_factor(3); - properties.set_charset_name("utf8"); - properties.set_collate_name("utf8_bin"); + properties.space_name_ref() = "default"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; std::vector zones = {"zone_0", "zone_1", "zone_2"}; - properties.set_zone_names(std::move(zones)); + properties.zone_names_ref() = std::move(zones); cpp2::CreateSpaceReq req; - req.set_properties(std::move(properties)); + req.properties_ref() = std::move(properties); auto* processor = CreateSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3570,7 +3570,7 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::GetSpaceReq req; - req.set_space_name("default"); + req.space_name_ref() = "default"; auto* processor = GetSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3590,8 +3590,8 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::RenameZoneReq req; - req.set_original_zone_name("zone_not_exist"); - req.set_zone_name("new_zone_name"); + req.original_zone_name_ref() = "zone_not_exist"; + req.zone_name_ref() = "new_zone_name"; auto* processor = RenameZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3600,8 +3600,8 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::RenameZoneReq req; - req.set_original_zone_name("zone_0"); - req.set_zone_name("zone_1"); + req.original_zone_name_ref() = "zone_0"; + req.zone_name_ref() = "zone_1"; auto* processor = RenameZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3610,8 +3610,8 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::RenameZoneReq req; - req.set_original_zone_name("zone_1"); - req.set_zone_name("z_1"); + req.original_zone_name_ref() = "zone_1"; + req.zone_name_ref() = "z_1"; auto* processor = RenameZoneProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -3620,7 +3620,7 @@ TEST(ProcessorTest, RenameZoneTest) { } { cpp2::GetSpaceReq req; - req.set_space_name("default"); + req.space_name_ref() = "default"; auto* processor = GetSpaceProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/RestoreProcessorTest.cpp b/src/meta/test/RestoreProcessorTest.cpp index 704698a4605..8ccc7b869bd 100644 --- a/src/meta/test/RestoreProcessorTest.cpp +++ b/src/meta/test/RestoreProcessorTest.cpp @@ -37,16 +37,16 @@ TEST(RestoreProcessorTest, RestoreTest) { bool ret = false; cpp2::SpaceDesc properties; GraphSpaceID id = 1; - properties.set_space_name("test_space"); + properties.space_name_ref() = "test_space"; int partNum = 10; - properties.set_partition_num(partNum); - properties.set_replica_factor(3); + properties.partition_num_ref() = partNum; + properties.replica_factor_ref() = 3; cpp2::SpaceDesc properties2; GraphSpaceID id2 = 2; - properties2.set_space_name("test_space2"); - properties2.set_partition_num(partNum); - properties2.set_replica_factor(3); + properties2.space_name_ref() = "test_space2"; + properties2.partition_num_ref() = partNum; + properties2.replica_factor_ref() = 3; auto spaceVal = MetaKeyUtils::spaceVal(properties); std::vector data; @@ -100,7 +100,7 @@ TEST(RestoreProcessorTest, RestoreTest) { auto backupName = folly::format("BACKUP_{}", MetaKeyUtils::genTimestampStr()).str(); auto spaceNames = std::make_unique>(); spaceNames->emplace_back("test_space"); - auto backupFiles = MetaServiceUtils::backupSpaces(kv.get(), spaces, backupName, spaceNames.get()); + auto backupFiles = MetaServiceUtils::backupTables(kv.get(), spaces, backupName, spaceNames.get()); DCHECK(nebula::hasValue(backupFiles)); { cpp2::RestoreMetaReq req; @@ -114,7 +114,7 @@ TEST(RestoreProcessorTest, RestoreTest) { return false; }); ASSERT_EQ(it, files.cend()); - req.set_files(std::move(files)); + req.files_ref() = std::move(files); std::vector hostPairs; HostAddr host4("127.0.0.4", 3360); HostAddr host5("127.0.0.5", 3360); @@ -126,7 +126,7 @@ TEST(RestoreProcessorTest, RestoreTest) { hostPairs.emplace_back(apache::thrift::FragileConstructor(), hm.first, hm.second); } - req.set_hosts(std::move(hostPairs)); + req.hosts_ref() = std::move(hostPairs); fs::TempDir restoreTootPath("/tmp/RestoreTest.XXXXXX"); std::unique_ptr kvRestore(MockCluster::initMetaKV(restoreTootPath.path())); std::vector restoreData; @@ -250,16 +250,16 @@ TEST(RestoreProcessorTest, RestoreFullTest) { bool ret = false; cpp2::SpaceDesc properties; GraphSpaceID id = 1; - properties.set_space_name("test_space"); + properties.space_name_ref() = "test_space"; int partNum = 10; - properties.set_partition_num(partNum); - properties.set_replica_factor(3); + properties.partition_num_ref() = partNum; + properties.replica_factor_ref() = 3; cpp2::SpaceDesc properties2; GraphSpaceID id2 = 2; - properties2.set_space_name("test_space2"); - properties2.set_partition_num(partNum); - properties2.set_replica_factor(3); + properties2.space_name_ref() = "test_space2"; + properties2.partition_num_ref() = partNum; + properties2.replica_factor_ref() = 3; auto spaceVal = MetaKeyUtils::spaceVal(properties); std::vector data; @@ -302,7 +302,7 @@ TEST(RestoreProcessorTest, RestoreFullTest) { std::unordered_set spaces = {id}; auto backupName = folly::format("BACKUP_{}", MetaKeyUtils::genTimestampStr()).str(); - auto backupFiles = MetaServiceUtils::backupSpaces(kv.get(), spaces, backupName, nullptr); + auto backupFiles = MetaServiceUtils::backupTables(kv.get(), spaces, backupName, nullptr); DCHECK(nebula::hasValue(backupFiles)); { cpp2::RestoreMetaReq req; @@ -316,7 +316,7 @@ TEST(RestoreProcessorTest, RestoreFullTest) { return false; }); ASSERT_EQ(it, files.cend()); - req.set_files(std::move(files)); + req.files_ref() = std::move(files); std::vector hostPairs; HostAddr host4("127.0.0.4", 3360); HostAddr host5("127.0.0.5", 3360); @@ -328,7 +328,7 @@ TEST(RestoreProcessorTest, RestoreFullTest) { hostPairs.emplace_back(apache::thrift::FragileConstructor(), hm.first, hm.second); } - req.set_hosts(std::move(hostPairs)); + req.hosts_ref() = std::move(hostPairs); fs::TempDir restoreTootPath("/tmp/RestoreFullTest.XXXXXX"); std::unique_ptr kvRestore(MockCluster::initMetaKV(restoreTootPath.path())); std::vector restoreData; diff --git a/src/meta/test/TestUtils.h b/src/meta/test/TestUtils.h index 2440486c3e1..5021e630c34 100644 --- a/src/meta/test/TestUtils.h +++ b/src/meta/test/TestUtils.h @@ -50,18 +50,18 @@ class TestUtils { bool isNull = true, int16_t typeLen = 0) { cpp2::ColumnDef column; - column.set_name(folly::stringPrintf("col_%d", index)); + column.name_ref() = folly::stringPrintf("col_%d", index); if (!defaultValue.empty()) { const auto& defaultExpr = *ConstantExpression::make(metaPool, defaultValue); - column.set_default_value(Expression::encode(defaultExpr)); + column.default_value_ref() = Expression::encode(defaultExpr); } - column.set_nullable(isNull); + column.nullable_ref() = isNull; cpp2::ColumnTypeDef typeDef; - typeDef.set_type(type); + typeDef.type_ref() = type; if (type == PropertyType::FIXED_STRING) { - typeDef.set_type_length(typeLen); + typeDef.type_length_ref() = typeLen; } - column.set_type(std::move(typeDef)); + column.type_ref() = std::move(typeDef); return column; } @@ -98,7 +98,7 @@ class TestUtils { registerHB(kv, hosts); { cpp2::ListHostsReq req; - req.set_type(cpp2::ListHostType::STORAGE); + req.type_ref() = cpp2::ListHostType::STORAGE; auto* processor = ListHostsProcessor::instance(kv); auto f = processor->getFuture(); @@ -178,9 +178,9 @@ class TestUtils { int32_t totalHost = 1) { // mock the part distribution like create space cpp2::SpaceDesc properties; - properties.set_space_name("test_space"); - properties.set_partition_num(partitionNum); - properties.set_replica_factor(replica); + properties.space_name_ref() = "test_space"; + properties.partition_num_ref() = partitionNum; + properties.replica_factor_ref() = replica; auto spaceVal = MetaKeyUtils::spaceVal(properties); std::vector data; data.emplace_back(MetaKeyUtils::indexSpaceKey("test_space"), @@ -221,15 +221,15 @@ class TestUtils { cpp2::Schema srcsch; for (auto i = 0; i < 2; i++) { cpp2::ColumnDef column; - column.set_name(folly::stringPrintf("tag_%d_col_%d", tagId, i)); + column.name_ref() = folly::stringPrintf("tag_%d_col_%d", tagId, i); if (i < 1) { - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; } else { - column.type.set_type(PropertyType::FIXED_STRING); - column.type.set_type_length(MAX_INDEX_TYPE_LENGTH); + column.type.type_ref() = PropertyType::FIXED_STRING; + column.type.type_length_ref() = MAX_INDEX_TYPE_LENGTH; } if (nullable) { - column.set_nullable(nullable); + column.nullable_ref() = nullable; } (*srcsch.columns_ref()).emplace_back(std::move(column)); } @@ -255,13 +255,13 @@ class TestUtils { std::vector columns) { GraphSpaceID space = 1; cpp2::IndexItem item; - item.set_index_id(indexID); - item.set_index_name(indexName); + item.index_id_ref() = indexID; + item.index_name_ref() = indexName; nebula::cpp2::SchemaID schemaID; - schemaID.set_tag_id(tagID); - item.set_schema_id(std::move(schemaID)); - item.set_schema_name(std::move(tagName)); - item.set_fields(std::move(columns)); + schemaID.tag_id_ref() = tagID; + item.schema_id_ref() = std::move(schemaID); + item.schema_name_ref() = std::move(tagName); + item.fields_ref() = std::move(columns); std::vector data; data.emplace_back(MetaKeyUtils::indexIndexKey(space, indexName), @@ -283,13 +283,13 @@ class TestUtils { std::vector columns) { GraphSpaceID space = 1; cpp2::IndexItem item; - item.set_index_id(indexID); - item.set_index_name(indexName); + item.index_id_ref() = indexID; + item.index_name_ref() = indexName; nebula::cpp2::SchemaID schemaID; - schemaID.set_edge_type(edgeType); - item.set_schema_id(std::move(schemaID)); - item.set_schema_name(std::move(edgeName)); - item.set_fields(std::move(columns)); + schemaID.edge_type_ref() = edgeType; + item.schema_id_ref() = std::move(schemaID); + item.schema_name_ref() = std::move(edgeName); + item.fields_ref() = std::move(columns); std::vector data; data.emplace_back(MetaKeyUtils::indexIndexKey(space, indexName), @@ -318,13 +318,13 @@ class TestUtils { cpp2::ColumnDef column; column.name = folly::stringPrintf("edge_%d_col_%d", edgeType, i); if (i < 1) { - column.type.set_type(PropertyType::INT64); + column.type.type_ref() = PropertyType::INT64; } else { - column.type.set_type(PropertyType::FIXED_STRING); - column.type.set_type_length(MAX_INDEX_TYPE_LENGTH); + column.type.type_ref() = PropertyType::FIXED_STRING; + column.type.type_length_ref() = MAX_INDEX_TYPE_LENGTH; } if (nullable) { - column.set_nullable(nullable); + column.nullable_ref() = nullable; } (*srcsch.columns_ref()).emplace_back(std::move(column)); } @@ -359,7 +359,7 @@ class TestUtils { cols.emplace_back(TestUtils::columnDef(9, PropertyType::TIMESTAMP, Value(123456), true)); cols.emplace_back(TestUtils::columnDef(10, PropertyType::DATE, Value(Date()), true)); cols.emplace_back(TestUtils::columnDef(11, PropertyType::DATETIME, Value(DateTime()), true)); - schema.set_columns(std::move(cols)); + schema.columns_ref() = std::move(cols); return schema; } diff --git a/src/meta/test/VerifyClientVersionTest.cpp b/src/meta/test/VerifyClientVersionTest.cpp index a72d6757ffa..7668bb18596 100644 --- a/src/meta/test/VerifyClientVersionTest.cpp +++ b/src/meta/test/VerifyClientVersionTest.cpp @@ -20,8 +20,8 @@ TEST(VerifyClientVersionTest, VersionTest) { std::unique_ptr kv(MockCluster::initMetaKV(rootPath.path())); { auto req = cpp2::VerifyClientVersionReq(); - req.set_client_version("1.0.1"); - req.set_build_version("1.0.1-nightly"); + req.client_version_ref() = "1.0.1"; + req.build_version_ref() = "1.0.1-nightly"; auto* processor = VerifyClientVersionProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -31,7 +31,7 @@ TEST(VerifyClientVersionTest, VersionTest) { { for (auto i = 0; i < 5; i++) { auto req = cpp2::VerifyClientVersionReq(); - req.set_host(HostAddr(std::to_string(i), i)); + req.host_ref() = HostAddr(std::to_string(i), i); auto* processor = VerifyClientVersionProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -43,9 +43,9 @@ TEST(VerifyClientVersionTest, VersionTest) { const ClusterID kClusterId = 10; for (auto i = 0; i < 5; i++) { auto req = cpp2::HBReq(); - req.set_role(cpp2::HostRole::GRAPH); - req.set_host(HostAddr(std::to_string(i), i)); - req.set_cluster_id(kClusterId); + req.role_ref() = cpp2::HostRole::GRAPH; + req.host_ref() = HostAddr(std::to_string(i), i); + req.cluster_id_ref() = kClusterId; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -55,7 +55,7 @@ TEST(VerifyClientVersionTest, VersionTest) { } { auto req = cpp2::ListHostsReq(); - req.set_type(cpp2::ListHostType::GRAPH); + req.type_ref() = cpp2::ListHostType::GRAPH; auto* processor = ListHostsProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/upgrade/MetaDataUpgrade.cpp b/src/meta/upgrade/MetaDataUpgrade.cpp index bff64a063e5..8bd89806738 100644 --- a/src/meta/upgrade/MetaDataUpgrade.cpp +++ b/src/meta/upgrade/MetaDataUpgrade.cpp @@ -51,13 +51,13 @@ Status MetaDataUpgrade::rewriteSpaces(const folly::StringPiece &key, const folly::StringPiece &val) { auto oldProps = meta::v1::MetaServiceUtilsV1::parseSpace(val); cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name(oldProps.get_space_name()); - spaceDesc.set_partition_num(oldProps.get_partition_num()); - spaceDesc.set_replica_factor(oldProps.get_replica_factor()); - spaceDesc.set_charset_name(oldProps.get_charset_name()); - spaceDesc.set_collate_name(oldProps.get_collate_name()); - (*spaceDesc.vid_type_ref()).set_type_length(8); - (*spaceDesc.vid_type_ref()).set_type(nebula::cpp2::PropertyType::INT64); + spaceDesc.space_name_ref() = oldProps.get_space_name(); + spaceDesc.partition_num_ref() = oldProps.get_partition_num(); + spaceDesc.replica_factor_ref() = oldProps.get_replica_factor(); + spaceDesc.charset_name_ref() = oldProps.get_charset_name(); + spaceDesc.collate_name_ref() = oldProps.get_collate_name(); + (*spaceDesc.vid_type_ref()).type_length_ref() = 8; + (*spaceDesc.vid_type_ref()).type_ref() = nebula::cpp2::PropertyType::INT64; NG_LOG_AND_RETURN_IF_ERROR(put(key, MetaKeyUtils::spaceVal(spaceDesc))); return Status::OK(); } @@ -82,12 +82,12 @@ Status MetaDataUpgrade::rewriteSchemas(const folly::StringPiece &key, cpp2::SchemaProp newSchemaProps; auto &schemaProp = oldSchema.get_schema_prop(); if (schemaProp.ttl_duration_ref().has_value()) { - newSchemaProps.set_ttl_duration(*schemaProp.get_ttl_duration()); + newSchemaProps.ttl_duration_ref() = *schemaProp.get_ttl_duration(); } if (schemaProp.ttl_col_ref().has_value()) { - newSchemaProps.set_ttl_col(*schemaProp.get_ttl_col()); + newSchemaProps.ttl_col_ref() = *schemaProp.get_ttl_col(); } - newSchema.set_schema_prop(std::move(newSchemaProps)); + newSchema.schema_prop_ref() = std::move(newSchemaProps); NG_LOG_AND_RETURN_IF_ERROR( convertToNewColumns((*oldSchema.columns_ref()), (*newSchema.columns_ref()))); @@ -102,15 +102,15 @@ Status MetaDataUpgrade::rewriteIndexes(const folly::StringPiece &key, const folly::StringPiece &val) { auto oldItem = meta::v1::MetaServiceUtilsV1::parseIndex(val); cpp2::IndexItem newItem; - newItem.set_index_id(oldItem.get_index_id()); - newItem.set_index_name(oldItem.get_index_name()); + newItem.index_id_ref() = oldItem.get_index_id(); + newItem.index_name_ref() = oldItem.get_index_name(); nebula::cpp2::SchemaID schemaId; if (oldItem.get_schema_id().getType() == meta::v1::cpp2::SchemaID::Type::tag_id) { - schemaId.set_tag_id(oldItem.get_schema_id().get_tag_id()); + schemaId.tag_id_ref() = oldItem.get_schema_id().get_tag_id(); } else { - schemaId.set_edge_type(oldItem.get_schema_id().get_edge_type()); + schemaId.edge_type_ref() = oldItem.get_schema_id().get_edge_type(); } - newItem.set_schema_id(schemaId); + newItem.schema_id_ref() = schemaId; NG_LOG_AND_RETURN_IF_ERROR( convertToNewIndexColumns((*oldItem.fields_ref()), (*newItem.fields_ref()))); NG_LOG_AND_RETURN_IF_ERROR(put(key, MetaKeyUtils::indexVal(newItem))); @@ -213,8 +213,9 @@ Status MetaDataUpgrade::convertToNewColumns(const std::vector(colDef.get_type().get_type())); + columnDef.name_ref() = colDef.get_name(); + columnDef.type.type_ref() = + static_cast(colDef.get_type().get_type()); if (colDef.default_value_ref().has_value()) { std::string encodeStr; switch (colDef.get_type().get_type()) { @@ -244,10 +245,10 @@ Status MetaDataUpgrade::convertToNewColumns(const std::vector &oldCols, std::vector &newCols) { for (auto &colDef : oldCols) { cpp2::ColumnDef columnDef; - columnDef.set_name(colDef.get_name()); + columnDef.name_ref() = colDef.get_name(); if (colDef.get_type().get_type() == meta::v1::cpp2::SupportedType::STRING) { cpp2::ColumnTypeDef type; - type.set_type(nebula::cpp2::PropertyType::FIXED_STRING); - type.set_type_length(FLAGS_string_index_limit); - columnDef.set_type(std::move(type)); + type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING; + type.type_length_ref() = FLAGS_string_index_limit; + columnDef.type_ref() = std::move(type); } else { - columnDef.type.set_type( - static_cast(colDef.get_type().get_type())); + columnDef.type.type_ref() = + static_cast(colDef.get_type().get_type()); } DCHECK(!colDef.default_value_ref().has_value()); if (FLAGS_null_type) { - columnDef.set_nullable(true); + columnDef.nullable_ref() = true; } newCols.emplace_back(std::move(columnDef)); } diff --git a/src/meta/upgrade/v1/MetaServiceUtilsV1.cpp b/src/meta/upgrade/v1/MetaServiceUtilsV1.cpp index a520a98370b..70f22ef6e17 100644 --- a/src/meta/upgrade/v1/MetaServiceUtilsV1.cpp +++ b/src/meta/upgrade/v1/MetaServiceUtilsV1.cpp @@ -35,8 +35,8 @@ std::vector MetaServiceUtilsV1::parsePartVal(folly::StringPiece VLOG(3) << "Total size:" << val.size() << ", host size:" << unitSize << ", host num:" << hostsNum; for (decltype(hostsNum) i = 0; i < hostsNum; i++) { cpp2::HostAddr h; - h.set_ip(*reinterpret_cast(val.data() + i * unitSize)); - h.set_port(*reinterpret_cast(val.data() + i * unitSize + sizeof(int32_t))); + h.ip_ref() = *reinterpret_cast(val.data() + i * unitSize); + h.port_ref() = *reinterpret_cast(val.data() + i * unitSize + sizeof(int32_t)); hosts.emplace_back(std::move(h)); } return hosts; @@ -44,13 +44,13 @@ std::vector MetaServiceUtilsV1::parsePartVal(folly::StringPiece cpp2::HostAddr MetaServiceUtilsV1::parseHostKey(folly::StringPiece key) { cpp2::HostAddr host; - memcpy(&host, key.data() + kHostsTable.size(), sizeof(host)); + memcpy(reinterpret_cast(&host), key.data() + kHostsTable.size(), sizeof(host)); return host; } cpp2::HostAddr MetaServiceUtilsV1::parseLeaderKey(folly::StringPiece key) { cpp2::HostAddr host; - memcpy(&host, key.data() + kLeadersTable.size(), sizeof(host)); + memcpy(reinterpret_cast(&host), key.data() + kLeadersTable.size(), sizeof(host)); return host; } @@ -88,9 +88,9 @@ cpp2::ConfigItem MetaServiceUtilsV1::parseConfigValue(folly::StringPiece rawData auto value = rawData.subpiece(offset, rawData.size() - offset); cpp2::ConfigItem item; - item.set_type(type); - item.set_mode(mode); - item.set_value(value.str()); + item.type_ref() = type; + item.mode_ref() = mode; + item.value_ref() = value.str(); return item; } diff --git a/src/mock/AdHocIndexManager.cpp b/src/mock/AdHocIndexManager.cpp index 0836e74d5c5..478dc4b030c 100644 --- a/src/mock/AdHocIndexManager.cpp +++ b/src/mock/AdHocIndexManager.cpp @@ -14,13 +14,13 @@ void AdHocIndexManager::addTagIndex(GraphSpaceID space, std::vector &&fields) { folly::RWSpinLock::WriteHolder wh(tagIndexLock_); IndexItem item; - item.set_index_id(indexID); - item.set_index_name(folly::stringPrintf("index_%d", indexID)); + item.index_id_ref() = indexID; + item.index_name_ref() = folly::stringPrintf("index_%d", indexID); nebula::cpp2::SchemaID schemaID; - schemaID.set_tag_id(tagID); - item.set_schema_id(schemaID); - item.set_schema_name(folly::stringPrintf("tag_%d", tagID)); - item.set_fields(std::move(fields)); + schemaID.tag_id_ref() = tagID; + item.schema_id_ref() = schemaID; + item.schema_name_ref() = folly::stringPrintf("tag_%d", tagID); + item.fields_ref() = std::move(fields); std::shared_ptr itemPtr = std::make_shared(item); auto iter = tagIndexes_.find(space); @@ -52,13 +52,13 @@ void AdHocIndexManager::addEdgeIndex(GraphSpaceID space, std::vector &&fields) { folly::RWSpinLock::WriteHolder wh(edgeIndexLock_); IndexItem item; - item.set_index_id(indexID); - item.set_index_name(folly::stringPrintf("index_%d", indexID)); + item.index_id_ref() = indexID; + item.index_name_ref() = folly::stringPrintf("index_%d", indexID); nebula::cpp2::SchemaID schemaID; - schemaID.set_edge_type(edgeType); - item.set_schema_id(schemaID); - item.set_schema_name(folly::stringPrintf("edge_%d", edgeType)); - item.set_fields(std::move(fields)); + schemaID.edge_type_ref() = edgeType; + item.schema_id_ref() = schemaID; + item.schema_name_ref() = folly::stringPrintf("edge_%d", edgeType); + item.fields_ref() = std::move(fields); std::shared_ptr itemPtr = std::make_shared(item); auto iter = edgeIndexes_.find(space); diff --git a/src/mock/AdHocSchemaManager.h b/src/mock/AdHocSchemaManager.h index e3c754dd353..35d9a2f7b03 100644 --- a/src/mock/AdHocSchemaManager.h +++ b/src/mock/AdHocSchemaManager.h @@ -108,7 +108,9 @@ class AdHocSchemaManager final : public nebula::meta::SchemaManager { return Status::Error("Unimplemented"); } - StatusOr getPartsNum(GraphSpaceID) override { return partNum_; } + StatusOr getPartsNum(GraphSpaceID) override { + return partNum_; + } protected: folly::RWSpinLock tagLock_; diff --git a/src/mock/MockCluster.cpp b/src/mock/MockCluster.cpp index ad4e91b44f8..76b27e5e9af 100644 --- a/src/mock/MockCluster.cpp +++ b/src/mock/MockCluster.cpp @@ -57,14 +57,15 @@ std::unique_ptr MockCluster::memPartMan( } // static -std::string MockCluster::localIP() { return "127.0.0.1"; } +std::string MockCluster::localIP() { + return "127.0.0.1"; +} // static std::unique_ptr MockCluster::initKV(kvstore::KVOptions options, HostAddr localHost) { auto ioPool = std::make_shared(4); - auto workers = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager( - 1, true /*stats*/); + auto workers = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager(1); workers->setNamePrefix("executor"); workers->start(); if (localHost.host == 0) { @@ -102,8 +103,7 @@ void MockCluster::startMeta(const std::string& rootPath, HostAddr addr) { } std::shared_ptr MockCluster::getWorkers() { - auto worker = - apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager(1, true); + auto worker = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager(1); worker->setNamePrefix("executor"); worker->start(); return worker; @@ -143,15 +143,15 @@ void MockCluster::initStorageKV(const char* dataPath, if (metaClient_ != nullptr) { LOG(INFO) << "Pull meta information from meta server"; nebula::meta::cpp2::SpaceDesc spaceDesc; - spaceDesc.set_space_name("test_space"); - spaceDesc.set_partition_num(6); - spaceDesc.set_replica_factor(1); - spaceDesc.set_charset_name("utf8"); - spaceDesc.set_collate_name("utf8_bin"); + spaceDesc.space_name_ref() = "test_space"; + spaceDesc.partition_num_ref() = 6; + spaceDesc.replica_factor_ref() = 1; + spaceDesc.charset_name_ref() = "utf8"; + spaceDesc.collate_name_ref() = "utf8_bin"; meta::cpp2::ColumnTypeDef type; - type.set_type(nebula::cpp2::PropertyType::FIXED_STRING); - type.set_type_length(32); - spaceDesc.set_vid_type(std::move(type)); + type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING; + type.type_length_ref() = 32; + spaceDesc.vid_type_ref() = std::move(type); auto ret = metaClient_->createSpace(spaceDesc).get(); if (!ret.ok()) { LOG(FATAL) << "can't create space"; diff --git a/src/mock/MockCluster.h b/src/mock/MockCluster.h index cd8d565a445..749594b3646 100644 --- a/src/mock/MockCluster.h +++ b/src/mock/MockCluster.h @@ -88,7 +88,9 @@ class MockCluster { static std::string localIP(); - int32_t getTotalParts() { return totalParts_; } + int32_t getTotalParts() { + return totalParts_; + } void stop() { if (metaClient_) { diff --git a/src/mock/MockData.cpp b/src/mock/MockData.cpp index a9fb3450c9a..6553dd07da5 100644 --- a/src/mock/MockData.cpp +++ b/src/mock/MockData.cpp @@ -323,8 +323,8 @@ std::shared_ptr MockData::mockPlayerTagSchema(Object schema->addField( "insertTime", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); meta::cpp2::SchemaProp prop; - prop.set_ttl_col("insertTime"); - prop.set_ttl_duration(FLAGS_mock_ttl_duration); + prop.ttl_col_ref() = "insertTime"; + prop.ttl_duration_ref() = FLAGS_mock_ttl_duration; schema->setProp(prop); } @@ -371,8 +371,8 @@ std::shared_ptr MockData::mockServeEdgeSchema(Object schema->addField( "insertTime", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); meta::cpp2::SchemaProp prop; - prop.set_ttl_col("insertTime"); - prop.set_ttl_duration(FLAGS_mock_ttl_duration); + prop.ttl_col_ref() = "insertTime"; + prop.ttl_duration_ref() = FLAGS_mock_ttl_duration; schema->setProp(prop); } @@ -402,24 +402,24 @@ std::vector MockData::mockGeneralTagIndexColumns( std::vector cols; meta::cpp2::ColumnDef col; col.name = "col_bool"; - col.type.set_type(PropertyType::BOOL); + col.type.type_ref() = PropertyType::BOOL; cols.emplace_back(std::move(col)); col.name = "col_int"; - col.type.set_type(PropertyType::INT64); + col.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(col)); col.name = "col_float"; - col.type.set_type(PropertyType::FLOAT); + col.type.type_ref() = PropertyType::FLOAT; cols.emplace_back(std::move(col)); col.name = "col_double"; - col.type.set_type(PropertyType::DOUBLE); + col.type.type_ref() = PropertyType::DOUBLE; cols.emplace_back(std::move(col)); col.name = "col_str"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); return cols; } @@ -428,16 +428,16 @@ std::vector MockData::mockPlayerTagIndexColumns() std::vector cols; meta::cpp2::ColumnDef col; col.name = "name"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); col.name = "age"; - col.type.set_type(PropertyType::INT64); + col.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(col)); col.name = "playing"; - col.type.set_type(PropertyType::BOOL); + col.type.type_ref() = PropertyType::BOOL; cols.emplace_back(std::move(col)); return cols; } @@ -446,8 +446,8 @@ std::vector MockData::mockTeamTagIndexColumns() { std::vector cols; meta::cpp2::ColumnDef col; col.name = "name"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); return cols; } @@ -456,7 +456,7 @@ std::vector MockData::mockSimpleTagIndexColumns() std::vector cols; meta::cpp2::ColumnDef col; col.name = "col_date"; - col.type.set_type(PropertyType::DATE); + col.type.type_ref() = PropertyType::DATE; cols.emplace_back(std::move(col)); return cols; } @@ -465,17 +465,17 @@ std::vector MockData::mockServeEdgeIndexColumns() std::vector cols; meta::cpp2::ColumnDef col; col.name = "playerName"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); col.name = "teamName"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); col.name = "startYear"; - col.type.set_type(PropertyType::INT64); + col.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(col)); return cols; } @@ -484,21 +484,22 @@ std::vector MockData::mockTeammateEdgeIndexColumn std::vector cols; meta::cpp2::ColumnDef col; col.name = "player1"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); col.name = "player2"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); col.name = "teamName"; - col.type.set_type(PropertyType::FIXED_STRING); - col.type.set_type_length(20); + col.type.type_ref() = PropertyType::FIXED_STRING; + col.type.type_length_ref() = 20; cols.emplace_back(std::move(col)); return cols; } + std::shared_ptr MockData::mockGeneralTagSchemaV1() { std::shared_ptr schema(new meta::NebulaSchemaProvider(0)); schema->addField("col_bool", PropertyType::BOOL); @@ -557,64 +558,64 @@ std::vector MockData::mockTypicaIndexColumns() { std::vector cols; meta::cpp2::ColumnDef col_bool; col_bool.name = "col_bool"; - col_bool.type.set_type(PropertyType::BOOL); + col_bool.type.type_ref() = PropertyType::BOOL; cols.emplace_back(std::move(col_bool)); meta::cpp2::ColumnDef col_bool_null; col_bool_null.name = "col_bool_null"; - col_bool_null.type.set_type(PropertyType::BOOL); - col_bool_null.set_nullable(true); + col_bool_null.type.type_ref() = PropertyType::BOOL; + col_bool_null.nullable_ref() = true; cols.emplace_back(std::move(col_bool_null)); meta::cpp2::ColumnDef col_bool_default; col_bool_default.name = "col_bool_default"; - col_bool_default.type.set_type(PropertyType::BOOL); + col_bool_default.type.type_ref() = PropertyType::BOOL; cols.emplace_back(std::move(col_bool_default)); meta::cpp2::ColumnDef col_int; col_int.name = "col_int"; - col_int.type.set_type(PropertyType::INT64); + col_int.type.type_ref() = PropertyType::INT64; cols.emplace_back(std::move(col_int)); meta::cpp2::ColumnDef col_int_null; col_int_null.name = "col_int_null"; - col_int_null.type.set_type(PropertyType::INT64); - col_int_null.set_nullable(true); + col_int_null.type.type_ref() = PropertyType::INT64; + col_int_null.nullable_ref() = true; cols.emplace_back(std::move(col_int_null)); meta::cpp2::ColumnDef col_float; col_float.name = "col_float"; - col_float.type.set_type(PropertyType::FLOAT); + col_float.type.type_ref() = PropertyType::FLOAT; cols.emplace_back(std::move(col_float)); meta::cpp2::ColumnDef col_float_null; col_float_null.name = "col_float_null"; - col_float_null.type.set_type(PropertyType::FLOAT); - col_float_null.set_nullable(true); + col_float_null.type.type_ref() = PropertyType::FLOAT; + col_float_null.nullable_ref() = true; cols.emplace_back(std::move(col_float_null)); meta::cpp2::ColumnDef col_str; col_str.name = "col_str"; - col_str.type.set_type(PropertyType::FIXED_STRING); - col_str.type.set_type_length(20); + col_str.type.type_ref() = PropertyType::FIXED_STRING; + col_str.type.type_length_ref() = 20; cols.emplace_back(std::move(col_str)); meta::cpp2::ColumnDef col_str_null; col_str_null.name = "col_str_null"; - col_str_null.type.set_type(PropertyType::FIXED_STRING); - col_str_null.type.set_type_length(20); - col_str_null.set_nullable(true); + col_str_null.type.type_ref() = PropertyType::FIXED_STRING; + col_str_null.type.type_length_ref() = 20; + col_str_null.nullable_ref() = true; cols.emplace_back(std::move(col_str_null)); meta::cpp2::ColumnDef col_date; col_date.name = "col_date"; - col_date.type.set_type(PropertyType::DATE); + col_date.type.type_ref() = PropertyType::DATE; cols.emplace_back(std::move(col_date)); meta::cpp2::ColumnDef col_date_null; col_date_null.name = "col_date_null"; - col_date_null.type.set_type(PropertyType::DATE); - col_date_null.set_nullable(true); + col_date_null.type.type_ref() = PropertyType::DATE; + col_date_null.nullable_ref() = true; cols.emplace_back(std::move(col_date_null)); return cols; } @@ -911,8 +912,8 @@ std::unordered_map> MockData::mockmMultiRankServ nebula::storage::cpp2::AddVerticesRequest MockData::mockAddVerticesReq(bool upper, int32_t parts) { nebula::storage::cpp2::AddVerticesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; auto retRecs = mockVertices(upper); @@ -921,14 +922,14 @@ nebula::storage::cpp2::AddVerticesRequest MockData::mockAddVerticesReq(bool uppe nebula::storage::cpp2::NewTag newTag; auto partId = std::hash()(rec.vId_) % parts + 1; - newTag.set_tag_id(rec.tId_); - newTag.set_props(std::move(rec.props_)); + newTag.tag_id_ref() = rec.tId_; + newTag.props_ref() = std::move(rec.props_); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(rec.vId_); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = rec.vId_; + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } return req; @@ -936,7 +937,7 @@ nebula::storage::cpp2::AddVerticesRequest MockData::mockAddVerticesReq(bool uppe nebula::storage::cpp2::DeleteVerticesRequest MockData::mockDeleteVerticesReq(int32_t parts) { nebula::storage::cpp2::DeleteVerticesRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; auto retRecs = mockVerticeIds(); for (auto& rec : retRecs) { @@ -948,21 +949,21 @@ nebula::storage::cpp2::DeleteVerticesRequest MockData::mockDeleteVerticesReq(int nebula::storage::cpp2::AddEdgesRequest MockData::mockAddEdgesReq(bool upper, int32_t parts) { nebula::storage::cpp2::AddEdgesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; auto retRecs = mockEdges(upper); for (auto& rec : retRecs) { nebula::storage::cpp2::NewEdge newEdge; nebula::storage::cpp2::EdgeKey edgeKey; auto partId = std::hash()(rec.srcId_) % parts + 1; - edgeKey.set_src(rec.srcId_); - edgeKey.set_edge_type(rec.type_); - edgeKey.set_ranking(rec.rank_); - edgeKey.set_dst(rec.dstId_); + edgeKey.src_ref() = rec.srcId_; + edgeKey.edge_type_ref() = rec.type_; + edgeKey.ranking_ref() = rec.rank_; + edgeKey.dst_ref() = rec.dstId_; - newEdge.set_key(std::move(edgeKey)); - newEdge.set_props(std::move(rec.props_)); + newEdge.key_ref() = std::move(edgeKey); + newEdge.props_ref() = std::move(rec.props_); (*req.parts_ref())[partId].emplace_back(std::move(newEdge)); } @@ -971,17 +972,17 @@ nebula::storage::cpp2::AddEdgesRequest MockData::mockAddEdgesReq(bool upper, int nebula::storage::cpp2::DeleteEdgesRequest MockData::mockDeleteEdgesReq(int32_t parts) { nebula::storage::cpp2::DeleteEdgesRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; auto retRecs = mockEdgeKeys(); for (auto& rec : retRecs) { auto partId = std::hash()(rec.srcId_) % parts + 1; nebula::storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(rec.srcId_); - edgeKey.set_edge_type(rec.type_); - edgeKey.set_ranking(rec.rank_); - edgeKey.set_dst(rec.dstId_); + edgeKey.src_ref() = rec.srcId_; + edgeKey.edge_type_ref() = rec.type_; + edgeKey.ranking_ref() = rec.rank_; + edgeKey.dst_ref() = rec.dstId_; (*req.parts_ref())[partId].emplace_back(std::move(edgeKey)); } return req; @@ -1059,8 +1060,8 @@ std::vector MockData::mockEdgesSpecifiedOrder() { nebula::storage::cpp2::AddVerticesRequest MockData::mockAddVerticesSpecifiedOrderReq( int32_t parts) { nebula::storage::cpp2::AddVerticesRequest req; - req.set_space_id(1); - req.set_if_not_exists(false); + req.space_id_ref() = 1; + req.if_not_exists_ref() = false; auto retRecs = mockVerticesSpecifiedOrder(); for (auto& rec : retRecs) { @@ -1085,13 +1086,13 @@ nebula::storage::cpp2::AddVerticesRequest MockData::mockAddVerticesSpecifiedOrde nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(rec.tId_); - newTag.set_props(std::move(rec.props_)); + newTag.tag_id_ref() = rec.tId_; + newTag.props_ref() = std::move(rec.props_); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(rec.vId_); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = rec.vId_; + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } return req; @@ -1100,8 +1101,8 @@ nebula::storage::cpp2::AddVerticesRequest MockData::mockAddVerticesSpecifiedOrde nebula::storage::cpp2::AddEdgesRequest MockData::mockAddEdgesSpecifiedOrderReq(int32_t parts) { nebula::storage::cpp2::AddEdgesRequest req; // Use space id is 1 when mock - req.set_space_id(1); - req.set_if_not_exists(false); + req.space_id_ref() = 1; + req.if_not_exists_ref() = false; auto retRecs = mockEdgesSpecifiedOrder(); @@ -1110,13 +1111,13 @@ nebula::storage::cpp2::AddEdgesRequest MockData::mockAddEdgesSpecifiedOrderReq(i nebula::storage::cpp2::NewEdge newEdge; nebula::storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(rec.srcId_); - edgeKey.set_edge_type(rec.type_); - edgeKey.set_ranking(rec.rank_); - edgeKey.set_dst(rec.dstId_); + edgeKey.src_ref() = rec.srcId_; + edgeKey.edge_type_ref() = rec.type_; + edgeKey.ranking_ref() = rec.rank_; + edgeKey.dst_ref() = rec.dstId_; - newEdge.set_key(std::move(edgeKey)); - newEdge.set_props(std::move(rec.props_)); + newEdge.key_ref() = std::move(edgeKey); + newEdge.props_ref() = std::move(rec.props_); (*req.parts_ref())[partId].emplace_back(std::move(newEdge)); std::vector colNames{"teamAvgScore", @@ -1126,7 +1127,7 @@ nebula::storage::cpp2::AddEdgesRequest MockData::mockAddEdgesSpecifiedOrderReq(i "startYear", "teamName", "playerName"}; - req.set_prop_names(std::move(colNames)); + req.prop_names_ref() = std::move(colNames); } return req; } @@ -1143,7 +1144,7 @@ EdgeData MockData::getReverseEdge(const EdgeData& edge) { nebula::storage::cpp2::KVPutRequest MockData::mockKVPut() { nebula::storage::cpp2::KVPutRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; const int32_t totalParts = 6; std::unordered_map> data; @@ -1155,13 +1156,13 @@ nebula::storage::cpp2::KVPutRequest MockData::mockKVPut() { pairs.emplace_back(std::move(pair)); data.emplace(part, std::move(pairs)); } - req.set_parts(std::move(data)); + req.parts_ref() = std::move(data); return req; } nebula::storage::cpp2::KVGetRequest MockData::mockKVGet() { nebula::storage::cpp2::KVGetRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; const int32_t totalParts = 6; std::unordered_map> data; @@ -1170,13 +1171,13 @@ nebula::storage::cpp2::KVGetRequest MockData::mockKVGet() { keys.emplace_back(folly::stringPrintf("key_%ld", part)); data.insert(std::make_pair(part, std::move(keys))); } - req.set_parts(std::move(data)); + req.parts_ref() = std::move(data); return req; } nebula::storage::cpp2::KVRemoveRequest MockData::mockKVRemove() { nebula::storage::cpp2::KVRemoveRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; const int32_t totalParts = 6; std::unordered_map> data; @@ -1185,7 +1186,7 @@ nebula::storage::cpp2::KVRemoveRequest MockData::mockKVRemove() { keys.emplace_back(folly::stringPrintf("key_%ld", part)); data.insert(std::make_pair(part, std::move(keys))); } - req.set_parts(std::move(data)); + req.parts_ref() = std::move(data); return req; } diff --git a/src/parser/AdminSentences.cpp b/src/parser/AdminSentences.cpp index e09bb6e5811..2716940daae 100644 --- a/src/parser/AdminSentences.cpp +++ b/src/parser/AdminSentences.cpp @@ -13,19 +13,29 @@ namespace nebula { -std::string ShowHostsSentence::toString() const { return std::string("SHOW HOSTS"); } +std::string ShowHostsSentence::toString() const { + return std::string("SHOW HOSTS"); +} -std::string ShowMetaLeaderSentence::toString() const { return std::string("SHOW META LEADER"); } +std::string ShowMetaLeaderSentence::toString() const { + return std::string("SHOW META LEADER"); +} -std::string ShowSpacesSentence::toString() const { return std::string("SHOW SPACES"); } +std::string ShowSpacesSentence::toString() const { + return std::string("SHOW SPACES"); +} std::string ShowCreateSpaceSentence::toString() const { return folly::stringPrintf("SHOW CREATE SPACE %s", name_.get()->c_str()); } -std::string ShowPartsSentence::toString() const { return std::string("SHOW PARTS"); } +std::string ShowPartsSentence::toString() const { + return std::string("SHOW PARTS"); +} -std::string ShowUsersSentence::toString() const { return std::string("SHOW USERS"); } +std::string ShowUsersSentence::toString() const { + return std::string("SHOW USERS"); +} std::string DescribeUserSentence::toString() const { return folly::stringPrintf("DESCRIBE USER %s", account_.get()->c_str()); @@ -35,15 +45,25 @@ std::string ShowRolesSentence::toString() const { return folly::stringPrintf("SHOW ROLES IN %s", name_.get()->c_str()); } -std::string ShowSnapshotsSentence::toString() const { return std::string("SHOW SNAPSHOTS"); } +std::string ShowSnapshotsSentence::toString() const { + return std::string("SHOW SNAPSHOTS"); +} -std::string ShowCharsetSentence::toString() const { return std::string("SHOW CHARSET"); } +std::string ShowCharsetSentence::toString() const { + return std::string("SHOW CHARSET"); +} -std::string ShowCollationSentence::toString() const { return std::string("SHOW COLLATION"); } +std::string ShowCollationSentence::toString() const { + return std::string("SHOW COLLATION"); +} -std::string ShowGroupsSentence::toString() const { return std::string("SHOW GROUPS"); } +std::string ShowGroupsSentence::toString() const { + return std::string("SHOW GROUPS"); +} -std::string ShowZonesSentence::toString() const { return std::string("SHOW ZONES"); } +std::string ShowZonesSentence::toString() const { + return std::string("SHOW ZONES"); +} std::string SpaceOptItem::toString() const { switch (optType_) { @@ -173,7 +193,9 @@ std::string HostList::toString() const { return buf; } -std::string CreateSnapshotSentence::toString() const { return "CREATE SNAPSHOT"; } +std::string CreateSnapshotSentence::toString() const { + return "CREATE SNAPSHOT"; +} std::string DropSnapshotSentence::toString() const { return folly::stringPrintf("DROP SNAPSHOT %s", name_.get()->c_str()); @@ -210,7 +232,9 @@ std::string RemoveListenerSentence::toString() const { return buf; } -std::string ShowListenerSentence::toString() const { return "SHOW LISTENER"; } +std::string ShowListenerSentence::toString() const { + return "SHOW LISTENER"; +} std::string AdminJobSentence::toString() const { switch (op_) { @@ -276,13 +300,21 @@ std::string AdminJobSentence::toString() const { LOG(FATAL) << "Unknown job operation " << static_cast(op_); } -meta::cpp2::AdminJobOp AdminJobSentence::getOp() const { return op_; } +meta::cpp2::AdminJobOp AdminJobSentence::getOp() const { + return op_; +} -meta::cpp2::AdminCmd AdminJobSentence::getCmd() const { return cmd_; } +meta::cpp2::AdminCmd AdminJobSentence::getCmd() const { + return cmd_; +} -const std::vector &AdminJobSentence::getParas() const { return paras_; } +const std::vector &AdminJobSentence::getParas() const { + return paras_; +} -void AdminJobSentence::addPara(const std::string ¶) { paras_.emplace_back(para); } +void AdminJobSentence::addPara(const std::string ¶) { + paras_.emplace_back(para); +} void AdminJobSentence::addPara(const NameLabelList ¶s) { const auto &labels = paras.labels(); @@ -290,9 +322,13 @@ void AdminJobSentence::addPara(const NameLabelList ¶s) { labels.begin(), labels.end(), [this](const auto ¶) { paras_.emplace_back(*para); }); } -std::string ShowStatsSentence::toString() const { return folly::stringPrintf("SHOW STATS"); } +std::string ShowStatsSentence::toString() const { + return folly::stringPrintf("SHOW STATS"); +} -std::string ShowTSClientsSentence::toString() const { return "SHOW TEXT SEARCH CLIENTS"; } +std::string ShowTSClientsSentence::toString() const { + return "SHOW TEXT SEARCH CLIENTS"; +} std::string SignInTextServiceSentence::toString() const { std::string buf; @@ -329,7 +365,9 @@ std::string SignInTextServiceSentence::toString() const { return buf; } -std::string SignOutTextServiceSentence::toString() const { return "SIGN OUT TEXT SERVICE"; } +std::string SignOutTextServiceSentence::toString() const { + return "SIGN OUT TEXT SERVICE"; +} std::string ShowSessionsSentence::toString() const { if (isSetSessionID()) { diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index b654700066c..529d6b44948 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -16,7 +16,9 @@ class ConfigRowItem; class ShowHostsSentence : public Sentence { public: - ShowHostsSentence() { kind_ = Kind::kShowHosts; } + ShowHostsSentence() { + kind_ = Kind::kShowHosts; + } explicit ShowHostsSentence(meta::cpp2::ListHostType type) : type_(type) { kind_ = Kind::kShowHosts; @@ -24,7 +26,9 @@ class ShowHostsSentence : public Sentence { std::string toString() const override; - meta::cpp2::ListHostType getType() const { return type_; } + meta::cpp2::ListHostType getType() const { + return type_; + } private: meta::cpp2::ListHostType type_; @@ -32,14 +36,18 @@ class ShowHostsSentence : public Sentence { class ShowMetaLeaderSentence : public Sentence { public: - ShowMetaLeaderSentence() { kind_ = Kind::kShowMetaLeader; } + ShowMetaLeaderSentence() { + kind_ = Kind::kShowMetaLeader; + } std::string toString() const override; }; class ShowSpacesSentence : public Sentence { public: - ShowSpacesSentence() { kind_ = Kind::kShowSpaces; } + ShowSpacesSentence() { + kind_ = Kind::kShowSpaces; + } std::string toString() const override; }; @@ -51,7 +59,9 @@ class ShowCreateSpaceSentence : public Sentence { } std::string toString() const override; - const std::string* spaceName() const { return name_.get(); } + const std::string* spaceName() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -59,14 +69,18 @@ class ShowCreateSpaceSentence : public Sentence { class ShowPartsSentence : public Sentence { public: - ShowPartsSentence() { kind_ = Kind::kShowParts; } + ShowPartsSentence() { + kind_ = Kind::kShowParts; + } explicit ShowPartsSentence(std::vector* list) { list_.reset(list); kind_ = Kind::kShowParts; } - std::vector* getList() const { return list_.get(); } + std::vector* getList() const { + return list_.get(); + } std::string toString() const override; @@ -76,7 +90,9 @@ class ShowPartsSentence : public Sentence { class ShowUsersSentence : public Sentence { public: - ShowUsersSentence() { kind_ = Kind::kShowUsers; } + ShowUsersSentence() { + kind_ = Kind::kShowUsers; + } std::string toString() const override; }; @@ -89,7 +105,9 @@ class DescribeUserSentence : public Sentence { std::string toString() const override; - const std::string* account() const { return account_.get(); } + const std::string* account() const { + return account_.get(); + } private: std::unique_ptr account_; @@ -104,7 +122,9 @@ class ShowRolesSentence : public Sentence { std::string toString() const override; - const std::string* name() const { return name_.get(); } + const std::string* name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -112,31 +132,41 @@ class ShowRolesSentence : public Sentence { class ShowSnapshotsSentence : public Sentence { public: - ShowSnapshotsSentence() { kind_ = Kind::kShowSnapshots; } + ShowSnapshotsSentence() { + kind_ = Kind::kShowSnapshots; + } std::string toString() const override; }; class ShowCharsetSentence final : public Sentence { public: - ShowCharsetSentence() { kind_ = Kind::kShowCharset; } + ShowCharsetSentence() { + kind_ = Kind::kShowCharset; + } std::string toString() const override; }; class ShowCollationSentence final : public Sentence { public: - ShowCollationSentence() { kind_ = Kind::kShowCollation; } + ShowCollationSentence() { + kind_ = Kind::kShowCollation; + } std::string toString() const override; }; class ShowGroupsSentence final : public Sentence { public: - ShowGroupsSentence() { kind_ = Kind::kShowGroups; } + ShowGroupsSentence() { + kind_ = Kind::kShowGroups; + } std::string toString() const override; }; class ShowZonesSentence final : public Sentence { public: - ShowZonesSentence() { kind_ = Kind::kShowZones; } + ShowZonesSentence() { + kind_ = Kind::kShowZones; + } std::string toString() const override; }; @@ -174,19 +204,29 @@ class SpaceOptItem final { optValue_ = val ? 1 : 0; } - int64_t asInt() const { return boost::get(optValue_); } + int64_t asInt() const { + return boost::get(optValue_); + } - const std::string& asString() const { return boost::get(optValue_); } + const std::string& asString() const { + return boost::get(optValue_); + } const meta::cpp2::ColumnTypeDef& asTypeDef() const { return boost::get(optValue_); } - bool isInt() const { return optValue_.which() == 0; } + bool isInt() const { + return optValue_.which() == 0; + } - bool isString() const { return optValue_.which() == 1; } + bool isString() const { + return optValue_.which() == 1; + } - bool isTypeDef() const { return optValue_.which() == 2; } + bool isTypeDef() const { + return optValue_.which() == 2; + } int64_t getPartitionNum() const { if (isInt()) { @@ -212,7 +252,7 @@ class SpaceOptItem final { } else { LOG(ERROR) << "vid type illegal."; static meta::cpp2::ColumnTypeDef unknownTypeDef; - unknownTypeDef.set_type(nebula::cpp2::PropertyType::UNKNOWN); + unknownTypeDef.type_ref() = nebula::cpp2::PropertyType::UNKNOWN; return unknownTypeDef; } } @@ -244,7 +284,9 @@ class SpaceOptItem final { } } - OptionType getOptType() const { return optType_; } + OptionType getOptType() const { + return optType_; + } bool getAtomicEdge() const { if (isInt()) { @@ -255,7 +297,9 @@ class SpaceOptItem final { } } - bool isVidType() { return optType_ == OptionType::VID_TYPE; } + bool isVidType() { + return optType_ == OptionType::VID_TYPE; + } std::string toString() const; @@ -266,7 +310,9 @@ class SpaceOptItem final { class SpaceOptList final { public: - void addOpt(SpaceOptItem* item) { items_.emplace_back(item); } + void addOpt(SpaceOptItem* item) { + items_.emplace_back(item); + } std::vector getOpts() const { std::vector result; @@ -299,19 +345,33 @@ class CreateSpaceSentence final : public CreateSentence { kind_ = Kind::kCreateSpace; } - const std::string* spaceName() const { return spaceName_.get(); } + const std::string* spaceName() const { + return spaceName_.get(); + } - const ZoneNameList* zoneNames() const { return zoneNames_.get(); } + const ZoneNameList* zoneNames() const { + return zoneNames_.get(); + } - void setOpts(SpaceOptList* spaceOpts) { spaceOpts_.reset(spaceOpts); } + void setOpts(SpaceOptList* spaceOpts) { + spaceOpts_.reset(spaceOpts); + } - void setZoneNames(ZoneNameList* names) { zoneNames_.reset(names); } + void setZoneNames(ZoneNameList* names) { + zoneNames_.reset(names); + } - const SpaceOptList* spaceOpts() const { return spaceOpts_.get(); } + const SpaceOptList* spaceOpts() const { + return spaceOpts_.get(); + } - void setComment(std::string* name) { comment_.reset(name); } + void setComment(std::string* name) { + comment_.reset(name); + } - const std::string* comment() const { return comment_.get(); } + const std::string* comment() const { + return comment_.get(); + } std::vector getOpts() { if (spaceOpts_ == nullptr) { @@ -338,9 +398,13 @@ class CreateSpaceAsSentence final : public CreateSentence { kind_ = Kind::kCreateSpaceAs; } - std::string getOldSpaceName() const { return *oldSpaceName_; } + std::string getOldSpaceName() const { + return *oldSpaceName_; + } - std::string getNewSpaceName() const { return *newSpaceName_; } + std::string getNewSpaceName() const { + return *newSpaceName_; + } std::string toString() const override; @@ -356,11 +420,17 @@ class DropSpaceSentence final : public DropSentence { kind_ = Kind::kDropSpace; } - void setClusterName(std::string* clusterName) { clusterName_.reset(clusterName); } + void setClusterName(std::string* clusterName) { + clusterName_.reset(clusterName); + } - const std::string* spaceName() const { return spaceName_.get(); } + const std::string* spaceName() const { + return spaceName_.get(); + } - const std::string* clusterName() const { return clusterName_.get(); } + const std::string* clusterName() const { + return clusterName_.get(); + } std::string toString() const override; @@ -376,7 +446,9 @@ class DescribeSpaceSentence final : public Sentence { kind_ = Kind::kDescribeSpace; } - const std::string* spaceName() const { return spaceName_.get(); } + const std::string* spaceName() const { + return spaceName_.get(); + } std::string toString() const override; @@ -386,7 +458,9 @@ class DescribeSpaceSentence final : public Sentence { class ConfigRowItem { public: - explicit ConfigRowItem(meta::cpp2::ConfigModule module) { module_ = module; } + explicit ConfigRowItem(meta::cpp2::ConfigModule module) { + module_ = module; + } ConfigRowItem(meta::cpp2::ConfigModule module, std::string* name, Expression* value) { module_ = module; @@ -405,13 +479,21 @@ class ConfigRowItem { updateItems_.reset(items); } - meta::cpp2::ConfigModule getModule() const { return module_; } + meta::cpp2::ConfigModule getModule() const { + return module_; + } - const std::string* getName() const { return name_.get(); } + const std::string* getName() const { + return name_.get(); + } - Expression* getValue() const { return value_; } + Expression* getValue() const { + return value_; + } - const UpdateList* getUpdateItems() const { return updateItems_.get(); } + const UpdateList* getUpdateItems() const { + return updateItems_.get(); + } std::string toString() const; @@ -429,7 +511,9 @@ class ConfigBaseSentence : public Sentence { configItem_.reset(item); } - ConfigRowItem* configItem() { return configItem_.get(); } + ConfigRowItem* configItem() { + return configItem_.get(); + } protected: std::unique_ptr configItem_; @@ -459,7 +543,9 @@ class GetConfigSentence final : public ConfigBaseSentence { class CreateSnapshotSentence final : public Sentence { public: - CreateSnapshotSentence() { kind_ = Kind::kCreateSnapshot; } + CreateSnapshotSentence() { + kind_ = Kind::kCreateSnapshot; + } std::string toString() const override; }; @@ -471,7 +557,9 @@ class DropSnapshotSentence final : public Sentence { name_.reset(name); } - const std::string* name() { return name_.get(); } + const std::string* name() { + return name_.get(); + } std::string toString() const override; @@ -487,9 +575,13 @@ class AddListenerSentence final : public Sentence { listeners_.reset(hosts); } - meta::cpp2::ListenerType type() const { return type_; } + meta::cpp2::ListenerType type() const { + return type_; + } - HostList* listeners() const { return listeners_.get(); } + HostList* listeners() const { + return listeners_.get(); + } std::string toString() const override; @@ -505,7 +597,9 @@ class RemoveListenerSentence final : public Sentence { type_ = type; } - meta::cpp2::ListenerType type() const { return type_; } + meta::cpp2::ListenerType type() const { + return type_; + } std::string toString() const override; @@ -515,7 +609,9 @@ class RemoveListenerSentence final : public Sentence { class ShowListenerSentence final : public Sentence { public: - ShowListenerSentence() { kind_ = Kind::kShowListener; } + ShowListenerSentence() { + kind_ = Kind::kShowListener; + } std::string toString() const override; }; @@ -547,14 +643,18 @@ class AdminJobSentence final : public Sentence { class ShowStatsSentence final : public Sentence { public: - ShowStatsSentence() { kind_ = Kind::kShowStats; } + ShowStatsSentence() { + kind_ = Kind::kShowStats; + } std::string toString() const override; }; class TSClientList final { public: - void addClient(nebula::meta::cpp2::FTClient* client) { clients_.emplace_back(client); } + void addClient(nebula::meta::cpp2::FTClient* client) { + clients_.emplace_back(client); + } std::string toString() const; @@ -573,7 +673,9 @@ class TSClientList final { class ShowTSClientsSentence final : public Sentence { public: - ShowTSClientsSentence() { kind_ = Kind::kShowTSClients; } + ShowTSClientsSentence() { + kind_ = Kind::kShowTSClients; + } std::string toString() const override; }; @@ -586,7 +688,9 @@ class SignInTextServiceSentence final : public Sentence { std::string toString() const override; - TSClientList* clients() const { return clients_.get(); } + TSClientList* clients() const { + return clients_.get(); + } private: std::unique_ptr clients_; @@ -594,14 +698,18 @@ class SignInTextServiceSentence final : public Sentence { class SignOutTextServiceSentence final : public Sentence { public: - SignOutTextServiceSentence() { kind_ = Kind::kSignOutTSService; } + SignOutTextServiceSentence() { + kind_ = Kind::kSignOutTSService; + } std::string toString() const override; }; class ShowSessionsSentence final : public Sentence { public: - ShowSessionsSentence() { kind_ = Kind::kShowSessions; } + ShowSessionsSentence() { + kind_ = Kind::kShowSessions; + } explicit ShowSessionsSentence(SessionID sessionId) { kind_ = Kind::kShowSessions; @@ -609,9 +717,13 @@ class ShowSessionsSentence final : public Sentence { setSessionId_ = true; } - bool isSetSessionID() const { return setSessionId_; } + bool isSetSessionID() const { + return setSessionId_; + } - SessionID getSessionID() const { return sessionId_; } + SessionID getSessionID() const { + return sessionId_; + } std::string toString() const override; @@ -627,7 +739,9 @@ class ShowQueriesSentence final : public Sentence { isAll_ = isAll; } - bool isAll() const { return isAll_; } + bool isAll() const { + return isAll_; + } std::string toString() const override; @@ -640,13 +754,21 @@ class QueryUniqueIdentifier final { explicit QueryUniqueIdentifier(Expression* epId, Expression* sessionId) : epId_(epId), sessionId_(sessionId) {} - Expression* sessionId() const { return sessionId_; } + Expression* sessionId() const { + return sessionId_; + } - Expression* epId() const { return epId_; } + Expression* epId() const { + return epId_; + } - void setSession() { isSetSession_ = true; } + void setSession() { + isSetSession_ = true; + } - bool isSetSession() const { return isSetSession_; } + bool isSetSession() const { + return isSetSession_; + } private: Expression* epId_{nullptr}; @@ -661,14 +783,20 @@ class KillQuerySentence final : public Sentence { identifier_.reset(identifier); } - Expression* sessionId() const { return identifier_->sessionId(); } + Expression* sessionId() const { + return identifier_->sessionId(); + } - Expression* epId() const { return identifier_->epId(); } + Expression* epId() const { + return identifier_->epId(); + } std::string toString() const override; private: - bool isSetSession() const { return identifier_->isSetSession(); } + bool isSetSession() const { + return identifier_->isSetSession(); + } std::unique_ptr identifier_; }; diff --git a/src/parser/Clauses.cpp b/src/parser/Clauses.cpp index e5eddbb8399..fcfbec8c07c 100644 --- a/src/parser/Clauses.cpp +++ b/src/parser/Clauses.cpp @@ -206,7 +206,9 @@ std::string YieldClause::toString() const { return buf; } -std::string GroupClause::toString() const { return groupColumns_->toString(); } +std::string GroupClause::toString() const { + return groupColumns_->toString(); +} std::string BoundClause::toString() const { std::string buf; diff --git a/src/parser/Clauses.h b/src/parser/Clauses.h index 4d7fa6c9b41..62cee580e5c 100644 --- a/src/parser/Clauses.h +++ b/src/parser/Clauses.h @@ -22,17 +22,29 @@ class StepClause final { nSteps_ = n; } - uint32_t steps() const { return mSteps_; } + uint32_t steps() const { + return mSteps_; + } - bool isMToN() const { return mSteps_ != nSteps_; } + bool isMToN() const { + return mSteps_ != nSteps_; + } - uint32_t mSteps() const { return mSteps_; } + uint32_t mSteps() const { + return mSteps_; + } - uint32_t nSteps() const { return nSteps_; } + uint32_t nSteps() const { + return nSteps_; + } - void setMSteps(uint32_t m) { mSteps_ = m; } + void setMSteps(uint32_t m) { + mSteps_ = m; + } - void setNSteps(uint32_t n) { nSteps_ = n; } + void setNSteps(uint32_t n) { + nSteps_ = n; + } std::string toString() const; @@ -43,9 +55,13 @@ class StepClause final { class VertexIDList final { public: - void add(Expression *expr) { vidList_.emplace_back(expr); } + void add(Expression *expr) { + vidList_.emplace_back(expr); + } - const std::vector &vidList() const { return vidList_; } + const std::vector &vidList() const { + return vidList_; + } std::string toString() const; @@ -55,15 +71,25 @@ class VertexIDList final { class VerticesClause { public: - explicit VerticesClause(VertexIDList *vidList) { vidList_.reset(vidList); } + explicit VerticesClause(VertexIDList *vidList) { + vidList_.reset(vidList); + } - explicit VerticesClause(Expression *ref) { ref_ = ref; } + explicit VerticesClause(Expression *ref) { + ref_ = ref; + } - auto vidList() const { return vidList_->vidList(); } + auto vidList() const { + return vidList_->vidList(); + } - auto isRef() const { return ref_ != nullptr; } + auto isRef() const { + return ref_ != nullptr; + } - auto ref() const { return ref_; } + auto ref() const { + return ref_; + } std::string toString() const; @@ -97,9 +123,13 @@ class OverEdge final { alias_.reset(alias); } - std::string *edge() const { return edge_.get(); } + std::string *edge() const { + return edge_.get(); + } - std::string *alias() const { return alias_.get(); } + std::string *alias() const { + return alias_.get(); + } std::string toString() const; @@ -110,7 +140,9 @@ class OverEdge final { class OverEdges final { public: - void addEdge(OverEdge *edge) { edges_.emplace_back(edge); } + void addEdge(OverEdge *edge) { + edges_.emplace_back(edge); + } std::vector edges() { std::vector result; @@ -143,13 +175,19 @@ class OverClause final { overEdges_ = std::make_unique(); } - std::vector edges() const { return overEdges_->edges(); } + std::vector edges() const { + return overEdges_->edges(); + } std::string toString() const; - storage::cpp2::EdgeDirection direction() const { return direction_; } + storage::cpp2::EdgeDirection direction() const { + return direction_; + } - bool isOverAll() const { return isOverAll_; } + bool isOverAll() const { + return isOverAll_; + } private: storage::cpp2::EdgeDirection direction_; @@ -164,13 +202,17 @@ class TruncateClause { isSample_ = isSample; } - Expression *truncate() const { return truncate_; } + Expression *truncate() const { + return truncate_; + } std::unique_ptr clone() const { return std::make_unique(truncate_->clone(), isSample_); } - bool isSample() const { return isSample_; } + bool isSample() const { + return isSample_; + } std::string toString() const; @@ -181,11 +223,17 @@ class TruncateClause { class WhereClause { public: - explicit WhereClause(Expression *filter) { filter_ = filter; } + explicit WhereClause(Expression *filter) { + filter_ = filter; + } - Expression *filter() const { return filter_; } + Expression *filter() const { + return filter_; + } - void setFilter(Expression *expr) { filter_ = expr; } + void setFilter(Expression *expr) { + filter_ = expr; + } std::unique_ptr clone() const { return std::make_unique(filter_->clone()); @@ -215,15 +263,25 @@ class YieldColumn final { return std::make_unique(expr_->clone(), alias_); } - void setExpr(Expression *expr) { expr_ = expr; } + void setExpr(Expression *expr) { + expr_ = expr; + } - Expression *expr() const { return expr_; } + Expression *expr() const { + return expr_; + } - void setAlias(const std::string &alias) { alias_ = alias; } + void setAlias(const std::string &alias) { + alias_ = alias; + } - const std::string &alias() const { return alias_; } + const std::string &alias() const { + return alias_; + } - std::string name() const { return alias_.empty() ? toString() : alias(); } + std::string name() const { + return alias_.empty() ? toString() : alias(); + } std::string toString() const; @@ -233,11 +291,15 @@ class YieldColumn final { }; bool operator==(const YieldColumn &l, const YieldColumn &r); -inline bool operator!=(const YieldColumn &l, const YieldColumn &r) { return !(l == r); } +inline bool operator!=(const YieldColumn &l, const YieldColumn &r) { + return !(l == r); +} class YieldColumns final { public: - void addColumn(YieldColumn *field) { columns_.emplace_back(field); } + void addColumn(YieldColumn *field) { + columns_.emplace_back(field); + } std::vector columns() const { std::vector result; @@ -256,9 +318,13 @@ class YieldColumns final { return names; } - size_t size() const { return columns_.size(); } + size_t size() const { + return columns_.size(); + } - bool empty() const { return columns_.empty(); } + bool empty() const { + return columns_.empty(); + } std::unique_ptr clone() const { auto cols = std::make_unique(); @@ -270,9 +336,13 @@ class YieldColumns final { std::string toString() const; - const YieldColumn *back() const { return columns_.back().get(); } + const YieldColumn *back() const { + return columns_.back().get(); + } - YieldColumn *back() { return columns_.back().get(); } + YieldColumn *back() { + return columns_.back().get(); + } bool hasAgg() const; @@ -287,11 +357,17 @@ class YieldClause final { distinct_ = distinct; } - std::vector columns() const { return yieldColumns_->columns(); } + std::vector columns() const { + return yieldColumns_->columns(); + } - YieldColumns *yields() const { return yieldColumns_.get(); } + YieldColumns *yields() const { + return yieldColumns_.get(); + } - bool isDistinct() const { return distinct_; } + bool isDistinct() const { + return distinct_; + } std::unique_ptr clone() const { auto cols = yieldColumns_->clone(); @@ -307,9 +383,13 @@ class YieldClause final { class GroupClause final { public: - explicit GroupClause(YieldColumns *fields) { groupColumns_.reset(fields); } + explicit GroupClause(YieldColumns *fields) { + groupColumns_.reset(fields); + } - std::vector columns() const { return groupColumns_->columns(); } + std::vector columns() const { + return groupColumns_->columns(); + } std::string toString() const; @@ -326,7 +406,9 @@ class BoundClause final { boundType_ = type; } - std::vector edges() const { return overEdges_->edges(); } + std::vector edges() const { + return overEdges_->edges(); + } std::string toString() const; @@ -343,13 +425,21 @@ class NameLabelList { public: NameLabelList() = default; - void add(std::string *label) { labels_.emplace_back(label); } + void add(std::string *label) { + labels_.emplace_back(label); + } - bool empty() const { return labels_.empty(); } + bool empty() const { + return labels_.empty(); + } - std::size_t size() const { return labels_.size(); } + std::size_t size() const { + return labels_.size(); + } - const std::string *front() const { return labels_.front().get(); } + const std::string *front() const { + return labels_.front().get(); + } std::vector labels() const { std::vector labels; diff --git a/src/parser/EdgeKey.h b/src/parser/EdgeKey.h index c65a77ec067..f5859eea855 100644 --- a/src/parser/EdgeKey.h +++ b/src/parser/EdgeKey.h @@ -27,11 +27,17 @@ class EdgeKey final { rank_ = rank; } - Expression *srcid() const { return srcid_; } + Expression *srcid() const { + return srcid_; + } - Expression *dstid() const { return dstid_; } + Expression *dstid() const { + return dstid_; + } - int64_t rank() { return rank_; } + int64_t rank() { + return rank_; + } std::string toString() const; @@ -45,7 +51,9 @@ class EdgeKeys final { public: EdgeKeys() = default; - void addEdgeKey(EdgeKey *key) { keys_.emplace_back(key); } + void addEdgeKey(EdgeKey *key) { + keys_.emplace_back(key); + } std::vector keys() const { std::vector result; @@ -70,17 +78,29 @@ class EdgeKeyRef final { isInputExpr_ = isInputExpr; } - Expression *srcid() const { return srcid_; } + Expression *srcid() const { + return srcid_; + } - Expression *dstid() const { return dstid_; } + Expression *dstid() const { + return dstid_; + } - Expression *rank() const { return rank_; } + Expression *rank() const { + return rank_; + } - Expression *type() const { return type_; } + Expression *type() const { + return type_; + } - void setType(Expression *type) { type_ = type; } + void setType(Expression *type) { + type_ = type; + } - bool isInputExpr() const { return isInputExpr_; } + bool isInputExpr() const { + return isInputExpr_; + } std::string toString() const; diff --git a/src/parser/ExplainSentence.h b/src/parser/ExplainSentence.h index 11b6b683847..58bf3b515dc 100644 --- a/src/parser/ExplainSentence.h +++ b/src/parser/ExplainSentence.h @@ -23,11 +23,17 @@ class ExplainSentence final : public Sentence { std::string toString() const override; - bool isProfile() const { return isProfile_; } + bool isProfile() const { + return isProfile_; + } - const std::string& formatType() const { return *formatType_; } + const std::string& formatType() const { + return *formatType_; + } - SequentialSentences* seqSentences() const { return seqSentences_.get(); } + SequentialSentences* seqSentences() const { + return seqSentences_.get(); + } private: bool isProfile_{false}; diff --git a/src/parser/GraphScanner.h b/src/parser/GraphScanner.h index 2f5340d3774..f7092a2231d 100644 --- a/src/parser/GraphScanner.h +++ b/src/parser/GraphScanner.h @@ -31,7 +31,9 @@ class GraphScanner : public yyFlexLexer { public: // Called by GQLParser to set the `readBuffer' callback, which would be // invoked by LexerInput to fill the stream buffer. - void setReadBuffer(std::function readBuffer) { readBuffer_ = readBuffer; } + void setReadBuffer(std::function readBuffer) { + readBuffer_ = readBuffer; + } // Manually invoked by GQLParser to recover from a failure state. // This makes the scanner reentrant. @@ -39,21 +41,35 @@ class GraphScanner : public yyFlexLexer { yy_flush_buffer(yy_buffer_stack ? yy_buffer_stack[yy_buffer_stack_top] : nullptr); } - void setQuery(std::string *query) { query_ = query; } + void setQuery(std::string *query) { + query_ = query; + } - std::string *query() { return query_; } + std::string *query() { + return query_; + } - void setUnaryMinus(bool v) { hasUnaryMinus_ = v; } + void setUnaryMinus(bool v) { + hasUnaryMinus_ = v; + } - bool hasUnaryMinus() const { return hasUnaryMinus_; } + bool hasUnaryMinus() const { + return hasUnaryMinus_; + } - void setIsIntMin(bool v) { isIntMin_ = v; } + void setIsIntMin(bool v) { + isIntMin_ = v; + } - bool isIntMin() const { return isIntMin_; } + bool isIntMin() const { + return isIntMin_; + } protected: // Called when YY_INPUT is invoked - int LexerInput(char *buf, int maxSize) override { return readBuffer_(buf, maxSize); } + int LexerInput(char *buf, int maxSize) override { + return readBuffer_(buf, maxSize); + } void makeSpaceForString(size_t len) { constexpr auto defaultSize = 256UL; @@ -74,7 +90,9 @@ class GraphScanner : public yyFlexLexer { sbufSize_ = newSize; } - char *sbuf() { return sbuf_.get(); } + char *sbuf() { + return sbuf_.get(); + } using TokenType = nebula::GraphParser::token; auto parseDecimal() { diff --git a/src/parser/MaintainSentences.cpp b/src/parser/MaintainSentences.cpp index ac70707fdf9..b16c6828281 100644 --- a/src/parser/MaintainSentences.cpp +++ b/src/parser/MaintainSentences.cpp @@ -351,9 +351,13 @@ std::string DropEdgeIndexSentence::toString() const { return folly::stringPrintf("DROP EDGE INDEX %s", indexName_.get()->c_str()); } -std::string ShowTagsSentence::toString() const { return folly::stringPrintf("SHOW TAGS"); } +std::string ShowTagsSentence::toString() const { + return folly::stringPrintf("SHOW TAGS"); +} -std::string ShowEdgesSentence::toString() const { return folly::stringPrintf("SHOW EDGES"); } +std::string ShowEdgesSentence::toString() const { + return folly::stringPrintf("SHOW EDGES"); +} std::string ShowCreateTagSentence::toString() const { return folly::stringPrintf("SHOW CREATE TAG %s", name_.get()->c_str()); @@ -458,7 +462,9 @@ std::string DescribeZoneSentence::toString() const { return folly::stringPrintf("DESCRIBE ZONE \"%s\"", zoneName_.get()->c_str()); } -std::string ListZonesSentence::toString() const { return folly::stringPrintf("SHOW ZONES"); } +std::string ListZonesSentence::toString() const { + return folly::stringPrintf("SHOW ZONES"); +} std::string AddHostsIntoZoneSentence::toString() const { std::string buf; @@ -504,6 +510,8 @@ std::string DropFTIndexSentence::toString() const { return folly::stringPrintf("DROP FULLTEXT INDEX %s", indexName_.get()->c_str()); } -std::string ShowFTIndexesSentence::toString() const { return "SHOW FULLTEXT INDEXES"; } +std::string ShowFTIndexesSentence::toString() const { + return "SHOW FULLTEXT INDEXES"; +} } // namespace nebula diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h index 6b620d9a6ed..9babeb127a0 100644 --- a/src/parser/MaintainSentences.h +++ b/src/parser/MaintainSentences.h @@ -30,21 +30,27 @@ class ColumnProperty final { explicit ColumnProperty(std::string *comment = nullptr) : v_(std::unique_ptr(comment)) {} - bool isNullable() const { return std::holds_alternative(v_); } + bool isNullable() const { + return std::holds_alternative(v_); + } bool nullable() const { DCHECK(isNullable()); return std::get(v_); } - bool isDefaultValue() const { return std::holds_alternative(v_); } + bool isDefaultValue() const { + return std::holds_alternative(v_); + } const auto *defaultValue() const { DCHECK(isDefaultValue()); return std::get(v_); } - bool isComment() const { return std::holds_alternative>(v_); } + bool isComment() const { + return std::holds_alternative>(v_); + } const auto *comment() const { DCHECK(isComment()); @@ -61,9 +67,13 @@ class ColumnProperties final { public: ColumnProperties() = default; - void addProperty(ColumnProperty *property) { properties_.emplace_back(property); } + void addProperty(ColumnProperty *property) { + properties_.emplace_back(property); + } - auto &properties() const { return properties_; } + auto &properties() const { + return properties_; + } std::string toString() const { std::stringstream str; @@ -91,15 +101,25 @@ class ColumnSpecification final { typeLen_(typeLen), geoShape_(geoShape) {} - nebula::cpp2::PropertyType type() const { return type_; } + nebula::cpp2::PropertyType type() const { + return type_; + } - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } - int16_t typeLen() const { return typeLen_; } + int16_t typeLen() const { + return typeLen_; + } - meta::cpp2::GeoShape geoShape() const { return geoShape_; } + meta::cpp2::GeoShape geoShape() const { + return geoShape_; + } - auto &properties() const { return properties_; } + auto &properties() const { + return properties_; + } std::string toString() const; @@ -114,7 +134,9 @@ class ColumnSpecification final { class ColumnSpecificationList final { public: ColumnSpecificationList() = default; - void addColumn(ColumnSpecification *column) { columns_.emplace_back(column); } + void addColumn(ColumnSpecification *column) { + columns_.emplace_back(column); + } std::vector columnSpecs() const { std::vector result; @@ -134,7 +156,9 @@ class ColumnNameList final { public: ColumnNameList() = default; - void addColumn(std::string *column) { columns_.emplace_back(column); } + void addColumn(std::string *column) { + columns_.emplace_back(column); + } std::vector columnNames() const { std::vector result; @@ -209,14 +233,20 @@ class SchemaPropItem final { } } - PropType getPropType() { return propType_; } + PropType getPropType() { + return propType_; + } std::string toString() const; private: - int64_t asInt() { return boost::get(propValue_); } + int64_t asInt() { + return boost::get(propValue_); + } - const std::string &asString() { return boost::get(propValue_); } + const std::string &asString() { + return boost::get(propValue_); + } bool asBool() { switch (propValue_.which()) { @@ -232,11 +262,17 @@ class SchemaPropItem final { return false; } - bool isInt() { return propValue_.which() == 0; } + bool isInt() { + return propValue_.which() == 0; + } - bool isBool() { return propValue_.which() == 1; } + bool isBool() { + return propValue_.which() == 1; + } - bool isString() { return propValue_.which() == 2; } + bool isString() { + return propValue_.which() == 2; + } private: Value propValue_; @@ -245,7 +281,9 @@ class SchemaPropItem final { class SchemaPropList final { public: - void addOpt(SchemaPropItem *item) { items_.emplace_back(item); } + void addOpt(SchemaPropItem *item) { + items_.emplace_back(item); + } std::vector getProps() const { std::vector result; @@ -276,11 +314,17 @@ class CreateTagSentence final : public CreateSentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } - std::vector columnSpecs() const { return columns_->columnSpecs(); } + std::vector columnSpecs() const { + return columns_->columnSpecs(); + } - std::vector getSchemaProps() const { return schemaProps_->getProps(); } + std::vector getSchemaProps() const { + return schemaProps_->getProps(); + } private: std::unique_ptr name_; @@ -303,11 +347,17 @@ class CreateEdgeSentence final : public CreateSentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } - std::vector columnSpecs() const { return columns_->columnSpecs(); } + std::vector columnSpecs() const { + return columns_->columnSpecs(); + } - std::vector getSchemaProps() const { return schemaProps_->getProps(); } + std::vector getSchemaProps() const { + return schemaProps_->getProps(); + } private: std::unique_ptr name_; @@ -329,11 +379,17 @@ class AlterSchemaOptItem final { colNames_.reset(colNames); } - std::vector columnSpecs() const { return columns_->columnSpecs(); } + std::vector columnSpecs() const { + return columns_->columnSpecs(); + } - std::vector columnNames() const { return colNames_->columnNames(); } + std::vector columnNames() const { + return colNames_->columnNames(); + } - OptionType getOptType() { return optType_; } + OptionType getOptType() { + return optType_; + } nebula::meta::cpp2::AlterSchemaOp toType(); @@ -348,7 +404,9 @@ class AlterSchemaOptItem final { class AlterSchemaOptList final { public: AlterSchemaOptList() = default; - void addOpt(AlterSchemaOptItem *item) { alterSchemaItems_.emplace_back(item); } + void addOpt(AlterSchemaOptItem *item) { + alterSchemaItems_.emplace_back(item); + } std::vector alterSchemaItems() const { std::vector result; @@ -375,11 +433,17 @@ class AlterTagSentence final : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } - std::vector getSchemaOpts() const { return opts_->alterSchemaItems(); } + std::vector getSchemaOpts() const { + return opts_->alterSchemaItems(); + } - std::vector getSchemaProps() const { return schemaProps_->getProps(); } + std::vector getSchemaProps() const { + return schemaProps_->getProps(); + } private: std::unique_ptr name_; @@ -398,11 +462,17 @@ class AlterEdgeSentence final : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } - std::vector getSchemaOpts() const { return opts_->alterSchemaItems(); } + std::vector getSchemaOpts() const { + return opts_->alterSchemaItems(); + } - std::vector getSchemaProps() const { return schemaProps_->getProps(); } + std::vector getSchemaProps() const { + return schemaProps_->getProps(); + } private: std::unique_ptr name_; @@ -419,7 +489,9 @@ class DescribeTagSentence final : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -434,7 +506,9 @@ class DescribeEdgeSentence final : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -449,7 +523,9 @@ class DropTagSentence final : public DropSentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -464,7 +540,9 @@ class DropEdgeSentence final : public DropSentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -499,7 +577,9 @@ class IndexParamItem final { paramValue_ = val; } - ParamType getParamType() { return paramType_; } + ParamType getParamType() { + return paramType_; + } StatusOr getS2MaxLevel() { if (paramType_ == S2_MAX_LEVEL) { @@ -526,7 +606,9 @@ class IndexParamItem final { class IndexParamList final { public: - void add(IndexParamItem *item) { items_.emplace_back(item); } + void add(IndexParamItem *item) { + items_.emplace_back(item); + } std::vector getParams() const { std::vector result; @@ -565,9 +647,13 @@ class CreateTagIndexSentence final : public CreateSentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } - const std::string *tagName() const { return tagName_.get(); } + const std::string *tagName() const { + return tagName_.get(); + } std::vector fields() const { std::vector result; @@ -578,9 +664,13 @@ class CreateTagIndexSentence final : public CreateSentence { return result; } - const IndexParamList *getIndexParamList() const { return indexParams_.get(); } + const IndexParamList *getIndexParamList() const { + return indexParams_.get(); + } - const std::string *comment() const { return comment_.get(); } + const std::string *comment() const { + return comment_.get(); + } private: std::unique_ptr indexName_; @@ -613,9 +703,13 @@ class CreateEdgeIndexSentence final : public CreateSentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } - const std::string *edgeName() const { return edgeName_.get(); } + const std::string *edgeName() const { + return edgeName_.get(); + } std::vector fields() const { std::vector result; @@ -626,9 +720,13 @@ class CreateEdgeIndexSentence final : public CreateSentence { return result; } - const IndexParamList *getIndexParamList() const { return indexParams_.get(); } + const IndexParamList *getIndexParamList() const { + return indexParams_.get(); + } - const std::string *comment() const { return comment_.get(); } + const std::string *comment() const { + return comment_.get(); + } private: std::unique_ptr indexName_; @@ -647,7 +745,9 @@ class DescribeTagIndexSentence final : public Sentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } private: std::unique_ptr indexName_; @@ -662,7 +762,9 @@ class DescribeEdgeIndexSentence final : public Sentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } private: std::unique_ptr indexName_; @@ -677,7 +779,9 @@ class DropTagIndexSentence final : public DropSentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } private: std::unique_ptr indexName_; @@ -692,7 +796,9 @@ class DropEdgeIndexSentence final : public DropSentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } private: std::unique_ptr indexName_; @@ -700,14 +806,18 @@ class DropEdgeIndexSentence final : public DropSentence { class ShowTagsSentence : public Sentence { public: - ShowTagsSentence() { kind_ = Kind::kShowTags; } + ShowTagsSentence() { + kind_ = Kind::kShowTags; + } std::string toString() const override; }; class ShowEdgesSentence : public Sentence { public: - ShowEdgesSentence() { kind_ = Kind::kShowEdges; } + ShowEdgesSentence() { + kind_ = Kind::kShowEdges; + } std::string toString() const override; }; @@ -721,7 +831,9 @@ class ShowCreateTagSentence : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -736,7 +848,9 @@ class ShowCreateEdgeSentence : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -751,7 +865,9 @@ class ShowTagIndexesSentence : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -766,7 +882,9 @@ class ShowEdgeIndexesSentence : public Sentence { std::string toString() const override; - const std::string *name() const { return name_.get(); } + const std::string *name() const { + return name_.get(); + } private: std::unique_ptr name_; @@ -774,14 +892,18 @@ class ShowEdgeIndexesSentence : public Sentence { class ShowTagIndexStatusSentence : public Sentence { public: - ShowTagIndexStatusSentence() { kind_ = Kind::kShowTagIndexStatus; } + ShowTagIndexStatusSentence() { + kind_ = Kind::kShowTagIndexStatus; + } std::string toString() const override; }; class ShowEdgeIndexStatusSentence : public Sentence { public: - ShowEdgeIndexStatusSentence() { kind_ = Kind::kShowEdgeIndexStatus; } + ShowEdgeIndexStatusSentence() { + kind_ = Kind::kShowEdgeIndexStatus; + } std::string toString() const override; }; @@ -795,7 +917,9 @@ class ShowCreateTagIndexSentence : public Sentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } private: std::unique_ptr indexName_; @@ -810,7 +934,9 @@ class ShowCreateEdgeIndexSentence : public Sentence { std::string toString() const override; - const std::string *indexName() const { return indexName_.get(); } + const std::string *indexName() const { + return indexName_.get(); + } private: std::unique_ptr indexName_; @@ -823,7 +949,9 @@ class AddHostsSentence : public Sentence { kind_ = Kind::kAddHosts; } - const HostList *hosts() const { return hosts_.get(); } + const HostList *hosts() const { + return hosts_.get(); + } std::string toString() const override; @@ -838,7 +966,9 @@ class DropHostsSentence : public Sentence { kind_ = Kind::kDropHosts; } - const HostList *hosts() const { return hosts_.get(); } + const HostList *hosts() const { + return hosts_.get(); + } std::string toString() const override; @@ -856,9 +986,13 @@ class MergeZoneSentence : public Sentence { std::string toString() const override; - const std::string *zoneName() const { return zoneName_.get(); } + const std::string *zoneName() const { + return zoneName_.get(); + } - const ZoneNameList *zoneNames() const { return zoneNames_.get(); } + const ZoneNameList *zoneNames() const { + return zoneNames_.get(); + } private: std::unique_ptr zoneName_; @@ -874,7 +1008,9 @@ class DropZoneSentence : public Sentence { std::string toString() const override; - const std::string *zoneName() const { return zoneName_.get(); } + const std::string *zoneName() const { + return zoneName_.get(); + } private: std::unique_ptr zoneName_; @@ -890,9 +1026,13 @@ class SplitZoneSentence : public Sentence { std::string toString() const override; - const std::string *zoneName() const { return zoneName_.get(); } + const std::string *zoneName() const { + return zoneName_.get(); + } - const ZoneNameList *zoneNames() const { return zoneNames_.get(); } + const ZoneNameList *zoneNames() const { + return zoneNames_.get(); + } private: std::unique_ptr zoneName_; @@ -909,9 +1049,13 @@ class RenameZoneSentence : public Sentence { std::string toString() const override; - const std::string *originalZoneName() const { return originalZoneName_.get(); } + const std::string *originalZoneName() const { + return originalZoneName_.get(); + } - const std::string *zoneName() const { return zoneName_.get(); } + const std::string *zoneName() const { + return zoneName_.get(); + } private: std::unique_ptr originalZoneName_; @@ -927,7 +1071,9 @@ class DescribeZoneSentence : public Sentence { std::string toString() const override; - const std::string *zoneName() const { return zoneName_.get(); } + const std::string *zoneName() const { + return zoneName_.get(); + } private: std::unique_ptr zoneName_; @@ -935,7 +1081,9 @@ class DescribeZoneSentence : public Sentence { class ListZonesSentence : public Sentence { public: - ListZonesSentence() { kind_ = Kind::kListZones; } + ListZonesSentence() { + kind_ = Kind::kListZones; + } std::string toString() const override; }; @@ -949,11 +1097,17 @@ class AddHostsIntoZoneSentence : public Sentence { kind_ = Kind::kAddHostsIntoZone; } - const std::string *zoneName() const { return zoneName_.get(); } + const std::string *zoneName() const { + return zoneName_.get(); + } - const HostList *address() const { return address_.get(); } + const HostList *address() const { + return address_.get(); + } - bool isNew() const { return isNew_; } + bool isNew() const { + return isNew_; + } std::string toString() const override; @@ -981,10 +1135,16 @@ class CreateFTIndexSentence final : public Sentence { std::string toString() const override; - bool isEdge() { return isEdge_; } - const std::string *indexName() const { return indexName_.get(); } + bool isEdge() { + return isEdge_; + } + const std::string *indexName() const { + return indexName_.get(); + } - const std::string *schemaName() const { return schemaName_.get(); } + const std::string *schemaName() const { + return schemaName_.get(); + } std::vector fields() const { std::vector result; @@ -1010,7 +1170,9 @@ class DropFTIndexSentence final : public Sentence { std::string toString() const override; - const std::string *name() const { return indexName_.get(); } + const std::string *name() const { + return indexName_.get(); + } private: std::unique_ptr indexName_; @@ -1018,7 +1180,9 @@ class DropFTIndexSentence final : public Sentence { class ShowFTIndexesSentence final : public Sentence { public: - ShowFTIndexesSentence() { kind_ = Kind::kShowFTIndexes; } + ShowFTIndexesSentence() { + kind_ = Kind::kShowFTIndexes; + } std::string toString() const override; }; diff --git a/src/parser/MatchSentence.cpp b/src/parser/MatchSentence.cpp index edfd0b8357a..8e26488797a 100644 --- a/src/parser/MatchSentence.cpp +++ b/src/parser/MatchSentence.cpp @@ -234,9 +234,13 @@ std::string MatchSentence::toString() const { return buf; } -MatchPathList::MatchPathList(MatchPath* path) { pathList_.emplace_back(path); } +MatchPathList::MatchPathList(MatchPath* path) { + pathList_.emplace_back(path); +} -void MatchPathList::add(MatchPath* path) { pathList_.emplace_back(path); } +void MatchPathList::add(MatchPath* path) { + pathList_.emplace_back(path); +} std::string MatchPathList::toString() const { std::string buf; diff --git a/src/parser/MatchSentence.h b/src/parser/MatchSentence.h index 34125ca49df..4fbc49f34b1 100644 --- a/src/parser/MatchSentence.h +++ b/src/parser/MatchSentence.h @@ -18,9 +18,13 @@ class MatchEdgeTypeList final { public: MatchEdgeTypeList() = default; - void add(std::string* item) { items_.emplace_back(item); } + void add(std::string* item) { + items_.emplace_back(item); + } - auto items() && { return std::move(items_); } + auto items() && { + return std::move(items_); + } private: std::vector> items_; @@ -33,9 +37,13 @@ class MatchStepRange final { max_ = max; } - auto min() const { return min_; } + auto min() const { + return min_; + } - auto max() const { return max_; } + auto max() const { + return max_; + } std::string toString() const; @@ -86,15 +94,25 @@ class MatchEdge final { direction_ = direction; } - auto direction() const { return direction_; } + auto direction() const { + return direction_; + } - const std::string& alias() const { return alias_; } + const std::string& alias() const { + return alias_; + } - auto& types() const { return types_; } + auto& types() const { + return types_; + } - const MapExpression* props() const { return props_; } + const MapExpression* props() const { + return props_; + } - auto* range() const { return range_.get(); } + auto* range() const { + return range_.get(); + } std::string toString() const; @@ -113,11 +131,17 @@ class MatchNodeLabel final { DCHECK(props == nullptr || props->kind() == Expression::Kind::kMap); } - const std::string* label() const { return label_.get(); } + const std::string* label() const { + return label_.get(); + } - const MapExpression* props() const { return props_; } + const MapExpression* props() const { + return props_; + } - MapExpression* props() { return props_; } + MapExpression* props() { + return props_; + } std::string toString() const { std::stringstream ss; @@ -135,9 +159,13 @@ class MatchNodeLabel final { class MatchNodeLabelList final { public: - void add(MatchNodeLabel* label) { labels_.emplace_back(label); } + void add(MatchNodeLabel* label) { + labels_.emplace_back(label); + } - const auto& labels() const { return labels_; } + const auto& labels() const { + return labels_; + } std::string toString() const { std::stringstream ss; @@ -159,13 +187,21 @@ class MatchNode final { props_ = static_cast(props); } - const std::string& alias() const { return alias_; } + const std::string& alias() const { + return alias_; + } - const auto* labels() const { return labels_.get(); } + const auto* labels() const { + return labels_.get(); + } - const MapExpression* props() const { return props_; } + const MapExpression* props() const { + return props_; + } - MapExpression* props() { return props_; } + MapExpression* props() { + return props_; + } std::string toString() const; @@ -177,26 +213,42 @@ class MatchNode final { class MatchPath final { public: - explicit MatchPath(MatchNode* node) { nodes_.emplace_back(node); } + explicit MatchPath(MatchNode* node) { + nodes_.emplace_back(node); + } void add(MatchEdge* edge, MatchNode* node) { edges_.emplace_back(edge); nodes_.emplace_back(node); } - void setAlias(std::string* alias) { alias_.reset(alias); } + void setAlias(std::string* alias) { + alias_.reset(alias); + } - const std::string* alias() const { return alias_.get(); } + const std::string* alias() const { + return alias_.get(); + } - const auto& nodes() const { return nodes_; } + const auto& nodes() const { + return nodes_; + } - const auto& edges() const { return edges_; } + const auto& edges() const { + return edges_; + } - size_t steps() const { return edges_.size(); } + size_t steps() const { + return edges_.size(); + } - const MatchNode* node(size_t i) const { return nodes_[i].get(); } + const MatchNode* node(size_t i) const { + return nodes_[i].get(); + } - const MatchEdge* edge(size_t i) const { return edges_[i].get(); } + const MatchEdge* edge(size_t i) const { + return edges_[i].get(); + } std::string toString() const; @@ -212,9 +264,13 @@ class MatchPathList final { void add(MatchPath* path); - size_t pathSize() const { return pathList_.size(); } + size_t pathSize() const { + return pathList_.size(); + } - const MatchPath* path(size_t i) const { return pathList_[i].get(); } + const MatchPath* path(size_t i) const { + return pathList_[i].get(); + } std::string toString() const; @@ -227,11 +283,17 @@ class MatchReturnItems final { explicit MatchReturnItems(bool includeExisting, YieldColumns* columns = nullptr) : includeExisting_(includeExisting), columns_(columns) {} - bool includeExisting() const { return includeExisting_; } + bool includeExisting() const { + return includeExisting_; + } - YieldColumns* columns() { return columns_.get(); } + YieldColumns* columns() { + return columns_.get(); + } - const YieldColumns* columns() const { return columns_.get(); } + const YieldColumns* columns() const { + return columns_.get(); + } std::string toString() const; @@ -254,19 +316,33 @@ class MatchReturn final { isDistinct_ = distinct; } - MatchReturnItems* returnItems() { return returnItems_.get(); } + MatchReturnItems* returnItems() { + return returnItems_.get(); + } - const MatchReturnItems* returnItems() const { return returnItems_.get(); } + const MatchReturnItems* returnItems() const { + return returnItems_.get(); + } - bool isDistinct() const { return isDistinct_; } + bool isDistinct() const { + return isDistinct_; + } - const Expression* skip() const { return skip_; } + const Expression* skip() const { + return skip_; + } - const Expression* limit() const { return limit_; } + const Expression* limit() const { + return limit_; + } - OrderFactors* orderFactors() { return orderFactors_.get(); } + OrderFactors* orderFactors() { + return orderFactors_.get(); + } - const OrderFactors* orderFactors() const { return orderFactors_.get(); } + const OrderFactors* orderFactors() const { + return orderFactors_.get(); + } std::string toString() const; @@ -285,16 +361,26 @@ class ReadingClause { kUnwind, kWith, }; - explicit ReadingClause(Kind kind) { kind_ = kind; } + explicit ReadingClause(Kind kind) { + kind_ = kind; + } virtual ~ReadingClause() = default; - auto kind() const { return kind_; } + auto kind() const { + return kind_; + } - bool isMatch() const { return kind() == Kind::kMatch; } + bool isMatch() const { + return kind() == Kind::kMatch; + } - bool isUnwind() const { return kind() == Kind::kUnwind; } + bool isUnwind() const { + return kind() == Kind::kUnwind; + } - bool isWith() const { return kind() == Kind::kWith; } + bool isWith() const { + return kind() == Kind::kWith; + } virtual std::string toString() const = 0; @@ -311,15 +397,25 @@ class MatchClause final : public ReadingClause { isOptional_ = optional; } - MatchPathList* pathList() { return pathList_.get(); } + MatchPathList* pathList() { + return pathList_.get(); + } - const MatchPathList* path() const { return pathList_.get(); } + const MatchPathList* path() const { + return pathList_.get(); + } - WhereClause* where() { return where_.get(); } + WhereClause* where() { + return where_.get(); + } - const WhereClause* where() const { return where_.get(); } + const WhereClause* where() const { + return where_.get(); + } - bool isOptional() const { return isOptional_; } + bool isOptional() const { + return isOptional_; + } std::string toString() const override; @@ -336,11 +432,17 @@ class UnwindClause final : public ReadingClause { alias_ = alias; } - Expression* expr() { return expr_; } + Expression* expr() { + return expr_; + } - const Expression* expr() const { return expr_; } + const Expression* expr() const { + return expr_; + } - const std::string& alias() const { return alias_; } + const std::string& alias() const { + return alias_; + } std::string toString() const override; @@ -366,27 +468,49 @@ class WithClause final : public ReadingClause { isDistinct_ = distinct; } - MatchReturnItems* returnItems() { return returnItems_.get(); } + MatchReturnItems* returnItems() { + return returnItems_.get(); + } - const MatchReturnItems* returnItems() const { return returnItems_.get(); } + const MatchReturnItems* returnItems() const { + return returnItems_.get(); + } - OrderFactors* orderFactors() { return orderFactors_.get(); } + OrderFactors* orderFactors() { + return orderFactors_.get(); + } - const OrderFactors* orderFactors() const { return orderFactors_.get(); } + const OrderFactors* orderFactors() const { + return orderFactors_.get(); + } - Expression* skip() { return skip_; } + Expression* skip() { + return skip_; + } - const Expression* skip() const { return skip_; } + const Expression* skip() const { + return skip_; + } - Expression* limit() { return limit_; } + Expression* limit() { + return limit_; + } - const Expression* limit() const { return limit_; } + const Expression* limit() const { + return limit_; + } - WhereClause* where() { return where_.get(); } + WhereClause* where() { + return where_.get(); + } - const WhereClause* where() const { return where_.get(); } + const WhereClause* where() const { + return where_.get(); + } - bool isDistinct() const { return isDistinct_; } + bool isDistinct() const { + return isDistinct_; + } std::string toString() const override; @@ -401,7 +525,9 @@ class WithClause final : public ReadingClause { class MatchClauseList final { public: - void add(ReadingClause* clause) { clauses_.emplace_back(clause); } + void add(ReadingClause* clause) { + clauses_.emplace_back(clause); + } void add(MatchClauseList* list) { DCHECK(list != nullptr); @@ -411,7 +537,9 @@ class MatchClauseList final { delete list; } - auto clauses() && { return std::move(clauses_); } + auto clauses() && { + return std::move(clauses_); + } private: std::vector> clauses_; @@ -425,13 +553,21 @@ class MatchSentence final : public Sentence { return_.reset(ret); } - auto& clauses() { return clauses_; } + auto& clauses() { + return clauses_; + } - const auto& clauses() const { return clauses_; } + const auto& clauses() const { + return clauses_; + } - const MatchReturn* ret() const { return return_.get(); } + const MatchReturn* ret() const { + return return_.get(); + } - MatchReturn* ret() { return return_.get(); } + MatchReturn* ret() { + return return_.get(); + } std::string toString() const override; diff --git a/src/parser/MutateSentences.cpp b/src/parser/MutateSentences.cpp index 6d53030b930..077d58d1b11 100644 --- a/src/parser/MutateSentences.cpp +++ b/src/parser/MutateSentences.cpp @@ -158,7 +158,9 @@ std::string UpdateItem::toString() const { return buf; } -StatusOr UpdateItem::toEvaledString() const { return Status::Error(std::string("")); } +StatusOr UpdateItem::toEvaledString() const { + return Status::Error(std::string("")); +} std::string UpdateList::toString() const { std::string buf; @@ -286,6 +288,8 @@ std::string DownloadSentence::toString() const { "DOWNLOAD HDFS \"hdfs://%s:%d%s\"", host_.get()->c_str(), port_, path_.get()->c_str()); } -std::string IngestSentence::toString() const { return "INGEST"; } +std::string IngestSentence::toString() const { + return "INGEST"; +} } // namespace nebula diff --git a/src/parser/MutateSentences.h b/src/parser/MutateSentences.h index 58758a65b44..5016b7e9889 100644 --- a/src/parser/MutateSentences.h +++ b/src/parser/MutateSentences.h @@ -15,7 +15,9 @@ namespace nebula { class PropertyList final { public: - void addProp(std::string *propname) { properties_.emplace_back(propname); } + void addProp(std::string *propname) { + properties_.emplace_back(propname); + } std::string toString() const; @@ -40,11 +42,17 @@ class VertexTagItem final { std::string toString() const; - const std::string *tagName() const { return tagName_.get(); } + const std::string *tagName() const { + return tagName_.get(); + } - bool isDefaultPropNames() const { return defaultPropNames_; } + bool isDefaultPropNames() const { + return defaultPropNames_; + } - void setDefaultPropNames() { defaultPropNames_ = true; } + void setDefaultPropNames() { + defaultPropNames_ = true; + } std::vector properties() const { if (nullptr == properties_) { @@ -61,7 +69,9 @@ class VertexTagItem final { class VertexTagList final { public: - void addTagItem(VertexTagItem *tagItem) { tagItems_.emplace_back(tagItem); } + void addTagItem(VertexTagItem *tagItem) { + tagItems_.emplace_back(tagItem); + } std::string toString() const; @@ -80,11 +90,15 @@ class VertexTagList final { class ValueList final { public: - void addValue(Expression *value) { values_.emplace_back(value); } + void addValue(Expression *value) { + values_.emplace_back(value); + } std::string toString() const; - const std::vector &values() const { return values_; } + const std::vector &values() const { + return values_; + } private: std::vector values_; @@ -97,9 +111,13 @@ class VertexRowItem final { values_.reset(values); } - Expression *id() const { return id_; } + Expression *id() const { + return id_; + } - std::vector values() const { return values_->values(); } + std::vector values() const { + return values_->values(); + } std::string toString() const; @@ -110,7 +128,9 @@ class VertexRowItem final { class VertexRowList final { public: - void addRow(VertexRowItem *row) { rows_.emplace_back(row); } + void addRow(VertexRowItem *row) { + rows_.emplace_back(row); + } /** * For now, we haven't execution plan cache supported. @@ -147,15 +167,23 @@ class InsertVerticesSentence final : public Sentence { kind_ = Kind::kInsertVertices; } - auto tagItems() const { return tagList_->tagItems(); } + auto tagItems() const { + return tagList_->tagItems(); + } - std::vector rows() const { return rows_->rows(); } + std::vector rows() const { + return rows_->rows(); + } std::string toString() const override; - bool isIfNotExists() const { return ifNotExists_; } + bool isIfNotExists() const { + return ifNotExists_; + } - bool ignoreExistedIndex() const { return ignoreExistedIndex_; } + bool ignoreExistedIndex() const { + return ignoreExistedIndex_; + } private: bool ifNotExists_{false}; @@ -179,13 +207,21 @@ class EdgeRowItem final { values_.reset(values); } - auto srcid() const { return srcid_; } + auto srcid() const { + return srcid_; + } - auto dstid() const { return dstid_; } + auto dstid() const { + return dstid_; + } - auto rank() const { return rank_; } + auto rank() const { + return rank_; + } - std::vector values() const { return values_->values(); } + std::vector values() const { + return values_->values(); + } std::string toString() const; @@ -198,7 +234,9 @@ class EdgeRowItem final { class EdgeRowList final { public: - void addRow(EdgeRowItem *row) { rows_.emplace_back(row); } + void addRow(EdgeRowItem *row) { + rows_.emplace_back(row); + } std::vector rows() const { std::vector result; @@ -227,9 +265,13 @@ class InsertEdgesSentence final : public Sentence { ignoreExistedIndex_ = ignoreExistedIndex; } - const std::string *edge() const { return edge_.get(); } + const std::string *edge() const { + return edge_.get(); + } - void setProps(PropertyList *props) { properties_.reset(props); } + void setProps(PropertyList *props) { + properties_.reset(props); + } std::vector properties() const { if (nullptr == properties_) { @@ -238,15 +280,25 @@ class InsertEdgesSentence final : public Sentence { return properties_->properties(); } - std::vector rows() const { return rows_->rows(); } + std::vector rows() const { + return rows_->rows(); + } - bool isIfNotExists() const { return ifNotExists_; } + bool isIfNotExists() const { + return ifNotExists_; + } - bool ignoreExistedIndex() const { return ignoreExistedIndex_; } + bool ignoreExistedIndex() const { + return ignoreExistedIndex_; + } - void setDefaultPropNames() { isDefaultPropNames_ = true; } + void setDefaultPropNames() { + isDefaultPropNames_ = true; + } - bool isDefaultPropNames() const { return isDefaultPropNames_; } + bool isDefaultPropNames() const { + return isDefaultPropNames_; + } std::string toString() const override; @@ -271,11 +323,17 @@ class UpdateItem final { value_ = value; } - std::string *getFieldName() const { return fieldStr_.get(); } + std::string *getFieldName() const { + return fieldStr_.get(); + } - const Expression *getFieldExpr() const { return fieldExpr_; } + const Expression *getFieldExpr() const { + return fieldExpr_; + } - const Expression *value() const { return value_; } + const Expression *value() const { + return value_; + } std::string toString() const; @@ -292,7 +350,9 @@ class UpdateList final { UpdateList() = default; ~UpdateList() = default; - void addItem(UpdateItem *item) { items_.emplace_back(item); } + void addItem(UpdateItem *item) { + items_.emplace_back(item); + } std::vector items() const { std::vector result; @@ -327,15 +387,25 @@ class UpdateBaseSentence : public Sentence { virtual ~UpdateBaseSentence() = default; - bool getInsertable() const { return insertable_; } + bool getInsertable() const { + return insertable_; + } - const UpdateList *updateList() const { return updateList_.get(); } + const UpdateList *updateList() const { + return updateList_.get(); + } - const WhenClause *whenClause() const { return whenClause_.get(); } + const WhenClause *whenClause() const { + return whenClause_.get(); + } - const YieldClause *yieldClause() const { return yieldClause_.get(); } + const YieldClause *yieldClause() const { + return yieldClause_.get(); + } - const std::string *getName() const { return name_.get(); } + const std::string *getName() const { + return name_.get(); + } protected: bool insertable_{false}; @@ -370,15 +440,25 @@ class UpdateVertexSentence final : public UpdateBaseSentence { ~UpdateVertexSentence() {} - bool getInsertable() const { return insertable_; } + bool getInsertable() const { + return insertable_; + } - Expression *getVid() const { return vid_; } + Expression *getVid() const { + return vid_; + } - const UpdateList *updateList() const { return updateList_.get(); } + const UpdateList *updateList() const { + return updateList_.get(); + } - const WhenClause *whenClause() const { return whenClause_.get(); } + const WhenClause *whenClause() const { + return whenClause_.get(); + } - const YieldClause *yieldClause() const { return yieldClause_.get(); } + const YieldClause *yieldClause() const { + return yieldClause_.get(); + } std::string toString() const override; @@ -403,11 +483,17 @@ class UpdateEdgeSentence final : public UpdateBaseSentence { rank_ = rank; } - Expression *getSrcId() const { return srcId_; } + Expression *getSrcId() const { + return srcId_; + } - Expression *getDstId() const { return dstId_; } + Expression *getDstId() const { + return dstId_; + } - int64_t getRank() const { return rank_; } + int64_t getRank() const { + return rank_; + } std::string toString() const override; @@ -427,10 +513,14 @@ class DeleteVerticesSentence final : public Sentence { DeleteVerticesSentence(Expression *ref, bool withEdge) : Sentence(Kind::kDeleteVertices), vertices_(new VerticesClause(ref)), withEdge_(withEdge) {} - const VerticesClause *vertices() const { return vertices_.get(); } + const VerticesClause *vertices() const { + return vertices_.get(); + } std::string toString() const override; - bool withEdge() const { return withEdge_; } + bool withEdge() const { + return withEdge_; + } private: std::unique_ptr vertices_; @@ -463,11 +553,17 @@ class DeleteTagsSentence final : public Sentence { tags_ = std::make_unique(); } - const VerticesClause *vertices() const { return vertices_.get(); } + const VerticesClause *vertices() const { + return vertices_.get(); + } - const NameLabelList *tags() const { return tags_.get(); } + const NameLabelList *tags() const { + return tags_.get(); + } - bool isAllTag() { return tags_->empty(); } + bool isAllTag() { + return tags_->empty(); + } std::string toString() const override; @@ -490,13 +586,21 @@ class DeleteEdgesSentence final : public Sentence { kind_ = Kind::kDeleteEdges; } - const std::string *edge() const { return edge_.get(); } + const std::string *edge() const { + return edge_.get(); + } - EdgeKeys *edgeKeys() const { return edgeKeys_.get(); } + EdgeKeys *edgeKeys() const { + return edgeKeys_.get(); + } - EdgeKeyRef *edgeKeyRef() const { return edgeKeyRef_.get(); } + EdgeKeyRef *edgeKeyRef() const { + return edgeKeyRef_.get(); + } - bool isRef() const { return edgeKeyRef_ != nullptr; } + bool isRef() const { + return edgeKeyRef_ != nullptr; + } std::string toString() const override; @@ -508,15 +612,25 @@ class DeleteEdgesSentence final : public Sentence { class DownloadSentence final : public Sentence { public: - DownloadSentence() { kind_ = Kind::kDownload; } + DownloadSentence() { + kind_ = Kind::kDownload; + } - const std::string *host() const { return host_.get(); } + const std::string *host() const { + return host_.get(); + } - int32_t port() const { return port_; } + int32_t port() const { + return port_; + } - void setPort(int32_t port) { port_ = port; } + void setPort(int32_t port) { + port_ = port; + } - const std::string *path() const { return path_.get(); } + const std::string *path() const { + return path_.get(); + } void setUrl(std::string &url) { static std::string hdfsPrefix = "hdfs://"; @@ -558,7 +672,9 @@ class DownloadSentence final : public Sentence { class IngestSentence final : public Sentence { public: - IngestSentence() { kind_ = Kind::kIngest; } + IngestSentence() { + kind_ = Kind::kIngest; + } std::string toString() const override; }; diff --git a/src/parser/ProcessControlSentences.h b/src/parser/ProcessControlSentences.h index cef5a538679..79feb3130c2 100644 --- a/src/parser/ProcessControlSentences.h +++ b/src/parser/ProcessControlSentences.h @@ -16,9 +16,13 @@ class ReturnSentence final : public Sentence { condition_.reset(condition); } - std::string* condition() const { return condition_.get(); } + std::string* condition() const { + return condition_.get(); + } - std::string* var() const { return var_.get(); } + std::string* var() const { + return var_.get(); + } std::string toString() const override; diff --git a/src/parser/Sentence.h b/src/parser/Sentence.h index 4e27150d368..57bb3c9c09e 100644 --- a/src/parser/Sentence.h +++ b/src/parser/Sentence.h @@ -134,7 +134,9 @@ class Sentence { kShowMetaLeader, }; - Kind kind() const { return kind_; } + Kind kind() const { + return kind_; + } protected: Sentence() = default; @@ -148,7 +150,9 @@ class CreateSentence : public Sentence { explicit CreateSentence(bool ifNotExist) : ifNotExist_{ifNotExist} {} virtual ~CreateSentence() {} - bool isIfNotExist() const { return ifNotExist_; } + bool isIfNotExist() const { + return ifNotExist_; + } private: bool ifNotExist_{false}; @@ -159,7 +163,9 @@ class DropSentence : public Sentence { explicit DropSentence(bool ifExists) : ifExists_{ifExists} {} virtual ~DropSentence() = default; - bool isIfExists() { return ifExists_; } + bool isIfExists() { + return ifExists_; + } private: bool ifExists_{false}; @@ -167,7 +173,9 @@ class DropSentence : public Sentence { class HostList final { public: - void addHost(HostAddr *addr) { hosts_.emplace_back(addr); } + void addHost(HostAddr *addr) { + hosts_.emplace_back(addr); + } std::string toString() const; @@ -192,7 +200,9 @@ class ZoneNameList final { public: ZoneNameList() = default; - void addZone(std::string *zone) { zones_.emplace_back(zone); } + void addZone(std::string *zone) { + zones_.emplace_back(zone); + } std::vector zoneNames() const { std::vector result; diff --git a/src/parser/SequentialSentences.h b/src/parser/SequentialSentences.h index 5cf192b26a5..fed91f10ce1 100644 --- a/src/parser/SequentialSentences.h +++ b/src/parser/SequentialSentences.h @@ -24,7 +24,9 @@ class SequentialSentences final : public Sentence { sentences_.emplace_back(sentence); } - void addSentence(Sentence *sentence) { sentences_.emplace_back(sentence); } + void addSentence(Sentence *sentence) { + sentences_.emplace_back(sentence); + } auto sentences() const { std::vector result; @@ -34,6 +36,10 @@ class SequentialSentences final : public Sentence { return result; } + size_t numSentences() const { + return sentences_.size(); + } + std::string toString() const override; private: diff --git a/src/parser/TraverseSentences.cpp b/src/parser/TraverseSentences.cpp index 037faf56fa4..24a613f215f 100644 --- a/src/parser/TraverseSentences.cpp +++ b/src/parser/TraverseSentences.cpp @@ -61,7 +61,9 @@ std::string LookupSentence::toString() const { return buf; } -std::string UseSentence::toString() const { return "USE " + *space_; } +std::string UseSentence::toString() const { + return "USE " + *space_; +} std::string SetSentence::toString() const { std::string buf; diff --git a/src/parser/TraverseSentences.h b/src/parser/TraverseSentences.h index d0c416d1913..9b685e1713d 100644 --- a/src/parser/TraverseSentences.h +++ b/src/parser/TraverseSentences.h @@ -27,25 +27,45 @@ class GoSentence final : public Sentence { truncateClause_.reset(truncate); } - void setYieldClause(YieldClause* clause) { yieldClause_.reset(clause); } + void setYieldClause(YieldClause* clause) { + yieldClause_.reset(clause); + } - const StepClause* stepClause() const { return stepClause_.get(); } + const StepClause* stepClause() const { + return stepClause_.get(); + } - const FromClause* fromClause() const { return fromClause_.get(); } + const FromClause* fromClause() const { + return fromClause_.get(); + } - const OverClause* overClause() const { return overClause_.get(); } + const OverClause* overClause() const { + return overClause_.get(); + } - const WhereClause* whereClause() const { return whereClause_.get(); } + const WhereClause* whereClause() const { + return whereClause_.get(); + } - WhereClause* whereClause() { return whereClause_.get(); } + WhereClause* whereClause() { + return whereClause_.get(); + } - const YieldClause* yieldClause() const { return yieldClause_.get(); } + const YieldClause* yieldClause() const { + return yieldClause_.get(); + } - YieldClause* yieldClause() { return yieldClause_.get(); } + YieldClause* yieldClause() { + return yieldClause_.get(); + } - const TruncateClause* truncateClause() const { return truncateClause_.get(); } + const TruncateClause* truncateClause() const { + return truncateClause_.get(); + } - TruncateClause* truncateClause() { return truncateClause_.get(); } + TruncateClause* truncateClause() { + return truncateClause_.get(); + } std::string toString() const override; @@ -62,11 +82,17 @@ class LookupSentence final : public Sentence { public: LookupSentence(std::string* from, WhereClause* where, YieldClause* yield); - const std::string& from() const { return *from_; } + const std::string& from() const { + return *from_; + } - const WhereClause* whereClause() const { return whereClause_.get(); } + const WhereClause* whereClause() const { + return whereClause_.get(); + } - const YieldClause* yieldClause() const { return yieldClause_.get(); } + const YieldClause* yieldClause() const { + return yieldClause_.get(); + } std::string toString() const override; @@ -83,7 +109,9 @@ class UseSentence final : public Sentence { space_.reset(space); } - const std::string* space() const { return space_.get(); } + const std::string* space() const { + return space_.get(); + } std::string toString() const override; @@ -104,15 +132,25 @@ class SetSentence final : public Sentence { std::string toString() const override; - auto left() { return left_.get(); } + auto left() { + return left_.get(); + } - auto right() { return right_.get(); } + auto right() { + return right_.get(); + } - Operator op() const { return op_; } + Operator op() const { + return op_; + } - void setDistinct() { distinct_ = true; } + void setDistinct() { + distinct_ = true; + } - bool distinct() const { return distinct_; } + bool distinct() const { + return distinct_; + } private: Operator op_; @@ -129,9 +167,13 @@ class PipedSentence final : public Sentence { right_.reset(right); } - Sentence* left() const { return left_.get(); } + Sentence* left() const { + return left_.get(); + } - Sentence* right() const { return right_.get(); } + Sentence* right() const { + return right_.get(); + } std::string toString() const override; @@ -148,9 +190,13 @@ class AssignmentSentence final : public Sentence { sentence_.reset(sentence); } - const std::string* var() const { return variable_.get(); } + const std::string* var() const { + return variable_.get(); + } - Sentence* sentence() const { return sentence_.get(); } + Sentence* sentence() const { + return sentence_.get(); + } std::string toString() const override; @@ -168,11 +214,17 @@ class OrderFactor final { orderType_ = op; } - Expression* expr() { return expr_; } + Expression* expr() { + return expr_; + } - void setExpr(Expression* expr) { expr_ = expr; } + void setExpr(Expression* expr) { + expr_ = expr; + } - OrderType orderType() { return orderType_; } + OrderType orderType() { + return orderType_; + } std::string toString() const; @@ -183,11 +235,17 @@ class OrderFactor final { class OrderFactors final { public: - void addFactor(OrderFactor* factor) { factors_.emplace_back(factor); } + void addFactor(OrderFactor* factor) { + factors_.emplace_back(factor); + } - auto& factors() { return factors_; } + auto& factors() { + return factors_; + } - const auto& factors() const { return factors_; } + const auto& factors() const { + return factors_; + } std::string toString() const; @@ -202,9 +260,13 @@ class OrderBySentence final : public Sentence { kind_ = Kind::kOrderBy; } - auto& factors() { return orderFactors_->factors(); } + auto& factors() { + return orderFactors_->factors(); + } - const auto& factors() const { return orderFactors_->factors(); } + const auto& factors() const { + return orderFactors_->factors(); + } std::string toString() const override; @@ -242,13 +304,21 @@ class FetchVerticesSentence final : public Sentence { yieldClause_.reset(clause); } - const NameLabelList* tags() const { return tags_->empty() ? nullptr : tags_.get(); } + const NameLabelList* tags() const { + return tags_->empty() ? nullptr : tags_.get(); + } - const VerticesClause* vertices() const { return vertices_.get(); } + const VerticesClause* vertices() const { + return vertices_.get(); + } - YieldClause* yieldClause() const { return yieldClause_.get(); } + YieldClause* yieldClause() const { + return yieldClause_.get(); + } - void setYieldClause(YieldClause* clause) { yieldClause_.reset(clause); } + void setYieldClause(YieldClause* clause) { + yieldClause_.reset(clause); + } std::string toString() const override; @@ -274,23 +344,41 @@ class FetchEdgesSentence final : public Sentence { yieldClause_.reset(clause); } - bool isRef() const { return keyRef_ != nullptr; } + bool isRef() const { + return keyRef_ != nullptr; + } - void setKeyRef(EdgeKeyRef* ref) { keyRef_.reset(ref); } + void setKeyRef(EdgeKeyRef* ref) { + keyRef_.reset(ref); + } - EdgeKeyRef* ref() const { return keyRef_.get(); } + EdgeKeyRef* ref() const { + return keyRef_.get(); + } - void setKeys(EdgeKeys* keys) { edgeKeys_.reset(keys); } + void setKeys(EdgeKeys* keys) { + edgeKeys_.reset(keys); + } - EdgeKeys* keys() const { return edgeKeys_.get(); } + EdgeKeys* keys() const { + return edgeKeys_.get(); + } - void setYieldClause(YieldClause* clause) { yieldClause_.reset(clause); } + void setYieldClause(YieldClause* clause) { + yieldClause_.reset(clause); + } - YieldClause* yieldClause() const { return yieldClause_.get(); } + YieldClause* yieldClause() const { + return yieldClause_.get(); + } - const std::string& edgeName() const { return *edge_->front(); } + const std::string& edgeName() const { + return *edge_->front(); + } - std::size_t edgeSize() const { return edge_->size(); } + std::size_t edgeSize() const { + return edge_->size(); + } std::string toString() const override; @@ -310,35 +398,65 @@ class FindPathSentence final : public Sentence { noLoop_ = noLoop; } - void setFrom(FromClause* clause) { from_.reset(clause); } + void setFrom(FromClause* clause) { + from_.reset(clause); + } - void setTo(ToClause* clause) { to_.reset(clause); } + void setTo(ToClause* clause) { + to_.reset(clause); + } - void setOver(OverClause* clause) { over_.reset(clause); } + void setOver(OverClause* clause) { + over_.reset(clause); + } - void setStep(StepClause* clause) { step_.reset(clause); } + void setStep(StepClause* clause) { + step_.reset(clause); + } - void setWhere(WhereClause* clause) { where_.reset(clause); } + void setWhere(WhereClause* clause) { + where_.reset(clause); + } - void setYield(YieldClause* yield) { yield_.reset(yield); } + void setYield(YieldClause* yield) { + yield_.reset(yield); + } - FromClause* from() const { return from_.get(); } + FromClause* from() const { + return from_.get(); + } - ToClause* to() const { return to_.get(); } + ToClause* to() const { + return to_.get(); + } - OverClause* over() const { return over_.get(); } + OverClause* over() const { + return over_.get(); + } - StepClause* step() const { return step_.get(); } + StepClause* step() const { + return step_.get(); + } - WhereClause* where() const { return where_.get(); } + WhereClause* where() const { + return where_.get(); + } - YieldClause* yield() const { return yield_.get(); } + YieldClause* yield() const { + return yield_.get(); + } - bool isShortest() const { return isShortest_; } + bool isShortest() const { + return isShortest_; + } - bool withProp() const { return withProp_; } + bool withProp() const { + return withProp_; + } - bool noLoop() const { return noLoop_; } + bool noLoop() const { + return noLoop_; + } std::string toString() const override; @@ -362,9 +480,13 @@ class LimitSentence final : public Sentence { std::string toString() const override; - int64_t offset() { return offset_; } + int64_t offset() { + return offset_; + } - int64_t count() { return count_; } + int64_t count() { + return count_; + } private: int64_t offset_{-1}; @@ -379,15 +501,25 @@ class YieldSentence final : public Sentence { kind_ = Kind::kYield; } - std::vector columns() const { return yieldClause_->columns(); } + std::vector columns() const { + return yieldClause_->columns(); + } - YieldColumns* yieldColumns() const { return yieldClause_->yields(); } + YieldColumns* yieldColumns() const { + return yieldClause_->yields(); + } - void setWhereClause(WhereClause* clause) { whereClause_.reset(clause); } + void setWhereClause(WhereClause* clause) { + whereClause_.reset(clause); + } - WhereClause* where() const { return whereClause_.get(); } + WhereClause* where() const { + return whereClause_.get(); + } - YieldClause* yield() const { return yieldClause_.get(); } + YieldClause* yield() const { + return yieldClause_.get(); + } std::string toString() const override; @@ -407,17 +539,29 @@ class GroupBySentence final : public Sentence { groupClause_.reset(groupby); } - void setGroupClause(GroupClause* clause) { groupClause_.reset(clause); } + void setGroupClause(GroupClause* clause) { + groupClause_.reset(clause); + } - void setHavingClause(WhereClause* clause) { havingClause_.reset(clause); } + void setHavingClause(WhereClause* clause) { + havingClause_.reset(clause); + } - void setYieldClause(YieldClause* clause) { yieldClause_.reset(clause); } + void setYieldClause(YieldClause* clause) { + yieldClause_.reset(clause); + } - const GroupClause* groupClause() const { return groupClause_.get(); } + const GroupClause* groupClause() const { + return groupClause_.get(); + } - const WhereClause* havingClause() const { return havingClause_.get(); } + const WhereClause* havingClause() const { + return havingClause_.get(); + } - const YieldClause* yieldClause() const { return yieldClause_.get(); } + const YieldClause* yieldClause() const { + return yieldClause_.get(); + } std::string toString() const override; @@ -446,19 +590,33 @@ class GetSubgraphSentence final : public Sentence { yield_.reset(yield); } - StepClause* step() const { return step_.get(); } + StepClause* step() const { + return step_.get(); + } - bool withProp() const { return withProp_; } + bool withProp() const { + return withProp_; + } - FromClause* from() const { return from_.get(); } + FromClause* from() const { + return from_.get(); + } - InBoundClause* in() const { return in_.get(); } + InBoundClause* in() const { + return in_.get(); + } - OutBoundClause* out() const { return out_.get(); } + OutBoundClause* out() const { + return out_.get(); + } - BothInOutClause* both() const { return both_.get(); } + BothInOutClause* both() const { + return both_.get(); + } - YieldClause* yield() const { return yield_.get(); } + YieldClause* yield() const { + return yield_.get(); + } std::string toString() const override; diff --git a/src/parser/UserSentences.h b/src/parser/UserSentences.h index 7f30bc4a6fd..cb8c51a3fad 100644 --- a/src/parser/UserSentences.h +++ b/src/parser/UserSentences.h @@ -16,9 +16,13 @@ class RoleTypeClause final { public: using RoleType = meta::cpp2::RoleType; - explicit RoleTypeClause(RoleType roleType) { roleType_ = roleType; } + explicit RoleTypeClause(RoleType roleType) { + roleType_ = roleType; + } - RoleType getRoleType() const { return roleType_; } + RoleType getRoleType() const { + return roleType_; + } std::string toString() const; @@ -34,13 +38,21 @@ class AclItemClause final { spaceName_.reset(spaceName); } - bool isSet() const { return isSet_; } + bool isSet() const { + return isSet_; + } - void setRoleTypeClause(RoleTypeClause* type) { type_.reset(type); } + void setRoleTypeClause(RoleTypeClause* type) { + type_.reset(type); + } - RoleTypeClause::RoleType getRoleType() const { return type_->getRoleType(); } + RoleTypeClause::RoleType getRoleType() const { + return type_->getRoleType(); + } - const std::string* getSpaceName() const { return spaceName_.get(); } + const std::string* getSpaceName() const { + return spaceName_.get(); + } std::string toString() const; @@ -59,11 +71,17 @@ class CreateUserSentence final : public Sentence { kind_ = Kind::kCreateUser; } - const std::string* getAccount() const { return account_.get(); } + const std::string* getAccount() const { + return account_.get(); + } - const std::string* getPassword() const { return password_.get(); } + const std::string* getPassword() const { + return password_.get(); + } - bool ifNotExists() const { return ifNotExists_; } + bool ifNotExists() const { + return ifNotExists_; + } std::string toString() const override; @@ -81,9 +99,13 @@ class AlterUserSentence final : public Sentence { kind_ = Kind::kAlterUser; } - const std::string* getAccount() const { return account_.get(); } + const std::string* getAccount() const { + return account_.get(); + } - const std::string* getPassword() const { return password_.get(); } + const std::string* getPassword() const { + return password_.get(); + } std::string toString() const override; @@ -100,9 +122,13 @@ class DropUserSentence final : public Sentence { kind_ = Kind::kDropUser; } - bool ifExists() const { return ifExists_; } + bool ifExists() const { + return ifExists_; + } - const std::string* getAccount() const { return account_.get(); } + const std::string* getAccount() const { + return account_.get(); + } std::string toString() const override; @@ -120,11 +146,17 @@ class ChangePasswordSentence final : public Sentence { kind_ = Kind::kChangePassword; } - const std::string* getAccount() const { return account_.get(); } + const std::string* getAccount() const { + return account_.get(); + } - const std::string* getNewPwd() const { return newPwd_.get(); } + const std::string* getNewPwd() const { + return newPwd_.get(); + } - const std::string* getOldPwd() const { return oldPwd_.get(); } + const std::string* getOldPwd() const { + return oldPwd_.get(); + } std::string toString() const override; @@ -141,11 +173,17 @@ class GrantSentence final : public Sentence { kind_ = Kind::kGrant; } - void setAclItemClause(AclItemClause* aclItemClause) { aclItemClause_.reset(aclItemClause); } + void setAclItemClause(AclItemClause* aclItemClause) { + aclItemClause_.reset(aclItemClause); + } - const AclItemClause* getAclItemClause() const { return aclItemClause_.get(); } + const AclItemClause* getAclItemClause() const { + return aclItemClause_.get(); + } - const std::string* getAccount() const { return account_.get(); } + const std::string* getAccount() const { + return account_.get(); + } std::string toString() const override; @@ -161,13 +199,21 @@ class RevokeSentence final : public Sentence { kind_ = Kind::kRevoke; } - void setAclItemClause(AclItemClause* aclItemClause) { aclItemClause_.reset(aclItemClause); } + void setAclItemClause(AclItemClause* aclItemClause) { + aclItemClause_.reset(aclItemClause); + } - const AclItemClause* getAclItemClause() const { return aclItemClause_.get(); } + const AclItemClause* getAclItemClause() const { + return aclItemClause_.get(); + } - AclItemClause* mutableAclItemClause() { return aclItemClause_.get(); } + AclItemClause* mutableAclItemClause() { + return aclItemClause_.get(); + } - const std::string* getAccount() const { return account_.get(); } + const std::string* getAccount() const { + return account_.get(); + } std::string toString() const override; diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 9026f103761..013c238d3d4 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -3,7 +3,7 @@ %no-lines %locations %define api.namespace { nebula } -%define parser_class_name { GraphParser } +%define api.parser.class { GraphParser } %lex-param { nebula::GraphScanner& scanner } %parse-param { nebula::GraphScanner& scanner } %parse-param { std::string &errmsg } @@ -1156,77 +1156,77 @@ geo_shape_type type_spec : KW_BOOL { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::BOOL); + $$->type_ref() = nebula::cpp2::PropertyType::BOOL; } | KW_INT8 { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::INT8); + $$->type_ref() = nebula::cpp2::PropertyType::INT8; } | KW_INT16 { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::INT16); + $$->type_ref() = nebula::cpp2::PropertyType::INT16; } | KW_INT32 { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::INT32); + $$->type_ref() = nebula::cpp2::PropertyType::INT32; } | KW_INT64 { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::INT64); + $$->type_ref() = nebula::cpp2::PropertyType::INT64; } | KW_INT { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::INT64); + $$->type_ref() = nebula::cpp2::PropertyType::INT64; } | KW_FLOAT { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::FLOAT); + $$->type_ref() = nebula::cpp2::PropertyType::FLOAT; } | KW_DOUBLE { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::DOUBLE); + $$->type_ref() = nebula::cpp2::PropertyType::DOUBLE; } | KW_STRING { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::STRING); + $$->type_ref() = nebula::cpp2::PropertyType::STRING; } | KW_FIXED_STRING L_PAREN INTEGER R_PAREN { if ($3 > std::numeric_limits::max()) { throw nebula::GraphParser::syntax_error(@3, "Out of range:"); } $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::FIXED_STRING); - $$->set_type_length($3); + $$->type_ref() = nebula::cpp2::PropertyType::FIXED_STRING; + $$->type_length_ref() = $3; } | KW_TIMESTAMP { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::TIMESTAMP); + $$->type_ref() = nebula::cpp2::PropertyType::TIMESTAMP; } | KW_DATE { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::DATE); + $$->type_ref() = nebula::cpp2::PropertyType::DATE; } | KW_TIME { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::TIME); + $$->type_ref() = nebula::cpp2::PropertyType::TIME; } | KW_DATETIME { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::DATETIME); + $$->type_ref() = nebula::cpp2::PropertyType::DATETIME; } | KW_GEOGRAPHY { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::GEOGRAPHY); - $$->set_geo_shape(meta::cpp2::GeoShape::ANY); + $$->type_ref() = nebula::cpp2::PropertyType::GEOGRAPHY; + $$->geo_shape_ref() = meta::cpp2::GeoShape::ANY; } | KW_GEOGRAPHY L_PAREN geo_shape_type R_PAREN { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::GEOGRAPHY); - $$->set_geo_shape($3); + $$->type_ref() = nebula::cpp2::PropertyType::GEOGRAPHY; + $$->geo_shape_ref() = $3; } | KW_DURATION { $$ = new meta::cpp2::ColumnTypeDef(); - $$->set_type(nebula::cpp2::PropertyType::DURATION); + $$->type_ref() = nebula::cpp2::PropertyType::DURATION; } ; @@ -1389,7 +1389,7 @@ vid throw nebula::GraphParser::syntax_error(@1, "Parameter is not supported in vid"); } else { throw nebula::GraphParser::syntax_error(@1, "Variable is not supported in vid"); - } + } } ; @@ -1910,46 +1910,46 @@ match_limit text_search_client_item : L_PAREN host_item R_PAREN { $$ = new nebula::meta::cpp2::FTClient(); - $$->set_host(*$2); + $$->host_ref() = *$2; delete $2; } | L_PAREN host_item COMMA KW_HTTP R_PAREN { $$ = new nebula::meta::cpp2::FTClient(); - $$->set_host(*$2); - $$->set_conn_type("http"); + $$->host_ref() = *$2; + $$->conn_type_ref() = "http"; delete $2; } | L_PAREN host_item COMMA KW_HTTPS R_PAREN { $$ = new nebula::meta::cpp2::FTClient(); - $$->set_host(*$2); - $$->set_conn_type("https"); + $$->host_ref() = *$2; + $$->conn_type_ref() = "https"; delete $2; } | L_PAREN host_item COMMA STRING COMMA STRING R_PAREN { $$ = new nebula::meta::cpp2::FTClient(); - $$->set_host(*$2); - $$->set_user(*$4); - $$->set_pwd(*$6); + $$->host_ref() = *$2; + $$->user_ref() = *$4; + $$->pwd_ref() = *$6; delete $2; delete $4; delete $6; } | L_PAREN host_item COMMA KW_HTTP COMMA STRING COMMA STRING R_PAREN { $$ = new nebula::meta::cpp2::FTClient(); - $$->set_host(*$2); - $$->set_user(*$6); - $$->set_pwd(*$8); - $$->set_conn_type("http"); + $$->host_ref() = *$2; + $$->user_ref() = *$6; + $$->pwd_ref() = *$8; + $$->conn_type_ref() = "http"; delete $2; delete $6; delete $8; } | L_PAREN host_item COMMA KW_HTTPS COMMA STRING COMMA STRING R_PAREN { $$ = new nebula::meta::cpp2::FTClient(); - $$->set_host(*$2); - $$->set_user(*$6); - $$->set_pwd(*$8); - $$->set_conn_type("https"); + $$->host_ref() = *$2; + $$->user_ref() = *$6; + $$->pwd_ref() = *$8; + $$->conn_type_ref() = "https"; delete $2; delete $6; delete $8; @@ -2587,7 +2587,7 @@ drop_edge_sentence index_field : name_label { $$ = new meta::cpp2::IndexFieldDef(); - $$->set_name($1->c_str()); + $$->name_ref() = $1->c_str(); delete $1; } | name_label L_PAREN INTEGER R_PAREN { @@ -2595,8 +2595,8 @@ index_field throw nebula::GraphParser::syntax_error(@3, "Out of range:"); } $$ = new meta::cpp2::IndexFieldDef(); - $$->set_name($1->c_str()); - $$->set_type_length($3); + $$->name_ref() = $1->c_str(); + $$->type_length_ref() = $3; delete $1; } ; diff --git a/src/parser/test/CMakeLists.txt b/src/parser/test/CMakeLists.txt index 8a08473f042..755d2c7a350 100644 --- a/src/parser/test/CMakeLists.txt +++ b/src/parser/test/CMakeLists.txt @@ -9,6 +9,9 @@ set(PARSER_TEST_LIBS $ $ $ + $ + $ + $ $ $ $ diff --git a/src/parser/test/ExpressionParsingTest.cpp b/src/parser/test/ExpressionParsingTest.cpp index d8f9e4e1bfd..e12e88420b2 100644 --- a/src/parser/test/ExpressionParsingTest.cpp +++ b/src/parser/test/ExpressionParsingTest.cpp @@ -38,7 +38,9 @@ class ExpressionParsingTest : public ::testing::Test { return expr_; } - void add(std::string expr, Expression *ast) { items_.emplace_back(std::move(expr), ast); } + void add(std::string expr, Expression *ast) { + items_.emplace_back(std::move(expr), ast); + } void run() { if (items_.empty()) { diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index 21908cd2aec..22e4cbdd0f8 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -14,8 +14,12 @@ namespace nebula { using graph::QueryContext; class ParserTest : public ::testing::Test { public: - void SetUp() override { qctx_ = std::make_unique(); } - void TearDown() override { qctx_.reset(); } + void SetUp() override { + qctx_ = std::make_unique(); + } + void TearDown() override { + qctx_.reset(); + } protected: StatusOr> parse(const std::string& query) { diff --git a/src/storage/BaseProcessor-inl.h b/src/storage/BaseProcessor-inl.h index acfb5bc2474..ae9c62bd673 100644 --- a/src/storage/BaseProcessor-inl.h +++ b/src/storage/BaseProcessor-inl.h @@ -60,8 +60,8 @@ template meta::cpp2::ColumnDef BaseProcessor::columnDef(std::string name, nebula::cpp2::PropertyType type) { nebula::meta::cpp2::ColumnDef column; - column.set_name(std::move(name)); - column.set_type(type); + column.name_ref() = std::move(name); + column.type_ref() = type; return column; } @@ -71,10 +71,10 @@ void BaseProcessor::pushResultCode(nebula::cpp2::ErrorCode code, HostAddr leader) { if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { cpp2::PartitionResult thriftRet; - thriftRet.set_code(code); - thriftRet.set_part_id(partId); + thriftRet.code_ref() = code; + thriftRet.part_id_ref() = partId; if (leader != HostAddr("", 0)) { - thriftRet.set_leader(leader); + thriftRet.leader_ref() = leader; } codes_.emplace_back(std::move(thriftRet)); } diff --git a/src/storage/BaseProcessor.h b/src/storage/BaseProcessor.h index 3d50de29abd..bc64c5bfa73 100644 --- a/src/storage/BaseProcessor.h +++ b/src/storage/BaseProcessor.h @@ -30,7 +30,9 @@ class BaseProcessor { virtual ~BaseProcessor() = default; - folly::Future getFuture() { return promise_.getFuture(); } + folly::Future getFuture() { + return promise_.getFuture(); + } protected: virtual void onFinished() { @@ -41,12 +43,12 @@ class BaseProcessor { } } - this->result_.set_latency_in_us(this->duration_.elapsedInUSec()); + this->result_.latency_in_us_ref() = this->duration_.elapsedInUSec(); if (!profileDetail_.empty()) { - this->result_.set_latency_detail_us(std::move(profileDetail_)); + this->result_.latency_detail_us_ref() = std::move(profileDetail_); } - this->result_.set_failed_parts(this->codes_); - this->resp_.set_result(std::move(this->result_)); + this->result_.failed_parts_ref() = this->codes_; + this->resp_.result_ref() = std::move(this->result_); this->promise_.setValue(std::move(this->resp_)); if (counters_) { diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index 4f263476edc..b4b71d961a7 100644 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -21,7 +21,6 @@ nebula_add_library( admin/RebuildEdgeIndexTask.cpp admin/RebuildFTIndexTask.cpp admin/StatsTask.cpp - admin/ListClusterInfoProcessor.cpp ) nebula_add_library( @@ -90,4 +89,5 @@ nebula_add_library( StorageServer.cpp ) +nebula_add_subdirectory(stats) nebula_add_subdirectory(test) diff --git a/src/storage/CommonUtils.h b/src/storage/CommonUtils.h index 66479abb766..fba3ea6f6b5 100644 --- a/src/storage/CommonUtils.h +++ b/src/storage/CommonUtils.h @@ -91,9 +91,13 @@ class StorageEnv { return IndexState::FINISHED; } - bool checkRebuilding(IndexState indexState) { return indexState == IndexState::BUILDING; } + bool checkRebuilding(IndexState indexState) { + return indexState == IndexState::BUILDING; + } - bool checkIndexLocked(IndexState indexState) { return indexState == IndexState::LOCKED; } + bool checkIndexLocked(IndexState indexState) { + return indexState == IndexState::LOCKED; + } }; class IndexCountWrapper { @@ -118,7 +122,9 @@ class IndexCountWrapper { return *this; } - ~IndexCountWrapper() { count_->fetch_sub(1, std::memory_order_release); } + ~IndexCountWrapper() { + count_->fetch_sub(1, std::memory_order_release); + } private: std::atomic* count_; @@ -187,17 +193,29 @@ class PlanContext { struct RuntimeContext { explicit RuntimeContext(PlanContext* planContext) : planContext_(planContext) {} - StorageEnv* env() const { return planContext_->env_; } + StorageEnv* env() const { + return planContext_->env_; + } - GraphSpaceID spaceId() const { return planContext_->spaceId_; } + GraphSpaceID spaceId() const { + return planContext_->spaceId_; + } - size_t vIdLen() const { return planContext_->vIdLen_; } + size_t vIdLen() const { + return planContext_->vIdLen_; + } - bool isIntId() const { return planContext_->isIntId_; } + bool isIntId() const { + return planContext_->isIntId_; + } - bool isEdge() const { return planContext_->isEdge_; } + bool isEdge() const { + return planContext_->isEdge_; + } - ObjectPool* objPool() { return &planContext_->objPool_; } + ObjectPool* objPool() { + return &planContext_->objPool_; + } bool isPlanKilled() { if (env() == nullptr) { diff --git a/src/storage/CompactionFilter.h b/src/storage/CompactionFilter.h index 9041ab47b9d..585077e36fe 100644 --- a/src/storage/CompactionFilter.h +++ b/src/storage/CompactionFilter.h @@ -186,7 +186,9 @@ class StorageCompactionFilterFactory final : public kvstore::KVCompactionFilterF return std::make_unique(schemaMan_, indexMan_, vIdLen_); } - const char* Name() const override { return "StorageCompactionFilterFactory"; } + const char* Name() const override { + return "StorageCompactionFilterFactory"; + } private: meta::SchemaManager* schemaMan_ = nullptr; diff --git a/src/storage/ExprVisitorBase.cpp b/src/storage/ExprVisitorBase.cpp index 9f56e8a977b..df2bd2a67dc 100644 --- a/src/storage/ExprVisitorBase.cpp +++ b/src/storage/ExprVisitorBase.cpp @@ -5,11 +5,21 @@ #include "storage/ExprVisitorBase.h" namespace nebula { namespace storage { -void ExprVisitorBase::visit(ConstantExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(UnaryExpression *expr) { expr->operand()->accept(this); } -void ExprVisitorBase::visit(TypeCastingExpression *expr) { expr->operand()->accept(this); } -void ExprVisitorBase::visit(LabelExpression *expr) { fatal(expr); } -void ExprVisitorBase::visit(LabelAttributeExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(ConstantExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(UnaryExpression *expr) { + expr->operand()->accept(this); +} +void ExprVisitorBase::visit(TypeCastingExpression *expr) { + expr->operand()->accept(this); +} +void ExprVisitorBase::visit(LabelExpression *expr) { + fatal(expr); +} +void ExprVisitorBase::visit(LabelAttributeExpression *expr) { + fatal(expr); +} // binary expression void ExprVisitorBase::visit(ArithmeticExpression *expr) { expr->left()->accept(this); @@ -23,7 +33,9 @@ void ExprVisitorBase::visit(SubscriptExpression *expr) { expr->left()->accept(this); expr->right()->accept(this); } -void ExprVisitorBase::visit(AttributeExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(AttributeExpression *expr) { + fatal(expr); +} void ExprVisitorBase::visit(LogicalExpression *expr) { for (auto operand : expr->operands()) { operand->accept(this); @@ -35,11 +47,19 @@ void ExprVisitorBase::visit(FunctionCallExpression *expr) { arg->accept(this); } } -void ExprVisitorBase::visit(AggregateExpression *expr) { fatal(expr); } -void ExprVisitorBase::visit(UUIDExpression *expr) { UNUSED(expr); } +void ExprVisitorBase::visit(AggregateExpression *expr) { + fatal(expr); +} +void ExprVisitorBase::visit(UUIDExpression *expr) { + UNUSED(expr); +} // variable expression -void ExprVisitorBase::visit(VariableExpression *expr) { fatal(expr); } -void ExprVisitorBase::visit(VersionedVariableExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(VariableExpression *expr) { + fatal(expr); +} +void ExprVisitorBase::visit(VersionedVariableExpression *expr) { + fatal(expr); +} // container expression void ExprVisitorBase::visit(ListExpression *expr) { for (auto item : expr->items()) { @@ -51,35 +71,75 @@ void ExprVisitorBase::visit(SetExpression *expr) { item->accept(this); } } -void ExprVisitorBase::visit(MapExpression *expr) { UNUSED(expr); } +void ExprVisitorBase::visit(MapExpression *expr) { + UNUSED(expr); +} // property Expression -void ExprVisitorBase::visit(TagPropertyExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(EdgePropertyExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(InputPropertyExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(VariablePropertyExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(DestPropertyExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(SourcePropertyExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(EdgeSrcIdExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(EdgeTypeExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(EdgeRankExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(EdgeDstIdExpression *expr) { UNUSED(expr); } +void ExprVisitorBase::visit(TagPropertyExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(EdgePropertyExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(InputPropertyExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(VariablePropertyExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(DestPropertyExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(SourcePropertyExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(EdgeSrcIdExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(EdgeTypeExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(EdgeRankExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(EdgeDstIdExpression *expr) { + UNUSED(expr); +} // vertex/edge expression -void ExprVisitorBase::visit(VertexExpression *expr) { UNUSED(expr); } -void ExprVisitorBase::visit(EdgeExpression *expr) { UNUSED(expr); } +void ExprVisitorBase::visit(VertexExpression *expr) { + UNUSED(expr); +} +void ExprVisitorBase::visit(EdgeExpression *expr) { + UNUSED(expr); +} // case expression -void ExprVisitorBase::visit(CaseExpression *expr) { UNUSED(expr); } +void ExprVisitorBase::visit(CaseExpression *expr) { + UNUSED(expr); +} // path build expression -void ExprVisitorBase::visit(PathBuildExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(PathBuildExpression *expr) { + fatal(expr); +} // column expression -void ExprVisitorBase::visit(ColumnExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(ColumnExpression *expr) { + fatal(expr); +} // predicate expression -void ExprVisitorBase::visit(PredicateExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(PredicateExpression *expr) { + fatal(expr); +} // list comprehension expression -void ExprVisitorBase::visit(ListComprehensionExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(ListComprehensionExpression *expr) { + fatal(expr); +} // reduce expression -void ExprVisitorBase::visit(ReduceExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(ReduceExpression *expr) { + fatal(expr); +} // subscript range expression -void ExprVisitorBase::visit(SubscriptRangeExpression *expr) { fatal(expr); } +void ExprVisitorBase::visit(SubscriptRangeExpression *expr) { + fatal(expr); +} } // namespace storage } // namespace nebula diff --git a/src/storage/GraphStorageServiceHandler.cpp b/src/storage/GraphStorageServiceHandler.cpp index 7f7f027af5e..579d0fd2a68 100644 --- a/src/storage/GraphStorageServiceHandler.cpp +++ b/src/storage/GraphStorageServiceHandler.cpp @@ -41,7 +41,7 @@ GraphStorageServiceHandler::GraphStorageServiceHandler(StorageEnv* env) : env_(e LOG(WARNING) << "Unknown value for --reader_handlers_type, using `cpu'"; } using TM = apache::thrift::concurrency::PriorityThreadManager; - auto pool = TM::newPriorityThreadManager(FLAGS_reader_handlers, true); + auto pool = TM::newPriorityThreadManager(FLAGS_reader_handlers); pool->setNamePrefix("reader-pool"); pool->start(); readerPool_ = std::move(pool); diff --git a/src/storage/MergeOperator.h b/src/storage/MergeOperator.h index bfce023322d..728a61d3b96 100644 --- a/src/storage/MergeOperator.h +++ b/src/storage/MergeOperator.h @@ -15,7 +15,9 @@ namespace storage { class NebulaOperator : public rocksdb::MergeOperator { public: - const char* Name() const override { return "NebulaMergeOperator"; } + const char* Name() const override { + return "NebulaMergeOperator"; + } private: bool FullMergeV2(const MergeOperationInput& merge_in, diff --git a/src/storage/StorageAdminServiceHandler.cpp b/src/storage/StorageAdminServiceHandler.cpp index 125a7c60e82..a81bde93052 100644 --- a/src/storage/StorageAdminServiceHandler.cpp +++ b/src/storage/StorageAdminServiceHandler.cpp @@ -9,7 +9,6 @@ #include "storage/admin/AdminTaskProcessor.h" #include "storage/admin/CreateCheckpointProcessor.h" #include "storage/admin/DropCheckpointProcessor.h" -#include "storage/admin/ListClusterInfoProcessor.h" #include "storage/admin/SendBlockSignProcessor.h" #include "storage/admin/StopAdminTaskProcessor.h" @@ -99,11 +98,5 @@ folly::Future StorageAdminServiceHandler::future_stopAdminT RETURN_FUTURE(processor); } -folly::Future StorageAdminServiceHandler::future_listClusterInfo( - const cpp2::ListClusterInfoReq& req) { - auto* processor = ListClusterInfoProcessor::instance(env_); - RETURN_FUTURE(processor); -} - } // namespace storage } // namespace nebula diff --git a/src/storage/StorageAdminServiceHandler.h b/src/storage/StorageAdminServiceHandler.h index 4e754a74ea3..6f8bf994cc3 100644 --- a/src/storage/StorageAdminServiceHandler.h +++ b/src/storage/StorageAdminServiceHandler.h @@ -50,9 +50,6 @@ class StorageAdminServiceHandler final : public cpp2::StorageAdminServiceSvIf { folly::Future future_stopAdminTask( const cpp2::StopAdminTaskRequest& req) override; - folly::Future future_listClusterInfo( - const cpp2::ListClusterInfoReq& req) override; - private: StorageEnv* env_{nullptr}; }; diff --git a/src/storage/StorageServer.cpp b/src/storage/StorageServer.cpp index c03ec525dcc..f29fdb490a1 100644 --- a/src/storage/StorageServer.cpp +++ b/src/storage/StorageServer.cpp @@ -7,6 +7,8 @@ #include +#include + #include "clients/storage/InternalStorageClient.h" #include "common/hdfs/HdfsCommandHelper.h" #include "common/meta/ServerBasedIndexManager.h" @@ -54,7 +56,9 @@ StorageServer::StorageServer(HostAddr localHost, walPath_(std::move(walPath)), listenerPath_(std::move(listenerPath)) {} -StorageServer::~StorageServer() { stop(); } +StorageServer::~StorageServer() { + stop(); +} std::unique_ptr StorageServer::getStoreInstance() { kvstore::KVOptions options; @@ -145,7 +149,7 @@ int32_t StorageServer::getAdminStoreSeqId() { bool StorageServer::start() { ioThreadPool_ = std::make_shared(FLAGS_num_io_threads); workers_ = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager( - FLAGS_num_worker_threads, true /*stats*/); + FLAGS_num_worker_threads); workers_->setNamePrefix("executor"); workers_->start(); @@ -160,6 +164,8 @@ bool StorageServer::start() { options.role_ = nebula::meta::cpp2::HostRole::LISTENER; } options.gitInfoSHA_ = gitInfoSha(); + options.rootPath_ = boost::filesystem::current_path().string(); + options.dataPaths_ = dataPaths_; metaClient_ = std::make_unique(ioThreadPool_, metaAddrs_, options); if (!metaClient_->waitForMetadReady()) { diff --git a/src/storage/admin/AdminProcessor.h b/src/storage/admin/AdminProcessor.h index bd55ef10955..bf352a6e925 100644 --- a/src/storage/admin/AdminProcessor.h +++ b/src/storage/admin/AdminProcessor.h @@ -11,6 +11,7 @@ #include "common/base/Base.h" #include "kvstore/NebulaStore.h" #include "kvstore/Part.h" +#include "kvstore/stats/KVStats.h" #include "storage/BaseProcessor.h" #include "storage/StorageFlags.h" @@ -19,7 +20,9 @@ namespace storage { class TransLeaderProcessor : public BaseProcessor { public: - static TransLeaderProcessor* instance(StorageEnv* env) { return new TransLeaderProcessor(env); } + static TransLeaderProcessor* instance(StorageEnv* env) { + return new TransLeaderProcessor(env); + } void process(const cpp2::TransLeaderReq& req) { CHECK_NOTNULL(env_->kvstore_); @@ -66,9 +69,10 @@ class TransLeaderProcessor : public BaseProcessor { onFinished(); return; } else if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { + stats::StatsManager::addValue(kTransferLeaderLatencyUs, part->execTime()); // To avoid dead lock, we use another ioThreadPool to check the // leader information. - folly::via(folly::getIOExecutor().get(), [this, part, spaceId, partId] { + folly::via(folly::getGlobalIOExecutor().get(), [this, part, spaceId, partId] { int retry = FLAGS_waiting_new_leader_retry_times; while (retry-- > 0) { auto leaderRet = env_->kvstore_->partLeader(spaceId, partId); @@ -116,7 +120,9 @@ class TransLeaderProcessor : public BaseProcessor { class AddPartProcessor : public BaseProcessor { public: - static AddPartProcessor* instance(StorageEnv* env) { return new AddPartProcessor(env); } + static AddPartProcessor* instance(StorageEnv* env) { + return new AddPartProcessor(env); + } void process(const cpp2::AddPartReq& req) { auto spaceId = req.get_space_id(); @@ -148,7 +154,9 @@ class AddPartProcessor : public BaseProcessor { class RemovePartProcessor : public BaseProcessor { public: - static RemovePartProcessor* instance(StorageEnv* env) { return new RemovePartProcessor(env); } + static RemovePartProcessor* instance(StorageEnv* env) { + return new RemovePartProcessor(env); + } void process(const cpp2::RemovePartReq& req) { auto spaceId = req.get_space_id(); @@ -169,7 +177,9 @@ class RemovePartProcessor : public BaseProcessor { class MemberChangeProcessor : public BaseProcessor { public: - static MemberChangeProcessor* instance(StorageEnv* env) { return new MemberChangeProcessor(env); } + static MemberChangeProcessor* instance(StorageEnv* env) { + return new MemberChangeProcessor(env); + } void process(const cpp2::MemberChangeReq& req) { CHECK_NOTNULL(env_->kvstore_); @@ -206,7 +216,9 @@ class MemberChangeProcessor : public BaseProcessor { class AddLearnerProcessor : public BaseProcessor { public: - static AddLearnerProcessor* instance(StorageEnv* env) { return new AddLearnerProcessor(env); } + static AddLearnerProcessor* instance(StorageEnv* env) { + return new AddLearnerProcessor(env); + } void process(const cpp2::AddLearnerReq& req) { auto spaceId = req.get_space_id(); @@ -296,7 +308,9 @@ class WaitingForCatchUpDataProcessor : public BaseProcessor class CheckPeersProcessor : public BaseProcessor { public: - static CheckPeersProcessor* instance(StorageEnv* env) { return new CheckPeersProcessor(env); } + static CheckPeersProcessor* instance(StorageEnv* env) { + return new CheckPeersProcessor(env); + } void process(const cpp2::CheckPeersReq& req) { auto spaceId = req.get_space_id(); @@ -323,7 +337,9 @@ class CheckPeersProcessor : public BaseProcessor { class GetLeaderProcessor : public BaseProcessor { public: - static GetLeaderProcessor* instance(StorageEnv* env) { return new GetLeaderProcessor(env); } + static GetLeaderProcessor* instance(StorageEnv* env) { + return new GetLeaderProcessor(env); + } void process(const cpp2::GetLeaderReq&) { CHECK_NOTNULL(env_->kvstore_); @@ -336,7 +352,7 @@ class GetLeaderProcessor : public BaseProcessor { leaderIds[spaceId].emplace_back(partLeader.get_part_id()); } } - resp_.set_leader_parts(std::move(leaderIds)); + resp_.leader_parts_ref() = std::move(leaderIds); this->onFinished(); } diff --git a/src/storage/admin/AdminTask.h b/src/storage/admin/AdminTask.h index 2e426192910..35f9a681c1f 100644 --- a/src/storage/admin/AdminTask.h +++ b/src/storage/admin/AdminTask.h @@ -25,7 +25,9 @@ class AdminSubTask { explicit AdminSubTask(std::function f) : run_(f) {} - nebula::cpp2::ErrorCode invoke() { return run_(); } + nebula::cpp2::ErrorCode invoke() { + return run_(); + } private: std::function run_; @@ -66,11 +68,17 @@ class AdminTask { virtual ~AdminTask() {} - virtual void setCallback(TCallBack cb) { ctx_.onFinish_ = cb; } + virtual void setCallback(TCallBack cb) { + ctx_.onFinish_ = cb; + } - virtual int8_t getPriority() { return static_cast(ctx_.pri_); } + virtual int8_t getPriority() { + return static_cast(ctx_.pri_); + } - virtual void finish() { finish(rc_); } + virtual void finish() { + finish(rc_); + } virtual void finish(nebula::cpp2::ErrorCode rc) { FLOG_INFO("task(%d, %d) finished, rc=[%s]", @@ -82,11 +90,17 @@ class AdminTask { ctx_.onFinish_(rc, statsItem); } - virtual int getJobId() { return ctx_.jobId_; } + virtual int getJobId() { + return ctx_.jobId_; + } - virtual int getTaskId() { return ctx_.taskId_; } + virtual int getTaskId() { + return ctx_.taskId_; + } - virtual GraphSpaceID getSpaceId() { return ctx_.parameters_.get_space_id(); } + virtual GraphSpaceID getSpaceId() { + return ctx_.parameters_.get_space_id(); + } virtual void setConcurrentReq(int concurrentReq) { if (concurrentReq > 0) { @@ -94,9 +108,13 @@ class AdminTask { } } - virtual size_t getConcurrentReq() { return ctx_.concurrentReq_; } + virtual size_t getConcurrentReq() { + return ctx_.concurrentReq_; + } - virtual nebula::cpp2::ErrorCode status() const { return rc_; } + virtual nebula::cpp2::ErrorCode status() const { + return rc_; + } virtual void subTaskFinish(nebula::cpp2::ErrorCode rc) { auto suc = nebula::cpp2::ErrorCode::SUCCEEDED; @@ -110,11 +128,17 @@ class AdminTask { rc_.compare_exchange_strong(suc, nebula::cpp2::ErrorCode::E_USER_CANCEL); } - virtual bool isRunning() { return running_; } + virtual bool isRunning() { + return running_; + } - virtual bool isCanceled() { return canceled_; } + virtual bool isCanceled() { + return canceled_; + } - meta::cpp2::AdminCmd cmdType() { return ctx_.cmd_; } + meta::cpp2::AdminCmd cmdType() { + return ctx_.cmd_; + } public: std::atomic unFinishedSubTask_; diff --git a/src/storage/admin/AdminTaskManager.cpp b/src/storage/admin/AdminTaskManager.cpp index c53a9655d27..255ecaa2442 100644 --- a/src/storage/admin/AdminTaskManager.cpp +++ b/src/storage/admin/AdminTaskManager.cpp @@ -90,7 +90,7 @@ void AdminTaskManager::handleUnreportedTasks() { apache::thrift::util::enumNameSafe(errCode)); if (seqId < env_->adminSeqId_) { if (jobStatus == nebula::meta::cpp2::JobStatus::RUNNING && pStats != nullptr) { - pStats->set_status(nebula::meta::cpp2::JobStatus::FAILED); + pStats->status_ref() = nebula::meta::cpp2::JobStatus::FAILED; } auto fut = env_->metaClient_->reportTaskFinish(jobId, taskId, errCode, pStats); futVec.emplace_back(std::move(jobId), std::move(taskId), std::move(key), std::move(fut)); diff --git a/src/storage/admin/AdminTaskProcessor.cpp b/src/storage/admin/AdminTaskProcessor.cpp index e8cee1ddeeb..bf3fe3429ec 100644 --- a/src/storage/admin/AdminTaskProcessor.cpp +++ b/src/storage/admin/AdminTaskProcessor.cpp @@ -24,20 +24,20 @@ void AdminTaskProcessor::process(const cpp2::AddAdminTaskRequest& req) { auto task = AdminTaskFactory::createAdminTask(env_, std::move(ctx)); if (task) { nebula::meta::cpp2::StatsItem statsItem; - statsItem.set_status(nebula::meta::cpp2::JobStatus::RUNNING); + statsItem.status_ref() = nebula::meta::cpp2::JobStatus::RUNNING; taskManager->saveTaskStatus( ctx.jobId_, ctx.taskId_, nebula::cpp2::ErrorCode::E_TASK_EXECUTION_FAILED, statsItem); taskManager->addAsyncTask(task); } else { cpp2::PartitionResult thriftRet; - thriftRet.set_code(nebula::cpp2::ErrorCode::E_INVALID_TASK_PARA); + thriftRet.code_ref() = nebula::cpp2::ErrorCode::E_INVALID_TASK_PARA; codes_.emplace_back(std::move(thriftRet)); } onFinished(); } void AdminTaskProcessor::onProcessFinished(nebula::meta::cpp2::StatsItem& result) { - resp_.set_stats(std::move(result)); + resp_.stats_ref() = std::move(result); } } // namespace storage diff --git a/src/storage/admin/AdminTaskProcessor.h b/src/storage/admin/AdminTaskProcessor.h index 350ec7bf042..8ce50201b96 100644 --- a/src/storage/admin/AdminTaskProcessor.h +++ b/src/storage/admin/AdminTaskProcessor.h @@ -18,7 +18,9 @@ namespace storage { class AdminTaskProcessor : public BaseProcessor { public: - static AdminTaskProcessor* instance(StorageEnv* env) { return new AdminTaskProcessor(env); } + static AdminTaskProcessor* instance(StorageEnv* env) { + return new AdminTaskProcessor(env); + } void process(const cpp2::AddAdminTaskRequest& req); diff --git a/src/storage/admin/CreateCheckpointProcessor.cpp b/src/storage/admin/CreateCheckpointProcessor.cpp index f33e04374e0..4bfadabc1fa 100644 --- a/src/storage/admin/CreateCheckpointProcessor.cpp +++ b/src/storage/admin/CreateCheckpointProcessor.cpp @@ -10,18 +10,30 @@ namespace storage { void CreateCheckpointProcessor::process(const cpp2::CreateCPRequest& req) { CHECK_NOTNULL(env_); - auto spaceId = req.get_space_id(); + auto spaceIdList = req.get_space_ids(); auto& name = req.get_name(); - auto ret = env_->kvstore_->createCheckpoint(spaceId, std::move(name)); - if (!ok(ret)) { - cpp2::PartitionResult thriftRet; - thriftRet.set_code(error(ret)); - codes_.emplace_back(std::move(thriftRet)); - onFinished(); - return; + + std::vector ckInfoList; + for (auto& spaceId : spaceIdList) { + auto ckRet = env_->kvstore_->createCheckpoint(spaceId, name); + if (!ok(ckRet) && error(ckRet) == nebula::cpp2::ErrorCode::E_SPACE_NOT_FOUND) { + LOG(ERROR) << folly::sformat("Space {} to create backup is not found", spaceId); + continue; + } + + if (!ok(ckRet)) { + cpp2::PartitionResult thriftRet; + thriftRet.code_ref() = error(ckRet); + codes_.emplace_back(std::move(thriftRet)); + onFinished(); + return; + } + + auto spaceCkList = std::move(nebula::value(ckRet)); + ckInfoList.insert(ckInfoList.end(), spaceCkList.begin(), spaceCkList.end()); } - resp_.set_info(std::move(nebula::value(ret))); + resp_.info_ref() = ckInfoList; onFinished(); } diff --git a/src/storage/admin/DropCheckpointProcessor.cpp b/src/storage/admin/DropCheckpointProcessor.cpp index c3bef9948fc..3626b0948a7 100644 --- a/src/storage/admin/DropCheckpointProcessor.cpp +++ b/src/storage/admin/DropCheckpointProcessor.cpp @@ -10,13 +10,21 @@ namespace storage { void DropCheckpointProcessor::process(const cpp2::DropCPRequest& req) { CHECK_NOTNULL(env_); - auto spaceId = req.get_space_id(); + auto spaceIdList = req.get_space_ids(); auto& name = req.get_name(); - auto retCode = env_->kvstore_->dropCheckpoint(spaceId, std::move(name)); - if (retCode != nebula::cpp2::ErrorCode::SUCCEEDED) { - cpp2::PartitionResult thriftRet; - thriftRet.set_code(retCode); - codes_.emplace_back(std::move(thriftRet)); + for (auto spaceId : spaceIdList) { + auto code = env_->kvstore_->dropCheckpoint(spaceId, std::move(name)); + + if (code == nebula::cpp2::ErrorCode::E_SPACE_NOT_FOUND) { + continue; + } + + if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { + cpp2::PartitionResult res; + res.code_ref() = code; + codes_.emplace_back(std::move(res)); + break; + } } onFinished(); diff --git a/src/storage/admin/ListClusterInfoProcessor.cpp b/src/storage/admin/ListClusterInfoProcessor.cpp deleted file mode 100644 index fa2e402af4a..00000000000 --- a/src/storage/admin/ListClusterInfoProcessor.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (c) 2021 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License. - */ - -#include "storage/admin/ListClusterInfoProcessor.h" - -#include - -#include "common/fs/FileUtils.h" - -namespace nebula { -namespace storage { - -void ListClusterInfoProcessor::process(const cpp2::ListClusterInfoReq& req) { - UNUSED(req); - CHECK_NOTNULL(env_); - - auto data_root = env_->kvstore_->getDataRoot(); - - std::vector realpaths; - bool failed = false; - std::transform(std::make_move_iterator(data_root.begin()), - std::make_move_iterator(data_root.end()), - std::back_inserter(realpaths), - [&failed](auto f) { - if (f[0] == '/') { - return f; - } - auto result = nebula::fs::FileUtils::realPath(f.c_str()); - if (!result.ok()) { - LOG(ERROR) << "Failed to get the absolute path of file: " << f; - failed = true; - return f; - } - return std::string(result.value()); - }); - if (failed) { - cpp2::PartitionResult thriftRet; - thriftRet.set_code(nebula::cpp2::ErrorCode::E_FAILED_GET_ABS_PATH); - codes_.emplace_back(std::move(thriftRet)); - onFinished(); - return; - } - nebula::cpp2::DirInfo dir; - dir.set_data(std::move(realpaths)); - dir.set_root(boost::filesystem::current_path().string()); - - resp_.set_dir(std::move(dir)); - - onFinished(); -} - -} // namespace storage -} // namespace nebula diff --git a/src/storage/admin/ListClusterInfoProcessor.h b/src/storage/admin/ListClusterInfoProcessor.h deleted file mode 100644 index 5628831f4f1..00000000000 --- a/src/storage/admin/ListClusterInfoProcessor.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (c) 2021 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License. - */ - -#ifndef STORAGE_ADMIN_LISTCLUSTERINFO_H_ -#define STORAGE_ADMIN_LISTCLUSTERINFO_H_ - -#include "common/base/Base.h" -#include "kvstore/KVEngine.h" -#include "kvstore/NebulaStore.h" -#include "storage/BaseProcessor.h" - -namespace nebula { -namespace storage { - -class ListClusterInfoProcessor : public BaseProcessor { - public: - static ListClusterInfoProcessor* instance(StorageEnv* env) { - return new ListClusterInfoProcessor(env); - } - - void process(const cpp2::ListClusterInfoReq& req); - - private: - explicit ListClusterInfoProcessor(StorageEnv* env) - : BaseProcessor(env) {} -}; - -} // namespace storage -} // namespace nebula -#endif // STORAGE_ADMIN_LISTCLUSTERINFO_H_ diff --git a/src/storage/admin/RebuildIndexTask.h b/src/storage/admin/RebuildIndexTask.h index 27d8695fa5d..69b508557a1 100644 --- a/src/storage/admin/RebuildIndexTask.h +++ b/src/storage/admin/RebuildIndexTask.h @@ -21,7 +21,9 @@ class RebuildIndexTask : public AdminTask { public: RebuildIndexTask(StorageEnv* env, TaskContext&& ctx); - ~RebuildIndexTask() { LOG(INFO) << "Release Rebuild Task"; } + ~RebuildIndexTask() { + LOG(INFO) << "Release Rebuild Task"; + } ErrorOr> genSubTasks() override; diff --git a/src/storage/admin/SendBlockSignProcessor.cpp b/src/storage/admin/SendBlockSignProcessor.cpp index 070f42c595e..0ee2e764324 100644 --- a/src/storage/admin/SendBlockSignProcessor.cpp +++ b/src/storage/admin/SendBlockSignProcessor.cpp @@ -9,17 +9,22 @@ namespace nebula { namespace storage { void SendBlockSignProcessor::process(const cpp2::BlockingSignRequest& req) { - auto spaceId = req.get_space_id(); + auto spaceIds = req.get_space_ids(); auto sign = req.get_sign() == cpp2::EngineSignType::BLOCK_ON; - LOG(INFO) << "Receive block sign for space " << req.get_space_id() << ", block: " << sign; - auto code = env_->kvstore_->setWriteBlocking(spaceId, sign); - if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { - cpp2::PartitionResult thriftRet; - thriftRet.set_code(code); - codes_.emplace_back(std::move(thriftRet)); - LOG(INFO) << "set block sign failed, error: " << apache::thrift::util::enumNameSafe(code); + for (auto spaceId : spaceIds) { + LOG(INFO) << "Receive block sign for space " << spaceId << ", block: " << sign; + auto code = env_->kvstore_->setWriteBlocking(spaceId, sign); + if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { + cpp2::PartitionResult thriftRet; + thriftRet.code_ref() = code; + codes_.emplace_back(std::move(thriftRet)); + LOG(INFO) << "set block sign failed, error: " << apache::thrift::util::enumNameSafe(code); + onFinished(); + return; + } } + onFinished(); } diff --git a/src/storage/admin/StatsTask.cpp b/src/storage/admin/StatsTask.cpp index bed6150949d..5ba1443bd6a 100644 --- a/src/storage/admin/StatsTask.cpp +++ b/src/storage/admin/StatsTask.cpp @@ -236,24 +236,24 @@ nebula::cpp2::ErrorCode StatsTask::genSubTask(GraphSpaceID spaceId, } } - statsItem.set_space_vertices(spaceVertices); - statsItem.set_space_edges(spaceEdges); + statsItem.space_vertices_ref() = spaceVertices; + statsItem.space_edges_ref() = spaceEdges; using Correlativities = std::vector; Correlativities positiveCorrelativity; for (const auto& entry : positiveRelevancy) { nebula::meta::cpp2::Correlativity partProportion; - partProportion.set_part_id(entry.first); + partProportion.part_id_ref() = entry.first; double proportion = static_cast(entry.second) / static_cast(spaceEdges); - partProportion.set_proportion(proportion); + partProportion.proportion_ref() = proportion; positiveCorrelativity.emplace_back(std::move(partProportion)); } Correlativities negativeCorrelativity; for (const auto& entry : negativeRelevancy) { nebula::meta::cpp2::Correlativity partProportion; - partProportion.set_part_id(entry.first); + partProportion.part_id_ref() = entry.first; double proportion = static_cast(entry.second) / static_cast(spaceEdges); - partProportion.set_proportion(proportion); + partProportion.proportion_ref() = proportion; negativeCorrelativity.emplace_back(std::move(partProportion)); } @@ -269,11 +269,11 @@ nebula::cpp2::ErrorCode StatsTask::genSubTask(GraphSpaceID spaceId, std::unordered_map positivePartCorrelativities; positivePartCorrelativities[part] = positiveCorrelativity; - statsItem.set_positive_part_correlativity(std::move(positivePartCorrelativities)); + statsItem.positive_part_correlativity_ref() = std::move(positivePartCorrelativities); std::unordered_map negativePartCorrelativities; negativePartCorrelativities[part] = negativeCorrelativity; - statsItem.set_negative_part_correlativity(std::move(negativePartCorrelativities)); + statsItem.negative_part_correlativity_ref() = std::move(negativePartCorrelativities); statistics_.emplace(part, std::move(statsItem)); LOG(INFO) << "Stats task finished"; @@ -286,11 +286,11 @@ void StatsTask::finish(nebula::cpp2::ErrorCode rc) { ctx_.taskId_, apache::thrift::util::enumNameSafe(rc).c_str()); nebula::meta::cpp2::StatsItem result; - result.set_status(nebula::meta::cpp2::JobStatus::FAILED); + result.status_ref() = nebula::meta::cpp2::JobStatus::FAILED; if (rc == nebula::cpp2::ErrorCode::SUCCEEDED && statistics_.size() == subTaskSize_) { - result.set_space_vertices(0); - result.set_space_edges(0); + result.space_vertices_ref() = 0; + result.space_edges_ref() = 0; for (auto& elem : statistics_) { auto item = elem.second; *result.space_vertices_ref() += *item.space_vertices_ref(); @@ -323,7 +323,7 @@ void StatsTask::finish(nebula::cpp2::ErrorCode rc) { .insert((*item.negative_part_correlativity_ref()).begin(), (*item.negative_part_correlativity_ref()).end()); } - result.set_status(nebula::meta::cpp2::JobStatus::FINISHED); + result.status_ref() = nebula::meta::cpp2::JobStatus::FINISHED; ctx_.onFinish_(rc, result); } else if (rc != nebula::cpp2::ErrorCode::SUCCEEDED) { ctx_.onFinish_(rc, result); diff --git a/src/storage/admin/StatsTask.h b/src/storage/admin/StatsTask.h index 672bcd2b27f..724524fc846 100644 --- a/src/storage/admin/StatsTask.h +++ b/src/storage/admin/StatsTask.h @@ -20,7 +20,9 @@ class StatsTask : public AdminTask { using AdminTask::finish; StatsTask(StorageEnv* env, TaskContext&& ctx) : AdminTask(env, std::move(ctx)) {} - ~StatsTask() { LOG(INFO) << "Release Stats Task"; } + ~StatsTask() { + LOG(INFO) << "Release Stats Task"; + } ErrorOr> genSubTasks() override; diff --git a/src/storage/admin/StopAdminTaskProcessor.cpp b/src/storage/admin/StopAdminTaskProcessor.cpp index a4e647011bc..686391487cc 100644 --- a/src/storage/admin/StopAdminTaskProcessor.cpp +++ b/src/storage/admin/StopAdminTaskProcessor.cpp @@ -17,7 +17,7 @@ void StopAdminTaskProcessor::process(const cpp2::StopAdminTaskRequest& req) { if (rc != nebula::cpp2::ErrorCode::SUCCEEDED) { cpp2::PartitionResult thriftRet; - thriftRet.set_code(rc); + thriftRet.code_ref() = rc; codes_.emplace_back(std::move(thriftRet)); } diff --git a/src/storage/context/StorageExpressionContext.h b/src/storage/context/StorageExpressionContext.h index 38ef72eba39..94883cf5160 100644 --- a/src/storage/context/StorageExpressionContext.h +++ b/src/storage/context/StorageExpressionContext.h @@ -72,10 +72,14 @@ class StorageExpressionContext final : public ExpressionContext { } // Get the specified property from the input, such as $-.prop_name - const Value& getInputProp(const std::string&) const override { return Value::kNullValue; } + const Value& getInputProp(const std::string&) const override { + return Value::kNullValue; + } // Get the value by column index - Value getColumn(int32_t) const override { return Value::kNullValue; } + Value getColumn(int32_t) const override { + return Value::kNullValue; + } // Get the specified property from the tag, such as tag.prop_name Value getTagProp(const std::string& tagName, const std::string& prop) const override; @@ -87,11 +91,17 @@ class StorageExpressionContext final : public ExpressionContext { // such as $^.tagName.prop_name Value getSrcProp(const std::string& tagName, const std::string& prop) const override; - size_t vIdLen() const { return vIdLen_; } + size_t vIdLen() const { + return vIdLen_; + } - bool hasNullableCol() const { return hasNullableCol_; } + bool hasNullableCol() const { + return hasNullableCol_; + } - const std::vector& indexCols() const { return fields_; } + const std::vector& indexCols() const { + return fields_; + } void setVar(const std::string& name, Value val) override { valueMap_[name].emplace_back(std::move(val)); @@ -102,10 +112,14 @@ class StorageExpressionContext final : public ExpressionContext { LOG(FATAL) << "Unimplemented"; } - Value getEdge() const override { LOG(FATAL) << "Unimplemented"; } + Value getEdge() const override { + LOG(FATAL) << "Unimplemented"; + } // index key - void reset(const std::string& key) { key_ = key; } + void reset(const std::string& key) { + key_ = key; + } // isEdge_ set in ctor void reset(RowReader* reader, const std::string& key) { diff --git a/src/storage/exec/AggregateNode.h b/src/storage/exec/AggregateNode.h index bdf1fcba26e..bfa0e861242 100644 --- a/src/storage/exec/AggregateNode.h +++ b/src/storage/exec/AggregateNode.h @@ -86,13 +86,21 @@ class AggregateNode : public IterateNode { } private: - VertexIDSlice srcId() const { return NebulaKeyUtils::getSrcId(context_->vIdLen(), this->key()); } + VertexIDSlice srcId() const { + return NebulaKeyUtils::getSrcId(context_->vIdLen(), this->key()); + } - EdgeType edgeType() const { return NebulaKeyUtils::getEdgeType(context_->vIdLen(), this->key()); } + EdgeType edgeType() const { + return NebulaKeyUtils::getEdgeType(context_->vIdLen(), this->key()); + } - EdgeRanking edgeRank() const { return NebulaKeyUtils::getRank(context_->vIdLen(), this->key()); } + EdgeRanking edgeRank() const { + return NebulaKeyUtils::getRank(context_->vIdLen(), this->key()); + } - VertexIDSlice dstId() const { return NebulaKeyUtils::getDstId(context_->vIdLen(), this->key()); } + VertexIDSlice dstId() const { + return NebulaKeyUtils::getDstId(context_->vIdLen(), this->key()); + } void initStatValue(EdgeContext* edgeContext) { stats_.clear(); diff --git a/src/storage/exec/EdgeNode.h b/src/storage/exec/EdgeNode.h index beee24665f3..c72c34c06c7 100644 --- a/src/storage/exec/EdgeNode.h +++ b/src/storage/exec/EdgeNode.h @@ -26,9 +26,13 @@ class EdgeNode : public IterateNode { return valueHandler(this->key(), this->reader(), props_); } - const std::string& getEdgeName() const { return edgeName_; } + const std::string& getEdgeName() const { + return edgeName_; + } - EdgeType edgeType() const { return edgeType_; } + EdgeType edgeType() const { + return edgeType_; + } protected: EdgeNode(RuntimeContext* context, @@ -85,15 +89,25 @@ class FetchEdgeNode final : public EdgeNode { name_ = "FetchEdgeNode"; } - bool valid() const override { return valid_; } + bool valid() const override { + return valid_; + } - void next() override { valid_ = false; } + void next() override { + valid_ = false; + } - folly::StringPiece key() const override { return key_; } + folly::StringPiece key() const override { + return key_; + } - folly::StringPiece val() const override { return val_; } + folly::StringPiece val() const override { + return val_; + } - RowReader* reader() const override { return reader_.get(); } + RowReader* reader() const override { + return reader_.get(); + } nebula::cpp2::ErrorCode doExecute(PartitionID partId, const cpp2::EdgeKey& edgeKey) override { valid_ = false; @@ -171,17 +185,29 @@ class SingleEdgeNode final : public EdgeNode { name_ = "SingleEdgeNode"; } - SingleEdgeIterator* iter() { return iter_.get(); } + SingleEdgeIterator* iter() { + return iter_.get(); + } - bool valid() const override { return iter_ && iter_->valid(); } + bool valid() const override { + return iter_ && iter_->valid(); + } - void next() override { iter_->next(); } + void next() override { + iter_->next(); + } - folly::StringPiece key() const override { return iter_->key(); } + folly::StringPiece key() const override { + return iter_->key(); + } - folly::StringPiece val() const override { return iter_->val(); } + folly::StringPiece val() const override { + return iter_->val(); + } - RowReader* reader() const override { return iter_->reader(); } + RowReader* reader() const override { + return iter_->reader(); + } nebula::cpp2::ErrorCode doExecute(PartitionID partId, const VertexID& vId) override { auto ret = RelNode::doExecute(partId, vId); diff --git a/src/storage/exec/HashJoinNode.h b/src/storage/exec/HashJoinNode.h index 5e6aad1ece1..15f512761cc 100644 --- a/src/storage/exec/HashJoinNode.h +++ b/src/storage/exec/HashJoinNode.h @@ -108,7 +108,9 @@ class HashJoinNode : public IterateNode { return nebula::cpp2::ErrorCode::SUCCEEDED; } - bool valid() const override { return iter_->valid(); } + bool valid() const override { + return iter_->valid(); + } void next() override { iter_->next(); @@ -117,12 +119,18 @@ class HashJoinNode : public IterateNode { } } - folly::StringPiece key() const override { return iter_->key(); } + folly::StringPiece key() const override { + return iter_->key(); + } - folly::StringPiece val() const override { return iter_->val(); } + folly::StringPiece val() const override { + return iter_->val(); + } // return the edge row reader which could pass filter - RowReader* reader() const override { return iter_->reader(); } + RowReader* reader() const override { + return iter_->reader(); + } private: // return true when the value iter points to a value which can pass ttl and diff --git a/src/storage/exec/IndexDedupNode.h b/src/storage/exec/IndexDedupNode.h index 8025c08124b..dfc1f2dbd47 100644 --- a/src/storage/exec/IndexDedupNode.h +++ b/src/storage/exec/IndexDedupNode.h @@ -47,7 +47,9 @@ class IndexDedupNode : public IndexNode { class RowWrapper { public: RowWrapper(const Row& row, const std::vector& posList); - inline const List& values() const { return values_; } + inline const List& values() const { + return values_; + } private: List values_; diff --git a/src/storage/exec/IndexNode.h b/src/storage/exec/IndexNode.h index 0db70ec8030..27131967700 100644 --- a/src/storage/exec/IndexNode.h +++ b/src/storage/exec/IndexNode.h @@ -88,11 +88,21 @@ class IndexNode { this->empty_ = result.empty_; return *this; } - inline bool success() { return code_ == ErrorCode::SUCCEEDED; } - inline bool hasData() { return success() && empty_ == false; } - inline Row row() && { return std::move(row_); } - inline Row& row() & { return row_; } - ErrorCode code() { return code_; } + inline bool success() { + return code_ == ErrorCode::SUCCEEDED; + } + inline bool hasData() { + return success() && empty_ == false; + } + inline Row row() && { + return std::move(row_); + } + inline Row& row() & { + return row_; + } + ErrorCode code() { + return code_; + } private: ErrorCode code_{ErrorCode::SUCCEEDED}; @@ -104,8 +114,12 @@ class IndexNode { explicit IndexNode(RuntimeContext* context, const std::string& name); virtual ~IndexNode() = default; virtual std::unique_ptr copy() = 0; - void addChild(std::unique_ptr child) { children_.emplace_back(std::move(child)); } - const std::vector>& children() { return children_; } + void addChild(std::unique_ptr child) { + children_.emplace_back(std::move(child)); + } + const std::vector>& children() { + return children_; + } virtual ::nebula::cpp2::ErrorCode init(InitContext& initCtx) { DCHECK_EQ(children_.size(), 1); return children_[0]->init(initCtx); @@ -116,7 +130,9 @@ class IndexNode { // inline nebula::cpp2::ErrorCode finish(); /* assist */ - const std::string& name() { return name_; } + const std::string& name() { + return name_; + } void enableProfileDetail(); virtual std::string identify() = 0; inline const time::Duration& duration(); @@ -186,7 +202,9 @@ inline void IndexNode::enableProfileDetail() { } } -inline const time::Duration& IndexNode::duration() { return duration_; } +inline const time::Duration& IndexNode::duration() { + return duration_; +} } // namespace storage } // namespace nebula diff --git a/src/storage/exec/IndexScanNode.cpp b/src/storage/exec/IndexScanNode.cpp index 426f02d752e..3b04ad0aadd 100644 --- a/src/storage/exec/IndexScanNode.cpp +++ b/src/storage/exec/IndexScanNode.cpp @@ -102,7 +102,9 @@ std::string Path::encodeValue(const Value& value, return val; } -const std::string& Path::toString() { return serializeString_; } +const std::string& Path::toString() { + return serializeString_; +} // End of Path diff --git a/src/storage/exec/IndexScanNode.h b/src/storage/exec/IndexScanNode.h index 61e8eb7d4b6..d0df49c5141 100644 --- a/src/storage/exec/IndexScanNode.h +++ b/src/storage/exec/IndexScanNode.h @@ -338,7 +338,9 @@ class Path { const std::vector& hints, int64_t vidLen); QualifiedStrategy::Result qualified(const folly::StringPiece& key); - virtual bool isRange() { return false; } + virtual bool isRange() { + return false; + } virtual QualifiedStrategy::Result qualified(const Map& rowData) = 0; virtual void resetPart(PartitionID partId) = 0; @@ -369,7 +371,9 @@ class PrefixPath : public Path { QualifiedStrategy::Result qualified(const Map& rowData) override; void resetPart(PartitionID partId) override; - const std::string& getPrefixKey() { return prefix_; } + const std::string& getPrefixKey() { + return prefix_; + } private: std::string prefix_; @@ -384,11 +388,21 @@ class RangePath : public Path { QualifiedStrategy::Result qualified(const Map& rowData) override; void resetPart(PartitionID partId) override; - inline bool includeStart() { return includeStart_; } - inline bool includeEnd() { return includeEnd_; } - inline const std::string& getStartKey() { return startKey_; } - inline const std::string& getEndKey() { return endKey_; } - bool isRange() override { return true; } + inline bool includeStart() { + return includeStart_; + } + inline bool includeEnd() { + return includeEnd_; + } + inline const std::string& getStartKey() { + return startKey_; + } + inline const std::string& getEndKey() { + return endKey_; + } + bool isRange() override { + return true; + } private: std::string startKey_, endKey_; diff --git a/src/storage/exec/IndexSelectionNode.h b/src/storage/exec/IndexSelectionNode.h index 04dd8694638..c41a09b512e 100644 --- a/src/storage/exec/IndexSelectionNode.h +++ b/src/storage/exec/IndexSelectionNode.h @@ -63,7 +63,9 @@ class IndexSelectionNode : public IndexNode { class ExprContext : public ExpressionContext { public: explicit ExprContext(const Map &colPos) : colPos_(colPos) {} - void setRow(const Row &row) { row_ = &row; } + void setRow(const Row &row) { + row_ = &row; + } Value getEdgeProp(const std::string &edgeType, const std::string &prop) const override; Value getTagProp(const std::string &tag, const std::string &prop) const override; // override @@ -91,8 +93,12 @@ class IndexSelectionNode : public IndexNode { UNUSED(prop); return fatal(__FILE__, __LINE__); } - Value getVertex(const std::string &) const override { return fatal(__FILE__, __LINE__); } - Value getEdge() const override { return fatal(__FILE__, __LINE__); } + Value getVertex(const std::string &) const override { + return fatal(__FILE__, __LINE__); + } + Value getEdge() const override { + return fatal(__FILE__, __LINE__); + } Value getColumn(int32_t index) const override { UNUSED(index); return fatal(__FILE__, __LINE__); @@ -116,14 +122,30 @@ class IndexSelectionNode : public IndexNode { class SelectionExprVisitor : public ExprVisitorBase { public: - void visit(EdgeSrcIdExpression *expr) override { requiredColumns_.insert(expr->prop()); } - void visit(EdgeTypeExpression *expr) override { requiredColumns_.insert(expr->prop()); } - void visit(EdgeRankExpression *expr) override { requiredColumns_.insert(expr->prop()); } - void visit(EdgeDstIdExpression *expr) override { requiredColumns_.insert(expr->prop()); } - void visit(TagPropertyExpression *expr) override { requiredColumns_.insert(expr->prop()); } - void visit(EdgePropertyExpression *expr) override { requiredColumns_.insert(expr->prop()); } - const Set &getRequiredColumns() { return requiredColumns_; } - ::nebula::cpp2::ErrorCode getCode() { return code_; } + void visit(EdgeSrcIdExpression *expr) override { + requiredColumns_.insert(expr->prop()); + } + void visit(EdgeTypeExpression *expr) override { + requiredColumns_.insert(expr->prop()); + } + void visit(EdgeRankExpression *expr) override { + requiredColumns_.insert(expr->prop()); + } + void visit(EdgeDstIdExpression *expr) override { + requiredColumns_.insert(expr->prop()); + } + void visit(TagPropertyExpression *expr) override { + requiredColumns_.insert(expr->prop()); + } + void visit(EdgePropertyExpression *expr) override { + requiredColumns_.insert(expr->prop()); + } + const Set &getRequiredColumns() { + return requiredColumns_; + } + ::nebula::cpp2::ErrorCode getCode() { + return code_; + } private: using ExprVisitorBase::visit; diff --git a/src/storage/exec/IndexVertexScanNode.h b/src/storage/exec/IndexVertexScanNode.h index 48be02e2d1a..116a0e70eae 100644 --- a/src/storage/exec/IndexVertexScanNode.h +++ b/src/storage/exec/IndexVertexScanNode.h @@ -38,7 +38,9 @@ class IndexVertexScanNode final : public IndexScanNode { Map decodeFromBase(const std::string& key, const std::string& value) override; using TagSchemas = std::vector>; - const TagSchemas& getSchema() override { return tag_; } + const TagSchemas& getSchema() override { + return tag_; + } TagSchemas tag_; using IndexItem = ::nebula::meta::cpp2::IndexItem; // Convenient for testing diff --git a/src/storage/exec/RelNode.h b/src/storage/exec/RelNode.h index f2c1d891180..1d01dc6d041 100644 --- a/src/storage/exec/RelNode.h +++ b/src/storage/exec/RelNode.h @@ -77,7 +77,9 @@ class RelNode { explicit RelNode(const std::string& name) : name_(name) {} - const std::string& name() const { return name_; } + const std::string& name() const { + return name_; + } std::string name_ = "RelNode"; std::vector*> dependencies_; @@ -90,9 +92,13 @@ class RelNode { template class QueryNode : public RelNode { public: - const Value& result() { return result_; } + const Value& result() { + return result_; + } - Value& mutableResult() { return result_; } + Value& mutableResult() { + return result_; + } protected: Value result_; @@ -114,7 +120,9 @@ class IterateNode : public QueryNode, public StorageIterator { explicit IterateNode(IterateNode* node) : upstream_(node) {} - bool valid() const override { return upstream_->valid(); } + bool valid() const override { + return upstream_->valid(); + } void next() override { do { @@ -122,16 +130,24 @@ class IterateNode : public QueryNode, public StorageIterator { } while (upstream_->valid() && !check()); } - folly::StringPiece key() const override { return upstream_->key(); } + folly::StringPiece key() const override { + return upstream_->key(); + } - folly::StringPiece val() const override { return upstream_->val(); } + folly::StringPiece val() const override { + return upstream_->val(); + } // return the edge row reader which could pass filter - RowReader* reader() const override { return upstream_->reader(); } + RowReader* reader() const override { + return upstream_->reader(); + } protected: // return true when the iterator points to a valid value - virtual bool check() { return true; } + virtual bool check() { + return true; + } IterateNode* upstream_; }; diff --git a/src/storage/exec/ScanNode.h b/src/storage/exec/ScanNode.h index 6602752b5c2..3876a5a4a59 100644 --- a/src/storage/exec/ScanNode.h +++ b/src/storage/exec/ScanNode.h @@ -13,7 +13,9 @@ namespace storage { using Cursor = std::string; -inline bool vTrue(const Value& v) { return v.isBool() && v.getBool(); } +inline bool vTrue(const Value& v) { + return v.isBool() && v.getBool(); +} // Node to scan vertices of one partition class ScanVertexPropNode : public QueryNode { @@ -92,7 +94,7 @@ class ScanVertexPropNode : public QueryNode { cpp2::ScanCursor c; if (iter->valid()) { - c.set_next_cursor(iter->key().str()); + c.next_cursor_ref() = iter->key().str(); } cursors_->emplace(partId, std::move(c)); return nebula::cpp2::ErrorCode::SUCCEEDED; @@ -243,7 +245,7 @@ class ScanEdgePropNode : public QueryNode { cpp2::ScanCursor c; if (iter->valid()) { - c.set_next_cursor(iter->key().str()); + c.next_cursor_ref() = iter->key().str(); } cursors_->emplace(partId, std::move(c)); return nebula::cpp2::ErrorCode::SUCCEEDED; diff --git a/src/storage/exec/StorageIterator.h b/src/storage/exec/StorageIterator.h index c4fc30d456b..9597a117ed9 100644 --- a/src/storage/exec/StorageIterator.h +++ b/src/storage/exec/StorageIterator.h @@ -52,7 +52,9 @@ class SingleEdgeIterator : public StorageIterator { } } - bool valid() const override { return reader_ != nullptr; } + bool valid() const override { + return reader_ != nullptr; + } void next() override { do { @@ -64,13 +66,21 @@ class SingleEdgeIterator : public StorageIterator { } while (!check()); } - folly::StringPiece key() const override { return iter_->key(); } + folly::StringPiece key() const override { + return iter_->key(); + } - folly::StringPiece val() const override { return iter_->val(); } + folly::StringPiece val() const override { + return iter_->val(); + } - RowReader* reader() const override { return reader_.get(); } + RowReader* reader() const override { + return reader_.get(); + } - EdgeType edgeType() const { return edgeType_; } + EdgeType edgeType() const { + return edgeType_; + } protected: // return true when the value iter to a valid edge value @@ -112,7 +122,9 @@ class MultiEdgeIterator : public StorageIterator { moveToNextValidIterator(); } - bool valid() const override { return curIter_ < iters_.size(); } + bool valid() const override { + return curIter_ < iters_.size(); + } void next() override { iters_[curIter_]->next(); @@ -121,16 +133,26 @@ class MultiEdgeIterator : public StorageIterator { } } - folly::StringPiece key() const override { return iters_[curIter_]->key(); } + folly::StringPiece key() const override { + return iters_[curIter_]->key(); + } - folly::StringPiece val() const override { return iters_[curIter_]->val(); } + folly::StringPiece val() const override { + return iters_[curIter_]->val(); + } - RowReader* reader() const override { return iters_[curIter_]->reader(); } + RowReader* reader() const override { + return iters_[curIter_]->reader(); + } - EdgeType edgeType() const { return iters_[curIter_]->edgeType(); } + EdgeType edgeType() const { + return iters_[curIter_]->edgeType(); + } // return the index of multiple iterators - size_t getIdx() const { return curIter_; } + size_t getIdx() const { + return curIter_; + } private: void moveToNextValidIterator() { @@ -153,13 +175,21 @@ class IndexIterator : public StorageIterator { virtual IndexID indexId() const = 0; - bool valid() const override { return !!iter_ && iter_->valid(); } + bool valid() const override { + return !!iter_ && iter_->valid(); + } - void next() override { iter_->next(); } + void next() override { + iter_->next(); + } - folly::StringPiece key() const override { return iter_->key(); } + folly::StringPiece key() const override { + return iter_->key(); + } - folly::StringPiece val() const override { return iter_->val(); } + folly::StringPiece val() const override { + return iter_->val(); + } protected: std::unique_ptr iter_; @@ -170,13 +200,21 @@ class VertexIndexIterator : public IndexIterator { VertexIndexIterator(std::unique_ptr iter, size_t vIdLen) : IndexIterator(std::move(iter)), vIdLen_(vIdLen) {} - RowReader* reader() const override { return nullptr; } + RowReader* reader() const override { + return nullptr; + } - IndexID indexId() const override { return IndexKeyUtils::getIndexId(iter_->key()); } + IndexID indexId() const override { + return IndexKeyUtils::getIndexId(iter_->key()); + } - VertexID vId() const { return IndexKeyUtils::getIndexVertexID(vIdLen_, iter_->key()).str(); } + VertexID vId() const { + return IndexKeyUtils::getIndexVertexID(vIdLen_, iter_->key()).str(); + } - folly::StringPiece val() const override { return iter_->val(); } + folly::StringPiece val() const override { + return iter_->val(); + } protected: size_t vIdLen_; @@ -187,17 +225,29 @@ class EdgeIndexIterator : public IndexIterator { EdgeIndexIterator(std::unique_ptr iter, size_t vIdLen) : IndexIterator(std::move(iter)), vIdLen_(vIdLen) {} - RowReader* reader() const override { return nullptr; } + RowReader* reader() const override { + return nullptr; + } - IndexID indexId() const override { return IndexKeyUtils::getIndexId(iter_->key()); } + IndexID indexId() const override { + return IndexKeyUtils::getIndexId(iter_->key()); + } - VertexID srcId() const { return IndexKeyUtils::getIndexSrcId(vIdLen_, iter_->key()).str(); } + VertexID srcId() const { + return IndexKeyUtils::getIndexSrcId(vIdLen_, iter_->key()).str(); + } - VertexID dstId() const { return IndexKeyUtils::getIndexDstId(vIdLen_, iter_->key()).str(); } + VertexID dstId() const { + return IndexKeyUtils::getIndexDstId(vIdLen_, iter_->key()).str(); + } - EdgeRanking ranking() const { return IndexKeyUtils::getIndexRank(vIdLen_, iter_->key()); } + EdgeRanking ranking() const { + return IndexKeyUtils::getIndexRank(vIdLen_, iter_->key()); + } - folly::StringPiece val() const override { return iter_->val(); } + folly::StringPiece val() const override { + return iter_->val(); + } protected: size_t vIdLen_; diff --git a/src/storage/exec/StoragePlan.h b/src/storage/exec/StoragePlan.h index 5a659bcccda..bb05f267eec 100644 --- a/src/storage/exec/StoragePlan.h +++ b/src/storage/exec/StoragePlan.h @@ -80,7 +80,9 @@ class StoragePlan { CHECK_LT(idx, nodes_.size()); return nodes_[idx].get(); } - const std::vector>>& getNodes() { return nodes_; } + const std::vector>>& getNodes() { + return nodes_; + } private: bool firstLoop_ = true; diff --git a/src/storage/exec/TagNode.h b/src/storage/exec/TagNode.h index e2086738518..80c46f9874f 100644 --- a/src/storage/exec/TagNode.h +++ b/src/storage/exec/TagNode.h @@ -76,22 +76,34 @@ class TagNode final : public IterateNode { return valueHandler(key_, reader_.get(), props_); } - bool valid() const override { return valid_; } + bool valid() const override { + return valid_; + } void next() override { // tag only has one valid record, so stop iterate valid_ = false; } - folly::StringPiece key() const override { return key_; } + folly::StringPiece key() const override { + return key_; + } - folly::StringPiece val() const override { return value_; } + folly::StringPiece val() const override { + return value_; + } - RowReader* reader() const override { return reader_.get(); } + RowReader* reader() const override { + return reader_.get(); + } - const std::string& getTagName() const { return tagName_; } + const std::string& getTagName() const { + return tagName_; + } - TagID tagId() const { return tagId_; } + TagID tagId() const { + return tagId_; + } void clear() { valid_ = false; diff --git a/src/storage/http/StorageHttpAdminHandler.cpp b/src/storage/http/StorageHttpAdminHandler.cpp index 5cb4befa4b1..b1f44f73c2d 100644 --- a/src/storage/http/StorageHttpAdminHandler.cpp +++ b/src/storage/http/StorageHttpAdminHandler.cpp @@ -102,7 +102,9 @@ void StorageHttpAdminHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void StorageHttpAdminHandler::requestComplete() noexcept { delete this; } +void StorageHttpAdminHandler::requestComplete() noexcept { + delete this; +} void StorageHttpAdminHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web service StorageHttpHandler got error: " << proxygen::getErrorString(error); diff --git a/src/storage/http/StorageHttpDownloadHandler.cpp b/src/storage/http/StorageHttpDownloadHandler.cpp index 7d0359037da..30b2cdfa169 100644 --- a/src/storage/http/StorageHttpDownloadHandler.cpp +++ b/src/storage/http/StorageHttpDownloadHandler.cpp @@ -127,7 +127,9 @@ void StorageHttpDownloadHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void StorageHttpDownloadHandler::requestComplete() noexcept { delete this; } +void StorageHttpDownloadHandler::requestComplete() noexcept { + delete this; +} void StorageHttpDownloadHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web Service StorageHttpDownloadHandler got error: " diff --git a/src/storage/http/StorageHttpIngestHandler.cpp b/src/storage/http/StorageHttpIngestHandler.cpp index 60af9220c04..8c44cf4bf72 100644 --- a/src/storage/http/StorageHttpIngestHandler.cpp +++ b/src/storage/http/StorageHttpIngestHandler.cpp @@ -81,7 +81,9 @@ void StorageHttpIngestHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void StorageHttpIngestHandler::requestComplete() noexcept { delete this; } +void StorageHttpIngestHandler::requestComplete() noexcept { + delete this; +} void StorageHttpIngestHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web Service MetaHttpIngestHandler Failed: " << proxygen::getErrorString(error); diff --git a/src/storage/http/StorageHttpPropertyHandler.cpp b/src/storage/http/StorageHttpPropertyHandler.cpp index ff76585db8d..ecb283364c7 100644 --- a/src/storage/http/StorageHttpPropertyHandler.cpp +++ b/src/storage/http/StorageHttpPropertyHandler.cpp @@ -94,7 +94,9 @@ void StorageHttpPropertyHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void StorageHttpPropertyHandler::requestComplete() noexcept { delete this; } +void StorageHttpPropertyHandler::requestComplete() noexcept { + delete this; +} void StorageHttpPropertyHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web service StorageHttpHandler got error: " << proxygen::getErrorString(error); diff --git a/src/storage/index/LookupProcessor.h b/src/storage/index/LookupProcessor.h index 1751f8f1c27..9954484bab1 100644 --- a/src/storage/index/LookupProcessor.h +++ b/src/storage/index/LookupProcessor.h @@ -26,7 +26,7 @@ class LookupProcessor : public BaseProcessor { : BaseProcessor(env, counters), executor_(executor) {} void doProcess(const cpp2::LookupIndexRequest& req); void onProcessFinished() { - BaseProcessor::resp_.set_data(std::move(resultDataSet_)); + BaseProcessor::resp_.data_ref() = std::move(resultDataSet_); } void profilePlan(IndexNode* plan); void runInSingleThread(const std::vector& parts, std::unique_ptr plan); diff --git a/src/storage/kv/GetProcessor.cpp b/src/storage/kv/GetProcessor.cpp index d1e55708917..97a51efc1d4 100644 --- a/src/storage/kv/GetProcessor.cpp +++ b/src/storage/kv/GetProcessor.cpp @@ -47,7 +47,7 @@ void GetProcessor::process(const cpp2::KVGetRequest& req) { } } - resp_.set_key_values(std::move(pairs)); + resp_.key_values_ref() = std::move(pairs); this->onFinished(); } diff --git a/src/storage/mutate/AddEdgesProcessor.cpp b/src/storage/mutate/AddEdgesProcessor.cpp index c878f4d3fb9..0cdac63284c 100644 --- a/src/storage/mutate/AddEdgesProcessor.cpp +++ b/src/storage/mutate/AddEdgesProcessor.cpp @@ -8,10 +8,12 @@ #include #include "codec/RowWriterV2.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { @@ -141,6 +143,7 @@ void AddEdgesProcessor::doProcess(const cpp2::AddEdgesRequest& req) { }); } else { doPut(spaceId_, partId, std::move(data)); + stats::StatsManager::addValue(kNumEdgesInserted, data.size()); } } } @@ -302,6 +305,7 @@ void AddEdgesProcessor::doProcessWithIndex(const cpp2::AddEdgesRequest& req) { break; } batchHolder->put(std::move(key), std::move(retEnc.value())); + stats::StatsManager::addValue(kNumEdgesInserted); } if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { env_->edgesML_->unlockBatch(dummyLock); diff --git a/src/storage/mutate/AddEdgesProcessor.h b/src/storage/mutate/AddEdgesProcessor.h index d34f5718218..bacc212bd06 100644 --- a/src/storage/mutate/AddEdgesProcessor.h +++ b/src/storage/mutate/AddEdgesProcessor.h @@ -7,6 +7,7 @@ #define STORAGE_MUTATE_ADDEDGESPROCESSOR_H_ #include "common/base/Base.h" +#include "common/stats/StatsManager.h" #include "kvstore/LogEncoder.h" #include "storage/BaseProcessor.h" #include "storage/StorageFlags.h" diff --git a/src/storage/mutate/AddVerticesProcessor.cpp b/src/storage/mutate/AddVerticesProcessor.cpp index dd431fe87bd..161dfb5e5e2 100644 --- a/src/storage/mutate/AddVerticesProcessor.cpp +++ b/src/storage/mutate/AddVerticesProcessor.cpp @@ -8,11 +8,13 @@ #include #include "codec/RowWriterV2.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" #include "storage/StorageFlags.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { @@ -127,6 +129,7 @@ void AddVerticesProcessor::doProcess(const cpp2::AddVerticesRequest& req) { handleAsync(spaceId_, partId, code); } else { doPut(spaceId_, partId, std::move(data)); + stats::StatsManager::addValue(kNumVerticesInserted, data.size()); } } } @@ -285,6 +288,7 @@ void AddVerticesProcessor::doProcessWithIndex(const cpp2::AddVerticesRequest& re * step 3 , Insert new vertex data */ batchHolder->put(std::move(key), std::move(retEnc.value())); + stats::StatsManager::addValue(kNumVerticesInserted); } if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { break; diff --git a/src/storage/mutate/DeleteEdgesProcessor.cpp b/src/storage/mutate/DeleteEdgesProcessor.cpp index ed031c60329..6c68f5b9e0a 100644 --- a/src/storage/mutate/DeleteEdgesProcessor.cpp +++ b/src/storage/mutate/DeleteEdgesProcessor.cpp @@ -7,9 +7,11 @@ #include +#include "common/stats/StatsManager.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { @@ -76,6 +78,7 @@ void DeleteEdgesProcessor::process(const cpp2::DeleteEdgesRequest& req) { continue; } doRemove(spaceId_, partId, std::move(keys)); + stats::StatsManager::addValue(kNumEdgesDeleted, keys.size()); } } else { for (auto& part : partEdges) { @@ -183,6 +186,7 @@ ErrorOr DeleteEdgesProcessor::deleteEdges( } } batchHolder->remove(std::move(key)); + stats::StatsManager::addValue(kNumEdgesDeleted); } else if (ret == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) { continue; } else { diff --git a/src/storage/mutate/DeleteTagsProcessor.cpp b/src/storage/mutate/DeleteTagsProcessor.cpp index 5109486e6fd..7ffc6f28696 100644 --- a/src/storage/mutate/DeleteTagsProcessor.cpp +++ b/src/storage/mutate/DeleteTagsProcessor.cpp @@ -5,10 +5,12 @@ #include "storage/mutate/DeleteTagsProcessor.h" +#include "common/stats/StatsManager.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" #include "storage/StorageFlags.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { @@ -60,6 +62,7 @@ void DeleteTagsProcessor::process(const cpp2::DeleteTagsRequest& req) { } } doRemove(spaceId_, partId, std::move(keys)); + stats::StatsManager::addValue(kNumTagsDeleted, keys.size()); } } else { for (const auto& part : parts) { @@ -146,6 +149,7 @@ ErrorOr DeleteTagsProcessor::deleteTags( } } batchHolder->remove(std::move(key)); + stats::StatsManager::addValue(kNumTagsDeleted); } } return encodeBatchValue(batchHolder->getBatch()); diff --git a/src/storage/mutate/DeleteVerticesProcessor.cpp b/src/storage/mutate/DeleteVerticesProcessor.cpp index 7be1cc31d0f..873f6b8d299 100644 --- a/src/storage/mutate/DeleteVerticesProcessor.cpp +++ b/src/storage/mutate/DeleteVerticesProcessor.cpp @@ -9,6 +9,7 @@ #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" #include "storage/StorageFlags.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { @@ -80,6 +81,7 @@ void DeleteVerticesProcessor::process(const cpp2::DeleteVerticesRequest& req) { continue; } doRemove(spaceId_, partId, std::move(keys)); + stats::StatsManager::addValue(kNumVerticesDeleted, keys.size()); } } else { for (auto& pv : partVertices) { @@ -170,6 +172,7 @@ ErrorOr DeleteVerticesProcessor::deleteVer } } batchHolder->remove(key.str()); + stats::StatsManager::addValue(kNumVerticesDeleted); iter->next(); } } diff --git a/src/storage/mutate/UpdateEdgeProcessor.cpp b/src/storage/mutate/UpdateEdgeProcessor.cpp index ecbd38f02a0..0f748075bfe 100644 --- a/src/storage/mutate/UpdateEdgeProcessor.cpp +++ b/src/storage/mutate/UpdateEdgeProcessor.cpp @@ -289,7 +289,9 @@ nebula::cpp2::ErrorCode UpdateEdgeProcessor::buildEdgeContext(const cpp2::Update return nebula::cpp2::ErrorCode::SUCCEEDED; } -void UpdateEdgeProcessor::onProcessFinished() { resp_.set_props(std::move(resultDataSet_)); } +void UpdateEdgeProcessor::onProcessFinished() { + resp_.props_ref() = std::move(resultDataSet_); +} } // namespace storage } // namespace nebula diff --git a/src/storage/mutate/UpdateEdgeProcessor.h b/src/storage/mutate/UpdateEdgeProcessor.h index 36943d24edc..a0c0a86ded4 100644 --- a/src/storage/mutate/UpdateEdgeProcessor.h +++ b/src/storage/mutate/UpdateEdgeProcessor.h @@ -51,7 +51,9 @@ class UpdateEdgeProcessor void onProcessFinished() override; - std::vector getReturnPropsExp() { return returnPropsExp_; } + std::vector getReturnPropsExp() { + return returnPropsExp_; + } void profilePlan(StoragePlan& plan) { auto& nodes = plan.getNodes(); for (auto& node : nodes) { diff --git a/src/storage/mutate/UpdateVertexProcessor.cpp b/src/storage/mutate/UpdateVertexProcessor.cpp index 92f1218b854..f54527ef702 100644 --- a/src/storage/mutate/UpdateVertexProcessor.cpp +++ b/src/storage/mutate/UpdateVertexProcessor.cpp @@ -271,7 +271,9 @@ nebula::cpp2::ErrorCode UpdateVertexProcessor::buildTagContext( return nebula::cpp2::ErrorCode::SUCCEEDED; } -void UpdateVertexProcessor::onProcessFinished() { resp_.set_props(std::move(resultDataSet_)); } +void UpdateVertexProcessor::onProcessFinished() { + resp_.props_ref() = std::move(resultDataSet_); +} } // namespace storage } // namespace nebula diff --git a/src/storage/query/GetNeighborsProcessor.cpp b/src/storage/query/GetNeighborsProcessor.cpp index 5d08b2ab7e3..42e65f8d033 100644 --- a/src/storage/query/GetNeighborsProcessor.cpp +++ b/src/storage/query/GetNeighborsProcessor.cpp @@ -461,7 +461,9 @@ nebula::cpp2::ErrorCode GetNeighborsProcessor::checkStatType( return nebula::cpp2::ErrorCode::SUCCEEDED; } -void GetNeighborsProcessor::onProcessFinished() { resp_.set_vertices(std::move(resultDataSet_)); } +void GetNeighborsProcessor::onProcessFinished() { + resp_.vertices_ref() = std::move(resultDataSet_); +} void GetNeighborsProcessor::profilePlan(StoragePlan& plan) { auto& nodes = plan.getNodes(); diff --git a/src/storage/query/GetPropProcessor.cpp b/src/storage/query/GetPropProcessor.cpp index 0e48f792278..9617e23e7d9 100644 --- a/src/storage/query/GetPropProcessor.cpp +++ b/src/storage/query/GetPropProcessor.cpp @@ -82,10 +82,10 @@ void GetPropProcessor::runInSingleThread(const cpp2::GetPropRequest& req) { auto partId = partEntry.first; for (const auto& row : partEntry.second) { cpp2::EdgeKey edgeKey; - edgeKey.set_src(row.values[0].getStr()); - edgeKey.set_edge_type(row.values[1].getInt()); - edgeKey.set_ranking(row.values[2].getInt()); - edgeKey.set_dst(row.values[3].getStr()); + edgeKey.src_ref() = row.values[0].getStr(); + edgeKey.edge_type_ref() = row.values[1].getInt(); + edgeKey.ranking_ref() = row.values[2].getInt(); + edgeKey.dst_ref() = row.values[3].getStr(); if (!NebulaKeyUtils::isValidVidLen( spaceVidLen_, (*edgeKey.src_ref()).getStr(), (*edgeKey.dst_ref()).getStr())) { @@ -167,10 +167,10 @@ folly::Future> GetPropProcessor: auto plan = buildEdgePlan(context, result); for (const auto& row : input) { cpp2::EdgeKey edgeKey; - edgeKey.set_src(row.values[0].getStr()); - edgeKey.set_edge_type(row.values[1].getInt()); - edgeKey.set_ranking(row.values[2].getInt()); - edgeKey.set_dst(row.values[3].getStr()); + edgeKey.src_ref() = row.values[0].getStr(); + edgeKey.edge_type_ref() = row.values[1].getInt(); + edgeKey.ranking_ref() = row.values[2].getInt(); + edgeKey.dst_ref() = row.values[3].getStr(); if (!NebulaKeyUtils::isValidVidLen( spaceVidLen_, (*edgeKey.src_ref()).getStr(), (*edgeKey.dst_ref()).getStr())) { @@ -305,7 +305,9 @@ void GetPropProcessor::buildEdgeColName(const std::vector& edgeP } } -void GetPropProcessor::onProcessFinished() { resp_.set_props(std::move(resultDataSet_)); } +void GetPropProcessor::onProcessFinished() { + resp_.props_ref() = std::move(resultDataSet_); +} } // namespace storage } // namespace nebula diff --git a/src/storage/query/QueryBaseProcessor-inl.h b/src/storage/query/QueryBaseProcessor-inl.h index 47b8f48c54f..d56e7ed300b 100644 --- a/src/storage/query/QueryBaseProcessor-inl.h +++ b/src/storage/query/QueryBaseProcessor-inl.h @@ -186,7 +186,7 @@ std::vector QueryBaseProcessor::buildAllTagProps() std::vector result; for (const auto& entry : tagContext_.schemas_) { cpp2::VertexProp tagProp; - tagProp.set_tag(entry.first); + tagProp.tag_ref() = entry.first; const auto& schema = entry.second.back(); auto count = schema->getNumFields(); for (size_t i = 0; i < count; i++) { @@ -207,9 +207,9 @@ std::vector QueryBaseProcessor::buildAllEdgeProps( std::vector result; for (const auto& entry : edgeContext_.schemas_) { cpp2::EdgeProp edgeProp; - edgeProp.set_type(entry.first); + edgeProp.type_ref() = entry.first; if (direction == cpp2::EdgeDirection::IN_EDGE) { - edgeProp.set_type(-edgeProp.get_type()); + edgeProp.type_ref() = -edgeProp.get_type(); } const auto& schema = entry.second.back(); auto count = schema->getNumFields(); @@ -219,7 +219,7 @@ std::vector QueryBaseProcessor::buildAllEdgeProps( } if (direction == cpp2::EdgeDirection::BOTH) { cpp2::EdgeProp reverse = edgeProp; - reverse.set_type(-edgeProp.get_type()); + reverse.type_ref() = -edgeProp.get_type(); result.emplace_back(std::move(reverse)); } result.emplace_back(std::move(edgeProp)); diff --git a/src/storage/query/QueryBaseProcessor.h b/src/storage/query/QueryBaseProcessor.h index 00dd8e97247..44255a34df4 100644 --- a/src/storage/query/QueryBaseProcessor.h +++ b/src/storage/query/QueryBaseProcessor.h @@ -42,7 +42,9 @@ struct PropContext { DST = 0x06, }; - explicit PropContext(const char* name) : name_(name) { setPropInKey(); } + explicit PropContext(const char* name) : name_(name) { + setPropInKey(); + } PropContext(const char* name, const meta::SchemaProviderIf::Field* field, diff --git a/src/storage/query/ScanEdgeProcessor.cpp b/src/storage/query/ScanEdgeProcessor.cpp index 7a8e99884ad..ae328d406b5 100644 --- a/src/storage/query/ScanEdgeProcessor.cpp +++ b/src/storage/query/ScanEdgeProcessor.cpp @@ -86,8 +86,8 @@ void ScanEdgeProcessor::buildEdgeColName(const std::vector& edge } void ScanEdgeProcessor::onProcessFinished() { - resp_.set_props(std::move(resultDataSet_)); - resp_.set_cursors(std::move(cursors_)); + resp_.props_ref() = std::move(resultDataSet_); + resp_.cursors_ref() = std::move(cursors_); } StoragePlan ScanEdgeProcessor::buildPlan( diff --git a/src/storage/query/ScanVertexProcessor.cpp b/src/storage/query/ScanVertexProcessor.cpp index 6c210f3c0dd..6dafcda714d 100644 --- a/src/storage/query/ScanVertexProcessor.cpp +++ b/src/storage/query/ScanVertexProcessor.cpp @@ -90,8 +90,8 @@ void ScanVertexProcessor::buildTagColName(const std::vector& t } void ScanVertexProcessor::onProcessFinished() { - resp_.set_props(std::move(resultDataSet_)); - resp_.set_cursors(std::move(cursors_)); + resp_.props_ref() = std::move(resultDataSet_); + resp_.cursors_ref() = std::move(cursors_); } StoragePlan ScanVertexProcessor::buildPlan( diff --git a/src/storage/stats/CMakeLists.txt b/src/storage/stats/CMakeLists.txt new file mode 100644 index 00000000000..6d5db5f3f4f --- /dev/null +++ b/src/storage/stats/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2021 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. + +nebula_add_library( + storage_stats_obj + OBJECT + StorageStats.cpp + ) diff --git a/src/storage/stats/StorageStats.cpp b/src/storage/stats/StorageStats.cpp new file mode 100644 index 00000000000..40f5181c195 --- /dev/null +++ b/src/storage/stats/StorageStats.cpp @@ -0,0 +1,28 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "clients/meta/stats/MetaClientStats.h" +#include "kvstore/stats/KVStats.h" + +namespace nebula { + +stats::CounterId kNumEdgesInserted; +stats::CounterId kNumVerticesInserted; +stats::CounterId kNumEdgesDeleted; +stats::CounterId kNumTagsDeleted; +stats::CounterId kNumVerticesDeleted; + +void initStorageStats() { + kNumEdgesInserted = stats::StatsManager::registerStats("num_edges_inserted", "rate, sum"); + kNumVerticesInserted = stats::StatsManager::registerStats("num_vertices_inserted", "rate, sum"); + kNumEdgesDeleted = stats::StatsManager::registerStats("num_edges_deleted", "rate, sum"); + kNumTagsDeleted = stats::StatsManager::registerStats("num_tags_deleted", "rate, sum"); + kNumVerticesDeleted = stats::StatsManager::registerStats("num_vertices_deleted", "rate, sum"); + + initMetaClientStats(); + initKVStats(); +} + +} // namespace nebula diff --git a/src/storage/stats/StorageStats.h b/src/storage/stats/StorageStats.h new file mode 100644 index 00000000000..11bf1a76315 --- /dev/null +++ b/src/storage/stats/StorageStats.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include "common/stats/StatsManager.h" + +namespace nebula { + +extern stats::CounterId kNumEdgesInserted; +extern stats::CounterId kNumVerticesInserted; +extern stats::CounterId kNumEdgesDeleted; +extern stats::CounterId kNumTagsDeleted; +extern stats::CounterId kNumVerticesDeleted; + +void initStorageStats(); + +} // namespace nebula diff --git a/src/storage/test/AddAndUpdateVertexAndEdgeBenchmark.cpp b/src/storage/test/AddAndUpdateVertexAndEdgeBenchmark.cpp index cd42c365932..34c8801585e 100644 --- a/src/storage/test/AddAndUpdateVertexAndEdgeBenchmark.cpp +++ b/src/storage/test/AddAndUpdateVertexAndEdgeBenchmark.cpp @@ -253,8 +253,8 @@ void setUp(storage::StorageEnv* ev) { cpp2::AddVerticesRequest buildAddVertexReq() { cpp2::AddVerticesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; vertexId = "Tony Parker"; @@ -274,14 +274,14 @@ cpp2::AddVerticesRequest buildAddVertexReq() { props.emplace_back(2); props.emplace_back("France"); props.emplace_back(5); - newTag.set_tag_id(1); - newTag.set_props(std::move(props)); + newTag.tag_id_ref() = 1; + newTag.props_ref() = std::move(props); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(vertexId); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = vertexId; + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); return req; } @@ -290,15 +290,15 @@ cpp2::AddEdgesRequest buildAddEdgeReq() { cpp2::AddEdgesRequest req; srcId = "Tony Parker"; dstId = "Spurs"; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; nebula::storage::cpp2::NewEdge newEdge; partId = std::hash()(srcId) % parts + 1; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(0); - edgeKey.set_dst(dstId); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 0; + edgeKey.dst_ref() = dstId; std::vector props; props.emplace_back(srcId); @@ -310,8 +310,8 @@ cpp2::AddEdgesRequest buildAddEdgeReq() { props.emplace_back(16.6); props.emplace_back("trade"); props.emplace_back(4); - newEdge.set_key(std::move(edgeKey)); - newEdge.set_props(std::move(props)); + newEdge.key_ref() = std::move(edgeKey); + newEdge.props_ref() = std::move(props); (*req.parts_ref())[partId].emplace_back(std::move(newEdge)); return req; @@ -319,34 +319,34 @@ cpp2::AddEdgesRequest buildAddEdgeReq() { cpp2::UpdateVertexRequest buildUpdateVertexReq(bool isVersionV2) { cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); - req.set_tag_id(tagId); + req.space_id_ref() = spaceId; + req.tag_id_ref() = tagId; vertexId = "Tim Duncan"; if (!isVersionV2) { vertexId += "v1"; } partId = std::hash()(vertexId) % parts + 1; - req.set_part_id(partId); - req.set_vertex_id(vertexId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; // Build updated props std::vector updatedProps; // int: player.age = 45 cpp2::UpdatedProp uProp1; - uProp1.set_name("age"); + uProp1.name_ref() = "age"; const auto& val1 = *ConstantExpression::make(pool, 45L); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); // string: player.country= China cpp2::UpdatedProp uProp2; - uProp2.set_name("country"); + uProp2.name_ref() = "country"; std::string col4new("China"); const auto& val2 = *ConstantExpression::make(pool, col4new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); // Build yield // Return player props: name, age, country @@ -360,14 +360,14 @@ cpp2::UpdateVertexRequest buildUpdateVertexReq(bool isVersionV2) { const auto& sourcePropExp3 = *SourcePropertyExpression::make(pool, "1", "country"); tmpProps.emplace_back(Expression::encode(sourcePropExp3)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; return req; } cpp2::UpdateEdgeRequest buildUpdateEdgeReq(bool isVersionV2) { cpp2::UpdateEdgeRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; srcId = "Tim Duncan"; if (!isVersionV2) { @@ -375,34 +375,34 @@ cpp2::UpdateEdgeRequest buildUpdateEdgeReq(bool isVersionV2) { } partId = std::hash()(srcId) % parts + 1; - req.set_part_id(partId); + req.part_id_ref() = partId; dstId = "Spurs"; rank = 0; edgeType = 101; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; // Build updated props std::vector updatedProps; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 20L); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); // bool: 101.type = trade cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); // Return serve props: playerName, teamName, teamCareer, type std::vector tmpProps; @@ -418,8 +418,8 @@ cpp2::UpdateEdgeRequest buildUpdateEdgeReq(bool isVersionV2) { const auto& edgePropExp4 = *EdgePropertyExpression::make(pool, "101", "type"); tmpProps.emplace_back(Expression::encode(edgePropExp4)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; return req; } @@ -428,7 +428,9 @@ cpp2::UpdateEdgeRequest buildUpdateEdgeReq(bool isVersionV2) { void insertVertex(int32_t iters) { nebula::storage::cpp2::AddVerticesRequest req; - BENCHMARK_SUSPEND { req = nebula::storage::buildAddVertexReq(); } + BENCHMARK_SUSPEND { + req = nebula::storage::buildAddVertexReq(); + } for (decltype(iters) i = 0; i < iters; i++) { // Test AddVertexRequest @@ -446,7 +448,9 @@ void insertVertex(int32_t iters) { void insertEdge(int32_t iters) { nebula::storage::cpp2::AddEdgesRequest req; - BENCHMARK_SUSPEND { req = nebula::storage::buildAddEdgeReq(); } + BENCHMARK_SUSPEND { + req = nebula::storage::buildAddEdgeReq(); + } for (decltype(iters) i = 0; i < iters; i++) { // Test AddVertexRequest @@ -463,7 +467,9 @@ void insertEdge(int32_t iters) { void updateVertex(int32_t iters, bool isVersion2) { nebula::storage::cpp2::UpdateVertexRequest req; - BENCHMARK_SUSPEND { req = nebula::storage::buildUpdateVertexReq(isVersion2); } + BENCHMARK_SUSPEND { + req = nebula::storage::buildUpdateVertexReq(isVersion2); + } for (decltype(iters) i = 0; i < iters; i++) { // Test UpdateVertexRequest @@ -481,7 +487,9 @@ void updateVertex(int32_t iters, bool isVersion2) { void updateEdge(int32_t iters, bool isVersion2) { nebula::storage::cpp2::UpdateEdgeRequest req; - BENCHMARK_SUSPEND { req = nebula::storage::buildUpdateEdgeReq(isVersion2); } + BENCHMARK_SUSPEND { + req = nebula::storage::buildUpdateEdgeReq(isVersion2); + } for (decltype(iters) i = 0; i < iters; i++) { // Test UpdateEdgeRequest @@ -497,17 +505,29 @@ void updateEdge(int32_t iters, bool isVersion2) { } } -BENCHMARK(update_vertexV1, iters) { updateVertex(iters, false); } +BENCHMARK(update_vertexV1, iters) { + updateVertex(iters, false); +} -BENCHMARK_RELATIVE(update_vertexV2, iters) { updateVertex(iters, true); } +BENCHMARK_RELATIVE(update_vertexV2, iters) { + updateVertex(iters, true); +} -BENCHMARK(update_edgeV1, iters) { updateEdge(iters, false); } +BENCHMARK(update_edgeV1, iters) { + updateEdge(iters, false); +} -BENCHMARK_RELATIVE(update_edgeV2, iters) { updateEdge(iters, true); } +BENCHMARK_RELATIVE(update_edgeV2, iters) { + updateEdge(iters, true); +} -BENCHMARK(insert_vertexV2, iters) { insertVertex(iters); } +BENCHMARK(insert_vertexV2, iters) { + insertVertex(iters); +} -BENCHMARK(insert_edgeV2, iters) { insertEdge(iters); } +BENCHMARK(insert_edgeV2, iters) { + insertEdge(iters); +} int main(int argc, char** argv) { folly::init(&argc, &argv, true); diff --git a/src/storage/test/AdminTaskManagerTest.cpp b/src/storage/test/AdminTaskManagerTest.cpp index deebf61c440..6d2de138134 100644 --- a/src/storage/test/AdminTaskManagerTest.cpp +++ b/src/storage/test/AdminTaskManagerTest.cpp @@ -51,9 +51,13 @@ struct HookableTask : public AdminTask { subTasks.emplace_back(subTask); } - void setJobId(int id) { ctx_.jobId_ = id; } + void setJobId(int id) { + ctx_.jobId_ = id; + } - void setTaskId(int id) { ctx_.taskId_ = id; } + void setTaskId(int id) { + ctx_.taskId_ = id; + } std::function fGenSubTasks; std::vector subTasks; diff --git a/src/storage/test/CMakeLists.txt b/src/storage/test/CMakeLists.txt index 2c6e0ea5a3c..5371ad3492c 100644 --- a/src/storage/test/CMakeLists.txt +++ b/src/storage/test/CMakeLists.txt @@ -52,6 +52,10 @@ set(storage_test_deps $ $ $ + $ + $ + $ + $ ) nebula_add_test( @@ -678,21 +682,6 @@ nebula_add_executable( boost_regex ) -nebula_add_test( - NAME - list_cluster_info_test - SOURCES - ListClusterInfoTest.cpp - OBJECTS - ${storage_test_deps} - LIBRARIES - ${ROCKSDB_LIBRARIES} - ${THRIFT_LIBRARIES} - ${PROXYGEN_LIBRARIES} - wangle - gtest -) - nebula_add_test( NAME chain_add_edge_test diff --git a/src/storage/test/ChainTestUtils.h b/src/storage/test/ChainTestUtils.h index e59d04aa8e4..13da0bf8473 100644 --- a/src/storage/test/ChainTestUtils.h +++ b/src/storage/test/ChainTestUtils.h @@ -176,7 +176,9 @@ class FakeChainUpdateProcessor : public ChainUpdateEdgeProcessorLocal { return ChainUpdateEdgeProcessorLocal::processLocal(code); } - void wrapAddUnfinishedEdge(ResumeType type) { addUnfinishedEdge(type); } + void wrapAddUnfinishedEdge(ResumeType type) { + addUnfinishedEdge(type); + } public: folly::Optional rcPrepareLocal; @@ -227,10 +229,10 @@ class MetaClientTestUpdater { UNUSED(ignoreItem); } meta::cpp2::ColumnTypeDef type; - type.set_type(nebula::cpp2::PropertyType::FIXED_STRING); - type.set_type_length(32); + type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING; + type.type_length_ref() = 32; - mClient->localCache_[mockSpaceId]->spaceDesc_.set_vid_type(std::move(type)); + mClient->localCache_[mockSpaceId]->spaceDesc_.vid_type_ref() = std::move(type); mClient->ready_ = true; return mClient; } @@ -249,8 +251,8 @@ class FakeInternalStorageClient : public InternalStorageClient { folly::Promise&& p, folly::EventBase* evb = nullptr) override { cpp2::ChainUpdateEdgeRequest chainReq; - chainReq.set_update_edge_request(req); - chainReq.set_term(termOfSrc); + chainReq.update_edge_request_ref() = req; + chainReq.term_ref() = termOfSrc; auto* proc = ChainUpdateEdgeProcessorRemote::instance(env_); auto f = proc->getFuture(); @@ -262,7 +264,9 @@ class FakeInternalStorageClient : public InternalStorageClient { UNUSED(evb); } - void setErrorCode(Code code) { code_ = code; } + void setErrorCode(Code code) { + code_ = code; + } void chainAddEdges(cpp2::AddEdgesRequest& req, TermID termId, @@ -291,14 +295,16 @@ class FakeInternalStorageClient : public InternalStorageClient { }; struct ChainUpdateEdgeTestHelper { - ChainUpdateEdgeTestHelper() { sEdgeType = std::to_string(std::abs(edgeType_)); } + ChainUpdateEdgeTestHelper() { + sEdgeType = std::to_string(std::abs(edgeType_)); + } cpp2::EdgeKey defaultEdgeKey() { cpp2::EdgeKey ret; - ret.set_src(srcId_); - ret.set_edge_type(edgeType_); - ret.set_ranking(rank_); - ret.set_dst(dstId_); + ret.src_ref() = srcId_; + ret.edge_type_ref() = edgeType_; + ret.ranking_ref() = rank_; + ret.dst_ref() = dstId_; return ret; } @@ -308,19 +314,19 @@ struct ChainUpdateEdgeTestHelper { std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; // ConstantExpression val1(20); const auto& val1 = *ConstantExpression::make(&objPool, 20); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.type = trade cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); // ConstantExpression val2(colnew); const auto& val2 = *ConstantExpression::make(&objPool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); return props; } @@ -352,7 +358,7 @@ struct ChainUpdateEdgeTestHelper { cpp2::UpdateEdgeRequest makeInvalidRequest() { VertexID srcInvalid{"Spurssssssss"}; auto edgeKey = defaultEdgeKey(); - edgeKey.set_src(srcInvalid); + edgeKey.src_ref() = srcInvalid; auto updateProps = defaultUpdateProps(); auto retProps = defaultRetProps(); return makeRequest(edgeKey, updateProps, retProps); @@ -363,12 +369,12 @@ struct ChainUpdateEdgeTestHelper { const std::vector& retCols) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()(edgeKey.get_src().getStr()) % mockPartNum + 1; - req.set_space_id(mockSpaceId); - req.set_part_id(partId); - req.set_edge_key(edgeKey); - req.set_updated_props(updateProps); - req.set_return_props(retCols); - req.set_insertable(false); + req.space_id_ref() = mockSpaceId; + req.part_id_ref() = partId; + req.edge_key_ref() = edgeKey; + req.updated_props_ref() = updateProps; + req.return_props_ref() = retCols; + req.insertable_ref() = false; return req; } diff --git a/src/storage/test/CheckpointTest.cpp b/src/storage/test/CheckpointTest.cpp index 8c50a07213e..c2a61f3d22a 100644 --- a/src/storage/test/CheckpointTest.cpp +++ b/src/storage/test/CheckpointTest.cpp @@ -37,8 +37,9 @@ TEST(CheckpointTest, simpleTest) { { auto* processor = CreateCheckpointProcessor::instance(env); cpp2::CreateCPRequest req; - req.set_space_id(1); - req.set_name("checkpoint_test"); + std::vector ids{1}; + req.space_ids_ref() = ids; + req.name_ref() = "checkpoint_test"; auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); diff --git a/src/storage/test/DeleteTagsTest.cpp b/src/storage/test/DeleteTagsTest.cpp index 2dca61007a6..01e173781c1 100644 --- a/src/storage/test/DeleteTagsTest.cpp +++ b/src/storage/test/DeleteTagsTest.cpp @@ -27,7 +27,7 @@ cpp2::GetPropRequest buildGetPropRequest( const std::vector>>& tags) { std::hash hash; cpp2::GetPropRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; for (const auto& vertex : vertices) { PartitionID partId = (hash(vertex) % totalParts) + 1; nebula::Row row; @@ -37,18 +37,18 @@ cpp2::GetPropRequest buildGetPropRequest( std::vector vertexProps; if (tags.empty()) { - req.set_vertex_props(std::move(vertexProps)); + req.vertex_props_ref() = std::move(vertexProps); } else { for (const auto& tag : tags) { TagID tagId = tag.first; cpp2::VertexProp tagProp; - tagProp.set_tag(tagId); + tagProp.tag_ref() = tagId; for (const auto& prop : tag.second) { (*tagProp.props_ref()).emplace_back(std::move(prop)); } vertexProps.emplace_back(std::move(tagProp)); } - req.set_vertex_props(std::move(vertexProps)); + req.vertex_props_ref() = std::move(vertexProps); } return req; } @@ -56,34 +56,34 @@ cpp2::GetPropRequest buildGetPropRequest( cpp2::LookupIndexRequest buildLookupRequest(int32_t totalParts, std::string playerName) { cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(1); + req.space_id_ref() = 1; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = 1; + indices.schema_id_ref() = schemaId; std::vector parts; for (PartitionID partId = 1; partId <= totalParts; partId++) { parts.emplace_back(partId); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("age"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(playerName)); - columnHint.set_column_name("name"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = Value(playerName); + columnHint.column_name_ref() = "name"; + columnHint.scan_type_ref() = cpp2::ScanType::PREFIX; std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(1); + context1.column_hints_ref() = std::move(columnHints); + context1.filter_ref() = ""; + context1.index_id_ref() = 1; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); return req; } @@ -91,7 +91,7 @@ cpp2::DeleteTagsRequest buildDeleteTagsRequest(int32_t totalParts, const std::vector& delTags) { std::hash hash; cpp2::DeleteTagsRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; for (const auto& delTag : delTags) { PartitionID partId = (hash(delTag.get_id().getStr()) % totalParts) + 1; (*req.parts_ref())[partId].emplace_back(std::move(delTag)); @@ -141,7 +141,7 @@ TEST(DeleteTagsTest, SimpleTest) { { std::vector delTags; cpp2::DelTags delTag; - delTag.set_id("Tim Duncan"); + delTag.id_ref() = "Tim Duncan"; (*delTag.tags_ref()).emplace_back(player); delTags.emplace_back(std::move(delTag)); auto req = buildDeleteTagsRequest(totalParts, delTags); diff --git a/src/storage/test/ElasticSearchBulkInsertTest.cpp b/src/storage/test/ElasticSearchBulkInsertTest.cpp index 61b2557ceda..cb7f3ae9741 100644 --- a/src/storage/test/ElasticSearchBulkInsertTest.cpp +++ b/src/storage/test/ElasticSearchBulkInsertTest.cpp @@ -132,8 +132,8 @@ class ElasticSearchBasicTest : public ::testing::Test { cpp2::AddVerticesRequest mockVerticesReq(int32_t parts, int64_t begin, int64_t end) { nebula::storage::cpp2::AddVerticesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; auto vertices = mockVertices(begin, end); @@ -142,14 +142,14 @@ class ElasticSearchBasicTest : public ::testing::Test { nebula::storage::cpp2::NewTag newTag; auto partId = std::hash()(vertex.vId_) % parts + 1; - newTag.set_tag_id(tagId_); - newTag.set_props(std::move(vertex.props_)); + newTag.tag_id_ref() = tagId_; + newTag.props_ref() = std::move(vertex.props_); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(vertex.vId_); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = vertex.vId_; + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } return req; @@ -168,7 +168,7 @@ class ElasticSearchBasicTest : public ::testing::Test { TEST_F(ElasticSearchBasicTest, SimpleTest) { FLAGS_heartbeat_interval_secs = 1; meta::cpp2::FTClient ftClient; - ftClient.set_host(HostAddr("127.0.0.1", esPort_)); + ftClient.host_ref() = HostAddr("127.0.0.1", esPort_); const nebula::ClusterID kClusterId = 10; mock::MockCluster cluster; cluster.startMeta(folly::stringPrintf("%s/meta", rootPath_->path())); @@ -189,13 +189,13 @@ TEST_F(ElasticSearchBasicTest, SimpleTest) { auto* mClient = cluster.metaClient_.get(); std::vector columns; columns.emplace_back(); - columns.back().set_name("col1"); - columns.back().type.set_type(PropertyType::STRING); + columns.back().name_ref() = "col1"; + columns.back().type.type_ref() = PropertyType::STRING; columns.emplace_back(); - columns.back().set_name("col2"); - columns.back().type.set_type(PropertyType::STRING); + columns.back().name_ref() = "col2"; + columns.back().type.type_ref() = PropertyType::STRING; meta::cpp2::Schema schema; - schema.set_columns(std::move(columns)); + schema.columns_ref() = std::move(columns); ret = mClient->createTagSchema(spaceId_, "tag1", schema).get(); ASSERT_TRUE(ret.ok()); tagId_ = std::move(ret).value(); diff --git a/src/storage/test/GetNeighborsBenchmark.cpp b/src/storage/test/GetNeighborsBenchmark.cpp index c7a8e96ab55..6945f06c482 100644 --- a/src/storage/test/GetNeighborsBenchmark.cpp +++ b/src/storage/test/GetNeighborsBenchmark.cpp @@ -93,7 +93,9 @@ void go(int32_t iters, const std::vector& playerProps, const std::vector& serveProps) { nebula::storage::cpp2::GetNeighborsRequest req; - BENCHMARK_SUSPEND { req = nebula::storage::buildRequest(vertex, playerProps, serveProps); } + BENCHMARK_SUSPEND { + req = nebula::storage::buildRequest(vertex, playerProps, serveProps); + } auto* env = gCluster->storageEnv_.get(); for (decltype(iters) i = 0; i < iters; i++) { auto* processor = nebula::storage::GetNeighborsProcessor::instance(env, nullptr, nullptr); @@ -121,7 +123,7 @@ void goFilter(int32_t iters, pool, nebula::EdgePropertyExpression::make(pool, folly::to(serve), "startYear"), nebula::ConstantExpression::make(pool, nebula::Value(value))); - (*req.traverse_spec_ref()).set_filter(nebula::Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = nebula::Expression::encode(exp); } else { // where serve.startYear < value && serve.endYear < value // since startYear always equal to endYear, the data of which can pass @@ -137,7 +139,7 @@ void goFilter(int32_t iters, pool, nebula::EdgePropertyExpression::make(pool, folly::to(serve), "endYear"), nebula::ConstantExpression::make(pool, nebula::Value(value)))); - (*req.traverse_spec_ref()).set_filter(nebula::Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = nebula::Expression::encode(exp); } } auto* env = gCluster->storageEnv_.get(); @@ -200,8 +202,8 @@ void goEdgeNode(int32_t iters, } CHECK_EQ(vertex.size(), resultDataSet.rowSize()); nebula::storage::cpp2::ResponseCommon result; - resp.set_result(std::move(result)); - resp.set_vertices(std::move(resultDataSet)); + resp.result_ref() = std::move(result); + resp.vertices_ref() = std::move(resultDataSet); auto encoded = encode(resp); folly::doNotOptimizeAway(encoded); } @@ -214,7 +216,9 @@ void prefix(int32_t iters, std::unique_ptr planCtx; std::unique_ptr context; nebula::storage::EdgeContext edgeContext; - BENCHMARK_SUSPEND { initContext(planCtx, context, edgeContext, serveProps); } + BENCHMARK_SUSPEND { + initContext(planCtx, context, edgeContext, serveProps); + } for (decltype(iters) i = 0; i < iters; i++) { nebula::storage::cpp2::GetNeighborsResponse resp; nebula::DataSet resultDataSet; @@ -292,8 +296,8 @@ void prefix(int32_t iters, } CHECK_EQ(vertex.size(), resultDataSet.rowSize()); nebula::storage::cpp2::ResponseCommon result; - resp.set_result(std::move(result)); - resp.set_vertices(std::move(resultDataSet)); + resp.result_ref() = std::move(result); + resp.vertices_ref() = std::move(resultDataSet); auto encoded = encode(resp); folly::doNotOptimizeAway(encoded); } @@ -318,7 +322,9 @@ void encodeBench(int32_t iters, } } -BENCHMARK(EncodeOneProperty, iters) { encodeBench(iters, {"Tim Duncan"}, {"name"}, {"teamName"}); } +BENCHMARK(EncodeOneProperty, iters) { + encodeBench(iters, {"Tim Duncan"}, {"name"}, {"teamName"}); +} BENCHMARK_RELATIVE(EncodeThreeProperty, iters) { encodeBench(iters, {"Tim Duncan"}, {"name"}, {"teamName", "startYear", "endYear"}); } @@ -334,8 +340,12 @@ BENCHMARK_DRAW_LINE(); // Players may serve more than one team, the total edges = teamCount * maxRank, // which would effect the final result, so select some player only serve one // team -BENCHMARK(OneVertexOneProperty, iters) { go(iters, {"Tim Duncan"}, {"name"}, {"teamName"}); } -BENCHMARK_RELATIVE(OneVertexOnlyId, iters) { go(iters, {"Tim Duncan"}, {"name"}, {nebula::kDst}); } +BENCHMARK(OneVertexOneProperty, iters) { + go(iters, {"Tim Duncan"}, {"name"}, {"teamName"}); +} +BENCHMARK_RELATIVE(OneVertexOnlyId, iters) { + go(iters, {"Tim Duncan"}, {"name"}, {nebula::kDst}); +} BENCHMARK_RELATIVE(OneVertexThreeProperty, iters) { go(iters, {"Tim Duncan"}, {"name"}, {"teamName", "startYear", "endYear"}); } @@ -354,7 +364,9 @@ BENCHMARK_RELATIVE(OneVertexOnePropertyOnlyKV, iters) { BENCHMARK_DRAW_LINE(); -BENCHMARK(NoFilter, iters) { go(iters, {"Tim Duncan"}, {"name"}, {"teamName"}); } +BENCHMARK(NoFilter, iters) { + go(iters, {"Tim Duncan"}, {"name"}, {"teamName"}); +} BENCHMARK_RELATIVE(OneFilterNonePass, iters) { goFilter(iters, {"Tim Duncan"}, {"name"}, {"teamName"}, FLAGS_max_rank * 0); } diff --git a/src/storage/test/GetNeighborsTest.cpp b/src/storage/test/GetNeighborsTest.cpp index 837f7da3681..95c4c455327 100644 --- a/src/storage/test/GetNeighborsTest.cpp +++ b/src/storage/test/GetNeighborsTest.cpp @@ -156,7 +156,7 @@ TEST(GetNeighborsTest, PropertyTest) { std::vector>> edges; tags.emplace_back(player, std::vector{"name", "age", "avgScore"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::OUT_EDGE); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::OUT_EDGE); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -175,7 +175,7 @@ TEST(GetNeighborsTest, PropertyTest) { std::vector>> edges; tags.emplace_back(player, std::vector{"name", "age", "avgScore"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::IN_EDGE); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::IN_EDGE); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -194,7 +194,7 @@ TEST(GetNeighborsTest, PropertyTest) { std::vector>> edges; tags.emplace_back(player, std::vector{"name", "age", "avgScore"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -213,7 +213,7 @@ TEST(GetNeighborsTest, PropertyTest) { std::vector>> edges; tags.emplace_back(team, std::vector{"name"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -505,43 +505,43 @@ TEST(GetNeighborsTest, StatTest) { { // count teamGames_ in all served history cpp2::StatProp statProp; - statProp.set_alias("Total games"); + statProp.alias_ref() = ("Total games"); const auto& exp = *EdgePropertyExpression::make(pool, folly::to(serve), "teamGames"); - statProp.set_prop(Expression::encode(exp)); - statProp.set_stat(cpp2::StatType::SUM); + statProp.prop_ref() = (Expression::encode(exp)); + statProp.stat_ref() = (cpp2::StatType::SUM); statProps.emplace_back(std::move(statProp)); } { // avg scores in all served teams cpp2::StatProp statProp; - statProp.set_alias("Avg scores in all served teams"); + statProp.alias_ref() = ("Avg scores in all served teams"); const auto& exp = *EdgePropertyExpression::make(pool, folly::to(serve), "teamAvgScore"); - statProp.set_prop(Expression::encode(exp)); - statProp.set_stat(cpp2::StatType::AVG); + statProp.prop_ref() = (Expression::encode(exp)); + statProp.stat_ref() = (cpp2::StatType::AVG); statProps.emplace_back(std::move(statProp)); } { // longest consecutive team career in a team cpp2::StatProp statProp; - statProp.set_alias("Longest consecutive team career in a team"); + statProp.alias_ref() = ("Longest consecutive team career in a team"); const auto& exp = *EdgePropertyExpression::make(pool, folly::to(serve), "teamCareer"); - statProp.set_prop(Expression::encode(exp)); - statProp.set_stat(cpp2::StatType::MAX); + statProp.prop_ref() = (Expression::encode(exp)); + statProp.stat_ref() = (cpp2::StatType::MAX); statProps.emplace_back(std::move(statProp)); } { // sum of rank in serve edge cpp2::StatProp statProp; - statProp.set_alias("Sum of rank in serve edge"); + statProp.alias_ref() = ("Sum of rank in serve edge"); const auto& exp = *EdgeRankExpression::make(pool, folly::to(serve)); - statProp.set_prop(Expression::encode(exp)); - statProp.set_stat(cpp2::StatType::SUM); + statProp.prop_ref() = (Expression::encode(exp)); + statProp.stat_ref() = (cpp2::StatType::SUM); statProps.emplace_back(std::move(statProp)); } - (*req.traverse_spec_ref()).set_stat_props(std::move(statProps)); + (*req.traverse_spec_ref()).stat_props_ref() = (std::move(statProps)); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -572,34 +572,34 @@ TEST(GetNeighborsTest, StatTest) { { // avg scores in all served teams cpp2::StatProp statProp; - statProp.set_alias("Avg scores in all served teams"); + statProp.alias_ref() = ("Avg scores in all served teams"); const auto& exp = *EdgePropertyExpression::make(pool, folly::to(serve), "teamAvgScore"); - statProp.set_prop(Expression::encode(exp)); - statProp.set_stat(cpp2::StatType::AVG); + statProp.prop_ref() = (Expression::encode(exp)); + statProp.stat_ref() = (cpp2::StatType::AVG); statProps.emplace_back(std::move(statProp)); } { // min avg scores in all served teams cpp2::StatProp statProp; - statProp.set_alias("Min scores in all served teams"); + statProp.alias_ref() = ("Min scores in all served teams"); const auto& exp = *EdgePropertyExpression::make(pool, folly::to(serve), "teamAvgScore"); - statProp.set_prop(Expression::encode(exp)); - statProp.set_stat(cpp2::StatType::MIN); + statProp.prop_ref() = (Expression::encode(exp)); + statProp.stat_ref() = (cpp2::StatType::MIN); statProps.emplace_back(std::move(statProp)); } { // max avg scores in all served teams cpp2::StatProp statProp; - statProp.set_alias("Max scores in all served teams"); + statProp.alias_ref() = ("Max scores in all served teams"); const auto& exp = *EdgePropertyExpression::make(pool, folly::to(serve), "teamAvgScore"); - statProp.set_prop(Expression::encode(exp)); - statProp.set_stat(cpp2::StatType::MAX); + statProp.prop_ref() = (Expression::encode(exp)); + statProp.stat_ref() = (cpp2::StatType::MAX); statProps.emplace_back(std::move(statProp)); } - (*req.traverse_spec_ref()).set_stat_props(std::move(statProps)); + (*req.traverse_spec_ref()).stat_props_ref() = (std::move(statProps)); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -641,7 +641,7 @@ TEST(GetNeighborsTest, LimitSampleTest) { tags.emplace_back(team, std::vector{"name"}); edges.emplace_back(-serve, std::vector{"playerName", "startYear", "teamCareer"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_limit(10); + (*req.traverse_spec_ref()).limit_ref() = (10); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -664,7 +664,7 @@ TEST(GetNeighborsTest, LimitSampleTest) { edges.emplace_back(teammate, std::vector{"player1", "player2", "teamName"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_limit(4); + (*req.traverse_spec_ref()).limit_ref() = (4); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); processor->process(req); @@ -689,8 +689,8 @@ TEST(GetNeighborsTest, LimitSampleTest) { tags.emplace_back(team, std::vector{"name"}); edges.emplace_back(-serve, std::vector{"playerName", "startYear", "teamCareer"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_limit(10); - (*req.traverse_spec_ref()).set_random(true); + (*req.traverse_spec_ref()).limit_ref() = (10); + (*req.traverse_spec_ref()).random_ref() = (true); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -713,8 +713,8 @@ TEST(GetNeighborsTest, LimitSampleTest) { edges.emplace_back(teammate, std::vector{"player1", "player2", "teamName"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_limit(4); - (*req.traverse_spec_ref()).set_random(true); + (*req.traverse_spec_ref()).limit_ref() = (4); + (*req.traverse_spec_ref()).random_ref() = (true); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); processor->process(req); @@ -746,8 +746,8 @@ TEST(GetNeighborsTest, LimitSampleTest) { edges.emplace_back(teammate, std::vector{"player1", "player2", "teamName"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_limit(5); - (*req.traverse_spec_ref()).set_random(true); + (*req.traverse_spec_ref()).limit_ref() = (5); + (*req.traverse_spec_ref()).random_ref() = (true); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); processor->process(req); @@ -841,7 +841,7 @@ TEST(GetNeighborsTest, MaxEdgReturnedPerVertexTest) { tags.emplace_back(team, std::vector{"name"}); edges.emplace_back(-serve, std::vector{"playerName", "startYear", "teamCareer"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_random(true); + (*req.traverse_spec_ref()).random_ref() = (true); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -866,7 +866,7 @@ TEST(GetNeighborsTest, MaxEdgReturnedPerVertexTest) { edges.emplace_back(teammate, std::vector{"player1", "player2", "teamName"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_random(true); + (*req.traverse_spec_ref()).random_ref() = (true); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); processor->process(req); @@ -900,7 +900,7 @@ TEST(GetNeighborsTest, MaxEdgReturnedPerVertexTest) { edges.emplace_back(teammate, std::vector{"player1", "player2", "teamName"}); auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_random(true); + (*req.traverse_spec_ref()).random_ref() = (true); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); processor->process(req); @@ -961,7 +961,7 @@ TEST(GetNeighborsTest, TtlTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1006,7 +1006,7 @@ TEST(GetNeighborsTest, TtlTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1195,7 +1195,7 @@ TEST(GetNeighborsTest, GoOverAllTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges, true); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1213,7 +1213,7 @@ TEST(GetNeighborsTest, GoOverAllTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1232,7 +1232,7 @@ TEST(GetNeighborsTest, GoOverAllTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1251,7 +1251,7 @@ TEST(GetNeighborsTest, GoOverAllTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::IN_EDGE); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::IN_EDGE); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1269,7 +1269,7 @@ TEST(GetNeighborsTest, GoOverAllTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::OUT_EDGE); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::OUT_EDGE); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1287,7 +1287,7 @@ TEST(GetNeighborsTest, GoOverAllTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1306,7 +1306,7 @@ TEST(GetNeighborsTest, GoOverAllTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1337,7 +1337,7 @@ TEST(GetNeighborsTest, MultiVersionTest) { std::vector>> tags; std::vector>> edges; auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); - (*req.traverse_spec_ref()).set_edge_direction(cpp2::EdgeDirection::BOTH); + (*req.traverse_spec_ref()).edge_direction_ref() = (cpp2::EdgeDirection::BOTH); auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1382,7 +1382,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, EdgePropertyExpression::make(pool, folly::to(serve), "teamAvgScore"), ConstantExpression::make(pool, Value(20))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1426,7 +1426,7 @@ TEST(GetNeighborsTest, FilterTest) { EdgePropertyExpression::make(pool, folly::to(serve), "endYear"), EdgePropertyExpression::make(pool, folly::to(serve), "startYear")), ConstantExpression::make(pool, Value(5))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1471,7 +1471,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, EdgePropertyExpression::make(pool, folly::to(serve), "teamCareer"), ConstantExpression::make(pool, Value(4)))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1509,7 +1509,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, EdgeDstIdExpression::make(pool, folly::to(serve)), ConstantExpression::make(pool, Value("Rockets"))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1554,7 +1554,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, SourcePropertyExpression::make(pool, folly::to(player), "games"), ConstantExpression::make(pool, Value(1000)))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1602,7 +1602,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, SourcePropertyExpression::make(pool, folly::to(player), "avgScore"), ConstantExpression::make(pool, Value(18)))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1688,7 +1688,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, EdgePropertyExpression::make(pool, folly::to(serve), "teamGames"), ConstantExpression::make(pool, Value(1000))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1736,7 +1736,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, EdgePropertyExpression::make(pool, folly::to(serve), "teamAvgScore"), ConstantExpression::make(pool, Value(15))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); @@ -1784,7 +1784,7 @@ TEST(GetNeighborsTest, FilterTest) { pool, EdgePropertyExpression::make(pool, folly::to(teammate), "startYear"), ConstantExpression::make(pool, Value(2002))); - (*req.traverse_spec_ref()).set_filter(Expression::encode(exp)); + (*req.traverse_spec_ref()).filter_ref() = (Expression::encode(exp)); } auto* processor = GetNeighborsProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); diff --git a/src/storage/test/GetPropTest.cpp b/src/storage/test/GetPropTest.cpp index 1ed42d03a1f..eb9e3a600dc 100644 --- a/src/storage/test/GetPropTest.cpp +++ b/src/storage/test/GetPropTest.cpp @@ -19,7 +19,7 @@ cpp2::GetPropRequest buildVertexRequest( const std::vector>>& tags) { std::hash hash; cpp2::GetPropRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; for (const auto& vertex : vertices) { PartitionID partId = (hash(vertex) % totalParts) + 1; nebula::Row row; @@ -29,18 +29,18 @@ cpp2::GetPropRequest buildVertexRequest( std::vector vertexProps; if (tags.empty()) { - req.set_vertex_props(std::move(vertexProps)); + req.vertex_props_ref() = std::move(vertexProps); } else { for (const auto& tag : tags) { TagID tagId = tag.first; cpp2::VertexProp tagProp; - tagProp.set_tag(tagId); + tagProp.tag_ref() = tagId; for (const auto& prop : tag.second) { (*tagProp.props_ref()).emplace_back(std::move(prop)); } vertexProps.emplace_back(std::move(tagProp)); } - req.set_vertex_props(std::move(vertexProps)); + req.vertex_props_ref() = std::move(vertexProps); } return req; } @@ -50,7 +50,7 @@ cpp2::GetPropRequest buildEdgeRequest( const std::vector& edgeKeys, const std::vector>>& edges) { cpp2::GetPropRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; for (const auto& edge : edgeKeys) { PartitionID partId = (std::hash()(edge.get_src()) % totalParts) + 1; nebula::Row row; @@ -63,18 +63,18 @@ cpp2::GetPropRequest buildEdgeRequest( std::vector edgeProps; if (edges.empty()) { - req.set_edge_props(std::move(edgeProps)); + req.edge_props_ref() = std::move(edgeProps); } else { for (const auto& edge : edges) { EdgeType edgeType = edge.first; cpp2::EdgeProp edgeProp; - edgeProp.set_type(edgeType); + edgeProp.type_ref() = edgeType; for (const auto& prop : edge.second) { (*edgeProp.props_ref()).emplace_back(std::move(prop)); } edgeProps.emplace_back(std::move(edgeProp)); } - req.set_edge_props(std::move(edgeProps)); + req.edge_props_ref() = std::move(edgeProps); } return req; } @@ -226,10 +226,10 @@ TEST(GetPropTest, PropertyTest) { std::vector edgeKeys; { cpp2::EdgeKey edgeKey; - edgeKey.set_src("Tim Duncan"); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(1997); - edgeKey.set_dst("Spurs"); + edgeKey.src_ref() = "Tim Duncan"; + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 1997; + edgeKey.dst_ref() = "Spurs"; edgeKeys.emplace_back(std::move(edgeKey)); } std::vector>> edges; @@ -253,10 +253,10 @@ TEST(GetPropTest, PropertyTest) { std::vector edgeKeys; { cpp2::EdgeKey edgeKey; - edgeKey.set_src("Tim Duncan"); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(1997); - edgeKey.set_dst("Spurs"); + edgeKey.src_ref() = "Tim Duncan"; + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 1997; + edgeKey.dst_ref() = "Spurs"; edgeKeys.emplace_back(std::move(edgeKey)); } std::vector>> edges; @@ -288,18 +288,18 @@ TEST(GetPropTest, PropertyTest) { std::vector edgeKeys; { cpp2::EdgeKey edgeKey; - edgeKey.set_src("Tim Duncan"); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(1997); - edgeKey.set_dst("Spurs"); + edgeKey.src_ref() = "Tim Duncan"; + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 1997; + edgeKey.dst_ref() = "Spurs"; edgeKeys.emplace_back(std::move(edgeKey)); } { cpp2::EdgeKey edgeKey; - edgeKey.set_src("Tony Parker"); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(2001); - edgeKey.set_dst("Spurs"); + edgeKey.src_ref() = "Tony Parker"; + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 2001; + edgeKey.dst_ref() = "Spurs"; edgeKeys.emplace_back(std::move(edgeKey)); } std::vector>> edges; @@ -374,10 +374,10 @@ TEST(GetPropTest, AllPropertyInOneSchemaTest) { std::vector edgeKeys; { cpp2::EdgeKey edgeKey; - edgeKey.set_src("Tim Duncan"); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(1997); - edgeKey.set_dst("Spurs"); + edgeKey.src_ref() = "Tim Duncan"; + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 1997; + edgeKey.dst_ref() = "Spurs"; edgeKeys.emplace_back(std::move(edgeKey)); } std::vector>> edges; @@ -449,10 +449,10 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) { std::vector edgeKeys; { cpp2::EdgeKey edgeKey; - edgeKey.set_src("Tim Duncan"); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(1997); - edgeKey.set_dst("Spurs"); + edgeKey.src_ref() = "Tim Duncan"; + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 1997; + edgeKey.dst_ref() = "Spurs"; edgeKeys.emplace_back(std::move(edgeKey)); } std::vector>> edges; diff --git a/src/storage/test/IndexScanLimitTest.cpp b/src/storage/test/IndexScanLimitTest.cpp index f4988f494a7..53164a20a20 100644 --- a/src/storage/test/IndexScanLimitTest.cpp +++ b/src/storage/test/IndexScanLimitTest.cpp @@ -36,8 +36,7 @@ class IndexScanLimitTest : public ::testing::Test { std::unique_ptr initKV(kvstore::KVOptions options) { HostAddr localHost; auto ioPool = std::make_shared(4); - auto workers = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager( - 1, true /*stats*/); + auto workers = apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager(1); workers->setNamePrefix("executor"); workers->start(); localHost.host = "0.0.0.0"; @@ -76,7 +75,7 @@ class IndexScanLimitTest : public ::testing::Test { std::vector cols; meta::cpp2::ColumnDef col; col.name = "col1"; - col.type.set_type(nebula::cpp2::PropertyType::INT64); + col.type.type_ref() = nebula::cpp2::PropertyType::INT64; cols.emplace_back(std::move(col)); return cols; } @@ -123,7 +122,7 @@ class IndexScanLimitTest : public ::testing::Test { data.emplace_back(std::move(tagKey), std::move(val)); if (indexMan_ != nullptr) { auto indexItem = std::make_unique(); - indexItem->set_fields(genCols()); + indexItem->fields_ref() = genCols(); if (indexMan_->getTagIndex(spaceId, tagIndex).ok()) { auto vertexIndexKeys = IndexKeyUtils::vertexIndexKeys( vertexLen, @@ -185,7 +184,9 @@ class IndexScanLimitTest : public ::testing::Test { EXPECT_TRUE(mockData()); } - void TearDown() override { delete rootPath_; } + void TearDown() override { + delete rootPath_; + } protected: fs::TempDir* rootPath_; @@ -199,20 +200,20 @@ class IndexScanLimitTest : public ::testing::Test { TEST_F(IndexScanLimitTest, LookupTagIndexLimit) { cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(tagId); - indices.set_schema_id(schemaId); - req.set_parts(parts); + schemaId.tag_id_ref() = tagId; + indices.schema_id_ref() = schemaId; + req.parts_ref() = parts; std::vector returnCols; returnCols.emplace_back(kVid); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); cpp2::IndexQueryContext context1; - context1.set_index_id(tagIndex); + context1.index_id_ref() = tagIndex; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); // verify all data { @@ -226,7 +227,7 @@ TEST_F(IndexScanLimitTest, LookupTagIndexLimit) { // limit == 0 { - req.set_limit(0); + req.limit_ref() = 0; auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -237,7 +238,7 @@ TEST_F(IndexScanLimitTest, LookupTagIndexLimit) { // limit == 1 { - req.set_limit(1); + req.limit_ref() = 1; auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -248,7 +249,7 @@ TEST_F(IndexScanLimitTest, LookupTagIndexLimit) { // limit 5 by each part { - req.set_limit(5); + req.limit_ref() = 5; auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -259,16 +260,16 @@ TEST_F(IndexScanLimitTest, LookupTagIndexLimit) { // limit 5 by each part through IndexScanNode->DataNode { - req.set_limit(5); + req.limit_ref() = 5; cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(111)); - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = Value(111); + columnHint.column_name_ref() = "col1"; + columnHint.scan_type_ref() = cpp2::ScanType::PREFIX; std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); req.return_columns_ref().value().emplace_back("col2"); - req.indices_ref().value().contexts_ref().value().begin()->set_column_hints( - std::move(columnHints)); + req.indices_ref().value().contexts_ref().value().begin()->column_hints_ref() = + std::move(columnHints); auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -279,19 +280,19 @@ TEST_F(IndexScanLimitTest, LookupTagIndexLimit) { // limit 5 by each part through IndexScanNode->DataNode->FilterNode { - req.set_limit(5); + req.limit_ref() = 5; cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(111)); - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = Value(111); + columnHint.column_name_ref() = "col1"; + columnHint.scan_type_ref() = cpp2::ScanType::PREFIX; std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); auto expr = RelationalExpression::makeNE(pool, TagPropertyExpression::make(pool, "100", "col1"), ConstantExpression::make(pool, Value(300L))); - req.indices_ref().value().contexts_ref().value().begin()->set_filter(expr->encode()); - req.indices_ref().value().contexts_ref().value().begin()->set_column_hints( - std::move(columnHints)); + req.indices_ref().value().contexts_ref().value().begin()->filter_ref() = expr->encode(); + req.indices_ref().value().contexts_ref().value().begin()->column_hints_ref() = + std::move(columnHints); auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -304,20 +305,20 @@ TEST_F(IndexScanLimitTest, LookupTagIndexLimit) { TEST_F(IndexScanLimitTest, LookupEdgeIndexLimit) { cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(edgeType); - indices.set_schema_id(schemaId); - req.set_parts(parts); + schemaId.edge_type_ref() = edgeType; + indices.schema_id_ref() = schemaId; + req.parts_ref() = parts; std::vector returnCols; returnCols.emplace_back(kSrc); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); cpp2::IndexQueryContext context1; - context1.set_index_id(edgeIndex); + context1.index_id_ref() = edgeIndex; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); // verify all data { @@ -331,7 +332,7 @@ TEST_F(IndexScanLimitTest, LookupEdgeIndexLimit) { // limit == 0 { - req.set_limit(0); + req.limit_ref() = 0; auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -342,7 +343,7 @@ TEST_F(IndexScanLimitTest, LookupEdgeIndexLimit) { // limit == 1 { - req.set_limit(1); + req.limit_ref() = 1; auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -353,7 +354,7 @@ TEST_F(IndexScanLimitTest, LookupEdgeIndexLimit) { // limit 5 by each part { - req.set_limit(5); + req.limit_ref() = 5; auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); @@ -364,16 +365,16 @@ TEST_F(IndexScanLimitTest, LookupEdgeIndexLimit) { // limit 5 by each part through IndexScanNode->DataNode { - req.set_limit(5); + req.limit_ref() = 5; cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(111)); - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = Value(111); + columnHint.column_name_ref() = "col1"; + columnHint.scan_type_ref() = cpp2::ScanType::PREFIX; std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); req.return_columns_ref().value().emplace_back("col2"); - req.indices_ref().value().contexts_ref().value().begin()->set_column_hints( - std::move(columnHints)); + req.indices_ref().value().contexts_ref().value().begin()->column_hints_ref() = + std::move(columnHints); auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); @@ -385,19 +386,19 @@ TEST_F(IndexScanLimitTest, LookupEdgeIndexLimit) { // limit 5 by each part through IndexScanNode->DataNode->FilterNode { - req.set_limit(5); + req.limit_ref() = 5; cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(111)); - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = Value(111); + columnHint.column_name_ref() = "col1"; + columnHint.scan_type_ref() = cpp2::ScanType::PREFIX; std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); auto expr = RelationalExpression::makeNE(pool, EdgePropertyExpression::make(pool, "200", "col1"), ConstantExpression::make(pool, Value(300L))); - req.indices_ref().value().contexts_ref().value().begin()->set_filter(expr->encode()); - req.indices_ref().value().contexts_ref().value().begin()->set_column_hints( - std::move(columnHints)); + req.indices_ref().value().contexts_ref().value().begin()->filter_ref() = expr->encode(); + req.indices_ref().value().contexts_ref().value().begin()->column_hints_ref() = + std::move(columnHints); auto* processor = LookupProcessor::instance(storageEnv_.get(), nullptr, nullptr); auto fut = processor->getFuture(); processor->process(req); diff --git a/src/storage/test/IndexTest.cpp b/src/storage/test/IndexTest.cpp index f0b7147e06a..30dcd46caaf 100644 --- a/src/storage/test/IndexTest.cpp +++ b/src/storage/test/IndexTest.cpp @@ -106,7 +106,9 @@ class IndexScanTestHelper { return ::nebula::cpp2::ErrorCode::SUCCEEDED; }; } - void setFatal(IndexScanNode* node, bool value) { node->fatalOnBaseNotFound_ = value; } + void setFatal(IndexScanNode* node, bool value) { + node->fatalOnBaseNotFound_ = value; + } }; class IndexScanTest : public ::testing::Test { protected: @@ -115,38 +117,38 @@ class IndexScanTest : public ::testing::Test { using ColumnHint = ::nebula::storage::cpp2::IndexColumnHint; static ColumnHint makeColumnHint(const std::string& name, const Value& value) { ColumnHint hint; - hint.set_column_name(name); - hint.set_begin_value(value); - hint.set_scan_type(cpp2::ScanType::PREFIX); + hint.column_name_ref() = name; + hint.begin_value_ref() = value; + hint.scan_type_ref() = cpp2::ScanType::PREFIX; return hint; } template static ColumnHint makeColumnHint(const std::string& name, const Value& begin, const Value& end) { ColumnHint hint; - hint.set_column_name(name); - hint.set_scan_type(cpp2::ScanType::RANGE); - hint.set_begin_value(begin); - hint.set_end_value(end); - hint.set_include_begin(includeBegin); - hint.set_include_end(includeEnd); + hint.column_name_ref() = name; + hint.scan_type_ref() = cpp2::ScanType::RANGE; + hint.begin_value_ref() = begin; + hint.end_value_ref() = end; + hint.include_begin_ref() = includeBegin; + hint.include_end_ref() = includeEnd; return hint; } template static ColumnHint makeBeginColumnHint(const std::string& name, const Value& begin) { ColumnHint hint; - hint.set_column_name(name); - hint.set_scan_type(cpp2::ScanType::RANGE); - hint.set_begin_value(begin); - hint.set_include_begin(include); + hint.column_name_ref() = name; + hint.scan_type_ref() = cpp2::ScanType::RANGE; + hint.begin_value_ref() = begin; + hint.include_begin_ref() = include; return hint; } template static ColumnHint makeEndColumnHint(const std::string& name, const Value& end) { ColumnHint hint; - hint.set_column_name(name); - hint.set_scan_type(cpp2::ScanType::RANGE); - hint.set_end_value(end); - hint.set_include_end(include); + hint.column_name_ref() = name; + hint.scan_type_ref() = cpp2::ScanType::RANGE; + hint.end_value_ref() = end; + hint.include_end_ref() = include; return hint; } static std::vector> encodeTag( @@ -223,7 +225,7 @@ class IndexScanTest : public ::testing::Test { }; TEST_F(IndexScanTest, Base) { auto rows = R"( - int | int + int | int 1 | 2 1 | 3 )"_row; @@ -969,7 +971,7 @@ TEST_F(IndexScanTest, Bool) { true | false false | false | false - true | + true | )"_row; auto schema = R"( a | bool | | @@ -1905,7 +1907,7 @@ class IndexTest : public ::testing::Test { TEST_F(IndexTest, Selection) { const auto rows = R"( - int | int + int | int 1 | 2 | 8 | 10 @@ -2005,7 +2007,7 @@ TEST_F(IndexTest, Limit) { } TEST_F(IndexTest, Dedup) { auto rows1 = R"( - int | int + int | int 1 | 2 1 | 3 2 | 2 diff --git a/src/storage/test/IndexTestUtil.h b/src/storage/test/IndexTestUtil.h index f5022ce3dd9..df2f831b91c 100644 --- a/src/storage/test/IndexTestUtil.h +++ b/src/storage/test/IndexTestUtil.h @@ -27,11 +27,21 @@ class MockKVIterator : public KVIterator { public: MockKVIterator(const KVMap& kv, KVMap::iterator&& iter) : kv_(kv), iter_(std::move(iter)) {} - bool valid() const { return iter_ != kv_.end() && validFunc_(iter_); } - void next() { iter_++; } - void prev() { iter_--; } - folly::StringPiece key() const { return folly::StringPiece(iter_->first); } - folly::StringPiece val() const { return folly::StringPiece(iter_->second); } + bool valid() const { + return iter_ != kv_.end() && validFunc_(iter_); + } + void next() { + iter_++; + } + void prev() { + iter_--; + } + folly::StringPiece key() const { + return folly::StringPiece(iter_->first); + } + folly::StringPiece val() const { + return folly::StringPiece(iter_->second); + } void setValidFunc(const std::function validFunc) { validFunc_ = validFunc; } @@ -361,7 +371,9 @@ class MockKVStore : public ::nebula::kvstore::KVStore { UNUSED(property); return ::nebula::cpp2::ErrorCode::SUCCEEDED; } - void put(const std::string& key, const std::string& value) { kv_[key] = value; } + void put(const std::string& key, const std::string& value) { + kv_[key] = value; + } private: using ::nebula::kvstore::KVStore::prefix; @@ -371,16 +383,26 @@ class MockKVStore : public ::nebula::kvstore::KVStore { class MockIndexNode : public IndexNode { public: explicit MockIndexNode(RuntimeContext* context) : IndexNode(context, "MockIndexNode") {} - ::nebula::cpp2::ErrorCode init(InitContext& initCtx) override { return initFunc(initCtx); } - std::unique_ptr copy() override { LOG(FATAL) << "Unexpect"; } + ::nebula::cpp2::ErrorCode init(InitContext& initCtx) override { + return initFunc(initCtx); + } + std::unique_ptr copy() override { + LOG(FATAL) << "Unexpect"; + } std::function nextFunc; std::function<::nebula::cpp2::ErrorCode(PartitionID)> executeFunc; std::function<::nebula::cpp2::ErrorCode(InitContext& initCtx)> initFunc; - std::string identify() override { return "MockIndexNode"; } + std::string identify() override { + return "MockIndexNode"; + } private: - Result doNext() override { return nextFunc(); } - ::nebula::cpp2::ErrorCode doExecute(PartitionID partId) override { return executeFunc(partId); }; + Result doNext() override { + return nextFunc(); + } + ::nebula::cpp2::ErrorCode doExecute(PartitionID partId) override { + return executeFunc(partId); + }; }; class RowParser { @@ -427,7 +449,9 @@ class RowParser { rowList_.emplace_back(std::move(row)); } } - const std::vector& getResult() { return rowList_; } + const std::vector& getResult() { + return rowList_; + } private: std::stringstream ss; @@ -484,7 +508,9 @@ class SchemaParser { schema->addField(name, type, length, nullable); } } - std::shared_ptr<::nebula::meta::NebulaSchemaProvider> getResult() { return schema; } + std::shared_ptr<::nebula::meta::NebulaSchemaProvider> getResult() { + return schema; + } private: std::stringstream ss; @@ -527,9 +553,9 @@ class IndexParser { int32_t id = std::stoi(match.str(3)); schemaName_ = name; if (match.str(1) == "TAG") { - schemaId_.set_tag_id(id); + schemaId_.tag_id_ref() = id; } else { - schemaId_.set_edge_type(id); + schemaId_.edge_type_ref() = id; } } std::vector> operator()(std::shared_ptr schema) { @@ -544,13 +570,13 @@ class IndexParser { } std::shared_ptr parse(const std::string& line) { auto ret = std::make_shared(); - ret->set_schema_id(schemaId_); - ret->set_schema_name(schemaName_); + ret->schema_id_ref() = schemaId_; + ret->schema_name_ref() = schemaName_; static std::regex pattern(R"(\((.+),(\d+)\):(.+))"); std::smatch match; CHECK(std::regex_match(line, match, pattern)); - ret->set_index_name(folly::trimWhitespace(folly::StringPiece(match.str(1)).toString())); - ret->set_index_id(std::stoi(match.str(2))); + ret->index_name_ref() = folly::trimWhitespace(folly::StringPiece(match.str(1)).toString()); + ret->index_id_ref() = std::stoi(match.str(2)); std::string columnStr = match.str(3); std::vector columns; folly::split(",", columnStr, columns); @@ -572,19 +598,19 @@ class IndexParser { } ::nebula::meta::cpp2::ColumnDef col; auto field = schema_->field(name); - col.set_name(name); + col.name_ref() = name; ::nebula::meta::cpp2::ColumnTypeDef type; if (length > 0) { - type.set_type_length(length); - type.set_type(::nebula::cpp2::PropertyType::FIXED_STRING); + type.type_length_ref() = length; + type.type_ref() = ::nebula::cpp2::PropertyType::FIXED_STRING; } else { - type.set_type(field->type()); + type.type_ref() = field->type(); } - col.set_type(type); - col.set_nullable(field->nullable()); + col.type_ref() = type; + col.nullable_ref() = field->nullable(); fields.emplace_back(std::move(col)); } - ret->set_fields(fields); + ret->fields_ref() = fields; return ret; } diff --git a/src/storage/test/IndexWithTTLTest.cpp b/src/storage/test/IndexWithTTLTest.cpp index a42a2392fcc..b5142e3517b 100644 --- a/src/storage/test/IndexWithTTLTest.cpp +++ b/src/storage/test/IndexWithTTLTest.cpp @@ -70,8 +70,8 @@ void createSchema(meta::SchemaManager* schemaMan, schema->addField( "c2", nebula::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); meta::cpp2::SchemaProp prop; - prop.set_ttl_col("c2"); - prop.set_ttl_duration(duration); + prop.ttl_col_ref() = "c2"; + prop.ttl_duration_ref() = duration; schema->setProp(prop); if (isEdge) { sm->addEdgeSchema(1, schemaId, std::move(schema)); @@ -89,7 +89,7 @@ void createIndex(meta::IndexManager* indexMan, std::vector cols; meta::cpp2::ColumnDef col; col.name = "c1"; - col.type.set_type(nebula::cpp2::PropertyType::INT64); + col.type.type_ref() = nebula::cpp2::PropertyType::INT64; cols.emplace_back(std::move(col)); if (isEdge) { im->addEdgeIndex(1, schemaId, indexId, std::move(cols)); @@ -100,20 +100,20 @@ void createIndex(meta::IndexManager* indexMan, void insertVertex(storage::StorageEnv* env, size_t vIdLen, TagID tagId) { cpp2::AddVerticesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = tagId; std::vector props; props.emplace_back(Value(1L)); props.emplace_back(Value(time::WallClock::fastNowInSec())); - newTag.set_props(std::move(props)); + newTag.props_ref() = std::move(props); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(convertVertexId(vIdLen, partId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = convertVertexId(vIdLen, partId); + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } auto* processor = AddVerticesProcessor::instance(env, nullptr); @@ -125,22 +125,22 @@ void insertVertex(storage::StorageEnv* env, size_t vIdLen, TagID tagId) { void insertEdge(storage::StorageEnv* env, size_t vIdLen, EdgeType edgeType) { cpp2::AddEdgesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::NewEdge newEdge; nebula::storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(convertVertexId(vIdLen, partId)); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(0); - edgeKey.set_dst(convertVertexId(vIdLen, partId + 6)); - newEdge.set_key(std::move(edgeKey)); + edgeKey.src_ref() = convertVertexId(vIdLen, partId); + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = 0; + edgeKey.dst_ref() = convertVertexId(vIdLen, partId + 6); + newEdge.key_ref() = std::move(edgeKey); std::vector props; props.emplace_back(Value(1L)); props.emplace_back(Value(time::WallClock::fastNowInSec())); - newEdge.set_props(std::move(props)); + newEdge.props_ref() = std::move(props); (*req.parts_ref())[partId].emplace_back(newEdge); - (*newEdge.key_ref()).set_edge_type(-edgeType); + (*newEdge.key_ref()).edge_type_ref() = -edgeType; (*req.parts_ref())[partId].emplace_back(std::move(newEdge)); } auto* processor = AddEdgesProcessor::instance(env, nullptr); @@ -272,26 +272,26 @@ TEST(IndexWithTTLTest, UpdateVerticesIndexWithTTL) { for (auto partId = 1; partId <= 6; partId++) { cpp2::UpdateVertexRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; VertexID vertexId = convertVertexId(vIdLen, partId); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(2021001); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = 2021001; std::vector updatedProps; cpp2::UpdatedProp uProp1; - uProp1.set_name("c1"); + uProp1.name_ref() = "c1"; const auto& val1 = *ConstantExpression::make(pool, 2L); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); cpp2::UpdatedProp uProp2; - uProp2.set_name("c2"); + uProp2.name_ref() = "c2"; const auto& val2 = *ConstantExpression::make(pool, 5555L); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); - req.set_insertable(false); + req.updated_props_ref() = std::move(updatedProps); + req.insertable_ref() = false; auto* processor = UpdateVertexProcessor::instance(env, nullptr); auto f = processor->getFuture(); @@ -343,32 +343,32 @@ TEST(IndexWithTTLTest, UpdateEdgesIndexWithTTL) { for (auto partId = 1; partId <= 6; partId++) { cpp2::UpdateEdgeRequest req; - req.set_space_id(1); - req.set_part_id(partId); + req.space_id_ref() = 1; + req.part_id_ref() = partId; VertexID srcId = convertVertexId(vIdLen, partId); VertexID dstId = convertVertexId(vIdLen, partId + 6); EdgeRanking rank = 0; storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(2021001); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = 2021001; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; std::vector updatedProps; cpp2::UpdatedProp uProp1; - uProp1.set_name("c1"); + uProp1.name_ref() = "c1"; const auto& val1 = *ConstantExpression::make(pool, 2L); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); cpp2::UpdatedProp uProp2; - uProp2.set_name("c2"); + uProp2.name_ref() = "c2"; const auto& val2 = *ConstantExpression::make(pool, 5555L); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); - req.set_insertable(false); + req.updated_props_ref() = std::move(updatedProps); + req.insertable_ref() = false; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); auto f = processor->getFuture(); @@ -422,16 +422,16 @@ TEST(IndexWithTTLTest, RebuildTagIndexWithTTL) { auto manager_ = AdminTaskManager::instance(); manager_->init(); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(parts); - parameter.set_task_specific_paras({"2021002"}); + parameter.parts_ref() = parts; + parameter.task_specific_paras_ref() = {"2021002"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_TAG_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(13); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_TAG_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 13; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -491,16 +491,16 @@ TEST(IndexWithTTLTest, RebuildEdgeIndexWithTTL) { auto manager_ = AdminTaskManager::instance(); manager_->init(); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(parts); - parameter.set_task_specific_paras({"2021002"}); + parameter.parts_ref() = parts; + parameter.task_specific_paras_ref() = {"2021002"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(13); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 13; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -562,16 +562,16 @@ TEST(IndexWithTTLTest, RebuildTagIndexWithTTLExpired) { auto manager_ = AdminTaskManager::instance(); manager_->init(); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(parts); - parameter.set_task_specific_paras({"2021002"}); + parameter.parts_ref() = parts; + parameter.task_specific_paras_ref() = {"2021002"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_TAG_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(13); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_TAG_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 13; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -633,16 +633,16 @@ TEST(IndexWithTTLTest, RebuildEdgeIndexWithTTLExpired) { auto manager_ = AdminTaskManager::instance(); manager_->init(); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(parts); - parameter.set_task_specific_paras({"2021002"}); + parameter.parts_ref() = parts; + parameter.task_specific_paras_ref() = {"2021002"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(15); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 15; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -685,29 +685,29 @@ TEST(IndexWithTTLTest, LookupTagIndexWithTTL) { auto* processor = LookupProcessor::instance(env, nullptr, nullptr); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(1); + req.space_id_ref() = 1; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(2021001); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = 2021001; + indices.schema_id_ref() = schemaId; std::vector parts; for (int32_t p = 1; p <= 6; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); auto expr = RelationalExpression::makeNE(pool, TagPropertyExpression::make(pool, "2021001", "c1"), ConstantExpression::make(pool, Value(34L))); cpp2::IndexQueryContext context1; - context1.set_filter(expr->encode()); - context1.set_index_id(2021002); + context1.filter_ref() = expr->encode(); + context1.index_id_ref() = 2021002; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -729,30 +729,30 @@ TEST(IndexWithTTLTest, LookupEdgeIndexWithTTL) { auto* processor = LookupProcessor::instance(env, nullptr, nullptr); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(1); + req.space_id_ref() = 1; nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(2021001); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = 2021001; + indices.schema_id_ref() = schemaId; std::vector parts; for (int32_t p = 1; p <= 6; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); auto expr = RelationalExpression::makeNE(pool, TagPropertyExpression::make(pool, "2021001", "c1"), ConstantExpression::make(pool, Value(34L))); cpp2::IndexQueryContext context1; - context1.set_filter(expr->encode()); - context1.set_index_id(2021002); + context1.filter_ref() = expr->encode(); + context1.index_id_ref() = 2021002; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -776,29 +776,29 @@ TEST(IndexWithTTLTest, LookupTagIndexWithTTLExpired) { auto* processor = LookupProcessor::instance(env, nullptr, nullptr); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(1); + req.space_id_ref() = 1; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(2021001); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = 2021001; + indices.schema_id_ref() = schemaId; std::vector parts; for (int32_t p = 1; p <= 6; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); auto expr = RelationalExpression::makeNE(pool, TagPropertyExpression::make(pool, "2021001", "c1"), ConstantExpression::make(pool, Value(34L))); cpp2::IndexQueryContext context1; - context1.set_filter(expr->encode()); - context1.set_index_id(2021002); + context1.filter_ref() = expr->encode(); + context1.index_id_ref() = 2021002; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -822,29 +822,29 @@ TEST(IndexWithTTLTest, LookupEdgeIndexWithTTLExpired) { auto* processor = LookupProcessor::instance(env, nullptr, nullptr); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(1); + req.space_id_ref() = 1; nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(2021001); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = 2021001; + indices.schema_id_ref() = schemaId; std::vector parts; for (int32_t p = 1; p <= 6; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); auto expr = RelationalExpression::makeNE(pool, TagPropertyExpression::make(pool, "2021001", "c1"), ConstantExpression::make(pool, Value(34L))); cpp2::IndexQueryContext context1; - context1.set_filter(expr->encode()); - context1.set_index_id(2021002); + context1.filter_ref() = expr->encode(); + context1.index_id_ref() = 2021002; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); diff --git a/src/storage/test/IndexWriteTest.cpp b/src/storage/test/IndexWriteTest.cpp index 23a92c4e5c6..486fda4702a 100644 --- a/src/storage/test/IndexWriteTest.cpp +++ b/src/storage/test/IndexWriteTest.cpp @@ -55,13 +55,13 @@ TEST(IndexTest, SimpleVerticesTest) { // verify insert { cpp2::AddVerticesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; // mock v2 vertices for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(3); + newTag.tag_id_ref() = 3; const Date date = {2020, 2, 20}; const DateTime dt = {2020, 2, 20, 10, 30, 45, 0}; std::vector props; @@ -76,11 +76,11 @@ TEST(IndexTest, SimpleVerticesTest) { props.emplace_back(Value(1L)); props.emplace_back(Value(std::move(date))); props.emplace_back(Value(std::move(dt))); - newTag.set_props(std::move(props)); + newTag.props_ref() = std::move(props); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(convertVertexId(vIdLen, partId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = convertVertexId(vIdLen, partId); + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } auto* processor = AddVerticesProcessor::instance(env, nullptr); @@ -107,7 +107,7 @@ TEST(IndexTest, SimpleVerticesTest) { { auto* processor = DeleteVerticesProcessor::instance(env, nullptr); cpp2::DeleteVerticesRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; for (auto partId = 1; partId <= 6; partId++) { std::vector vertices; vertices.emplace_back(Value(convertVertexId(vIdLen, partId))); @@ -144,17 +144,17 @@ TEST(IndexTest, SimpleEdgesTest) { // verify insert { cpp2::AddEdgesRequest req; - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; // mock v2 edges for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::NewEdge newEdge; nebula::storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(convertVertexId(vIdLen, partId)); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(0); - edgeKey.set_dst(convertVertexId(vIdLen, partId + 6)); - newEdge.set_key(std::move(edgeKey)); + edgeKey.src_ref() = convertVertexId(vIdLen, partId); + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 0; + edgeKey.dst_ref() = convertVertexId(vIdLen, partId + 6); + newEdge.key_ref() = std::move(edgeKey); std::vector props; props.emplace_back(Value("col1")); props.emplace_back(Value("col2")); @@ -163,9 +163,9 @@ TEST(IndexTest, SimpleEdgesTest) { props.emplace_back(Value(5L)); props.emplace_back(Value(6L)); props.emplace_back(Value(7.7F)); - newEdge.set_props(std::move(props)); + newEdge.props_ref() = std::move(props); (*req.parts_ref())[partId].emplace_back(newEdge); - (*newEdge.key_ref()).set_edge_type(-101); + (*newEdge.key_ref()).edge_type_ref() = -101; (*req.parts_ref())[partId].emplace_back(std::move(newEdge)); } auto* processor = AddEdgesProcessor::instance(env, nullptr); @@ -192,15 +192,15 @@ TEST(IndexTest, SimpleEdgesTest) { { auto* processor = DeleteEdgesProcessor::instance(env, nullptr); cpp2::DeleteEdgesRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(convertVertexId(vIdLen, partId)); - edgeKey.set_edge_type(101); - edgeKey.set_ranking(0); - edgeKey.set_dst(convertVertexId(vIdLen, partId + 6)); + edgeKey.src_ref() = convertVertexId(vIdLen, partId); + edgeKey.edge_type_ref() = 101; + edgeKey.ranking_ref() = 0; + edgeKey.dst_ref() = convertVertexId(vIdLen, partId + 6); (*req.parts_ref())[partId].emplace_back(edgeKey); - edgeKey.set_edge_type(-101); + edgeKey.edge_type_ref() = -101; (*req.parts_ref())[partId].emplace_back(std::move(edgeKey)); } auto fut = processor->getFuture(); @@ -252,17 +252,17 @@ TEST(IndexTest, VerticesValueTest) { // verify insert { cpp2::AddVerticesRequest req; - req.set_space_id(spaceId); - req.set_if_not_exists(true); + req.space_id_ref() = spaceId; + req.if_not_exists_ref() = true; std::unordered_map> propNames; propNames[tagId] = { "col_bool", "col_int", "col_float", "col_float_null", "col_str", "col_date"}; - req.set_prop_names(std::move(propNames)); + req.prop_names_ref() = std::move(propNames); // mock v2 vertices for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = tagId; const Date date = {2020, 1, 20}; std::vector props; props.emplace_back(Value(true)); @@ -271,11 +271,11 @@ TEST(IndexTest, VerticesValueTest) { props.emplace_back(Value(5.5f)); props.emplace_back(Value("string")); props.emplace_back(Value(std::move(date))); - newTag.set_props(std::move(props)); + newTag.props_ref() = std::move(props); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(convertVertexId(vIdLen, partId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = convertVertexId(vIdLen, partId); + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } auto* processor = AddVerticesProcessor::instance(env, nullptr); @@ -319,7 +319,7 @@ TEST(IndexTest, VerticesValueTest) { // col_date_null values.emplace_back(nullValue); auto indexItem = std::make_unique(); - indexItem->set_fields(mock::MockData::mockTypicaIndexColumns()); + indexItem->fields_ref() = mock::MockData::mockTypicaIndexColumns(); auto indexes = IndexKeyUtils::encodeValues(std::move(values), indexItem.get()); for (auto partId = 1; partId <= 6; partId++) { @@ -371,24 +371,24 @@ TEST(IndexTest, AlterTagIndexTest) { // verify insert { cpp2::AddVerticesRequest req; - req.set_space_id(spaceId); - req.set_if_not_exists(true); + req.space_id_ref() = spaceId; + req.if_not_exists_ref() = true; // mock v2 vertices for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = tagId; std::vector props; props.emplace_back(Value(true)); props.emplace_back(Value(1L)); props.emplace_back(Value(1.1f)); props.emplace_back(Value(1.1f)); props.emplace_back(Value("string")); - newTag.set_props(std::move(props)); + newTag.props_ref() = std::move(props); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(convertVertexId(vIdLen, partId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = convertVertexId(vIdLen, partId); + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } auto* processor = AddVerticesProcessor::instance(env, nullptr); @@ -425,13 +425,13 @@ TEST(IndexTest, AlterTagIndexTest) { // verify insert { cpp2::AddVerticesRequest req; - req.set_space_id(spaceId); - req.set_if_not_exists(false); + req.space_id_ref() = spaceId; + req.if_not_exists_ref() = false; // mock v2 vertices for (auto partId = 1; partId <= 6; partId++) { nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = tagId; const Date date = {2020, 2, 20}; const DateTime dt = {2020, 2, 20, 10, 30, 45, 0}; std::vector props; @@ -446,11 +446,11 @@ TEST(IndexTest, AlterTagIndexTest) { props.emplace_back(Value(1L)); props.emplace_back(Value(std::move(date))); props.emplace_back(Value(std::move(dt))); - newTag.set_props(std::move(props)); + newTag.props_ref() = std::move(props); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(convertVertexId(vIdLen, partId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = convertVertexId(vIdLen, partId); + newVertex.tags_ref() = std::move(newTags); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } auto* processor = AddVerticesProcessor::instance(env, nullptr); diff --git a/src/storage/test/KillQueryTest.cpp b/src/storage/test/KillQueryTest.cpp index fbedbd7a2d9..815ddad74a5 100644 --- a/src/storage/test/KillQueryTest.cpp +++ b/src/storage/test/KillQueryTest.cpp @@ -73,9 +73,9 @@ TEST_F(KillQueryTest, GetNeighbors) { auto req = QueryTestUtils::buildRequest(totalParts, vertices, over, tags, edges); cpp2::RequestCommon common; - common.set_session_id(1); - common.set_plan_id(1); - req.set_common(common); + common.session_id_ref() = 1; + common.plan_id_ref() = 1; + req.common_ref() = common; auto fut = processor->getFuture(); processor->process(req); cpp2::GetNeighborsResponse resp = std::move(fut).get(); @@ -100,39 +100,39 @@ TEST_F(KillQueryTest, TagIndex) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = 1; + indices.schema_id_ref() = schemaId; std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("age"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); cpp2::IndexColumnHint columnHint; std::string name = "Rudy Gay"; - columnHint.set_begin_value(Value(name)); - columnHint.set_column_name("name"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = Value(name); + columnHint.column_name_ref() = "name"; + columnHint.scan_type_ref() = cpp2::ScanType::PREFIX; std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(1); + context1.column_hints_ref() = std::move(columnHints); + context1.filter_ref() = ""; + context1.index_id_ref() = 1; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); cpp2::RequestCommon common; - common.set_session_id(1); - common.set_plan_id(1); - req.set_common(common); + common.session_id_ref() = 1; + common.plan_id_ref() = 1; + req.common_ref() = common; auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -160,15 +160,15 @@ TEST_F(KillQueryTest, EdgeIndex) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(102); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = 102; + indices.schema_id_ref() = schemaId; std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::string tony = "Tony Parker"; std::string manu = "Manu Ginobili"; std::vector returnCols; @@ -177,25 +177,25 @@ TEST_F(KillQueryTest, EdgeIndex) { returnCols.emplace_back(kRank); returnCols.emplace_back(kDst); returnCols.emplace_back("teamName"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = std::move(returnCols); cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(tony)); - columnHint.set_column_name("player1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = Value(tony); + columnHint.column_name_ref() = "player1"; + columnHint.scan_type_ref() = cpp2::ScanType::PREFIX; std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(102); + context1.column_hints_ref() = std::move(columnHints); + context1.filter_ref() = ""; + context1.index_id_ref() = 102; decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = std::move(contexts); + req.indices_ref() = std::move(indices); cpp2::RequestCommon common; - common.set_session_id(1); - common.set_plan_id(1); - req.set_common(common); + common.session_id_ref() = 1; + common.plan_id_ref() = 1; + req.common_ref() = common; auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); diff --git a/src/storage/test/ListClusterInfoTest.cpp b/src/storage/test/ListClusterInfoTest.cpp deleted file mode 100644 index 3a3e3105eba..00000000000 --- a/src/storage/test/ListClusterInfoTest.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (c) 2019 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License. - */ - -#include - -#include "common/base/Base.h" -#include "common/fs/TempDir.h" -#include "mock/MockCluster.h" -#include "mock/MockData.h" -#include "storage/admin/ListClusterInfoProcessor.h" - -namespace nebula { -namespace storage { -TEST(ListClusterInfoTest, simpleTest) { - fs::TempDir dataPath("/tmp/ListClusterInfo_Test_src.XXXXXX"); - mock::MockCluster cluster; - cluster.initStorageKV(dataPath.path()); - auto* env = cluster.storageEnv_.get(); - - // Begin list clusterinfo - { - auto* processor = ListClusterInfoProcessor::instance(env); - cpp2::ListClusterInfoReq req; - auto fut = processor->getFuture(); - processor->process(req); - auto resp = std::move(fut).get(); - EXPECT_EQ(0, resp.result.failed_parts.size()); - auto data_root = env->kvstore_->getDataRoot(); - auto dir = resp.get_dir(); - ASSERT_EQ(dir.get_data().size(), data_root.size()); - int i = 0; - for (auto d : dir.get_data()) { - ASSERT_EQ(d, data_root[i]); - i++; - } - std::cout << dir.get_root() << std::endl; - ASSERT_FALSE(dir.get_data().empty()); - } -} - -} // namespace storage -} // namespace nebula - -int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); - folly::init(&argc, &argv, true); - google::SetStderrLogging(google::INFO); - return RUN_ALL_TESTS(); -} diff --git a/src/storage/test/LookupIndexTest.cpp b/src/storage/test/LookupIndexTest.cpp index 2e750da42c2..629ed1d9a50 100644 --- a/src/storage/test/LookupIndexTest.cpp +++ b/src/storage/test/LookupIndexTest.cpp @@ -39,7 +39,9 @@ auto pool = &objPool; class LookupIndexTest : public ::testing::TestWithParam { public: - void SetUp() override { FLAGS_query_concurrently = GetParam(); } + void SetUp() override { + FLAGS_query_concurrently = GetParam(); + } void TearDown() override {} }; @@ -137,34 +139,34 @@ TEST_P(LookupIndexTest, LookupIndexTestV1) { { cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(1); + req.space_id_ref() = 1; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(3); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = 3; + indices.schema_id_ref() = schemaId; std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back("col_bool"); returnCols.emplace_back("col_int"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(true)); - columnHint.set_column_name("col_bool"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(true)); + columnHint.column_name_ref() = ("col_bool"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(3); + context1.column_hints_ref() = (std::move(columnHints)); + context1.filter_ref() = (""); + context1.index_id_ref() = (3); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); processor->process(req); @@ -229,35 +231,35 @@ TEST_P(LookupIndexTest, SimpleTagIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("age"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; std::string name = "Rudy Gay"; - columnHint.set_begin_value(Value(name)); - columnHint.set_column_name("name"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(name)); + columnHint.column_name_ref() = ("name"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(1); + context1.column_hints_ref() = (std::move(columnHints)); + context1.filter_ref() = (""); + context1.index_id_ref() = (1); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -297,49 +299,49 @@ TEST_P(LookupIndexTest, SimpleTagIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("age"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); // player.name_ == "Rudy Gay" cpp2::IndexColumnHint columnHint1; std::string name1 = "Rudy Gay"; - columnHint1.set_begin_value(Value(name1)); - columnHint1.set_column_name("name"); - columnHint1.set_scan_type(cpp2::ScanType::PREFIX); + columnHint1.begin_value_ref() = (Value(name1)); + columnHint1.column_name_ref() = ("name"); + columnHint1.scan_type_ref() = (cpp2::ScanType::PREFIX); // player.name_ == "Kobe Bryant" cpp2::IndexColumnHint columnHint2; std::string name2 = "Kobe Bryant"; - columnHint2.set_begin_value(Value(name2)); - columnHint2.set_column_name("name"); - columnHint2.set_scan_type(cpp2::ScanType::PREFIX); + columnHint2.begin_value_ref() = (Value(name2)); + columnHint2.column_name_ref() = ("name"); + columnHint2.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints1; columnHints1.emplace_back(std::move(columnHint1)); std::vector columnHints2; columnHints2.emplace_back(std::move(columnHint2)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints1)); - context1.set_filter(""); - context1.set_index_id(1); + context1.column_hints_ref() = (std::move(columnHints1)); + context1.filter_ref() = (""); + context1.index_id_ref() = (1); cpp2::IndexQueryContext context2; - context2.set_column_hints(std::move(columnHints2)); - context2.set_filter(""); - context2.set_index_id(1); + context2.column_hints_ref() = (std::move(columnHints2)); + context2.filter_ref() = (""); + context2.index_id_ref() = (1); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); contexts.emplace_back(std::move(context2)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -400,15 +402,15 @@ TEST_P(LookupIndexTest, SimpleEdgeIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(102); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (102); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::string tony = "Tony Parker"; std::string manu = "Manu Ginobili"; std::vector returnCols; @@ -417,21 +419,21 @@ TEST_P(LookupIndexTest, SimpleEdgeIndexTest) { returnCols.emplace_back(kRank); returnCols.emplace_back(kDst); returnCols.emplace_back("teamName"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(tony)); - columnHint.set_column_name("player1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(tony)); + columnHint.column_name_ref() = ("player1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(102); + context1.column_hints_ref() = (std::move(columnHints)); + context1.filter_ref() = (""); + context1.index_id_ref() = (102); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -485,15 +487,15 @@ TEST_P(LookupIndexTest, SimpleEdgeIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(102); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (102); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::string tony = "Tony Parker"; std::string manu = "Manu Ginobili"; std::string yao = "Yao Ming"; @@ -504,34 +506,34 @@ TEST_P(LookupIndexTest, SimpleEdgeIndexTest) { returnCols.emplace_back(kRank); returnCols.emplace_back(kDst); returnCols.emplace_back("teamName"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); // teammates.player1 == "Tony Parker" cpp2::IndexColumnHint columnHint1; - columnHint1.set_begin_value(Value(tony)); - columnHint1.set_column_name("player1"); - columnHint1.set_scan_type(cpp2::ScanType::PREFIX); + columnHint1.begin_value_ref() = (Value(tony)); + columnHint1.column_name_ref() = ("player1"); + columnHint1.scan_type_ref() = (cpp2::ScanType::PREFIX); // teammates.player1 == "Yao Ming" cpp2::IndexColumnHint columnHint2; - columnHint2.set_begin_value(Value(yao)); - columnHint2.set_column_name("player1"); - columnHint2.set_scan_type(cpp2::ScanType::PREFIX); + columnHint2.begin_value_ref() = (Value(yao)); + columnHint2.column_name_ref() = ("player1"); + columnHint2.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints1; columnHints1.emplace_back(std::move(columnHint1)); std::vector columnHints2; columnHints2.emplace_back(std::move(columnHint2)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints1)); - context1.set_filter(""); - context1.set_index_id(102); + context1.column_hints_ref() = (std::move(columnHints1)); + context1.filter_ref() = (""); + context1.index_id_ref() = (102); cpp2::IndexQueryContext context2; - context2.set_column_hints(std::move(columnHints2)); - context2.set_filter(""); - context2.set_index_id(102); + context2.column_hints_ref() = (std::move(columnHints2)); + context2.filter_ref() = (""); + context2.index_id_ref() = (102); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); contexts.emplace_back(std::move(context2)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -618,39 +620,39 @@ TEST_P(LookupIndexTest, TagIndexFilterTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("age"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; std::string name = "Rudy Gay"; - columnHint.set_begin_value(Value(name)); - columnHint.set_column_name("name"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(name)); + columnHint.column_name_ref() = ("name"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); + context1.column_hints_ref() = (std::move(columnHints)); const auto& expr = *RelationalExpression::makeEQ(pool, TagPropertyExpression::make(pool, "player", "age"), ConstantExpression::make(pool, Value(34L))); - context1.set_filter(expr.encode()); - context1.set_index_id(1); + context1.filter_ref() = (expr.encode()); + context1.index_id_ref() = (1); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -694,39 +696,39 @@ TEST_P(LookupIndexTest, TagIndexFilterTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("age"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; std::string name = "Rudy Gay"; - columnHint.set_begin_value(Value(name)); - columnHint.set_column_name("name"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(name)); + columnHint.column_name_ref() = ("name"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); + context1.column_hints_ref() = (std::move(columnHints)); const auto& expr = *RelationalExpression::makeGT(pool, TagPropertyExpression::make(pool, "player", "age"), ConstantExpression::make(pool, Value(34L))); - context1.set_filter(expr.encode()); - context1.set_index_id(1); + context1.filter_ref() = (expr.encode()); + context1.index_id_ref() = (1); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -777,15 +779,15 @@ TEST_P(LookupIndexTest, EdgeIndexFilterTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(102); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (102); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::string tony = "Tony Parker"; std::string manu = "Manu Ginobili"; std::vector returnCols; @@ -794,25 +796,25 @@ TEST_P(LookupIndexTest, EdgeIndexFilterTest) { returnCols.emplace_back(kRank); returnCols.emplace_back(kDst); returnCols.emplace_back("teamName"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(tony)); - columnHint.set_column_name("player1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(tony)); + columnHint.column_name_ref() = ("player1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); + context1.column_hints_ref() = (std::move(columnHints)); // const auto& expr = *RelationalExpression::makeEQ( // pool, // EdgePropertyExpression::make(pool, "Teammate", "teamName"), // ConstantExpression::make(pool, Value("Spurs"))); - context1.set_filter(""); - context1.set_index_id(102); + context1.filter_ref() = (""); + context1.index_id_ref() = (102); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -871,15 +873,15 @@ TEST_P(LookupIndexTest, EdgeIndexFilterTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(102); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (102); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::string tony = "Tony Parker"; std::string manu = "Manu Ginobili"; std::vector returnCols; @@ -888,25 +890,25 @@ TEST_P(LookupIndexTest, EdgeIndexFilterTest) { returnCols.emplace_back(kRank); returnCols.emplace_back(kDst); returnCols.emplace_back("teamName"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(tony)); - columnHint.set_column_name("player1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(tony)); + columnHint.column_name_ref() = ("player1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); + context1.column_hints_ref() = (std::move(columnHints)); const auto& expr = *RelationalExpression::makeNE(pool, EdgePropertyExpression::make(pool, "Teammate", "teamName"), ConstantExpression::make(pool, Value("Spurs"))); - context1.set_filter(expr.encode()); - context1.set_index_id(102); + context1.filter_ref() = (expr.encode()); + context1.index_id_ref() = (102); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -958,35 +960,35 @@ TEST_P(LookupIndexTest, TagIndexWithDataTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("games"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; std::string name = "Rudy Gay"; - columnHint.set_begin_value(Value(name)); - columnHint.set_column_name("name"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(name)); + columnHint.column_name_ref() = ("name"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(1); + context1.column_hints_ref() = (std::move(columnHints)); + context1.filter_ref() = (""); + context1.index_id_ref() = (1); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -1045,15 +1047,15 @@ TEST_P(LookupIndexTest, EdgeIndexWithDataTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(102); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (102); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::string tony = "Tony Parker"; std::string manu = "Manu Ginobili"; std::vector returnCols; @@ -1062,21 +1064,21 @@ TEST_P(LookupIndexTest, EdgeIndexWithDataTest) { returnCols.emplace_back(kRank); returnCols.emplace_back(kDst); returnCols.emplace_back("startYear"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); cpp2::IndexColumnHint columnHint; - columnHint.set_begin_value(Value(tony)); - columnHint.set_column_name("player1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (Value(tony)); + columnHint.column_name_ref() = ("player1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints; columnHints.emplace_back(std::move(columnHint)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints)); - context1.set_filter(""); - context1.set_index_id(102); + context1.column_hints_ref() = (std::move(columnHints)); + context1.filter_ref() = (""); + context1.index_id_ref() = (102); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -1144,23 +1146,23 @@ TEST_P(LookupIndexTest, TagWithPropStatsVerticesIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); cpp2::IndexQueryContext context1; - context1.set_filter(""); - context1.set_index_id(4); + context1.filter_ref() = (""); + context1.index_id_ref() = (4); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); - req.set_return_columns({kVid, kTag}); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); + req.return_columns_ref() = {kVid, kTag}; auto fut = processor->getFuture(); processor->process(req); @@ -1217,23 +1219,23 @@ TEST_P(LookupIndexTest, TagWithoutPropStatsVerticesIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); cpp2::IndexQueryContext context1; - context1.set_filter(""); - context1.set_index_id(4); + context1.filter_ref() = (""); + context1.index_id_ref() = (4); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); - req.set_return_columns({kVid, kTag}); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); + req.return_columns_ref() = {kVid, kTag}; auto fut = processor->getFuture(); processor->process(req); @@ -1291,23 +1293,23 @@ TEST_P(LookupIndexTest, EdgeWithPropStatsVerticesIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(101); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (101); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); cpp2::IndexQueryContext context1; - context1.set_filter(""); - context1.set_index_id(103); + context1.filter_ref() = (""); + context1.index_id_ref() = (103); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); - req.set_return_columns({kSrc, kType, kRank, kDst}); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); + req.return_columns_ref() = {kSrc, kType, kRank, kDst}; auto fut = processor->getFuture(); processor->process(req); @@ -1374,23 +1376,23 @@ TEST_P(LookupIndexTest, EdgeWithoutPropStatsVerticesIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(101); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (101); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); cpp2::IndexQueryContext context1; - context1.set_filter(""); - context1.set_index_id(103); + context1.filter_ref() = (""); + context1.index_id_ref() = (103); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); - req.set_return_columns({kSrc, kType, kRank, kDst}); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); + req.return_columns_ref() = {kSrc, kType, kRank, kDst}; auto fut = processor->getFuture(); processor->process(req); @@ -1446,15 +1448,15 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { meta::cpp2::ColumnDef col1; col1.name = "col1"; - col1.type.set_type(PropertyType::INT64); - col1.set_nullable(true); + col1.type.type_ref() = (PropertyType::INT64); + col1.nullable_ref() = (true); cols.emplace_back(std::move(col1)); meta::cpp2::ColumnDef col2; col2.name = "col2"; - col2.type.set_type(PropertyType::FIXED_STRING); - col2.type.set_type_length(20); - col2.set_nullable(true); + col2.type.type_ref() = (PropertyType::FIXED_STRING); + col2.type.type_length_ref() = (20); + col2.nullable_ref() = (true); cols.emplace_back(std::move(col2)); indexMan->addTagIndex(spaceId, tagId, indexId, std::move(cols)); @@ -1467,27 +1469,27 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { { PartitionID partId = 1; cpp2::AddVerticesRequest req; - req.set_space_id(spaceId); - req.set_if_not_exists(true); + req.space_id_ref() = (spaceId); + req.if_not_exists_ref() = (true); std::unordered_map> propNames; propNames[tagId] = {"col1", "col2", "col3", "col4"}; - req.set_prop_names(std::move(propNames)); + req.prop_names_ref() = (std::move(propNames)); { // all not null VertexID vId = "1_a_1_a"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(1)); props.emplace_back(Value("aaa")); props.emplace_back(Value(1)); props.emplace_back(Value("aaa")); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = genVid(vId); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -1495,17 +1497,17 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { VertexID vId = "string_null"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(2)); props.emplace_back(NullType::__NULL__); props.emplace_back(Value(2)); props.emplace_back(NullType::__NULL__); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -1513,17 +1515,17 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { VertexID vId = "int_null"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(NullType::__NULL__); props.emplace_back(Value("bbb")); props.emplace_back(NullType::__NULL__); props.emplace_back(Value("bbb")); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -1531,17 +1533,17 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { VertexID vId = "3_c_null_null"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(3)); props.emplace_back(Value("ccc")); props.emplace_back(NullType::__NULL__); props.emplace_back(NullType::__NULL__); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -1549,17 +1551,17 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { VertexID vId = "3_c_3_c"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(3)); props.emplace_back(Value("ccc")); props.emplace_back(Value(3)); props.emplace_back(Value("ccc")); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -1567,17 +1569,17 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { VertexID vId = "all_null"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(NullType::__NULL__); props.emplace_back(NullType::__NULL__); props.emplace_back(NullType::__NULL__); props.emplace_back(NullType::__NULL__); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } @@ -1588,27 +1590,27 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { EXPECT_EQ(0, resp.result.failed_parts.size()); } cpp2::LookupIndexRequest req; - req.set_space_id(spaceId); - req.set_parts({1, 2, 3, 4, 5, 6}); - req.set_return_columns({kVid}); + req.space_id_ref() = (spaceId); + req.parts_ref() = {1, 2, 3, 4, 5, 6}; + req.return_columns_ref() = {kVid}; { LOG(INFO) << "lookup on tag where tag.col1 == 0"; cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value(0); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (0); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints({columnHint}); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = {columnHint}; cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1621,21 +1623,21 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { { LOG(INFO) << "lookup on tag where tag.col1 == 1"; cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value(1); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (1); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints({columnHint}); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = {columnHint}; cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1651,30 +1653,30 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { std::vector columnHints; { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value(1); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (1); columnHints.emplace_back(std::move(columnHint)); } { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col2"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value("aaa"); + columnHint.column_name_ref() = ("col2"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = ("aaa"); columnHints.emplace_back(std::move(columnHint)); } cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = ""; + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1688,22 +1690,22 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { { LOG(INFO) << "lookup on tag where tag.col1 < 2"; cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::RANGE); - columnHint.set_begin_value(std::numeric_limits::min()); - columnHint.set_end_value(2); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::RANGE); + columnHint.begin_value_ref() = (std::numeric_limits::min()); + columnHint.end_value_ref() = (2); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints({columnHint}); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = {columnHint}; cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1717,22 +1719,22 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { { LOG(INFO) << "lookup on tag where tag.col1 >= 2"; cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::RANGE); - columnHint.set_begin_value(2); - columnHint.set_end_value(std::numeric_limits::max()); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::RANGE); + columnHint.begin_value_ref() = (2); + columnHint.end_value_ref() = (std::numeric_limits::max()); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints({columnHint}); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = {columnHint}; cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1748,22 +1750,22 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { { LOG(INFO) << "lookup on tag where tag.col1 > 2"; cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::RANGE); - columnHint.set_begin_value(3); - columnHint.set_end_value(std::numeric_limits::max()); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::RANGE); + columnHint.begin_value_ref() = (3); + columnHint.end_value_ref() = (std::numeric_limits::max()); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints({columnHint}); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = {columnHint}; cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1782,16 +1784,16 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { std::vector columnHints; { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value(3); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (3); columnHints.emplace_back(std::move(columnHint)); } { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col2"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value("ccc"); + columnHint.column_name_ref() = ("col2"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = ("ccc"); columnHints.emplace_back(std::move(columnHint)); } @@ -1801,16 +1803,16 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { ConstantExpression::make(pool, Value(1))); cpp2::IndexQueryContext context; - context.set_filter(expr.encode()); - context.set_index_id(222); - context.set_column_hints(columnHints); + context.filter_ref() = (expr.encode()); + context.index_id_ref() = (222); + context.column_hints_ref() = (columnHints); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1829,16 +1831,16 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { std::vector columnHints; { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value(3); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (3); columnHints.emplace_back(std::move(columnHint)); } { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col2"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value("ccc"); + columnHint.column_name_ref() = ("col2"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = ("ccc"); columnHints.emplace_back(std::move(columnHint)); } const auto& expr = @@ -1847,16 +1849,16 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { ConstantExpression::make(pool, Value(5))); cpp2::IndexQueryContext context; - context.set_filter(expr.encode()); - context.set_index_id(222); - context.set_column_hints(columnHints); + context.filter_ref() = (expr.encode()); + context.index_id_ref() = (222); + context.column_hints_ref() = (columnHints); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1875,16 +1877,16 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { std::vector columnHints; { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col1"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value(3); + columnHint.column_name_ref() = ("col1"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = (3); columnHints.emplace_back(std::move(columnHint)); } { cpp2::IndexColumnHint columnHint; - columnHint.set_column_name("col2"); - columnHint.set_scan_type(cpp2::ScanType::PREFIX); - columnHint.set_begin_value("ccc"); + columnHint.column_name_ref() = ("col2"); + columnHint.scan_type_ref() = (cpp2::ScanType::PREFIX); + columnHint.begin_value_ref() = ("ccc"); columnHints.emplace_back(std::move(columnHint)); } const auto& expr = *nebula::LogicalExpression::makeAnd( @@ -1897,16 +1899,16 @@ TEST_P(LookupIndexTest, NullableInIndexAndFilterTest) { ConstantExpression::make(pool, Value("a")))); cpp2::IndexQueryContext context; - context.set_filter(expr.encode()); - context.set_index_id(222); - context.set_column_hints(columnHints); + context.filter_ref() = (expr.encode()); + context.index_id_ref() = (222); + context.column_hints_ref() = (columnHints); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); + schemaId.tag_id_ref() = (111); cpp2::IndexSpec indices; - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -1943,10 +1945,10 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { auto nullColumnDef = [strColLen](const std::string& name, const PropertyType type) { meta::cpp2::ColumnDef col; col.name = name; - col.type.set_type(type); - col.set_nullable(true); + col.type.type_ref() = (type); + col.nullable_ref() = (true); if (type == PropertyType::FIXED_STRING) { - col.type.set_type_length(strColLen); + col.type.type_length_ref() = (strColLen); } return col; }; @@ -1966,27 +1968,27 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { { PartitionID partId = 1; cpp2::AddVerticesRequest req; - req.set_space_id(spaceId); - req.set_if_not_exists(true); + req.space_id_ref() = (spaceId); + req.if_not_exists_ref() = (true); std::unordered_map> propNames; propNames[tagId] = {"col_bool", "col_int", "col_double", "col_str"}; - req.set_prop_names(std::move(propNames)); + req.prop_names_ref() = (std::move(propNames)); { // all not null VertexID vId = "true_1_1.0_a"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(true)); props.emplace_back(Value(1)); props.emplace_back(Value(1.0f)); props.emplace_back(Value("aaa")); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -1994,17 +1996,17 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { VertexID vId = "null_2_2.0_b"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(NullType::__NULL__); props.emplace_back(Value(2)); props.emplace_back(Value(2.0f)); props.emplace_back(Value("bbb")); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -2012,17 +2014,17 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { VertexID vId = "false_null_3.0_c"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(false)); props.emplace_back(NullType::__NULL__); props.emplace_back(Value(3.0f)); props.emplace_back(Value("ccc")); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -2030,17 +2032,17 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { VertexID vId = "true_4_null_d"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(true)); props.emplace_back(Value(4)); props.emplace_back(NullType::__NULL__); props.emplace_back(Value("ddd")); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -2048,17 +2050,17 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { VertexID vId = "false_5_5.0_null"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(Value(false)); props.emplace_back(Value(5)); props.emplace_back(Value(5.0f)); props.emplace_back(NullType::__NULL__); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } { @@ -2066,17 +2068,17 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { VertexID vId = "all_null"; nebula::storage::cpp2::NewVertex newVertex; nebula::storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = (tagId); std::vector props; props.emplace_back(NullType::__NULL__); props.emplace_back(NullType::__NULL__); props.emplace_back(NullType::__NULL__); props.emplace_back(NullType::__NULL__); - newTag.set_props(std::move(props)); + newTag.props_ref() = (std::move(props)); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(genVid(vId)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = (genVid(vId)); + newVertex.tags_ref() = (std::move(newTags)); (*req.parts_ref())[partId].emplace_back(std::move(newVertex)); } @@ -2092,17 +2094,17 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { const Value& begin, const Value& end) { cpp2::IndexColumnHint hint; - hint.set_column_name(col); - hint.set_scan_type(scanType); - hint.set_begin_value(begin); - hint.set_end_value(end); + hint.column_name_ref() = (col); + hint.scan_type_ref() = (scanType); + hint.begin_value_ref() = (begin); + hint.end_value_ref() = (end); return hint; }; cpp2::LookupIndexRequest req; - req.set_space_id(spaceId); - req.set_parts({1, 2, 3, 4, 5, 6}); - req.set_return_columns({kVid}); + req.space_id_ref() = (spaceId); + req.parts_ref() = {1, 2, 3, 4, 5, 6}; + req.return_columns_ref() = {kVid}; // bool range scan will be forbidden in query engine, so only test prefix for // bool @@ -2112,16 +2114,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_bool", cpp2::ScanType::PREFIX, Value(true), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2140,16 +2142,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_int", cpp2::ScanType::PREFIX, Value(1), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2168,16 +2170,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { "col_int", cpp2::ScanType::RANGE, Value(3), Value(std::numeric_limits::max()))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2196,16 +2198,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { "col_int", cpp2::ScanType::RANGE, Value(std::numeric_limits::min()), Value(4))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2224,16 +2226,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_int", cpp2::ScanType::RANGE, Value(0), Value(3))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2252,16 +2254,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_int", cpp2::ScanType::RANGE, Value(0), Value(10))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2284,16 +2286,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { Value(2.0))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2316,16 +2318,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { Value(std::numeric_limits::max()))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2346,16 +2348,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHint("col_double", cpp2::ScanType::RANGE, Value(0.0), Value(10.0))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2376,16 +2378,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_str", cpp2::ScanType::PREFIX, Value("aaa"), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2410,16 +2412,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHint("col_str", cpp2::ScanType::RANGE, Value(begin), Value(end))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2441,16 +2443,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_str", cpp2::ScanType::RANGE, Value("a"), Value("c"))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2468,16 +2470,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHint("col_bool", cpp2::ScanType::PREFIX, Value(NullType::__NULL__), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2498,16 +2500,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHint("col_int", cpp2::ScanType::PREFIX, Value(NullType::__NULL__), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2531,16 +2533,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHint("col_double", cpp2::ScanType::PREFIX, Value(NullType::__NULL__), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2566,16 +2568,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHint("col_str", cpp2::ScanType::PREFIX, Value(NullType::__NULL__), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2597,16 +2599,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_str", cpp2::ScanType::PREFIX, Value("ddd"), Value())); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2630,16 +2632,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { "col_str", cpp2::ScanType::RANGE, Value(std::string(strColLen, '\0')), Value("d"))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2665,16 +2667,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { Value(std::numeric_limits::max()))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2693,16 +2695,16 @@ TEST_P(LookupIndexTest, NullablePropertyTest) { columnHints.emplace_back(columnHint("col_int", cpp2::ScanType::RANGE, Value(0), Value(10))); cpp2::IndexQueryContext context; - context.set_filter(""); - context.set_index_id(222); - context.set_column_hints(std::move(columnHints)); + context.filter_ref() = (""); + context.index_id_ref() = (222); + context.column_hints_ref() = (std::move(columnHints)); cpp2::IndexSpec indices; nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(111); - indices.set_schema_id(schemaId); - indices.set_contexts({context}); - req.set_indices(std::move(indices)); + schemaId.tag_id_ref() = (111); + indices.schema_id_ref() = (schemaId); + indices.contexts_ref() = {context}; + req.indices_ref() = (std::move(indices)); auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); auto fut = processor->getFuture(); @@ -2750,49 +2752,49 @@ TEST_P(LookupIndexTest, DeDupTagIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_tag_id(1); - indices.set_schema_id(schemaId); + schemaId.tag_id_ref() = (1); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::vector returnCols; returnCols.emplace_back(kVid); returnCols.emplace_back(kTag); returnCols.emplace_back("age"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); // player.name_ == "Rudy Gay" cpp2::IndexColumnHint columnHint1; std::string name1 = "Rudy Gay"; - columnHint1.set_begin_value(Value(name1)); - columnHint1.set_column_name("name"); - columnHint1.set_scan_type(cpp2::ScanType::PREFIX); + columnHint1.begin_value_ref() = (Value(name1)); + columnHint1.column_name_ref() = ("name"); + columnHint1.scan_type_ref() = (cpp2::ScanType::PREFIX); // player.name_ == "Rudy Gay" cpp2::IndexColumnHint columnHint2; std::string name2 = "Rudy Gay"; - columnHint2.set_begin_value(Value(name2)); - columnHint2.set_column_name("name"); - columnHint2.set_scan_type(cpp2::ScanType::PREFIX); + columnHint2.begin_value_ref() = (Value(name2)); + columnHint2.column_name_ref() = ("name"); + columnHint2.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints1; columnHints1.emplace_back(std::move(columnHint1)); std::vector columnHints2; columnHints2.emplace_back(std::move(columnHint2)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints1)); - context1.set_filter(""); - context1.set_index_id(1); + context1.column_hints_ref() = (std::move(columnHints1)); + context1.filter_ref() = (""); + context1.index_id_ref() = (1); cpp2::IndexQueryContext context2; - context2.set_column_hints(std::move(columnHints2)); - context2.set_filter(""); - context2.set_index_id(1); + context2.column_hints_ref() = (std::move(columnHints2)); + context2.filter_ref() = (""); + context2.index_id_ref() = (1); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); contexts.emplace_back(std::move(context2)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); @@ -2848,15 +2850,15 @@ TEST_P(LookupIndexTest, DedupEdgeIndexTest) { auto* processor = LookupProcessor::instance(env, nullptr, threadPool.get()); cpp2::LookupIndexRequest req; nebula::storage::cpp2::IndexSpec indices; - req.set_space_id(spaceId); + req.space_id_ref() = (spaceId); nebula::cpp2::SchemaID schemaId; - schemaId.set_edge_type(102); - indices.set_schema_id(schemaId); + schemaId.edge_type_ref() = (102); + indices.schema_id_ref() = (schemaId); std::vector parts; for (int32_t p = 1; p <= totalParts; p++) { parts.emplace_back(p); } - req.set_parts(std::move(parts)); + req.parts_ref() = (std::move(parts)); std::string tony = "Tony Parker"; std::string manu = "Manu Ginobili"; std::vector returnCols; @@ -2865,33 +2867,33 @@ TEST_P(LookupIndexTest, DedupEdgeIndexTest) { returnCols.emplace_back(kRank); returnCols.emplace_back(kDst); returnCols.emplace_back("teamName"); - req.set_return_columns(std::move(returnCols)); + req.return_columns_ref() = (std::move(returnCols)); // teammates.player1 == "Tony Parker" cpp2::IndexColumnHint columnHint1; - columnHint1.set_begin_value(Value(tony)); - columnHint1.set_column_name("player1"); - columnHint1.set_scan_type(cpp2::ScanType::PREFIX); + columnHint1.begin_value_ref() = (Value(tony)); + columnHint1.column_name_ref() = ("player1"); + columnHint1.scan_type_ref() = (cpp2::ScanType::PREFIX); cpp2::IndexColumnHint columnHint2; - columnHint2.set_begin_value(Value(tony)); - columnHint2.set_column_name("player1"); - columnHint2.set_scan_type(cpp2::ScanType::PREFIX); + columnHint2.begin_value_ref() = (Value(tony)); + columnHint2.column_name_ref() = ("player1"); + columnHint2.scan_type_ref() = (cpp2::ScanType::PREFIX); std::vector columnHints1; columnHints1.emplace_back(std::move(columnHint1)); std::vector columnHints2; columnHints2.emplace_back(std::move(columnHint2)); cpp2::IndexQueryContext context1; - context1.set_column_hints(std::move(columnHints1)); - context1.set_filter(""); - context1.set_index_id(102); + context1.column_hints_ref() = (std::move(columnHints1)); + context1.filter_ref() = (""); + context1.index_id_ref() = (102); cpp2::IndexQueryContext context2; - context2.set_column_hints(std::move(columnHints2)); - context2.set_filter(""); - context2.set_index_id(102); + context2.column_hints_ref() = (std::move(columnHints2)); + context2.filter_ref() = (""); + context2.index_id_ref() = (102); decltype(indices.contexts) contexts; contexts.emplace_back(std::move(context1)); contexts.emplace_back(std::move(context2)); - indices.set_contexts(std::move(contexts)); - req.set_indices(std::move(indices)); + indices.contexts_ref() = (std::move(contexts)); + req.indices_ref() = (std::move(indices)); auto fut = processor->getFuture(); processor->process(req); auto resp = std::move(fut).get(); diff --git a/src/storage/test/MockHdfsHelper.h b/src/storage/test/MockHdfsHelper.h index 9d6f1ac9a7e..0fe5ccaa841 100644 --- a/src/storage/test/MockHdfsHelper.h +++ b/src/storage/test/MockHdfsHelper.h @@ -35,7 +35,9 @@ class MockHdfsOKHelper : public nebula::hdfs::HdfsHelper { return ""; } - bool checkHadoopPath() override { return true; } + bool checkHadoopPath() override { + return true; + } }; class MockHdfsExistHelper : public nebula::hdfs::HdfsHelper { @@ -62,7 +64,9 @@ class MockHdfsExistHelper : public nebula::hdfs::HdfsHelper { return "copyToLocal: `/data/': File exists"; } - bool checkHadoopPath() override { return true; } + bool checkHadoopPath() override { + return true; + } }; } // namespace storage diff --git a/src/storage/test/QueryTestUtils.h b/src/storage/test/QueryTestUtils.h index 05b2371e69d..a655e8b4629 100644 --- a/src/storage/test/QueryTestUtils.h +++ b/src/storage/test/QueryTestUtils.h @@ -303,7 +303,7 @@ class QueryTestUtils { std::hash hash; cpp2::GetNeighborsRequest req; nebula::storage::cpp2::TraverseSpec traverseSpec; - req.set_space_id(1); + req.space_id_ref() = 1; (*req.column_names_ref()).emplace_back(kVid); for (const auto& vertex : vertices) { PartitionID partId = (hash(vertex) % totalParts) + 1; @@ -317,36 +317,37 @@ class QueryTestUtils { std::vector vertexProps; if (tags.empty() && !returnNoneProps) { - traverseSpec.set_vertex_props(std::move(vertexProps)); + traverseSpec.vertex_props_ref() = std::move(vertexProps); } else if (!returnNoneProps) { for (const auto& tag : tags) { TagID tagId = tag.first; cpp2::VertexProp tagProp; - tagProp.set_tag(tagId); + tagProp.tag_ref() = tagId; for (const auto& prop : tag.second) { (*tagProp.props_ref()).emplace_back(std::move(prop)); } vertexProps.emplace_back(std::move(tagProp)); } - traverseSpec.set_vertex_props(std::move(vertexProps)); + traverseSpec.vertex_props_ref() = std::move(vertexProps); } std::vector edgeProps; if (edges.empty() && !returnNoneProps) { - traverseSpec.set_edge_props(std::move(edgeProps)); + traverseSpec.edge_props_ref() = std::move(edgeProps); } else if (!returnNoneProps) { for (const auto& edge : edges) { EdgeType edgeType = edge.first; cpp2::EdgeProp edgeProp; - edgeProp.set_type(edgeType); + edgeProp.type_ref() = edgeType; for (const auto& prop : edge.second) { (*edgeProp.props_ref()).emplace_back(std::move(prop)); } edgeProps.emplace_back(std::move(edgeProp)); } - traverseSpec.set_edge_props(std::move(edgeProps)); + traverseSpec.edge_props_ref() = std::move(edgeProps); } - req.set_traverse_spec(std::move(traverseSpec)); + + req.traverse_spec_ref() = std::move(traverseSpec); return req; } diff --git a/src/storage/test/RebuildIndexTest.cpp b/src/storage/test/RebuildIndexTest.cpp index 4dc34c715ec..c31d7318a0e 100644 --- a/src/storage/test/RebuildIndexTest.cpp +++ b/src/storage/test/RebuildIndexTest.cpp @@ -72,16 +72,16 @@ TEST_F(RebuildIndexTest, RebuildTagIndexCheckALLData) { } cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(parts); - parameter.set_task_specific_paras({"4", "5"}); + parameter.parts_ref() = parts; + parameter.task_specific_paras_ref() = {"4", "5"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_TAG_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(13); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_TAG_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 13; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -159,16 +159,16 @@ TEST_F(RebuildIndexTest, RebuildEdgeIndexCheckALLData) { } cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(parts); - parameter.set_task_specific_paras({"103", "104"}); + parameter.parts_ref() = parts; + parameter.task_specific_paras_ref() = {"103", "104"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(16); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 16; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -256,16 +256,16 @@ TEST_F(RebuildIndexTest, RebuildTagIndexWithDelete) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(std::move(parts)); - parameter.set_task_specific_paras({"4", "5"}); + parameter.parts_ref() = std::move(parts); + parameter.task_specific_paras_ref() = {"4", "5"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_TAG_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(11); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_TAG_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 11; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -317,16 +317,16 @@ TEST_F(RebuildIndexTest, RebuildTagIndexWithAppend) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(std::move(parts)); - parameter.set_task_specific_paras({"4", "5"}); + parameter.parts_ref() = std::move(parts); + parameter.task_specific_paras_ref() = {"4", "5"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_TAG_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(12); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_TAG_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 12; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -362,16 +362,16 @@ TEST_F(RebuildIndexTest, RebuildTagIndex) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(std::move(parts)); + parameter.parts_ref() = std::move(parts); cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_TAG_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(13); - parameter.set_task_specific_paras({"4", "5"}); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_TAG_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 13; + parameter.task_specific_paras_ref() = {"4", "5"}; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -417,16 +417,16 @@ TEST_F(RebuildIndexTest, RebuildEdgeIndexWithDelete) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(std::move(parts)); - parameter.set_task_specific_paras({"103", "104"}); + parameter.parts_ref() = std::move(parts); + parameter.task_specific_paras_ref() = {"103", "104"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(14); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 14; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -479,16 +479,16 @@ TEST_F(RebuildIndexTest, RebuildEdgeIndexWithAppend) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(std::move(parts)); - parameter.set_task_specific_paras({"103", "104"}); + parameter.parts_ref() = std::move(parts); + parameter.task_specific_paras_ref() = {"103", "104"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(15); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 15; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); @@ -523,16 +523,16 @@ TEST_F(RebuildIndexTest, RebuildEdgeIndex) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(1); + parameter.space_id_ref() = 1; std::vector parts = {1, 2, 3, 4, 5, 6}; - parameter.set_parts(std::move(parts)); - parameter.set_task_specific_paras({"103", "104"}); + parameter.parts_ref() = std::move(parts); + parameter.task_specific_paras_ref() = {"103", "104"}; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX); - request.set_job_id(++gJobId); - request.set_task_id(16); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::REBUILD_EDGE_INDEX; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 16; + request.para_ref() = std::move(parameter); auto callback = [](nebula::cpp2::ErrorCode, nebula::meta::cpp2::StatsItem&) {}; TaskContext context(request, callback); diff --git a/src/storage/test/ScanEdgePropBenchmark.cpp b/src/storage/test/ScanEdgePropBenchmark.cpp index 92bb6b01cd7..713ed89b23a 100644 --- a/src/storage/test/ScanEdgePropBenchmark.cpp +++ b/src/storage/test/ScanEdgePropBenchmark.cpp @@ -23,7 +23,9 @@ class TestSingleEdgeIterator : public storage::StorageIterator { explicit TestSingleEdgeIterator(std::unique_ptr iter) : iter_(std::move(iter)) {} - bool valid() const override { return iter_->valid(); } + bool valid() const override { + return iter_->valid(); + } void next() override { do { @@ -31,15 +33,23 @@ class TestSingleEdgeIterator : public storage::StorageIterator { } while (iter_->valid() && !check()); } - folly::StringPiece key() const override { return iter_->key(); } + folly::StringPiece key() const override { + return iter_->key(); + } - folly::StringPiece val() const override { return iter_->val(); } + folly::StringPiece val() const override { + return iter_->val(); + } - RowReader* reader() const override { return reader_.get(); } + RowReader* reader() const override { + return reader_.get(); + } private: // return true when the value iter to a valid edge value - bool check() { return true; } + bool check() { + return true; + } std::unique_ptr iter_; std::unique_ptr reader_; diff --git a/src/storage/test/ScanEdgeTest.cpp b/src/storage/test/ScanEdgeTest.cpp index 3b6b30cd6d0..42c41907f9b 100644 --- a/src/storage/test/ScanEdgeTest.cpp +++ b/src/storage/test/ScanEdgeTest.cpp @@ -23,32 +23,32 @@ cpp2::ScanEdgeRequest buildRequest( int64_t endTime = std::numeric_limits::max(), bool onlyLatestVer = false) { cpp2::ScanEdgeRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; cpp2::ScanCursor c; CHECK_EQ(partIds.size(), cursors.size()); std::unordered_map parts; for (std::size_t i = 0; i < partIds.size(); ++i) { if (!cursors[i].empty()) { - c.set_next_cursor(cursors[i]); + c.next_cursor_ref() = cursors[i]; } parts.emplace(partIds[i], c); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector edgeProps; for (const auto& edge : edges) { EdgeType edgeType = edge.first; cpp2::EdgeProp edgeProp; - edgeProp.set_type(edgeType); + edgeProp.type_ref() = edgeType; for (const auto& prop : edge.second) { (*edgeProp.props_ref()).emplace_back(std::move(prop)); } edgeProps.emplace_back(std::move(edgeProp)); } - req.set_return_columns(std::move(edgeProps)); - req.set_limit(rowLimit); - req.set_start_time(startTime); - req.set_end_time(endTime); - req.set_only_latest_version(onlyLatestVer); + req.return_columns_ref() = std::move(edgeProps); + req.limit_ref() = rowLimit; + req.start_time_ref() = startTime; + req.end_time_ref() = endTime; + req.only_latest_version_ref() = onlyLatestVer; return req; } @@ -317,7 +317,7 @@ TEST(ScanEdgeTest, FilterTest) { Expression* filter = EdgePropertyExpression::make(&pool, "101", kSrc); filter = RelationalExpression::makeEQ( &pool, filter, ConstantExpression::make(&pool, "Damian Lillard")); - req.set_filter(filter->encode()); + req.filter_ref() = filter->encode(); auto* processor = ScanEdgeProcessor::instance(env, nullptr); auto f = processor->getFuture(); processor->process(req); diff --git a/src/storage/test/ScanVertexTest.cpp b/src/storage/test/ScanVertexTest.cpp index 6f232ef25df..61f9e006cea 100644 --- a/src/storage/test/ScanVertexTest.cpp +++ b/src/storage/test/ScanVertexTest.cpp @@ -23,32 +23,32 @@ cpp2::ScanVertexRequest buildRequest( int64_t endTime = std::numeric_limits::max(), bool onlyLatestVer = false) { cpp2::ScanVertexRequest req; - req.set_space_id(1); + req.space_id_ref() = 1; cpp2::ScanCursor c; CHECK_EQ(partIds.size(), cursors.size()); std::unordered_map parts; for (std::size_t i = 0; i < partIds.size(); ++i) { if (!cursors[i].empty()) { - c.set_next_cursor(cursors[i]); + c.next_cursor_ref() = cursors[i]; } parts.emplace(partIds[i], c); } - req.set_parts(std::move(parts)); + req.parts_ref() = std::move(parts); std::vector vertexProps; for (const auto& tag : tags) { TagID tagId = tag.first; cpp2::VertexProp vertexProp; - vertexProp.set_tag(tagId); + vertexProp.tag_ref() = tagId; for (const auto& prop : tag.second) { (*vertexProp.props_ref()).emplace_back(std::move(prop)); } vertexProps.emplace_back(std::move(vertexProp)); } - req.set_return_columns(std::move(vertexProps)); - req.set_limit(rowLimit); - req.set_start_time(startTime); - req.set_end_time(endTime); - req.set_only_latest_version(onlyLatestVer); + req.return_columns_ref() = std::move(vertexProps); + req.limit_ref() = rowLimit; + req.start_time_ref() = startTime; + req.end_time_ref() = endTime; + req.only_latest_version_ref() = onlyLatestVer; return req; } @@ -459,7 +459,7 @@ TEST(ScanVertexTest, FilterTest) { Expression* filter = TagPropertyExpression::make(&pool, "1", "name"); filter = RelationalExpression::makeEQ(&pool, filter, ConstantExpression::make(&pool, "Kobe Bryant")); - req.set_filter(filter->encode()); + req.filter_ref() = filter->encode(); auto* processor = ScanVertexProcessor::instance(env, nullptr); auto f = processor->getFuture(); processor->process(req); @@ -486,7 +486,7 @@ TEST(ScanVertexTest, FilterTest) { &pool, filter, UnaryExpression::makeIsEmpty(&pool, TagPropertyExpression::make(&pool, "2", "name"))); - req.set_filter(filter->encode()); + req.filter_ref() = filter->encode(); auto* processor = ScanVertexProcessor::instance(env, nullptr); auto f = processor->getFuture(); processor->process(req); diff --git a/src/storage/test/StatsTaskTest.cpp b/src/storage/test/StatsTaskTest.cpp index dc8746e7ee3..50bd936180d 100644 --- a/src/storage/test/StatsTaskTest.cpp +++ b/src/storage/test/StatsTaskTest.cpp @@ -65,14 +65,14 @@ TEST_F(StatsTaskTest, StatsTagAndEdgeData) { { cpp2::TaskPara parameter; - parameter.set_space_id(spaceId); - parameter.set_parts(parts); + parameter.space_id_ref() = spaceId; + parameter.parts_ref() = parts; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::STATS); - request.set_job_id(++gJobId); - request.set_task_id(13); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::STATS; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 13; + request.para_ref() = std::move(parameter); nebula::meta::cpp2::StatsItem statsItem; auto callback = [&](nebula::cpp2::ErrorCode ret, nebula::meta::cpp2::StatsItem& result) { @@ -130,14 +130,14 @@ TEST_F(StatsTaskTest, StatsTagAndEdgeData) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(spaceId); - parameter.set_parts(parts); + parameter.space_id_ref() = spaceId; + parameter.parts_ref() = parts; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::STATS); - request.set_job_id(++gJobId); - request.set_task_id(14); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::STATS; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 14; + request.para_ref() = std::move(parameter); nebula::meta::cpp2::StatsItem statsItem; auto callback = [&](nebula::cpp2::ErrorCode ret, nebula::meta::cpp2::StatsItem& result) { @@ -201,14 +201,14 @@ TEST_F(StatsTaskTest, StatsTagAndEdgeData) { EXPECT_EQ(0, resp.result.failed_parts.size()); cpp2::TaskPara parameter; - parameter.set_space_id(spaceId); - parameter.set_parts(parts); + parameter.space_id_ref() = spaceId; + parameter.parts_ref() = parts; cpp2::AddAdminTaskRequest request; - request.set_cmd(meta::cpp2::AdminCmd::STATS); - request.set_job_id(++gJobId); - request.set_task_id(15); - request.set_para(std::move(parameter)); + request.cmd_ref() = meta::cpp2::AdminCmd::STATS; + request.job_id_ref() = ++gJobId; + request.task_id_ref() = 15; + request.para_ref() = std::move(parameter); nebula::meta::cpp2::StatsItem statsItem; auto callback = [&](nebula::cpp2::ErrorCode ret, nebula::meta::cpp2::StatsItem& result) { diff --git a/src/storage/test/StorageClientTest.cpp b/src/storage/test/StorageClientTest.cpp index 6b7dd2ec136..bdf8bea0342 100644 --- a/src/storage/test/StorageClientTest.cpp +++ b/src/storage/test/StorageClientTest.cpp @@ -346,7 +346,9 @@ class TestStorageClient : public StorageClient { explicit TestStorageClient(std::shared_ptr ioThreadPool) : StorageClient(ioThreadPool, nullptr) {} - StatusOr partsNum(GraphSpaceID) const override { return parts_.size(); } + StatusOr partsNum(GraphSpaceID) const override { + return parts_.size(); + } StatusOr getPartMeta(GraphSpaceID, PartitionID partId) const override { auto it = parts_.find(partId); diff --git a/src/storage/test/StorageDAGBenchmark.cpp b/src/storage/test/StorageDAGBenchmark.cpp index c06f779f0b6..c742343d3b0 100644 --- a/src/storage/test/StorageDAGBenchmark.cpp +++ b/src/storage/test/StorageDAGBenchmark.cpp @@ -187,7 +187,9 @@ StoragePlan chainStorageDAG() { BENCHMARK(future_fanout, iters) { FutureDAG dag; - BENCHMARK_SUSPEND { dag = fanoutFutureDAG(); } + BENCHMARK_SUSPEND { + dag = fanoutFutureDAG(); + } for (size_t i = 0; i < iters; i++) { dag.go(0, "fanoutFutureDAG"); } @@ -195,7 +197,9 @@ BENCHMARK(future_fanout, iters) { BENCHMARK_RELATIVE(recursive_fanout, iters) { StoragePlan dag; - BENCHMARK_SUSPEND { dag = fanoutStorageDAG(); } + BENCHMARK_SUSPEND { + dag = fanoutStorageDAG(); + } for (size_t i = 0; i < iters; i++) { dag.go(0, "fanoutStorageDAG"); } @@ -205,7 +209,9 @@ BENCHMARK_DRAW_LINE(); BENCHMARK(future_chain, iters) { FutureDAG dag; - BENCHMARK_SUSPEND { dag = chainFutureDAG(); } + BENCHMARK_SUSPEND { + dag = chainFutureDAG(); + } for (size_t i = 0; i < iters; i++) { dag.go(0, "chainFutureDAG"); } @@ -213,7 +219,9 @@ BENCHMARK(future_chain, iters) { BENCHMARK_RELATIVE(recursive_chain, iters) { StoragePlan dag; - BENCHMARK_SUSPEND { dag = chainStorageDAG(); } + BENCHMARK_SUSPEND { + dag = chainStorageDAG(); + } for (size_t i = 0; i < iters; i++) { dag.go(0, "chainStorageDAG"); } diff --git a/src/storage/test/StorageHttpPropertyHandlerTest.cpp b/src/storage/test/StorageHttpPropertyHandlerTest.cpp index 471d7b2242f..5d3729eda17 100644 --- a/src/storage/test/StorageHttpPropertyHandlerTest.cpp +++ b/src/storage/test/StorageHttpPropertyHandlerTest.cpp @@ -78,8 +78,8 @@ TEST(StorageHttpPropertyHandlerTest, ValidRequest) { std::string expect = R"([ { - "Engine 0": "0", - "Engine 1": "0" + "Engine 0": "96", + "Engine 1": "96" } ])"; EXPECT_EQ(expect, request("/rocksdb_property?space=1&property=rocksdb.block-cache-usage")); @@ -88,8 +88,8 @@ TEST(StorageHttpPropertyHandlerTest, ValidRequest) { std::string expect = R"([ { - "Engine 0": "0", - "Engine 1": "0" + "Engine 0": "96", + "Engine 1": "96" }, { "Engine 0": "0", diff --git a/src/storage/test/StorageIndexWriteBenchmark.cpp b/src/storage/test/StorageIndexWriteBenchmark.cpp index b76fe4edd6b..49cd0a1f783 100644 --- a/src/storage/test/StorageIndexWriteBenchmark.cpp +++ b/src/storage/test/StorageIndexWriteBenchmark.cpp @@ -112,16 +112,16 @@ std::vector genVertices(size_t vLen, int32_t& vId) { for (auto i = 0; i < FLAGS_bulk_insert_size; i++) { NewVertex newVertex; NewTag newTag; - newTag.set_tag_id(tagId); + newTag.tag_id_ref() = tagId; std::vector props; props.emplace_back(Value(1L + i)); props.emplace_back(Value(2L + i)); props.emplace_back(Value(3L + i)); - newTag.set_props(std::move(props)); + newTag.props_ref() = std::move(props); std::vector newTags; newTags.push_back(std::move(newTag)); - newVertex.set_id(toVertexId(vLen, vId++)); - newVertex.set_tags(std::move(newTags)); + newVertex.id_ref() = toVertexId(vLen, vId++); + newVertex.tags_ref() = std::move(newTags); vertices.emplace_back(std::move(newVertex)); } return vertices; @@ -130,8 +130,8 @@ std::vector genVertices(size_t vLen, int32_t& vId) { bool processVertices(StorageEnv* env, int32_t& vId) { cpp2::AddVerticesRequest req; BENCHMARK_SUSPEND { - req.set_space_id(1); - req.set_if_not_exists(true); + req.space_id_ref() = 1; + req.if_not_exists_ref() = true; auto newVertex = genVertices(32, vId); (*req.parts_ref())[1] = std::move(newVertex); }; @@ -338,15 +338,25 @@ void insertVerticesMultIndex() { }; } -BENCHMARK(withoutIndex) { insertVertices(true); } +BENCHMARK(withoutIndex) { + insertVertices(true); +} -BENCHMARK(unmatchIndex) { insertUnmatchIndex(); } +BENCHMARK(unmatchIndex) { + insertUnmatchIndex(); +} -BENCHMARK(attachIndex) { insertVertices(false); } +BENCHMARK(attachIndex) { + insertVertices(false); +} -BENCHMARK(duplicateVerticesIndex) { insertDupVertices(); } +BENCHMARK(duplicateVerticesIndex) { + insertDupVertices(); +} -BENCHMARK(multipleIndex) { insertVerticesMultIndex(); } +BENCHMARK(multipleIndex) { + insertVerticesMultIndex(); +} } // namespace storage } // namespace nebula diff --git a/src/storage/test/TossTestExecutor.h b/src/storage/test/TossTestExecutor.h index 99e81c550a5..bda7b9b9219 100644 --- a/src/storage/test/TossTestExecutor.h +++ b/src/storage/test/TossTestExecutor.h @@ -23,7 +23,9 @@ class StorageResponseReader { c.begin(), c.end(), [](auto it) { return it.second == cpp2::ErrorCode::E_LEADER_CHANGED; }); } - std::vector& data() { return resp_->responses(); } + std::vector& data() { + return resp_->responses(); + } cpp2::ErrorCode firstErrCode() { for (auto& p : resp_->failedParts()) { @@ -55,7 +57,9 @@ class GetNeighborsExecutor { data_ = run(uniEdges); } - std::vector data() { return data_; } + std::vector data() { + return data_; + } std::vector uniqueEdges(const std::vector& __edges) { std::vector edges(__edges); @@ -234,9 +238,13 @@ struct AddEdgeExecutor { } while (retry-- > 0); } - bool ok() { return code_ == cpp2::ErrorCode::SUCCEEDED; } + bool ok() { + return code_ == cpp2::ErrorCode::SUCCEEDED; + } - cpp2::ErrorCode code() { return code_; } + cpp2::ErrorCode code() { + return code_; + } }; struct GetPropsExecutor { @@ -257,7 +265,9 @@ struct GetPropsExecutor { GetPropsExecutor(TestSpace* s, std::vector edges) : GetPropsExecutor(s, edges[0]) {} - std::vector data() { return result_; } + std::vector data() { + return result_; + } void rpc() { nebula::Row row; diff --git a/src/storage/test/UpdateEdgeTest.cpp b/src/storage/test/UpdateEdgeTest.cpp index 0dc6b115229..8ad2bb7a117 100644 --- a/src/storage/test/UpdateEdgeTest.cpp +++ b/src/storage/test/UpdateEdgeTest.cpp @@ -124,37 +124,37 @@ TEST(UpdateEdgeTest, No_Filter_Test) { LOG(INFO) << "Build UpdateEdgeRequest..."; cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 20); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.type = trade cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -173,8 +173,8 @@ TEST(UpdateEdgeTest, No_Filter_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -232,37 +232,37 @@ TEST(UpdateEdgeTest, No_Filter_Test) { LOG(INFO) << "Build UpdateEdgeRequest..."; cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Spurs") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; // src = Spurs, edge_type = -101, ranking = 1997, dst = Tim Duncan VertexID srcId = "Spurs"; VertexID dstId = "Tim Duncan"; EdgeRanking rank = 1997; EdgeType edgeType = -101; storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 20); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.type = trade cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -281,8 +281,8 @@ TEST(UpdateEdgeTest, No_Filter_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -354,19 +354,19 @@ TEST(UpdateEdgeTest, Filter_Yield_Test) { LOG(INFO) << "Build UpdateEdgeRequest..."; cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build filter..."; // left int: 101.startYear = 1997 @@ -380,25 +380,25 @@ TEST(UpdateEdgeTest, Filter_Yield_Test) { auto* right = RelationalExpression::makeEQ(pool, srcExp2, priExp2); // left AND right is true auto logExp = LogicalExpression::makeAnd(pool, left, right); - req.set_condition(Expression::encode(*logExp)); + req.condition_ref() = Expression::encode(*logExp); LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 20); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.type = trade cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -417,8 +417,8 @@ TEST(UpdateEdgeTest, Filter_Yield_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -493,53 +493,53 @@ TEST(UpdateEdgeTest, Insertable_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Brandon Ingram") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Brandon Ingram"; VertexID dstId = "Lakers"; EdgeRanking rank = 2016; EdgeType edgeType = 101; // src = Brandon Ingram, edge_type = 101, ranking = 2016, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // string: 101.playerName = Brandon Ingram cpp2::UpdatedProp uProp1; - uProp1.set_name("playerName"); + uProp1.name_ref() = "playerName"; std::string col1new("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // string: 101.teamName = Lakers cpp2::UpdatedProp uProp2; - uProp2.set_name("teamName"); + uProp2.name_ref() = "teamName"; std::string col2new("Lakers"); const auto& val2 = *ConstantExpression::make(pool, col2new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); // int: 101.startYear = 2016 cpp2::UpdatedProp uProp3; - uProp3.set_name("startYear"); + uProp3.name_ref() = "startYear"; const auto& val3 = *ConstantExpression::make(pool, 2016L); - uProp3.set_value(Expression::encode(val3)); + uProp3.value_ref() = Expression::encode(val3); props.emplace_back(uProp3); // int: 101.teamCareer = 1 cpp2::UpdatedProp uProp4; - uProp4.set_name("teamCareer"); + uProp4.name_ref() = "teamCareer"; const auto& val4 = *ConstantExpression::make(pool, 1L); - uProp4.set_value(Expression::encode(val4)); + uProp4.value_ref() = Expression::encode(val4); props.emplace_back(uProp4); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -558,8 +558,8 @@ TEST(UpdateEdgeTest, Insertable_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -629,36 +629,36 @@ TEST(UpdateEdgeTest, Invalid_Update_Prop_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 30); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.birth = 1997 cpp2::UpdatedProp uProp2; - uProp2.set_name("birth"); + uProp2.name_ref() = "birth"; const auto& val2 = *ConstantExpression::make(pool, 1997); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -675,8 +675,8 @@ TEST(UpdateEdgeTest, Invalid_Update_Prop_Test) { const auto& edgePropExp4 = *EdgePropertyExpression::make(pool, "101", "type"); tmpProps.emplace_back(Expression::encode(edgePropExp4)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -725,19 +725,19 @@ TEST(UpdateEdgeTest, Invalid_Filter_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build filter..."; // left int: 101.startYear = 1997 @@ -751,25 +751,25 @@ TEST(UpdateEdgeTest, Invalid_Filter_Test) { auto* right = RelationalExpression::makeEQ(pool, srcExp2, priExp2); // left AND right is true auto logExp = LogicalExpression::makeAnd(pool, left, right); - req.set_condition(Expression::encode(*logExp)); + req.condition_ref() = Expression::encode(*logExp); LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 30); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.birth = 1997 cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -786,8 +786,8 @@ TEST(UpdateEdgeTest, Invalid_Filter_Test) { const auto& edgePropExp4 = *EdgePropertyExpression::make(pool, "101", "type"); tmpProps.emplace_back(Expression::encode(edgePropExp4)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -836,53 +836,53 @@ TEST(UpdateEdgeTest, Insertable_Filter_value_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Brandon Ingram") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Brandon Ingram"; VertexID dstId = "Lakers"; EdgeRanking rank = 2016; EdgeType edgeType = 101; // src = Brandon Ingram, edge_type = 101, ranking = 2016, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // string: 101.playerName = Brandon Ingram cpp2::UpdatedProp uProp1; - uProp1.set_name("playerName"); + uProp1.name_ref() = "playerName"; std::string col1new("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // string: 101.teamName = Lakers cpp2::UpdatedProp uProp2; - uProp2.set_name("teamName"); + uProp2.name_ref() = "teamName"; std::string col2new("Lakers"); const auto& val2 = *ConstantExpression::make(pool, col2new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); // int: 101.startYear = 2016 cpp2::UpdatedProp uProp3; - uProp3.set_name("startYear"); + uProp3.name_ref() = "startYear"; const auto& val3 = *ConstantExpression::make(pool, 2016L); - uProp3.set_value(Expression::encode(val3)); + uProp3.value_ref() = Expression::encode(val3); props.emplace_back(uProp3); // int: 101.teamCareer = 1 cpp2::UpdatedProp uProp4; - uProp4.set_name("teamCareer"); + uProp4.name_ref() = "teamCareer"; const auto& val4 = *ConstantExpression::make(pool, 1L); - uProp4.set_value(Expression::encode(val4)); + uProp4.value_ref() = Expression::encode(val4); props.emplace_back(uProp4); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build filter..."; // filter is valid, but filter value is false @@ -897,7 +897,7 @@ TEST(UpdateEdgeTest, Insertable_Filter_value_Test) { auto* right = RelationalExpression::makeEQ(pool, srcExp2, priExp2); // left AND right is false auto logExp = LogicalExpression::makeAnd(pool, left, right); - req.set_condition(Expression::encode(*logExp)); + req.condition_ref() = Expression::encode(*logExp); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -916,8 +916,8 @@ TEST(UpdateEdgeTest, Insertable_Filter_value_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -1002,23 +1002,23 @@ TEST(UpdateEdgeTest, CorruptDataTest) { LOG(INFO) << "Build UpdateEdgeRequest..."; cpp2::UpdateEdgeRequest req; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; // src = Lonzo Ball, edge_type = 101, ranking = 2017, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 2 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 2); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); LOG(INFO) << "Build yield..."; @@ -1033,8 +1033,8 @@ TEST(UpdateEdgeTest, CorruptDataTest) { const auto& edgePropExp3 = *EdgePropertyExpression::make(pool, "101", "teamCareer"); tmpProps.emplace_back(Expression::encode(edgePropExp3)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -1068,37 +1068,37 @@ TEST(UpdateEdgeTest, TTL_NoInsert_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Brandon Ingram, edge_type = 101, ranking = 2016, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 30); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.birth = 1997 cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -1109,8 +1109,8 @@ TEST(UpdateEdgeTest, TTL_NoInsert_Test) { const auto& edgePropExp4 = *EdgePropertyExpression::make(pool, "101", "type"); tmpProps.emplace_back(Expression::encode(edgePropExp4)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; sleep(FLAGS_mock_ttl_duration + 1); @@ -1146,46 +1146,46 @@ TEST(UpdateEdgeTest, TTL_Insert_No_Exist_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Brandon Ingram, edge_type = 101, ranking = 2016, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.playerName = Tim cpp2::UpdatedProp uProp1; - uProp1.set_name("playerName"); + uProp1.name_ref() = "playerName"; std::string col1new("Tim"); const auto& val1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.teamName = 1997 cpp2::UpdatedProp uProp2; - uProp2.set_name("teamName"); + uProp2.name_ref() = "teamName"; std::string col2new("Spurs"); const auto& val2 = *ConstantExpression::make(pool, col2new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); // int: 101.teamCareer = 1 cpp2::UpdatedProp uProp3; - uProp3.set_name("teamCareer"); + uProp3.name_ref() = "teamCareer"; const auto& val3 = *ConstantExpression::make(pool, 1); - uProp3.set_value(Expression::encode(val3)); + uProp3.value_ref() = Expression::encode(val3); props.emplace_back(uProp3); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -1204,8 +1204,8 @@ TEST(UpdateEdgeTest, TTL_Insert_No_Exist_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; sleep(FLAGS_mock_ttl_duration + 1); @@ -1280,46 +1280,46 @@ TEST(UpdateEdgeTest, TTL_Insert_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Brandon Ingram, edge_type = 101, ranking = 2016, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.playerName = Tim cpp2::UpdatedProp uProp1; - uProp1.set_name("playerName"); + uProp1.name_ref() = "playerName"; std::string col1new("Tim Duncan"); const auto& val1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.teamName = 1997 cpp2::UpdatedProp uProp2; - uProp2.set_name("teamName"); + uProp2.name_ref() = "teamName"; std::string col2new("Spurs"); const auto& val2 = *ConstantExpression::make(pool, col2new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); // bool: 101.teamCareer = 40 cpp2::UpdatedProp uProp3; - uProp3.set_name("teamCareer"); + uProp3.name_ref() = "teamCareer"; const auto& val3 = *ConstantExpression::make(pool, 40); - uProp3.set_value(Expression::encode(val3)); + uProp3.value_ref() = Expression::encode(val3); props.emplace_back(uProp3); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -1338,8 +1338,8 @@ TEST(UpdateEdgeTest, TTL_Insert_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; sleep(FLAGS_mock_ttl_duration + 1); @@ -1429,37 +1429,37 @@ TEST(UpdateEdgeTest, Yield_Key_Test) { LOG(INFO) << "Build UpdateEdgeRequest..."; cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 20); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.type = trade cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -1489,8 +1489,8 @@ TEST(UpdateEdgeTest, Yield_Key_Test) { const auto& edgeTypeExp8 = *EdgeTypeExpression::make(pool, "101"); tmpProps.emplace_back(Expression::encode(edgeTypeExp8)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -1560,37 +1560,37 @@ TEST(UpdateEdgeTest, Yield_Illegal_Key_Test) { LOG(INFO) << "Build UpdateEdgeRequest..."; cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // int: 101.teamCareer = 20 cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *ConstantExpression::make(pool, 20); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // bool: 101.type = trade cpp2::UpdatedProp uProp2; - uProp2.set_name("type"); + uProp2.name_ref() = "type"; std::string colnew("trade"); const auto& val2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer, type @@ -1619,8 +1619,8 @@ TEST(UpdateEdgeTest, Yield_Illegal_Key_Test) { const auto& edgeTypeExp8 = *EdgeTypeExpression::make(pool, "1013"); tmpProps.emplace_back(Expression::encode(edgeTypeExp8)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -1669,44 +1669,44 @@ TEST(UpdateEdgeTest, Insertable_No_Default_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Brandon Ingram") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Brandon Ingram"; VertexID dstId = "Lakers"; EdgeRanking rank = 2016; EdgeType edgeType = 101; // src = Brandon Ingram, edge_type = 101, ranking = 2016, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // string: 101.playerName = Brandon Ingram cpp2::UpdatedProp uProp1; - uProp1.set_name("playerName"); + uProp1.name_ref() = "playerName"; std::string col1new("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // string: 101.teamName = Lakers cpp2::UpdatedProp uProp2; - uProp2.set_name("teamName"); + uProp2.name_ref() = "teamName"; std::string col2new("Lakers"); const auto& val2 = *ConstantExpression::make(pool, col2new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); // int: 101.startYear = 2016 cpp2::UpdatedProp uProp3; - uProp3.set_name("startYear"); + uProp3.name_ref() = "startYear"; const auto& val3 = *ConstantExpression::make(pool, 2016L); - uProp3.set_value(Expression::encode(val3)); + uProp3.value_ref() = Expression::encode(val3); props.emplace_back(uProp3); LOG(INFO) << "Build yield..."; @@ -1721,8 +1721,8 @@ TEST(UpdateEdgeTest, Insertable_No_Default_Test) { const auto& edgePropExp3 = *EdgePropertyExpression::make(pool, "101", "teamCareer"); tmpProps.emplace_back(Expression::encode(edgePropExp3)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -1753,53 +1753,53 @@ TEST(UpdateEdgeTest, Insertable_In_Set_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Brandon Ingram") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Brandon Ingram"; VertexID dstId = "Lakers"; EdgeRanking rank = 2016; EdgeType edgeType = 101; // src = Brandon Ingram, edge_type = 101, ranking = 2016, dst = Lakers storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // string: 101.playerName = Brandon Ingram cpp2::UpdatedProp uProp1; - uProp1.set_name("playerName"); + uProp1.name_ref() = "playerName"; std::string col1new("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); // string: 101.teamName = Lakers cpp2::UpdatedProp uProp2; - uProp2.set_name("teamName"); + uProp2.name_ref() = "teamName"; std::string col2new("Lakers"); const auto& val2 = *ConstantExpression::make(pool, col2new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); props.emplace_back(uProp2); // int: 101.startYear = 2016 cpp2::UpdatedProp uProp3; - uProp3.set_name("startYear"); + uProp3.name_ref() = "startYear"; const auto& val3 = *ConstantExpression::make(pool, 2016L); - uProp3.set_value(Expression::encode(val3)); + uProp3.value_ref() = Expression::encode(val3); props.emplace_back(uProp3); // int: 101.teamCareer = 1 cpp2::UpdatedProp uProp4; - uProp4.set_name("teamCareer"); + uProp4.name_ref() = "teamCareer"; const auto& val4 = *ConstantExpression::make(pool, 1L); - uProp4.set_value(Expression::encode(val4)); + uProp4.value_ref() = Expression::encode(val4); props.emplace_back(uProp4); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer @@ -1815,8 +1815,8 @@ TEST(UpdateEdgeTest, Insertable_In_Set_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -1882,30 +1882,30 @@ TEST(UpdateEdgeTest, Update_Multi_edge_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // string: Serve.teamCareer_ = Teammate.endYear_ cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *EdgePropertyExpression::make(pool, "102", "endYear"); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamCareer @@ -1921,8 +1921,8 @@ TEST(UpdateEdgeTest, Update_Multi_edge_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -1968,30 +1968,30 @@ TEST(UpdateEdgeTest, Upsert_Multi_edge_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // string: Serve.teamCareer_ = Teammate.endYear_ cpp2::UpdatedProp uProp1; - uProp1.set_name("teamCareer"); + uProp1.name_ref() = "teamCareer"; const auto& val1 = *EdgePropertyExpression::make(pool, "102", "endYear"); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer @@ -2007,8 +2007,8 @@ TEST(UpdateEdgeTest, Upsert_Multi_edge_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); @@ -2054,30 +2054,30 @@ TEST(UpdateEdgeTest, Upsert_Field_Type_And_Value_Match_Test) { cpp2::UpdateEdgeRequest req; auto partId = std::hash()("Tim Duncan") % parts + 1; - req.set_space_id(spaceId); - req.set_part_id(partId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; VertexID srcId = "Tim Duncan"; VertexID dstId = "Spurs"; EdgeRanking rank = 1997; EdgeType edgeType = 101; // src = Tim Duncan, edge_type = 101, ranking = 1997, dst = Spurs storage::cpp2::EdgeKey edgeKey; - edgeKey.set_src(srcId); - edgeKey.set_edge_type(edgeType); - edgeKey.set_ranking(rank); - edgeKey.set_dst(dstId); - req.set_edge_key(edgeKey); + edgeKey.src_ref() = srcId; + edgeKey.edge_type_ref() = edgeType; + edgeKey.ranking_ref() = rank; + edgeKey.dst_ref() = dstId; + req.edge_key_ref() = edgeKey; LOG(INFO) << "Build updated props..."; std::vector props; // string: Serve.type_ = 2011(value int) cpp2::UpdatedProp uProp1; - uProp1.set_name("type"); + uProp1.name_ref() = "type"; const auto& val1 = *ConstantExpression::make(pool, 2016L); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); props.emplace_back(uProp1); - req.set_updated_props(std::move(props)); + req.updated_props_ref() = std::move(props); LOG(INFO) << "Build yield..."; // Return serve props: playerName, teamName, teamCareer @@ -2093,8 +2093,8 @@ TEST(UpdateEdgeTest, Upsert_Field_Type_And_Value_Match_Test) { addEdgePropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateEdgeRequest..."; auto* processor = UpdateEdgeProcessor::instance(env, nullptr); diff --git a/src/storage/test/UpdateVertexTest.cpp b/src/storage/test/UpdateVertexTest.cpp index 35dceb7d91e..0b4b73108db 100644 --- a/src/storage/test/UpdateVertexTest.cpp +++ b/src/storage/test/UpdateVertexTest.cpp @@ -115,30 +115,30 @@ TEST(UpdateVertexTest, No_Filter_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = 45 cpp2::UpdatedProp uProp1; - uProp1.set_name("age"); + uProp1.name_ref() = "age"; const auto& val1 = *ConstantExpression::make(pool, 45L); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); // string: player.country= China cpp2::UpdatedProp uProp2; - uProp2.set_name("country"); + uProp2.name_ref() = "country"; std::string col4new("China"); const auto& val2 = *ConstantExpression::make(pool, col4new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -154,8 +154,8 @@ TEST(UpdateVertexTest, No_Filter_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateVertexRequest..."; auto* processor = UpdateVertexProcessor::instance(env, nullptr); @@ -217,12 +217,12 @@ TEST(UpdateVertexTest, Filter_Yield_Test2) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build filter..."; // left int: 1.startYear = 1997 @@ -236,24 +236,24 @@ TEST(UpdateVertexTest, Filter_Yield_Test2) { auto* right = RelationalExpression::makeEQ(pool, srcExp2, priExp2); // left AND right is true auto logExp = LogicalExpression::makeAnd(pool, left, right); - req.set_condition(Expression::encode(*logExp)); + req.condition_ref() = Expression::encode(*logExp); LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = 46 cpp2::UpdatedProp uProp1; - uProp1.set_name("age"); + uProp1.name_ref() = "age"; const auto& val1 = *ConstantExpression::make(pool, 46L); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); // string: player.country= China cpp2::UpdatedProp uProp2; - uProp2.set_name("country"); + uProp2.name_ref() = "country"; std::string col4new("China"); const auto& val2 = *ConstantExpression::make(pool, col4new); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; { @@ -270,8 +270,8 @@ TEST(UpdateVertexTest, Filter_Yield_Test2) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; } LOG(INFO) << "Test UpdateVertexRequest..."; @@ -336,30 +336,30 @@ TEST(UpdateVertexTest, Insertable_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Brandon Ingram") % parts + 1; VertexID vertexId("Brandon Ingram"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // string: player.name= "Brandon Ingram" cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; std::string colnew("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, colnew); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); // int: player.age = 20 cpp2::UpdatedProp uProp2; - uProp2.set_name("age"); + uProp2.name_ref() = "age"; const auto& val2 = *ConstantExpression::make(pool, 20L); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -376,8 +376,8 @@ TEST(UpdateVertexTest, Insertable_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; } LOG(INFO) << "Test UpdateVertexRequest..."; @@ -439,28 +439,28 @@ TEST(UpdateVertexTest, Invalid_Update_Prop_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = 46 cpp2::UpdatedProp uProp1; - uProp1.set_name("age"); + uProp1.name_ref() = "age"; const auto& uVal1 = *ConstantExpression::make(pool, 46L); - uProp1.set_value(Expression::encode(uVal1)); + uProp1.value_ref() = Expression::encode(uVal1); updatedProps.emplace_back(uProp1); // int: player.birth = 1997 invalid cpp2::UpdatedProp uProp2; - uProp2.set_name("birth"); + uProp2.name_ref() = "birth"; const auto& uVal2 = *ConstantExpression::make(pool, 1997L); - uProp2.set_value(Expression::encode(uVal2)); + uProp2.value_ref() = Expression::encode(uVal2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age @@ -472,9 +472,9 @@ TEST(UpdateVertexTest, Invalid_Update_Prop_Test) { const auto& sourcePropExp2 = *SourcePropertyExpression::make(pool, "1", "age"); tmpProps.emplace_back(Expression::encode(sourcePropExp2)); - req.set_return_props(std::move(tmpProps)); + req.return_props_ref() = std::move(tmpProps); } - req.set_insertable(false); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateVertexRequest..."; auto* processor = UpdateVertexProcessor::instance(env, nullptr); @@ -519,12 +519,12 @@ TEST(UpdateVertexTest, Invalid_Filter_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build filter..."; // left int: 1.startYear = 1997 @@ -539,25 +539,25 @@ TEST(UpdateVertexTest, Invalid_Filter_Test) { auto* right = RelationalExpression::makeEQ(pool, srcExp2, priExp2); // left AND right is true auto logExp = LogicalExpression::makeAnd(pool, left, right); - req.set_condition(Expression::encode(*logExp)); + req.condition_ref() = Expression::encode(*logExp); LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = 46 cpp2::UpdatedProp uProp1; - uProp1.set_name("age"); + uProp1.name_ref() = "age"; const auto& uVal1 = *ConstantExpression::make(pool, 46L); - uProp1.set_value(Expression::encode(uVal1)); + uProp1.value_ref() = Expression::encode(uVal1); updatedProps.emplace_back(uProp1); // string: player.country= America cpp2::UpdatedProp uProp2; - uProp2.set_name("country"); + uProp2.name_ref() = "country"; std::string colnew("China"); const auto& uVal2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(uVal2)); + uProp2.value_ref() = Expression::encode(uVal2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -572,9 +572,9 @@ TEST(UpdateVertexTest, Invalid_Filter_Test) { const auto& sourcePropExp3 = *SourcePropertyExpression::make(pool, "1", "country"); tmpProps.emplace_back(Expression::encode(sourcePropExp3)); - req.set_return_props(std::move(tmpProps)); + req.return_props_ref() = std::move(tmpProps); } - req.set_insertable(false); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateVertexRequest..."; auto* processor = UpdateVertexProcessor::instance(env, nullptr); @@ -620,30 +620,30 @@ TEST(UpdateVertexTest, Insertable_Filter_Value_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Brandon Ingram") % parts + 1; VertexID vertexId("Brandon Ingram"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // string: player.name= "Brandon Ingram" cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; std::string colnew("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, colnew); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); // int: player.age = 20 cpp2::UpdatedProp uProp2; - uProp2.set_name("age"); + uProp2.name_ref() = "age"; const auto& val2 = *ConstantExpression::make(pool, 20L); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build filter..."; // filter is valid, but filter value is false @@ -658,7 +658,7 @@ TEST(UpdateVertexTest, Insertable_Filter_Value_Test) { auto* right = RelationalExpression::makeEQ(pool, srcExp2, priExp2); // left AND right is false auto logExp = LogicalExpression::makeAnd(pool, left, right); - req.set_condition(Expression::encode(*logExp)); + req.condition_ref() = Expression::encode(*logExp); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -675,8 +675,8 @@ TEST(UpdateVertexTest, Insertable_Filter_Value_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; } LOG(INFO) << "Test UpdateVertexRequest..."; @@ -749,20 +749,20 @@ TEST(UpdateVertexTest, CorruptDataTest) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.space_id_ref() = spaceId; + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = 23 cpp2::UpdatedProp uProp1; - uProp1.set_name("age"); + uProp1.name_ref() = "age"; const auto& uVal1 = *ConstantExpression::make(pool, 23L); - uProp1.set_value(Expression::encode(uVal1)); + uProp1.value_ref() = Expression::encode(uVal1); updatedProps.emplace_back(uProp1); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -770,8 +770,8 @@ TEST(UpdateVertexTest, CorruptDataTest) { const auto& sourcePropExp1 = *SourcePropertyExpression::make(pool, "1", "country"); tmpProps.emplace_back(Expression::encode(sourcePropExp1)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateVertexRequest..."; auto* processor = UpdateVertexProcessor::instance(env, nullptr); @@ -805,29 +805,29 @@ TEST(UpdateVertexTest, TTL_NoInsert_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = 45 cpp2::UpdatedProp uProp1; - uProp1.set_name("age"); + uProp1.name_ref() = "age"; const auto& uVal1 = *ConstantExpression::make(pool, 45L); - uProp1.set_value(Expression::encode(uVal1)); + uProp1.value_ref() = Expression::encode(uVal1); updatedProps.emplace_back(uProp1); // string: player.country= China cpp2::UpdatedProp uProp2; - uProp2.set_name("country"); + uProp2.name_ref() = "country"; std::string colnew("China"); const auto& uVal2 = *ConstantExpression::make(pool, colnew); - uProp2.set_value(Expression::encode(uVal2)); + uProp2.value_ref() = Expression::encode(uVal2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -842,9 +842,9 @@ TEST(UpdateVertexTest, TTL_NoInsert_Test) { const auto& sourcePropExp3 = *SourcePropertyExpression::make(pool, "1", "country"); tmpProps.emplace_back(Expression::encode(sourcePropExp3)); - req.set_return_props(std::move(tmpProps)); + req.return_props_ref() = std::move(tmpProps); } - req.set_insertable(false); + req.insertable_ref() = false; sleep(FLAGS_mock_ttl_duration + 1); @@ -880,31 +880,31 @@ TEST(UpdateVertexTest, TTL_Insert_No_Exist_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim") % parts + 1; VertexID vertexId("Tim"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // string: 1.name = Tim cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; std::string col1new("Tim"); const auto& uVal1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(uVal1)); + uProp1.value_ref() = Expression::encode(uVal1); updatedProps.emplace_back(uProp1); // int: player.age = 20 cpp2::UpdatedProp uProp2; - uProp2.set_name("age"); + uProp2.name_ref() = "age"; const auto& uVal2 = *ConstantExpression::make(pool, 20L); - uProp2.set_value(Expression::encode(uVal2)); + uProp2.value_ref() = Expression::encode(uVal2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -921,9 +921,9 @@ TEST(UpdateVertexTest, TTL_Insert_No_Exist_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); + req.return_props_ref() = std::move(tmpProps); } - req.set_insertable(true); + req.insertable_ref() = true; sleep(FLAGS_mock_ttl_duration + 1); @@ -990,40 +990,40 @@ TEST(UpdateVertexTest, TTL_Insert_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // string: 1.name = Tim Duncan cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; std::string col1new("Tim Duncan"); const auto& uVal1 = *ConstantExpression::make(pool, col1new); - uProp1.set_value(Expression::encode(uVal1)); + uProp1.value_ref() = Expression::encode(uVal1); updatedProps.emplace_back(uProp1); // int: 1.age = 50L cpp2::UpdatedProp uProp2; - uProp2.set_name("age"); + uProp2.name_ref() = "age"; const auto& uVal2 = *ConstantExpression::make(pool, 50L); - uProp2.set_value(Expression::encode(uVal2)); + uProp2.value_ref() = Expression::encode(uVal2); updatedProps.emplace_back(uProp2); // string: player.country= China cpp2::UpdatedProp uProp3; - uProp3.set_name("country"); + uProp3.name_ref() = "country"; std::string col3new("China"); const auto& uVal3 = *ConstantExpression::make(pool, col3new); - uProp3.set_value(Expression::encode(uVal3)); + uProp3.value_ref() = Expression::encode(uVal3); updatedProps.emplace_back(uProp3); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -1040,9 +1040,9 @@ TEST(UpdateVertexTest, TTL_Insert_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); + req.return_props_ref() = std::move(tmpProps); } - req.set_insertable(true); + req.insertable_ref() = true; sleep(FLAGS_mock_ttl_duration + 1); @@ -1131,21 +1131,21 @@ TEST(UpdateVertexTest, Insertable_No_Default_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Brandon Ingram") % parts + 1; VertexID vertexId("Brandon Ingram"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // string: player.name= "Brandon Ingram" cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; std::string colnew("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, colnew); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); LOG(INFO) << "Build yield..."; @@ -1158,8 +1158,8 @@ TEST(UpdateVertexTest, Insertable_No_Default_Test) { const auto& sourcePropExp2 = *SourcePropertyExpression::make(pool, "1", "age"); tmpProps.emplace_back(Expression::encode(sourcePropExp2)); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; } LOG(INFO) << "Test UpdateVertexRequest..."; @@ -1191,30 +1191,30 @@ TEST(UpdateVertexTest, Insertable_In_Set_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Brandon Ingram") % parts + 1; VertexID vertexId("Brandon Ingram"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // string: player.name= "Brandon Ingram" cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; std::string colnew("Brandon Ingram"); const auto& val1 = *ConstantExpression::make(pool, colnew); - uProp1.set_value(Expression::encode(val1)); + uProp1.value_ref() = Expression::encode(val1); updatedProps.emplace_back(uProp1); // int: player.age = $^.player.career cpp2::UpdatedProp uProp2; - uProp2.set_name("age"); + uProp2.name_ref() = "age"; const auto& val2 = *SourcePropertyExpression::make(pool, "1", "career"); - uProp2.set_value(Expression::encode(val2)); + uProp2.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp2); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age @@ -1228,8 +1228,8 @@ TEST(UpdateVertexTest, Insertable_In_Set_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; } LOG(INFO) << "Test UpdateVertexRequest..."; @@ -1288,24 +1288,24 @@ TEST(UpdateVertexTest, Update_Multi_tag_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = $^.team.career cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; // value is another tag expression const auto& val2 = *SourcePropertyExpression::make(pool, "2", "name"); - uProp1.set_value(Expression::encode(val2)); + uProp1.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp1); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -1315,8 +1315,8 @@ TEST(UpdateVertexTest, Update_Multi_tag_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(false); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = false; LOG(INFO) << "Test UpdateVertexRequest..."; auto* processor = UpdateVertexProcessor::instance(env, nullptr); @@ -1358,24 +1358,24 @@ TEST(UpdateVertexTest, Upsert_Multi_tag_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // int: player.age = $^.team.career cpp2::UpdatedProp uProp1; - uProp1.set_name("name"); + uProp1.name_ref() = "name"; // value is another tag expression const auto& val2 = *SourcePropertyExpression::make(pool, "2", "name"); - uProp1.set_value(Expression::encode(val2)); + uProp1.value_ref() = Expression::encode(val2); updatedProps.emplace_back(uProp1); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -1385,8 +1385,8 @@ TEST(UpdateVertexTest, Upsert_Multi_tag_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateVertexRequest..."; auto* processor = UpdateVertexProcessor::instance(env, nullptr); @@ -1428,23 +1428,23 @@ TEST(UpdateVertexTest, Upsert_Field_Type_And_Value_Match_Test) { LOG(INFO) << "Build UpdateVertexRequest..."; cpp2::UpdateVertexRequest req; - req.set_space_id(spaceId); + req.space_id_ref() = spaceId; auto partId = std::hash()("Tim Duncan") % parts + 1; VertexID vertexId("Tim Duncan"); - req.set_part_id(partId); - req.set_vertex_id(vertexId); - req.set_tag_id(tagId); + req.part_id_ref() = partId; + req.vertex_id_ref() = vertexId; + req.tag_id_ref() = tagId; LOG(INFO) << "Build updated props..."; std::vector updatedProps; // string: player.country_ = 2011(value int) cpp2::UpdatedProp uProp1; - uProp1.set_name("country"); + uProp1.name_ref() = "country"; const auto& uVal1 = *ConstantExpression::make(pool, 2011L); - uProp1.set_value(Expression::encode(uVal1)); + uProp1.value_ref() = Expression::encode(uVal1); updatedProps.emplace_back(uProp1); - req.set_updated_props(std::move(updatedProps)); + req.updated_props_ref() = std::move(updatedProps); LOG(INFO) << "Build yield..."; // Return player props: name, age, country @@ -1454,8 +1454,8 @@ TEST(UpdateVertexTest, Upsert_Field_Type_And_Value_Match_Test) { addTagPropInKey(tmpProps); - req.set_return_props(std::move(tmpProps)); - req.set_insertable(true); + req.return_props_ref() = std::move(tmpProps); + req.insertable_ref() = true; LOG(INFO) << "Test UpdateVertexRequest..."; auto* processor = UpdateVertexProcessor::instance(env, nullptr); diff --git a/src/storage/transaction/ChainAddEdgesGroupProcessor.cpp b/src/storage/transaction/ChainAddEdgesGroupProcessor.cpp index 3af8a2bc9cc..56323288c25 100644 --- a/src/storage/transaction/ChainAddEdgesGroupProcessor.cpp +++ b/src/storage/transaction/ChainAddEdgesGroupProcessor.cpp @@ -47,9 +47,9 @@ void ChainAddEdgesGroupProcessor::shuffleRequest(const cpp2::AddEdgesRequest& re auto genNewReq = [&](auto& reqIn) { cpp2::AddEdgesRequest ret; - ret.set_space_id(reqIn.get_space_id()); - ret.set_prop_names(reqIn.get_prop_names()); - ret.set_if_not_exists(reqIn.get_if_not_exists()); + ret.space_id_ref() = reqIn.get_space_id(); + ret.prop_names_ref() = reqIn.get_prop_names(); + ret.if_not_exists_ref() = reqIn.get_if_not_exists(); return ret; }; diff --git a/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp b/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp index 182484a4de0..72e983302f1 100644 --- a/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp +++ b/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp @@ -398,9 +398,9 @@ cpp2::AddEdgesRequest ChainAddEdgesProcessorLocal::reverseRequest( ConsistUtil::reverseEdgeKeyInplace(*newEdgeRef.key_ref()); } } - reversedRequest.set_space_id(req.get_space_id()); - reversedRequest.set_prop_names(req.get_prop_names()); - reversedRequest.set_if_not_exists(req.get_if_not_exists()); + reversedRequest.space_id_ref() = (req.get_space_id()); + reversedRequest.prop_names_ref() = (req.get_prop_names()); + reversedRequest.if_not_exists_ref() = (req.get_if_not_exists()); return reversedRequest; } @@ -414,14 +414,14 @@ void ChainAddEdgesProcessorLocal::finish() { cpp2::AddEdgesRequest ChainAddEdgesProcessorLocal::makeSingleEdgeRequest( PartitionID partId, const cpp2::NewEdge& edge) { cpp2::AddEdgesRequest req; - req.set_space_id(req_.get_space_id()); - req.set_prop_names(req_.get_prop_names()); - req.set_if_not_exists(req_.get_if_not_exists()); + req.space_id_ref() = (req_.get_space_id()); + req.prop_names_ref() = (req_.get_prop_names()); + req.if_not_exists_ref() = (req_.get_if_not_exists()); std::unordered_map> newParts; newParts[partId].emplace_back(edge); - req.set_parts(newParts); + req.parts_ref() = (newParts); return req; } diff --git a/src/storage/transaction/ChainAddEdgesProcessorLocal.h b/src/storage/transaction/ChainAddEdgesProcessorLocal.h index 8e2329158a2..68333e7d210 100644 --- a/src/storage/transaction/ChainAddEdgesProcessorLocal.h +++ b/src/storage/transaction/ChainAddEdgesProcessorLocal.h @@ -32,7 +32,9 @@ class ChainAddEdgesProcessorLocal : public BaseProcessor, folly::SemiFuture processLocal(Code code) override; - void setRemotePartId(PartitionID remotePartId) { remotePartId_ = remotePartId; } + void setRemotePartId(PartitionID remotePartId) { + remotePartId_ = remotePartId; + } void finish() override; diff --git a/src/storage/transaction/ChainBaseProcessor.h b/src/storage/transaction/ChainBaseProcessor.h index f7ff514d23a..c20f7dc6e84 100644 --- a/src/storage/transaction/ChainBaseProcessor.h +++ b/src/storage/transaction/ChainBaseProcessor.h @@ -23,13 +23,21 @@ class ChainBaseProcessor { public: virtual ~ChainBaseProcessor() = default; - virtual folly::SemiFuture prepareLocal() { return Code::SUCCEEDED; } + virtual folly::SemiFuture prepareLocal() { + return Code::SUCCEEDED; + } - virtual folly::SemiFuture processRemote(Code code) { return code; } + virtual folly::SemiFuture processRemote(Code code) { + return code; + } - virtual folly::SemiFuture processLocal(Code code) { return code; } + virtual folly::SemiFuture processLocal(Code code) { + return code; + } - virtual folly::Future getFinished() { return finished_.getFuture(); } + virtual folly::Future getFinished() { + return finished_.getFuture(); + } virtual void finish() = 0; diff --git a/src/storage/transaction/ChainUpdateEdgeProcessorLocal.cpp b/src/storage/transaction/ChainUpdateEdgeProcessorLocal.cpp index 1264e05421e..443da4093fa 100644 --- a/src/storage/transaction/ChainUpdateEdgeProcessorLocal.cpp +++ b/src/storage/transaction/ChainUpdateEdgeProcessorLocal.cpp @@ -225,13 +225,13 @@ cpp2::UpdateEdgeRequest ChainUpdateEdgeProcessorLocal::reverseRequest( const cpp2::UpdateEdgeRequest& req) { cpp2::UpdateEdgeRequest reversedRequest(req); auto reversedEdgeKey = ConsistUtil::reverseEdgeKey(req.get_edge_key()); - reversedRequest.set_edge_key(reversedEdgeKey); + reversedRequest.edge_key_ref() = reversedEdgeKey; auto partsNum = env_->metaClient_->partsNum(req.get_space_id()); CHECK(partsNum.ok()); auto srcVid = reversedRequest.get_edge_key().get_src().getStr(); auto partId = env_->metaClient_->partId(partsNum.value(), srcVid); - reversedRequest.set_part_id(partId); + reversedRequest.part_id_ref() = partId; return reversedRequest; } diff --git a/src/storage/transaction/ConsistUtil.cpp b/src/storage/transaction/ConsistUtil.cpp index 4edea1dfe0e..e720012bd3b 100644 --- a/src/storage/transaction/ConsistUtil.cpp +++ b/src/storage/transaction/ConsistUtil.cpp @@ -16,9 +16,13 @@ namespace storage { static const std::string kPrimeTable{"__prime__"}; // NOLINT static const std::string kDoublePrimeTable{"__prime_prime__"}; // NOLINT -std::string ConsistUtil::primeTable() { return kPrimeTable; } +std::string ConsistUtil::primeTable() { + return kPrimeTable; +} -std::string ConsistUtil::doublePrimeTable() { return kDoublePrimeTable; } +std::string ConsistUtil::doublePrimeTable() { + return kDoublePrimeTable; +} std::string ConsistUtil::primePrefix(PartitionID partId) { return kPrimeTable + NebulaKeyUtils::edgePrefix(partId); @@ -133,10 +137,10 @@ int64_t ConsistUtil::getTimestamp(const std::string& val) noexcept { cpp2::AddEdgesRequest ConsistUtil::toAddEdgesRequest(const cpp2::ChainAddEdgesRequest& req) { cpp2::AddEdgesRequest ret; - ret.set_space_id(req.get_space_id()); - ret.set_parts(req.get_parts()); - ret.set_prop_names(req.get_prop_names()); - ret.set_if_not_exists(req.get_if_not_exists()); + ret.space_id_ref() = req.get_space_id(); + ret.parts_ref() = req.get_parts(); + ret.prop_names_ref() = req.get_prop_names(); + ret.if_not_exists_ref() = req.get_if_not_exists(); return ret; } diff --git a/src/storage/transaction/ConsistUtil.h b/src/storage/transaction/ConsistUtil.h index 2fa79cda934..a507802bdf0 100644 --- a/src/storage/transaction/ConsistUtil.h +++ b/src/storage/transaction/ConsistUtil.h @@ -96,9 +96,13 @@ class ConsistUtil final { static void reverseEdgeKeyInplace(cpp2::EdgeKey& edgeKey); - static std::string insertIdentifier() noexcept { return "a"; } + static std::string insertIdentifier() noexcept { + return "a"; + } - static std::string updateIdentifier() noexcept { return "u"; } + static std::string updateIdentifier() noexcept { + return "u"; + } static std::pair versionOfUpdateReq( StorageEnv* env, const cpp2::UpdateEdgeRequest& req); diff --git a/src/storage/transaction/TransactionManager.h b/src/storage/transaction/TransactionManager.h index 198a7466a1d..83441b958ea 100644 --- a/src/storage/transaction/TransactionManager.h +++ b/src/storage/transaction/TransactionManager.h @@ -45,11 +45,15 @@ class TransactionManager { }); } - folly::Executor* getExecutor() { return exec_.get(); } + folly::Executor* getExecutor() { + return exec_.get(); + } LockCore* getLockCore(GraphSpaceID spaceId, PartitionID partId, bool checkWhiteList = true); - InternalStorageClient* getInternalClient() { return iClient_; } + InternalStorageClient* getInternalClient() { + return iClient_; + } StatusOr getTerm(GraphSpaceID spaceId, PartitionID partId); diff --git a/src/tools/db-dump/CMakeLists.txt b/src/tools/db-dump/CMakeLists.txt index a90c14639ed..80919a420a6 100644 --- a/src/tools/db-dump/CMakeLists.txt +++ b/src/tools/db-dump/CMakeLists.txt @@ -34,6 +34,10 @@ set(tools_test_deps $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/db-upgrade/CMakeLists.txt b/src/tools/db-upgrade/CMakeLists.txt index 3a5985fa4dd..2f4bbdbee17 100644 --- a/src/tools/db-upgrade/CMakeLists.txt +++ b/src/tools/db-upgrade/CMakeLists.txt @@ -42,6 +42,10 @@ nebula_add_executable( $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/meta-dump/CMakeLists.txt b/src/tools/meta-dump/CMakeLists.txt index 37a804eac3e..466b91ef62d 100644 --- a/src/tools/meta-dump/CMakeLists.txt +++ b/src/tools/meta-dump/CMakeLists.txt @@ -39,6 +39,10 @@ nebula_add_executable( $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/simple-kv-verify/CMakeLists.txt b/src/tools/simple-kv-verify/CMakeLists.txt index e5c95581711..81de926c583 100644 --- a/src/tools/simple-kv-verify/CMakeLists.txt +++ b/src/tools/simple-kv-verify/CMakeLists.txt @@ -38,6 +38,10 @@ nebula_add_executable( $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/storage-perf/CMakeLists.txt b/src/tools/storage-perf/CMakeLists.txt index 5bff542fca6..41f9b0a18a5 100644 --- a/src/tools/storage-perf/CMakeLists.txt +++ b/src/tools/storage-perf/CMakeLists.txt @@ -34,6 +34,10 @@ set(perf_test_deps $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/storage-perf/StoragePerfTool.cpp b/src/tools/storage-perf/StoragePerfTool.cpp index 8fb47a9dac9..ae95292ee85 100644 --- a/src/tools/storage-perf/StoragePerfTool.cpp +++ b/src/tools/storage-perf/StoragePerfTool.cpp @@ -80,7 +80,7 @@ class Perf { nebula::meta::cpp2::Schema schema; nebula::meta::cpp2::ColumnDef column; column.name = "col_1"; - column.type.set_type(nebula::cpp2::PropertyType::STRING); + column.type.type_ref() = nebula::cpp2::PropertyType::STRING; (*schema.columns_ref()).emplace_back(std::move(column)); auto ret = mClient_->createTagSchema(spaceId_, FLAGS_tag_name, schema).get(); if (!ret.ok()) { @@ -108,7 +108,7 @@ class Perf { nebula::meta::cpp2::Schema schema; nebula::meta::cpp2::ColumnDef column; column.name = "col_1"; - column.type.set_type(nebula::cpp2::PropertyType::STRING); + column.type.type_ref() = nebula::cpp2::PropertyType::STRING; (*schema.columns_ref()).emplace_back(std::move(column)); auto ret = mClient_->createEdgeSchema(spaceId_, FLAGS_edge_name, schema).get(); if (!ret.ok()) { @@ -195,8 +195,8 @@ class Perf { std::vector vertexProps() { std::vector vertexProps; cpp2::VertexProp vertexProp; - vertexProp.set_tag(tagId_); - vertexProp.set_props(tagProps_[tagId_]); + vertexProp.tag_ref() = tagId_; + vertexProp.props_ref() = tagProps_[tagId_]; vertexProps.emplace_back(std::move(vertexProp)); return vertexProps; } @@ -204,8 +204,8 @@ class Perf { std::vector edgeProps() { std::vector edgeProps; cpp2::EdgeProp edgeProp; - edgeProp.set_type(edgeType_); - edgeProp.set_props(edgeProps_); + edgeProp.type_ref() = edgeType_; + edgeProp.props_ref() = edgeProps_; edgeProps.emplace_back(std::move(edgeProp)); return edgeProps; } @@ -243,15 +243,15 @@ class Perf { for (int32_t i = 0; i < FLAGS_batch_num; i++) { storage::cpp2::NewVertex v; - v.set_id(std::to_string(vintId)); + v.id_ref() = std::to_string(vintId); vintId++; std::vector newTags; storage::cpp2::NewTag newTag; - newTag.set_tag_id(tagId_); + newTag.tag_id_ref() = tagId_; auto props = genData(tagProps_[tagId_].size()); - newTag.set_props(std::move(props)); + newTag.props_ref() = std::move(props); newTags.emplace_back(std::move(newTag)); - v.set_tags(std::move(newTags)); + v.tags_ref() = std::move(newTags); newVertices.emplace_back(std::move(v)); } return newVertices; @@ -264,13 +264,13 @@ class Perf { for (int32_t i = 0; i < FLAGS_batch_num; i++) { cpp2::NewEdge edge; cpp2::EdgeKey eKey; - eKey.set_src(std::to_string(vintId)); - eKey.set_edge_type(edgeType_); - eKey.set_dst(std::to_string(vintId + 1)); - eKey.set_ranking(0); - edge.set_key(std::move(eKey)); + eKey.src_ref() = std::to_string(vintId); + eKey.edge_type_ref() = edgeType_; + eKey.dst_ref() = std::to_string(vintId + 1); + eKey.ranking_ref() = 0; + edge.key_ref() = std::move(eKey); auto props = genData(edgeProps_.size()); - edge.set_props(std::move(props)); + edge.props_ref() = std::move(props); edges.emplace_back(std::move(edge)); vintId++; } diff --git a/src/webservice/Common.h b/src/webservice/Common.h index a4aacf0205a..08c0156ebaf 100644 --- a/src/webservice/Common.h +++ b/src/webservice/Common.h @@ -29,8 +29,12 @@ enum class HttpStatusCode : int32_t { class WebServiceUtils final { public: - static int32_t to(HttpStatusCode code) { return static_cast(code); } - static std::string toString(HttpStatusCode code) { return kStatusStringMap_[code]; } + static int32_t to(HttpStatusCode code) { + return static_cast(code); + } + static std::string toString(HttpStatusCode code) { + return kStatusStringMap_[code]; + } private: static std::unordered_map kStatusStringMap_; diff --git a/src/webservice/GetFlagsHandler.cpp b/src/webservice/GetFlagsHandler.cpp index 85c2b3d641f..ad8ea573c56 100644 --- a/src/webservice/GetFlagsHandler.cpp +++ b/src/webservice/GetFlagsHandler.cpp @@ -79,7 +79,9 @@ void GetFlagsHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void GetFlagsHandler::requestComplete() noexcept { delete this; } +void GetFlagsHandler::requestComplete() noexcept { + delete this; +} void GetFlagsHandler::onError(ProxygenError err) noexcept { LOG(ERROR) << "Web service GetFlagsHandler got error: " << proxygen::getErrorString(err); diff --git a/src/webservice/GetStatsHandler.cpp b/src/webservice/GetStatsHandler.cpp index 12bd66037ec..cc75b71b66f 100644 --- a/src/webservice/GetStatsHandler.cpp +++ b/src/webservice/GetStatsHandler.cpp @@ -82,7 +82,9 @@ void GetStatsHandler::addOneStat(folly::dynamic& vals, vals.push_back(folly::dynamic::object(statName, error)); } -void GetStatsHandler::requestComplete() noexcept { delete this; } +void GetStatsHandler::requestComplete() noexcept { + delete this; +} void GetStatsHandler::onError(ProxygenError err) noexcept { LOG(ERROR) << "Web service GetStatsHandler got error: " << proxygen::getErrorString(err); diff --git a/src/webservice/NotFoundHandler.cpp b/src/webservice/NotFoundHandler.cpp index 3444805dde8..2747e0b3b37 100644 --- a/src/webservice/NotFoundHandler.cpp +++ b/src/webservice/NotFoundHandler.cpp @@ -37,7 +37,9 @@ void NotFoundHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void NotFoundHandler::requestComplete() noexcept { delete this; } +void NotFoundHandler::requestComplete() noexcept { + delete this; +} void NotFoundHandler::onError(ProxygenError err) noexcept { LOG(ERROR) << "Web service NotFoundHandler got error: " << proxygen::getErrorString(err); diff --git a/src/webservice/Router.h b/src/webservice/Router.h index 806af99fa05..dcf112b2d8a 100644 --- a/src/webservice/Router.h +++ b/src/webservice/Router.h @@ -37,9 +37,13 @@ class Route final { setPath(path); } - void setNext(Route *next) { next_ = next; } + void setNext(Route *next) { + next_ = next; + } - Route *next() const { return next_; } + Route *next() const { + return next_; + } bool matches(proxygen::HTTPMethod method, const std::string &path) const; @@ -72,13 +76,21 @@ class Router final : public cpp::NonCopyable, public cpp::NonMovable { proxygen::RequestHandler *dispatch(const proxygen::HTTPMessage *msg) const; - Route &get(const std::string &path) { return route(proxygen::HTTPMethod::GET, path); } + Route &get(const std::string &path) { + return route(proxygen::HTTPMethod::GET, path); + } - Route &post(const std::string &path) { return route(proxygen::HTTPMethod::POST, path); } + Route &post(const std::string &path) { + return route(proxygen::HTTPMethod::POST, path); + } - Route &put(const std::string &path) { return route(proxygen::HTTPMethod::PUT, path); } + Route &put(const std::string &path) { + return route(proxygen::HTTPMethod::PUT, path); + } - Route &del(const std::string &path) { return route(proxygen::HTTPMethod::DELETE, path); } + Route &del(const std::string &path) { + return route(proxygen::HTTPMethod::DELETE, path); + } Route &route(proxygen::HTTPMethod method, const std::string &path); diff --git a/src/webservice/SetFlagsHandler.cpp b/src/webservice/SetFlagsHandler.cpp index f6a5970badc..26b6f621232 100644 --- a/src/webservice/SetFlagsHandler.cpp +++ b/src/webservice/SetFlagsHandler.cpp @@ -88,7 +88,9 @@ void SetFlagsHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void SetFlagsHandler::requestComplete() noexcept { delete this; } +void SetFlagsHandler::requestComplete() noexcept { + delete this; +} void SetFlagsHandler::onError(ProxygenError err) noexcept { LOG(ERROR) << "Web service SetFlagsHandler got error: " << proxygen::getErrorString(err); diff --git a/src/webservice/StatusHandler.cpp b/src/webservice/StatusHandler.cpp index f2cad292ed8..a2ffb9c76b4 100644 --- a/src/webservice/StatusHandler.cpp +++ b/src/webservice/StatusHandler.cpp @@ -55,7 +55,9 @@ void StatusHandler::onUpgrade(UpgradeProtocol) noexcept { // Do nothing } -void StatusHandler::requestComplete() noexcept { delete this; } +void StatusHandler::requestComplete() noexcept { + delete this; +} void StatusHandler::onError(ProxygenError error) noexcept { LOG(ERROR) << "Web service StorageHttpHandler got error: " << proxygen::getErrorString(error); diff --git a/src/webservice/WebService.h b/src/webservice/WebService.h index 6637590f506..bd34004abd4 100644 --- a/src/webservice/WebService.h +++ b/src/webservice/WebService.h @@ -44,7 +44,9 @@ class WebService final { NG_MUST_USE_RESULT Status start(); // Check whether web service is started - bool started() const { return started_; } + bool started() const { + return started_; + } private: bool started_{false}; diff --git a/src/webservice/test/RouterTest.cpp b/src/webservice/test/RouterTest.cpp index 1bbd60949fb..04190df902a 100644 --- a/src/webservice/test/RouterTest.cpp +++ b/src/webservice/test/RouterTest.cpp @@ -12,9 +12,13 @@ class RouterTest : public ::testing::Test { public: - void SetUp() override { router_ = std::make_unique("test"); } + void SetUp() override { + router_ = std::make_unique("test"); + } - void TearDown() override { router_.reset(); } + void TearDown() override { + router_.reset(); + } static void found(const nebula::web::Router* router, const proxygen::HTTPMessage* msg) { std::unique_ptr handler(router->dispatch(msg)); @@ -26,9 +30,13 @@ class RouterTest : public ::testing::Test { ASSERT_TRUE(handler); } - void found(const proxygen::HTTPMessage* msg) const { found(router_.get(), msg); } + void found(const proxygen::HTTPMessage* msg) const { + found(router_.get(), msg); + } - void notFound(const proxygen::HTTPMessage* msg) const { notFound(router_.get(), msg); } + void notFound(const proxygen::HTTPMessage* msg) const { + notFound(router_.get(), msg); + } protected: std::unique_ptr router_; diff --git a/src/webservice/test/StatsReaderTest.cpp b/src/webservice/test/StatsReaderTest.cpp index 4ef357f1258..7789c65ea6b 100644 --- a/src/webservice/test/StatsReaderTest.cpp +++ b/src/webservice/test/StatsReaderTest.cpp @@ -126,7 +126,7 @@ TEST(StatsReaderTest, GetStatsTest) { { // get all stats(sum,count,avg,rate) std::string resp; - ASSERT_TRUE(getUrl("/stats?stats= ", resp)); + ASSERT_TRUE(getUrl("/stats?stats=", resp)); EXPECT_FALSE(resp.empty()); } diff --git a/tests/tck/features/admin/Sessions.feature b/tests/tck/features/admin/Sessions.feature index de812fad7f1..af935515c4a 100644 --- a/tests/tck/features/admin/Sessions.feature +++ b/tests/tck/features/admin/Sessions.feature @@ -12,8 +12,8 @@ Feature: Test sessions SHOW SESSIONS; """ Then the result should contain: - | SessionId | UserName | SpaceName | CreateTime | UpdateTime | GraphAddr | Timezone | ClientIp | - | /\d+/ | "root" | "" | /.*/ | /.*/ | /.*/ | 0 | "127.0.0.1" | + | SessionId | UserName | SpaceName | CreateTime | UpdateTime | GraphAddr | Timezone | ClientIp | + | /\d+/ | "root" | "" | /.*/ | /.*/ | /.*/ | 0 | /.*(127.0.0.1)$/ | When executing query: """ CREATE USER user1 WITH PASSWORD 'nebula1'; @@ -28,6 +28,6 @@ Feature: Test sessions SHOW SESSIONS; """ Then the result should contain, replace the holders with cluster info: - | SessionId | UserName | SpaceName | CreateTime | UpdateTime | GraphAddr | Timezone | ClientIp | - | /\d+/ | "root" | "s1" | /.*/ | /.*/ | "127.0.0.1:${cluster.graphd_processes[0].tcp_port}" | 0 | "127.0.0.1" | - | /\d+/ | "user1" | "" | /.*/ | /.*/ | "127.0.0.1:${cluster.graphd_processes[1].tcp_port}" | 0 | "127.0.0.1" | + | SessionId | UserName | SpaceName | CreateTime | UpdateTime | GraphAddr | Timezone | ClientIp | + | /\d+/ | "root" | "s1" | /.*/ | /.*/ | "127.0.0.1:${cluster.graphd_processes[0].tcp_port}" | 0 | /.*(127.0.0.1)$/ | + | /\d+/ | "user1" | "" | /.*/ | /.*/ | "127.0.0.1:${cluster.graphd_processes[1].tcp_port}" | 0 | /.*(127.0.0.1)$/ | diff --git a/tests/tck/features/go/GoYieldVertexEdge.feature b/tests/tck/features/go/GoYieldVertexEdge.feature index 418d739e072..5fbba5aec71 100644 --- a/tests/tck/features/go/GoYieldVertexEdge.feature +++ b/tests/tck/features/go/GoYieldVertexEdge.feature @@ -1809,3 +1809,117 @@ Feature: Go Yield Vertex And Edge Sentence | "Grant Hill" | "Grant Hill" | [:like "Grant Hill"->"Tracy McGrady" @0 {likeness: 90}] | ("Grant Hill" :player{age: 46, name: "Grant Hill"}) | ("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"}) | | "Vince Carter" | "Vince Carter" | [:like "Vince Carter"->"Tracy McGrady" @0 {likeness: 90}] | ("Vince Carter" :player{age: 42, name: "Vince Carter"}) | ("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"}) | | "Yao Ming" | "Yao Ming" | [:like "Yao Ming"->"Tracy McGrady" @0 {likeness: 90}] | ("Yao Ming" :player{age: 38, name: "Yao Ming"}) | ("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"}) | + + Scenario: support properties function in where + When executing query: + """ + GO FROM 'Tim Duncan' OVER like WHERE properties($$).age > 38 YIELD edge as e, $$ as dst + """ + Then the result should be, in any order, with relax comparison: + | e | dst | + | [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + When executing query: + """ + GO FROM 'Tim Duncan' OVER like WHERE properties(edge).age > 38 YIELD edge as e, $$ as dst + """ + Then the result should be, in any order, with relax comparison: + | e | dst | + When executing query: + """ + GO FROM 'Tim Duncan' OVER like WHERE properties(edge).likeness > 80 YIELD edge as e, $$ as dst + """ + Then the result should be, in any order, with relax comparison: + | e | dst | + | [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + | [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + When executing query: + """ + GO 1 TO 2 STEPS FROM 'Russell Westbrook' OVER * where properties($$).age > 20 YIELD $$ as dst + """ + Then the result should be, in any order, with relax comparison: + | dst | + | ("James Harden" :player{age: 29, name: "James Harden"}) | + | ("Paul George" :player{age: 28, name: "Paul George"}) | + | ("Russell Westbrook" :player{age: 30, name: "Russell Westbrook"}) | + | ("Russell Westbrook" :player{age: 30, name: "Russell Westbrook"}) | + When executing query: + """ + GO 1 TO 2 STEPS FROM 'Tony Parker' OVER like BIDIRECT where properties($$).age > 30 YIELD DISTINCT properties(edge) as props, edge as e + """ + Then the result should be, in any order, with relax comparison: + | props | e | + | {likeness: 80} | [:like "Boris Diaw"->"Tony Parker" @0 {likeness: 80}] | + | {likeness: 95} | [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] | + | {likeness: 75} | [:like "LaMarcus Aldridge"->"Tony Parker" @0 {likeness: 75}] | + | {likeness: 50} | [:like "Marco Belinelli"->"Tony Parker" @0 {likeness: 50}] | + | {likeness: 95} | [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] | + | {likeness: 90} | [:like "Tony Parker"->"LaMarcus Aldridge" @0 {likeness: 90}] | + | {likeness: 95} | [:like "Tony Parker"->"Manu Ginobili" @0 {likeness: 95}] | + | {likeness: 83} | [:like "Danny Green"->"Marco Belinelli" @0 {likeness: 83}] | + | {likeness: 90} | [:like "Manu Ginobili"->"Tim Duncan" @0 {likeness: 90}] | + | {likeness: 60} | [:like "Marco Belinelli"->"Danny Green" @0 {likeness: 60}] | + | {likeness: 55} | [:like "Marco Belinelli"->"Tim Duncan" @0 {likeness: 55}] | + | {likeness: 90} | [:like "Tiago Splitter"->"Manu Ginobili" @0 {likeness: 90}] | + | {likeness: 80} | [:like "Aron Baynes"->"Tim Duncan" @0 {likeness: 80}] | + | {likeness: 80} | [:like "Boris Diaw"->"Tim Duncan" @0 {likeness: 80}] | + | {likeness: 70} | [:like "Danny Green"->"Tim Duncan" @0 {likeness: 70}] | + | {likeness: 99} | [:like "Dejounte Murray"->"Danny Green" @0 {likeness: 99}] | + | {likeness: 75} | [:like "LaMarcus Aldridge"->"Tim Duncan" @0 {likeness: 75}] | + | {likeness: 99} | [:like "Dejounte Murray"->"Marco Belinelli" @0 {likeness: 99}] | + | {likeness: 99} | [:like "Dejounte Murray"->"Manu Ginobili" @0 {likeness: 99}] | + | {likeness: 80} | [:like "Shaquille O'Neal"->"Tim Duncan" @0 {likeness: 80}] | + | {likeness: 80} | [:like "Tiago Splitter"->"Tim Duncan" @0 {likeness: 80}] | + | {likeness: 99} | [:like "Dejounte Murray"->"Chris Paul" @0 {likeness: 99}] | + | {likeness: 95} | [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] | + | {likeness: 99} | [:like "Dejounte Murray"->"Tony Parker" @0 {likeness: 99}] | + | {likeness: 99} | [:like "Dejounte Murray"->"LeBron James" @0 {likeness: 99}] | + | {likeness: 70} | [:like "Rudy Gay"->"LaMarcus Aldridge" @0 {likeness: 70}] | + | {likeness: 99} | [:like "Dejounte Murray"->"Tim Duncan" @0 {likeness: 99}] | + When executing query: + """ + GO FROM 'Danny Green' OVER like YIELD src(edge) AS src, dst(edge) AS dst | + GO FROM $-.dst OVER teammate where properties($$).age > 35 YIELD $-.src AS src, $-.dst, $$ as dst + """ + Then the result should be, in any order, with relax comparison: + | src | $-.dst | dst | + | "Danny Green" | "Tim Duncan" | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + | "Danny Green" | "Tim Duncan" | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + When executing query: + """ + GO FROM 'Danny Green' OVER like YIELD src(edge) AS src, dst(edge) AS dst | + GO FROM $-.dst OVER teammate where properties($^).age > 35 YIELD $-.src AS src, $-.dst, $$ as dst + """ + Then the result should be, in any order, with relax comparison: + | src | $-.dst | dst | + | "Danny Green" | "Tim Duncan" | ("Danny Green" :player{age: 31, name: "Danny Green"}) | + | "Danny Green" | "Tim Duncan" | ("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"}) | + | "Danny Green" | "Tim Duncan" | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + | "Danny Green" | "Tim Duncan" | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + When executing query: + """ + GO 2 STEPS FROM 'Kobe Bryant' OVER like REVERSELY WHERE properties(edge).likeness != 80 YIELD $$ as dst, edge as e + """ + Then the result should be, in any order, with relax comparison: + | dst | e | + | ("Marc Gasol" :player{age: 34, name: "Marc Gasol"}) | [:like "Marc Gasol"->"Paul Gasol" @0 {likeness: 99}] | + | ("Grant Hill" :player{age: 46, name: "Grant Hill"}) | [:like "Grant Hill"->"Tracy McGrady" @0 {likeness: 90}] | + | ("Vince Carter" :player{age: 42, name: "Vince Carter"}) | [:like "Vince Carter"->"Tracy McGrady" @0 {likeness: 90}] | + | ("Yao Ming" :player{age: 38, name: "Yao Ming"}) | [:like "Yao Ming"->"Tracy McGrady" @0 {likeness: 90}] | + When executing query: + """ + $var = GO FROM "Tim Duncan", "Chris Paul" OVER like WHERE properties($$).age > 20 YIELD id($$) as id; + GO FROM $var.id OVER * WHERE properties(edge).likeness > 80 YIELD $$ as dst + """ + Then the result should be, in any order, with relax comparison: + | dst | + | ("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"}) | + | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + | ("LeBron James" :player{age: 34, name: "LeBron James"}) | + | ("Chris Paul" :player{age: 33, name: "Chris Paul"}) | + | ("Carmelo Anthony" :player{age: 34, name: "Carmelo Anthony"}) | + | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + | ("Ray Allen" :player{age: 43, name: "Ray Allen"}) | + | ("LeBron James" :player{age: 34, name: "LeBron James"}) | + | ("Chris Paul" :player{age: 33, name: "Chris Paul"}) | + | ("Dwyane Wade" :player{age: 37, name: "Dwyane Wade"}) | diff --git a/third-party/install-gcc.sh b/third-party/install-gcc.sh index 3e27aa49252..dcbcd254641 100755 --- a/third-party/install-gcc.sh +++ b/third-party/install-gcc.sh @@ -19,7 +19,7 @@ fi exit 1 } -version=7.5.0 +version=9.3.0 url_base=https://oss-cdn.nebula-graph.com.cn/toolset this_dir=$(dirname $(readlink -f $0)) diff --git a/third-party/install-third-party.sh b/third-party/install-third-party.sh index 5ed1f5dbad7..42e44f904e4 100755 --- a/third-party/install-third-party.sh +++ b/third-party/install-third-party.sh @@ -19,15 +19,15 @@ then exit $? fi -[[ -z $version ]] && version=2.0 +[[ -z $version ]] && version=3.0 url_base=https://oss-cdn.nebula-graph.com.cn/third-party/$version this_dir=$(dirname $(readlink -f $0)) cxx_cmd=${CXX:-g++} # We consider two derivatives: Red Hat and Debian # Place preset libc versions of each from newer to older -libc_preset_versions=( 2.32 2.31 2.28 2.27 2.23 2.17 ) -gcc_preset_versions=( 10.1.0 9.3.0 9.2.0 9.1.0 8.3.0 7.5.0 7.1.0 ) +libc_preset_versions=( 2.34 2.32 2.31 2.29 2.28 2.27 2.23 2.17 ) +gcc_preset_versions=( 11.2.0 10.1.0 9.3.0 9.2.0 9.1.0 8.3.0 7.5.0 7.1.0 ) selected_libc_version= selected_gcc_version=