Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put dataVersionKey on create space for storage #3817

Merged
merged 9 commits into from
Jan 26, 2022
4 changes: 4 additions & 0 deletions src/common/utils/NebulaKeyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,8 @@ std::string NebulaKeyUtils::dataVersionKey() {
return "\xFF\xFF\xFF\xFF";
}

std::string NebulaKeyUtils::dataVersionValue() {
return "3.0";
}

} // namespace nebula
2 changes: 2 additions & 0 deletions src/common/utils/NebulaKeyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ class NebulaKeyUtils final {

static std::string dataVersionKey();

static std::string dataVersionValue();

static_assert(sizeof(NebulaKeyType) == sizeof(PartitionID));

private:
Expand Down
12 changes: 12 additions & 0 deletions src/kvstore/RocksEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
Expand Down