From c286996115ab809bc3fe7e965375d102c90a6a0e Mon Sep 17 00:00:00 2001 From: nebula-bots <88429921+nebula-bots@users.noreply.github.com> Date: Fri, 28 Jan 2022 15:28:42 +0800 Subject: [PATCH] put dataVersionKey on create space for storage (#563) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? - [x] bug - [ ] feature - [ ] enhancement #### What problem(s) does this PR solve? Issue(s) number: close #3777 Description: Put dataVersionKey when create space #### How do you solve it? #### Special notes for your reviewer, ex. impact of this fix, design document, etc: #### Checklist: Tests: - [ ] Unit test(positive and negative cases) - [ ] Function test - [ ] Performance test - [ ] N/A Affects: - [ ] Documentation affected (Please add the label if documentation needs to be modified.) - [ ] Incompatibility (If it breaks the compatibility, please describe it and add the label.) - [ ] If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).) - [ ] Performance impacted: Consumes more CPU/Memory #### Release notes: Please confirm whether to be reflected in release notes and how to describe: > ex. Fixed the bug ..... Migrated from vesoft-inc/nebula#3817 Co-authored-by: hs.zhang <22708345+cangfengzhs@users.noreply.github.com> --- src/common/utils/NebulaKeyUtils.cpp | 4 ++++ src/common/utils/NebulaKeyUtils.h | 2 ++ src/kvstore/RocksEngine.cpp | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/common/utils/NebulaKeyUtils.cpp b/src/common/utils/NebulaKeyUtils.cpp index ef923ad424d..a08ced1d5d0 100644 --- a/src/common/utils/NebulaKeyUtils.cpp +++ b/src/common/utils/NebulaKeyUtils.cpp @@ -310,6 +310,10 @@ std::string NebulaKeyUtils::dataVersionKey() { return "\xFF\xFF\xFF\xFF"; } +std::string NebulaKeyUtils::dataVersionValue() { + return "3.0"; +} + std::string NebulaKeyUtils::cacheKey(GraphSpaceID spaceId, const folly::StringPiece& key) { std::string ret; ret.reserve(sizeof(GraphSpaceID) + key.size()); diff --git a/src/common/utils/NebulaKeyUtils.h b/src/common/utils/NebulaKeyUtils.h index 9aa663bec6a..56b0b417ca3 100644 --- a/src/common/utils/NebulaKeyUtils.h +++ b/src/common/utils/NebulaKeyUtils.h @@ -313,6 +313,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 6a5ef04baf6..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,6 +125,17 @@ RocksEngine::RocksEngine(GraphSpaceID spaceId, status = rocksdb::DB::Open(options, path, &db); } CHECK(status.ok()) << status.ToString(); + 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(), NebulaKeyUtils::dataVersionValue()); + } + CHECK(status.ok()) << status.ToString(); + } db_.reset(db); extractorLen_ = sizeof(PartitionID) + vIdLen; partsNum_ = allParts().size();