From 3ae51253ef2ff9260f25f4f019f775868b2e3994 Mon Sep 17 00:00:00 2001 From: "hs.zhang" <22708345+cangfengzhs@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:32:22 +0800 Subject: [PATCH 1/2] put dataVersionKey on create space for storage --- src/kvstore/RocksEngine.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/kvstore/RocksEngine.cpp b/src/kvstore/RocksEngine.cpp index 6a5ef04baf6..55f4deaec56 100644 --- a/src/kvstore/RocksEngine.cpp +++ b/src/kvstore/RocksEngine.cpp @@ -124,6 +124,16 @@ RocksEngine::RocksEngine(GraphSpaceID spaceId, status = rocksdb::DB::Open(options, path, &db); } CHECK(status.ok()) << status.ToString(); + if (!readonly && spaceId_ != 0 /* only for storage*/) { + rocksdb::ReadOptions readOptions; + std::string dataVersionValue = ""; + status = db->Get(readOptions, NebulaKeyUtils::dataVersionKey(), &dataVersionValue); + if (status.IsNotFound()) { + rocksdb::WriteOptions writeOptions; + status = db->Put(writeOptions, NebulaKeyUtils::dataVersionKey(), "3.0"); + } + CHECK(status.ok()) << status.ToString(); + } db_.reset(db); extractorLen_ = sizeof(PartitionID) + vIdLen; partsNum_ = allParts().size(); From 20d94c1316f8f2a70ac1a4125116b75bec6e86f3 Mon Sep 17 00:00:00 2001 From: "hs.zhang" <22708345+cangfengzhs@users.noreply.github.com> Date: Wed, 26 Jan 2022 16:02:52 +0800 Subject: [PATCH 2/2] address some comments --- src/common/utils/NebulaKeyUtils.cpp | 4 ++++ src/common/utils/NebulaKeyUtils.h | 2 ++ src/kvstore/RocksEngine.cpp | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common/utils/NebulaKeyUtils.cpp b/src/common/utils/NebulaKeyUtils.cpp index 0a91dd7b622..8c81230ec48 100644 --- a/src/common/utils/NebulaKeyUtils.cpp +++ b/src/common/utils/NebulaKeyUtils.cpp @@ -265,4 +265,8 @@ std::string NebulaKeyUtils::dataVersionKey() { return "\xFF\xFF\xFF\xFF"; } +std::string NebulaKeyUtils::dataVersionValue() { + return "3.0"; +} + } // namespace nebula diff --git a/src/common/utils/NebulaKeyUtils.h b/src/common/utils/NebulaKeyUtils.h index 5b62dde095f..ce04c56dd1c 100644 --- a/src/common/utils/NebulaKeyUtils.h +++ b/src/common/utils/NebulaKeyUtils.h @@ -274,6 +274,8 @@ class NebulaKeyUtils final { static std::string dataVersionKey(); + static std::string dataVersionValue(); + static_assert(sizeof(NebulaKeyType) == sizeof(PartitionID)); private: diff --git a/src/kvstore/RocksEngine.cpp b/src/kvstore/RocksEngine.cpp index 55f4deaec56..6cd542c00a7 100644 --- a/src/kvstore/RocksEngine.cpp +++ b/src/kvstore/RocksEngine.cpp @@ -10,6 +10,7 @@ #include "common/base/Base.h" #include "common/fs/FileUtils.h" +#include "common/utils/MetaKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "kvstore/KVStore.h" @@ -124,13 +125,14 @@ RocksEngine::RocksEngine(GraphSpaceID spaceId, status = rocksdb::DB::Open(options, path, &db); } CHECK(status.ok()) << status.ToString(); - if (!readonly && spaceId_ != 0 /* only for storage*/) { + if (!readonly && spaceId_ != kDefaultSpaceId /* only for storage*/) { rocksdb::ReadOptions readOptions; std::string dataVersionValue = ""; status = db->Get(readOptions, NebulaKeyUtils::dataVersionKey(), &dataVersionValue); if (status.IsNotFound()) { rocksdb::WriteOptions writeOptions; - status = db->Put(writeOptions, NebulaKeyUtils::dataVersionKey(), "3.0"); + status = db->Put( + writeOptions, NebulaKeyUtils::dataVersionKey(), NebulaKeyUtils::dataVersionValue()); } CHECK(status.ok()) << status.ToString(); }