From c28a948ed83bcda5b32cf2c630ae3d0b7087fb03 Mon Sep 17 00:00:00 2001 From: zhangguoqing Date: Wed, 22 May 2019 15:32:57 +0800 Subject: [PATCH] move the KeyUtils from storage to common/base named NebulaKeyUtils (#402) --- src/common/base/CMakeLists.txt | 1 + .../base/NebulaKeyUtils.cpp} | 28 ++++++------ .../base/NebulaKeyUtils.h} | 21 +++++---- src/common/base/test/CMakeLists.txt | 12 +++++ src/common/base/test/NebulaKeyUtilsTest.cpp | 44 +++++++++++++++++++ src/storage/AddEdgesProcessor.cpp | 6 +-- src/storage/AddVerticesProcessor.cpp | 6 +-- src/storage/CMakeLists.txt | 1 - src/storage/QueryBaseProcessor.inl | 30 +++++++------ src/storage/QueryBoundProcessor.cpp | 1 - src/storage/QueryEdgePropsProcessor.cpp | 6 +-- src/storage/QueryStatsProcessor.cpp | 1 - src/storage/QueryVertexPropsProcessor.cpp | 1 - src/storage/test/AddEdgesTest.cpp | 5 +-- src/storage/test/AddVerticesTest.cpp | 4 +- src/storage/test/CMakeLists.txt | 28 ------------ src/storage/test/KeyUtilsTest.cpp | 42 ------------------ src/storage/test/QueryBoundTest.cpp | 16 +++---- src/storage/test/QueryEdgePropsTest.cpp | 4 +- src/storage/test/QueryStatsTest.cpp | 6 +-- src/storage/test/QueryVertexPropsTest.cpp | 4 +- .../test/StorageServiceHandlerTest.cpp | 4 +- 22 files changed, 129 insertions(+), 142 deletions(-) rename src/{storage/KeyUtils.cpp => common/base/NebulaKeyUtils.cpp} (73%) rename src/{storage/KeyUtils.h => common/base/NebulaKeyUtils.h} (88%) create mode 100644 src/common/base/test/NebulaKeyUtilsTest.cpp delete mode 100644 src/storage/test/KeyUtilsTest.cpp diff --git a/src/common/base/CMakeLists.txt b/src/common/base/CMakeLists.txt index ce97b21fec2..fd384a21973 100644 --- a/src/common/base/CMakeLists.txt +++ b/src/common/base/CMakeLists.txt @@ -6,6 +6,7 @@ add_library( Status.cpp SanitizerOptions.cpp SignalHandler.cpp + NebulaKeyUtils.cpp ) add_dependencies(base_obj third-party) IF(${PCHSupport_FOUND}) diff --git a/src/storage/KeyUtils.cpp b/src/common/base/NebulaKeyUtils.cpp similarity index 73% rename from src/storage/KeyUtils.cpp rename to src/common/base/NebulaKeyUtils.cpp index 88eca38231c..3c218bd708f 100644 --- a/src/storage/KeyUtils.cpp +++ b/src/common/base/NebulaKeyUtils.cpp @@ -4,14 +4,13 @@ * attached with Common Clause Condition 1.0, found in the LICENSES directory. */ -#include "storage/KeyUtils.h" +#include "base/NebulaKeyUtils.h" namespace nebula { -namespace storage { // static -std::string KeyUtils::vertexKey(PartitionID partId, VertexID vId, - TagID tagId, TagVersion ts) { +std::string NebulaKeyUtils::vertexKey(PartitionID partId, VertexID vId, + TagID tagId, TagVersion ts) { std::string key; key.reserve(kVertexLen); key.append(reinterpret_cast(&partId), sizeof(PartitionID)) @@ -22,12 +21,12 @@ std::string KeyUtils::vertexKey(PartitionID partId, VertexID vId, } // static -std::string KeyUtils::edgeKey(PartitionID partId, - VertexID srcId, - EdgeType type, - EdgeRanking rank, - VertexID dstId, - EdgeVersion ts) { +std::string NebulaKeyUtils::edgeKey(PartitionID partId, + VertexID srcId, + EdgeType type, + EdgeRanking rank, + VertexID dstId, + EdgeVersion ts) { std::string key; key.reserve(kEdgeLen); key.append(reinterpret_cast(&partId), sizeof(PartitionID)) @@ -40,7 +39,7 @@ std::string KeyUtils::edgeKey(PartitionID partId, } // static -std::string KeyUtils::prefix(PartitionID partId, VertexID srcId, EdgeType type) { +std::string NebulaKeyUtils::prefix(PartitionID partId, VertexID srcId, EdgeType type) { std::string key; key.reserve(sizeof(PartitionID) + sizeof(VertexID) + sizeof(EdgeType)); key.append(reinterpret_cast(&partId), sizeof(PartitionID)) @@ -50,7 +49,7 @@ std::string KeyUtils::prefix(PartitionID partId, VertexID srcId, EdgeType type) } // static -std::string KeyUtils::prefix(PartitionID partId, VertexID vId) { +std::string NebulaKeyUtils::prefix(PartitionID partId, VertexID vId) { std::string key; key.reserve(sizeof(PartitionID) + sizeof(VertexID)); key.append(reinterpret_cast(&partId), sizeof(PartitionID)) @@ -59,8 +58,8 @@ std::string KeyUtils::prefix(PartitionID partId, VertexID vId) { } // static -std::string KeyUtils::prefix(PartitionID partId, VertexID src, EdgeType type, - EdgeRanking ranking, VertexID dst) { +std::string NebulaKeyUtils::prefix(PartitionID partId, VertexID src, EdgeType type, + EdgeRanking ranking, VertexID dst) { std::string key; key.reserve(sizeof(PartitionID) + sizeof(VertexID) + sizeof(EdgeType) + sizeof(VertexID) + sizeof(EdgeRanking)); @@ -72,6 +71,5 @@ std::string KeyUtils::prefix(PartitionID partId, VertexID src, EdgeType type, return key; } -} // namespace storage } // namespace nebula diff --git a/src/storage/KeyUtils.h b/src/common/base/NebulaKeyUtils.h similarity index 88% rename from src/storage/KeyUtils.h rename to src/common/base/NebulaKeyUtils.h index be58d3b2657..e52cf731aa3 100644 --- a/src/storage/KeyUtils.h +++ b/src/common/base/NebulaKeyUtils.h @@ -4,13 +4,12 @@ * attached with Common Clause Condition 1.0, found in the LICENSES directory. */ -#ifndef STORAGE_KEYUTILS_H_ -#define STORAGE_KEYUTILS_H_ +#ifndef COMMON_BASE_NEBULAKEYUTILS_H_ +#define COMMON_BASE_NEBULAKEYUTILS_H_ #include "base/Base.h" namespace nebula { -namespace storage { /** * VertexKeyUtils: @@ -29,9 +28,9 @@ using Edge = std::tuple; /** * This class supply some utils for transition between Vertex/Edge and key in kvstore. * */ -class KeyUtils final { +class NebulaKeyUtils final { public: - ~KeyUtils() = default; + ~NebulaKeyUtils() = default; /** * Generate vertex key for kv store * */ @@ -62,6 +61,12 @@ class KeyUtils final { return rawKey.size() == kVertexLen; } + static int32_t getTagId(folly::StringPiece rawKey) { + CHECK_EQ(rawKey.size(), kVertexLen); + auto offset = sizeof(PartitionID) + sizeof(VertexID); + return readInt(rawKey.data() + offset, sizeof(TagID)); + } + static bool isEdge(const std::string& rawKey) { return rawKey.size() == kEdgeLen; } @@ -72,7 +77,6 @@ class KeyUtils final { rawKey.size() - sizeof(PartitionID)); } - static int64_t getDstId(folly::StringPiece rawKey) { CHECK_EQ(rawKey.size(), kEdgeLen); auto offset = kEdgeLen - sizeof(EdgeVersion) - sizeof(VertexID); @@ -102,7 +106,7 @@ class KeyUtils final { } private: - KeyUtils() = delete; + NebulaKeyUtils() = delete; private: static constexpr int32_t kVertexLen = sizeof(PartitionID) + sizeof(VertexID) @@ -112,7 +116,6 @@ class KeyUtils final { + sizeof(EdgeRanking) + sizeof(EdgeVersion); }; -} // namespace storage } // namespace nebula -#endif // STORAGE_KEYUTILS_H_ +#endif // COMMON_BASE_NEBULAKEYUTILS_H_ diff --git a/src/common/base/test/CMakeLists.txt b/src/common/base/test/CMakeLists.txt index b3f3f758360..6fd0d068b01 100644 --- a/src/common/base/test/CMakeLists.txt +++ b/src/common/base/test/CMakeLists.txt @@ -98,3 +98,15 @@ nebula_link_libraries( gtest_main ) nebula_add_test(signal_handler_test) + +add_executable( + nebulakey_utils_test + NebulaKeyUtilsTest.cpp + $ +) +nebula_link_libraries( + nebulakey_utils_test + gtest + gtest_main +) +nebula_add_test(nebulakey_utils_test) diff --git a/src/common/base/test/NebulaKeyUtilsTest.cpp b/src/common/base/test/NebulaKeyUtilsTest.cpp new file mode 100644 index 00000000000..2e9c7013875 --- /dev/null +++ b/src/common/base/test/NebulaKeyUtilsTest.cpp @@ -0,0 +1,44 @@ +/* Copyright (c) 2018 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#include "base/Base.h" +#include "base/NebulaKeyUtils.h" +#include + +namespace nebula { + +TEST(NebulaKeyUtilsTest, SimpleTest) { + PartitionID partId = 0L; + VertexID srcId = 1001L, dstId = 2001L; + TagID tagId = 1001; + TagVersion tagVersion = 20L; + EdgeType type = 101; + EdgeRanking rank = 10L; + EdgeVersion edgeVersion = 20; + + auto vertexKey = NebulaKeyUtils::vertexKey(partId, srcId, tagId, tagVersion); + CHECK(NebulaKeyUtils::isVertex(vertexKey)); + CHECK_EQ(tagId, NebulaKeyUtils::getTagId(vertexKey)); + + auto edgeKey = NebulaKeyUtils::edgeKey(partId, srcId, type, rank, dstId, edgeVersion); + CHECK(NebulaKeyUtils::isEdge(edgeKey)); + CHECK_EQ(srcId, NebulaKeyUtils::getSrcId(edgeKey)); + CHECK_EQ(dstId, NebulaKeyUtils::getDstId(edgeKey)); + CHECK_EQ(type, NebulaKeyUtils::getEdgeType(edgeKey)); + CHECK_EQ(rank, NebulaKeyUtils::getRank(edgeKey)); +} + +} // 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/AddEdgesProcessor.cpp b/src/storage/AddEdgesProcessor.cpp index 690a791fdf0..6c3d83feca7 100644 --- a/src/storage/AddEdgesProcessor.cpp +++ b/src/storage/AddEdgesProcessor.cpp @@ -4,10 +4,10 @@ * attached with Common Clause Condition 1.0, found in the LICENSES directory. */ #include "storage/AddEdgesProcessor.h" +#include "base/NebulaKeyUtils.h" #include #include #include "time/TimeUtils.h" -#include "storage/KeyUtils.h" namespace nebula { namespace storage { @@ -21,8 +21,8 @@ void AddEdgesProcessor::process(const cpp2::AddEdgesRequest& req) { auto partId = partEdges.first; std::vector data; std::for_each(partEdges.second.begin(), partEdges.second.end(), [&](auto& edge){ - auto key = KeyUtils::edgeKey(partId, edge.key.src, edge.key.edge_type, - edge.key.ranking, edge.key.dst, version); + auto key = NebulaKeyUtils::edgeKey(partId, edge.key.src, edge.key.edge_type, + edge.key.ranking, edge.key.dst, version); data.emplace_back(std::move(key), std::move(edge.get_props())); }); doPut(spaceId, partId, std::move(data)); diff --git a/src/storage/AddVerticesProcessor.cpp b/src/storage/AddVerticesProcessor.cpp index b553673e58d..03dd2851447 100644 --- a/src/storage/AddVerticesProcessor.cpp +++ b/src/storage/AddVerticesProcessor.cpp @@ -5,10 +5,10 @@ */ #include "storage/AddVerticesProcessor.h" +#include "base/NebulaKeyUtils.h" #include #include #include "time/TimeUtils.h" -#include "storage/KeyUtils.h" namespace nebula { namespace storage { @@ -27,8 +27,8 @@ void AddVerticesProcessor::process(const cpp2::AddVerticesRequest& req) { std::for_each(vertices.begin(), vertices.end(), [&](auto& v){ const auto& tags = v.get_tags(); std::for_each(tags.begin(), tags.end(), [&](auto& tag) { - auto key = KeyUtils::vertexKey(partId, v.get_id(), - tag.get_tag_id(), now); + auto key = NebulaKeyUtils::vertexKey(partId, v.get_id(), + tag.get_tag_id(), now); data.emplace_back(std::move(key), std::move(tag.get_props())); }); }); diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index fa16b4e1c94..3129a7b0cc9 100644 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -1,7 +1,6 @@ add_library( storage_service_handler OBJECT StorageServiceHandler.cpp - KeyUtils.cpp StorageHttpHandler.cpp AddVerticesProcessor.cpp AddEdgesProcessor.cpp diff --git a/src/storage/QueryBaseProcessor.inl b/src/storage/QueryBaseProcessor.inl index 2ebd6f1a756..a9f41a1a4a4 100644 --- a/src/storage/QueryBaseProcessor.inl +++ b/src/storage/QueryBaseProcessor.inl @@ -4,8 +4,8 @@ * attached with Common Clause Condition 1.0, found in the LICENSES directory. */ #include "storage/QueryBaseProcessor.h" +#include "base/NebulaKeyUtils.h" #include -#include "storage/KeyUtils.h" #include "dataman/RowReader.h" #include "dataman/RowWriter.h" @@ -43,20 +43,24 @@ void QueryBaseProcessor::collectProps(RowReader* reader, case PropContext::PropInKeyType::NONE: break; case PropContext::PropInKeyType::SRC: - VLOG(3) << "collect _src, value = " << KeyUtils::getSrcId(key); - collector->collectInt64(ResultType::SUCCEEDED, KeyUtils::getSrcId(key), prop); + VLOG(3) << "collect _src, value = " << NebulaKeyUtils::getSrcId(key); + collector->collectInt64(ResultType::SUCCEEDED, + NebulaKeyUtils::getSrcId(key), prop); continue; case PropContext::PropInKeyType::DST: - VLOG(3) << "collect _dst, value = " << KeyUtils::getDstId(key); - collector->collectInt64(ResultType::SUCCEEDED, KeyUtils::getDstId(key), prop); + VLOG(3) << "collect _dst, value = " << NebulaKeyUtils::getDstId(key); + collector->collectInt64(ResultType::SUCCEEDED, + NebulaKeyUtils::getDstId(key), prop); continue; case PropContext::PropInKeyType::TYPE: - VLOG(3) << "collect _type, value = " << KeyUtils::getEdgeType(key); - collector->collectInt32(ResultType::SUCCEEDED, KeyUtils::getEdgeType(key), prop); + VLOG(3) << "collect _type, value = " << NebulaKeyUtils::getEdgeType(key); + collector->collectInt32(ResultType::SUCCEEDED, + NebulaKeyUtils::getEdgeType(key), prop); continue; case PropContext::PropInKeyType::RANK: - VLOG(3) << "collect _rank, value = " << KeyUtils::getRank(key); - collector->collectInt64(ResultType::SUCCEEDED, KeyUtils::getRank(key), prop); + VLOG(3) << "collect _rank, value = " << NebulaKeyUtils::getRank(key); + collector->collectInt64(ResultType::SUCCEEDED, + NebulaKeyUtils::getRank(key), prop); continue; } if (reader != nullptr) { @@ -194,7 +198,7 @@ kvstore::ResultCode QueryBaseProcessor::collectVertexProps( TagID tagId, std::vector& props, Collector* collector) { - auto prefix = KeyUtils::prefix(partId, vId, tagId); + auto prefix = NebulaKeyUtils::prefix(partId, vId, tagId); std::unique_ptr iter; auto ret = this->kvstore_->prefix(spaceId_, partId, prefix, &iter); if (ret != kvstore::ResultCode::SUCCEEDED) { @@ -219,7 +223,7 @@ kvstore::ResultCode QueryBaseProcessor::collectEdgeProps( EdgeType edgeType, std::vector& props, EdgeProcessor proc) { - auto prefix = KeyUtils::prefix(partId, vId, edgeType); + auto prefix = NebulaKeyUtils::prefix(partId, vId, edgeType); std::unique_ptr iter; auto ret = this->kvstore_->prefix(spaceId_, partId, prefix, &iter); if (ret != kvstore::ResultCode::SUCCEEDED || !iter) { @@ -231,8 +235,8 @@ kvstore::ResultCode QueryBaseProcessor::collectEdgeProps( for (; iter->valid(); iter->next()) { auto key = iter->key(); auto val = iter->val(); - auto rank = KeyUtils::getRank(key); - auto dstId = KeyUtils::getDstId(key); + auto rank = NebulaKeyUtils::getRank(key); + auto dstId = NebulaKeyUtils::getDstId(key); if (!firstLoop && rank == lastRank && lastDstId == dstId) { VLOG(3) << "Only get the latest version for each edge."; continue; diff --git a/src/storage/QueryBoundProcessor.cpp b/src/storage/QueryBoundProcessor.cpp index 522cf7e1cec..6aa5dd099af 100644 --- a/src/storage/QueryBoundProcessor.cpp +++ b/src/storage/QueryBoundProcessor.cpp @@ -7,7 +7,6 @@ #include "storage/QueryBoundProcessor.h" #include #include "time/Duration.h" -#include "storage/KeyUtils.h" #include "dataman/RowReader.h" #include "dataman/RowWriter.h" diff --git a/src/storage/QueryEdgePropsProcessor.cpp b/src/storage/QueryEdgePropsProcessor.cpp index 9e8bf19034c..067a005388d 100644 --- a/src/storage/QueryEdgePropsProcessor.cpp +++ b/src/storage/QueryEdgePropsProcessor.cpp @@ -5,9 +5,9 @@ */ #include "storage/QueryEdgePropsProcessor.h" +#include "base/NebulaKeyUtils.h" #include #include "time/Duration.h" -#include "storage/KeyUtils.h" #include "dataman/RowReader.h" #include "dataman/RowWriter.h" @@ -19,8 +19,8 @@ kvstore::ResultCode QueryEdgePropsProcessor::collectEdgesProps( const cpp2::EdgeKey& edgeKey, std::vector& props, RowSetWriter& rsWriter) { - auto prefix = KeyUtils::prefix(partId, edgeKey.src, edgeKey.edge_type, - edgeKey.ranking, edgeKey.dst); + auto prefix = NebulaKeyUtils::prefix(partId, edgeKey.src, edgeKey.edge_type, + edgeKey.ranking, edgeKey.dst); std::unique_ptr iter; auto ret = kvstore_->prefix(spaceId_, partId, prefix, &iter); // Only use the latest version. diff --git a/src/storage/QueryStatsProcessor.cpp b/src/storage/QueryStatsProcessor.cpp index 308a4311b44..705264cf7e8 100644 --- a/src/storage/QueryStatsProcessor.cpp +++ b/src/storage/QueryStatsProcessor.cpp @@ -6,7 +6,6 @@ #include "storage/QueryStatsProcessor.h" #include #include "time/Duration.h" -#include "storage/KeyUtils.h" #include "dataman/RowReader.h" #include "dataman/RowWriter.h" diff --git a/src/storage/QueryVertexPropsProcessor.cpp b/src/storage/QueryVertexPropsProcessor.cpp index a70866b74b3..ad35586a57a 100644 --- a/src/storage/QueryVertexPropsProcessor.cpp +++ b/src/storage/QueryVertexPropsProcessor.cpp @@ -7,7 +7,6 @@ #include "storage/QueryVertexPropsProcessor.h" #include #include "time/Duration.h" -#include "storage/KeyUtils.h" #include "dataman/RowReader.h" #include "dataman/RowWriter.h" diff --git a/src/storage/test/AddEdgesTest.cpp b/src/storage/test/AddEdgesTest.cpp index dd5f7f795d8..49160bc5242 100644 --- a/src/storage/test/AddEdgesTest.cpp +++ b/src/storage/test/AddEdgesTest.cpp @@ -5,13 +5,12 @@ */ #include "base/Base.h" +#include "base/NebulaKeyUtils.h" #include #include #include "fs/TempDir.h" #include "storage/test/TestUtils.h" #include "storage/AddEdgesProcessor.h" -#include "storage/KeyUtils.h" - namespace nebula { namespace storage { @@ -46,7 +45,7 @@ TEST(AddEdgesTest, SimpleTest) { LOG(INFO) << "Check data in kv store..."; for (auto partId = 0; partId < 3; partId++) { for (auto srcId = 10 * partId; srcId < 10 * (partId + 1); srcId++) { - auto prefix = KeyUtils::prefix(partId, srcId, srcId*100 + 1); + auto prefix = NebulaKeyUtils::prefix(partId, srcId, srcId*100 + 1); std::unique_ptr iter; EXPECT_EQ(kvstore::ResultCode::SUCCEEDED, kv->prefix(0, partId, prefix, &iter)); int num = 0; diff --git a/src/storage/test/AddVerticesTest.cpp b/src/storage/test/AddVerticesTest.cpp index a41ede6f167..a9c8b7f1c89 100644 --- a/src/storage/test/AddVerticesTest.cpp +++ b/src/storage/test/AddVerticesTest.cpp @@ -5,12 +5,12 @@ */ #include "base/Base.h" +#include "base/NebulaKeyUtils.h" #include #include #include "fs/TempDir.h" #include "storage/test/TestUtils.h" #include "storage/AddVerticesProcessor.h" -#include "storage/KeyUtils.h" namespace nebula { namespace storage { @@ -51,7 +51,7 @@ TEST(AddVerticesTest, SimpleTest) { LOG(INFO) << "Check data in kv store..."; for (auto partId = 0; partId < 3; partId++) { for (auto vertexId = 10 * partId; vertexId < 10 * (partId + 1); vertexId++) { - auto prefix = KeyUtils::prefix(partId, vertexId); + auto prefix = NebulaKeyUtils::prefix(partId, vertexId); std::unique_ptr iter; EXPECT_EQ(kvstore::ResultCode::SUCCEEDED, kv->prefix(0, partId, prefix, &iter)); TagID tagId = 0; diff --git a/src/storage/test/CMakeLists.txt b/src/storage/test/CMakeLists.txt index bd4a329a91c..e1287ae113c 100644 --- a/src/storage/test/CMakeLists.txt +++ b/src/storage/test/CMakeLists.txt @@ -1,31 +1,3 @@ -add_executable( - key_utils_test - KeyUtilsTest.cpp - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ -) -nebula_link_libraries( - key_utils_test - ${ROCKSDB_LIBRARIES} - ${THRIFT_LIBRARIES} - wangle - gtest -) -nebula_add_test(key_utils_test) - - add_executable( add_vertices_test AddVerticesTest.cpp diff --git a/src/storage/test/KeyUtilsTest.cpp b/src/storage/test/KeyUtilsTest.cpp deleted file mode 100644 index 3916e90cc46..00000000000 --- a/src/storage/test/KeyUtilsTest.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) 2018 vesoft inc. All rights reserved. - * - * This source code is licensed under Apache 2.0 License, - * attached with Common Clause Condition 1.0, found in the LICENSES directory. - */ - -#include "base/Base.h" -#include -#include "fs/TempDir.h" -#include "storage/KeyUtils.h" - - -namespace nebula { -namespace storage { - -TEST(KeyUtilsTest, SimpleTest) { - PartitionID partId = 0L; - VertexID srcId = 1001L, dstId = 2001L; - EdgeType type = 101; - EdgeRanking rank = 10L; - EdgeVersion version = 20; - auto edgeKey = KeyUtils::edgeKey(partId, srcId, type, rank, dstId, version); - - CHECK(KeyUtils::isEdge(edgeKey)); - CHECK_EQ(srcId, KeyUtils::getSrcId(edgeKey)); - CHECK_EQ(dstId, KeyUtils::getDstId(edgeKey)); - CHECK_EQ(type, KeyUtils::getEdgeType(edgeKey)); - CHECK_EQ(rank, KeyUtils::getRank(edgeKey)); -} - -} // 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/QueryBoundTest.cpp b/src/storage/test/QueryBoundTest.cpp index 9e2d79d0236..007c34f099d 100644 --- a/src/storage/test/QueryBoundTest.cpp +++ b/src/storage/test/QueryBoundTest.cpp @@ -5,13 +5,13 @@ */ #include "base/Base.h" +#include "base/NebulaKeyUtils.h" #include #include #include #include "fs/TempDir.h" #include "storage/test/TestUtils.h" #include "storage/QueryBoundProcessor.h" -#include "storage/KeyUtils.h" #include "dataman/RowSetReader.h" #include "dataman/RowReader.h" @@ -23,7 +23,7 @@ void mockData(kvstore::KVStore* kv) { std::vector data; for (auto vertexId = partId * 10; vertexId < (partId + 1) * 10; vertexId++) { for (auto tagId = 3001; tagId < 3010; tagId++) { - auto key = KeyUtils::vertexKey(partId, vertexId, tagId, 0); + auto key = NebulaKeyUtils::vertexKey(partId, vertexId, tagId, 0); RowWriter writer; for (uint64_t numInt = 0; numInt < 3; numInt++) { writer << numInt; @@ -39,9 +39,9 @@ void mockData(kvstore::KVStore* kv) { VLOG(3) << "Write part " << partId << ", vertex " << vertexId << ", dst " << dstId; // Write multi versions, we should get the latest version. for (auto version = 0; version < 3; version++) { - auto key = KeyUtils::edgeKey(partId, vertexId, 101, - 0, dstId, - std::numeric_limits::max() - version); + auto key = NebulaKeyUtils::edgeKey(partId, vertexId, 101, + 0, dstId, + std::numeric_limits::max() - version); RowWriter writer(nullptr); for (uint64_t numInt = 0; numInt < 10; numInt++) { writer << numInt; @@ -57,9 +57,9 @@ void mockData(kvstore::KVStore* kv) { for (auto srcId = 20001; srcId <= 20005; srcId++) { VLOG(3) << "Write part " << partId << ", vertex " << vertexId << ", src " << srcId; for (auto version = 0; version < 3; version++) { - auto key = KeyUtils::edgeKey(partId, vertexId, -101, - 0, srcId, - std::numeric_limits::max() - version); + auto key = NebulaKeyUtils::edgeKey(partId, vertexId, -101, + 0, srcId, + std::numeric_limits::max() - version); data.emplace_back(std::move(key), ""); } } diff --git a/src/storage/test/QueryEdgePropsTest.cpp b/src/storage/test/QueryEdgePropsTest.cpp index 00de98bf59e..5db1e561a92 100644 --- a/src/storage/test/QueryEdgePropsTest.cpp +++ b/src/storage/test/QueryEdgePropsTest.cpp @@ -5,12 +5,12 @@ */ #include "base/Base.h" +#include "base/NebulaKeyUtils.h" #include #include #include "fs/TempDir.h" #include "storage/test/TestUtils.h" #include "storage/QueryEdgePropsProcessor.h" -#include "storage/KeyUtils.h" #include "dataman/RowSetReader.h" #include "dataman/RowReader.h" @@ -24,7 +24,7 @@ void mockData(kvstore::KVStore* kv) { // Generate 7 edges for each source vertex id for (auto dstId = 10001; dstId <= 10007; dstId++) { VLOG(3) << "Write part " << partId << ", vertex " << vertexId << ", dst " << dstId; - auto key = KeyUtils::edgeKey(partId, vertexId, 101, dstId - 10001, dstId, 0); + auto key = NebulaKeyUtils::edgeKey(partId, vertexId, 101, dstId - 10001, dstId, 0); RowWriter writer(nullptr); for (int64_t numInt = 0; numInt < 10; numInt++) { writer << numInt; diff --git a/src/storage/test/QueryStatsTest.cpp b/src/storage/test/QueryStatsTest.cpp index 2855d74d3bb..ab92195a1cd 100644 --- a/src/storage/test/QueryStatsTest.cpp +++ b/src/storage/test/QueryStatsTest.cpp @@ -5,12 +5,12 @@ */ #include "base/Base.h" +#include "base/NebulaKeyUtils.h" #include #include #include "fs/TempDir.h" #include "storage/test/TestUtils.h" #include "storage/QueryStatsProcessor.h" -#include "storage/KeyUtils.h" #include "dataman/RowSetReader.h" #include "dataman/RowReader.h" @@ -22,7 +22,7 @@ void mockData(kvstore::KVStore* kv) { std::vector data; for (auto vertexId = partId * 10; vertexId < (partId + 1) * 10; vertexId++) { for (auto tagId = 3001; tagId < 3010; tagId++) { - auto key = KeyUtils::vertexKey(partId, vertexId, tagId, 0); + auto key = NebulaKeyUtils::vertexKey(partId, vertexId, tagId, 0); RowWriter writer; for (int64_t numInt = 0; numInt < 3; numInt++) { writer << numInt; @@ -36,7 +36,7 @@ void mockData(kvstore::KVStore* kv) { // Generate 7 edges for each edgeType. for (auto dstId = 10001; dstId <= 10007; dstId++) { VLOG(3) << "Write part " << partId << ", vertex " << vertexId << ", dst " << dstId; - auto key = KeyUtils::edgeKey(partId, vertexId, 101, dstId - 10001, dstId, 0); + auto key = NebulaKeyUtils::edgeKey(partId, vertexId, 101, dstId - 10001, dstId, 0); RowWriter writer(nullptr); for (int64_t numInt = 0; numInt < 10; numInt++) { writer << numInt; diff --git a/src/storage/test/QueryVertexPropsTest.cpp b/src/storage/test/QueryVertexPropsTest.cpp index 0359196ead5..1a784236ef1 100644 --- a/src/storage/test/QueryVertexPropsTest.cpp +++ b/src/storage/test/QueryVertexPropsTest.cpp @@ -5,12 +5,12 @@ */ #include "base/Base.h" +#include "base/NebulaKeyUtils.h" #include #include #include "fs/TempDir.h" #include "storage/test/TestUtils.h" #include "storage/QueryVertexPropsProcessor.h" -#include "storage/KeyUtils.h" #include "dataman/RowSetReader.h" #include "dataman/RowReader.h" @@ -28,7 +28,7 @@ TEST(QueryVertexPropsTest, SimpleTest) { std::vector data; for (auto vertexId = partId * 10; vertexId < (partId + 1) * 10; vertexId++) { for (auto tagId = 3001; tagId < 3010; tagId++) { - auto key = KeyUtils::vertexKey(partId, vertexId, tagId, 0); + auto key = NebulaKeyUtils::vertexKey(partId, vertexId, tagId, 0); RowWriter writer; for (int64_t numInt = 0; numInt < 3; numInt++) { writer << numInt; diff --git a/src/storage/test/StorageServiceHandlerTest.cpp b/src/storage/test/StorageServiceHandlerTest.cpp index 8790bd6aecc..e419bf852d7 100644 --- a/src/storage/test/StorageServiceHandlerTest.cpp +++ b/src/storage/test/StorageServiceHandlerTest.cpp @@ -5,12 +5,12 @@ */ #include "base/Base.h" +#include "base/NebulaKeyUtils.h" #include #include "fs/TempDir.h" #include "storage/test/TestUtils.h" #include "storage/AddVerticesProcessor.h" #include "storage/StorageServiceHandler.h" -#include "storage/KeyUtils.h" namespace nebula { namespace storage { @@ -35,7 +35,7 @@ TEST(StorageServiceHandlerTest, FutureAddVerticesTest) { ASSERT_EQ(0, resp.result.failed_codes.size()); LOG(INFO) << "Verify the vertices data..."; - auto prefix = KeyUtils::prefix(1, 19); + auto prefix = NebulaKeyUtils::prefix(1, 19); std::unique_ptr iter; ASSERT_EQ(kvstore::ResultCode::SUCCEEDED, kvstore->prefix(0, 1, prefix, &iter)); TagID tagId = 0;