Skip to content

Commit

Permalink
put dataVersionKey on create space for storage (vesoft-inc#3817)
Browse files Browse the repository at this point in the history
* put dataVersionKey on create space for storage

* address some comments

Co-authored-by: Doodle <[email protected]>
Co-authored-by: Sophie <[email protected]>
  • Loading branch information
3 people authored and liwenhui-soul committed Jan 29, 2022
1 parent 4aa9552 commit d141e1f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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

0 comments on commit d141e1f

Please sign in to comment.