From f2cd7ac62162977cca048395ceb220eb7af83994 Mon Sep 17 00:00:00 2001 From: "hs.zhang" <22708345+cangfengzhs@users.noreply.github.com> Date: Wed, 26 Jan 2022 21:55:39 +0800 Subject: [PATCH] put dataVersionKey on create space for storage (#3817) * put dataVersionKey on create space for storage * address some comments Co-authored-by: Doodle <13706157+critical27@users.noreply.github.com> Co-authored-by: Sophie <84560950+Sophie-Xie@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 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 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();