Skip to content

Commit

Permalink
put dataVersionKey on create space for storage (vesoft-inc#563)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution!
In order to review PR more efficiently, please add information according to the template.
-->

#### What type of PR is this?
- [x] bug
- [ ] feature
- [ ] enhancement

#### What problem(s) does this PR solve?
Issue(s) number: 
close vesoft-inc#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#3817

Co-authored-by: hs.zhang <[email protected]>
  • Loading branch information
nebula-bots and cangfengzhs authored Jan 28, 2022
1 parent e601683 commit c286996
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 @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/common/utils/NebulaKeyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,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 c286996

Please sign in to comment.