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

fix kv snapshot data inconsist #4055

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/common/utils/NebulaKeyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ std::string NebulaKeyUtils::kvKey(PartitionID partId, const folly::StringPiece&
return key;
}

std::string NebulaKeyUtils::kvPrefix(PartitionID partId) {
PartitionID item = (partId << kPartitionOffset) | static_cast<uint32_t>(NebulaKeyType::kKeyValue);
std::string key;
key.reserve(sizeof(PartitionID));
key.append(reinterpret_cast<const char*>(&item), sizeof(PartitionID));
return key;
}

// static
std::string NebulaKeyUtils::tagPrefix(size_t vIdLen,
PartitionID partId,
Expand Down Expand Up @@ -237,6 +245,7 @@ std::vector<std::string> NebulaKeyUtils::snapshotPrefix(PartitionID partId) {
result.emplace_back(tagPrefix(partId));
result.emplace_back(edgePrefix(partId));
result.emplace_back(IndexKeyUtils::indexPrefix(partId));
result.emplace_back(kvPrefix(partId));
// kSystem will be written when balance data
// kOperation will be blocked by jobmanager later
}
Expand Down
1 change: 1 addition & 0 deletions src/common/utils/NebulaKeyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class NebulaKeyUtils final {
static std::string systemPartKey(PartitionID partId);

static std::string kvKey(PartitionID partId, const folly::StringPiece& name);
static std::string kvPrefix(PartitionID partId);

/**
* Prefix for tag
Expand Down
14 changes: 12 additions & 2 deletions src/kvstore/Part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,19 @@ nebula::cpp2::ErrorCode Part::cleanup() {
LOG(INFO) << idStr_ << "Clean rocksdb part data";
auto batch = engine_->startBatchWrite();
// Remove the vertex, edge, index, systemCommitKey, operation data under the part

const auto& kvPre = NebulaKeyUtils::kvPrefix(partId_);
auto ret =
batch->removeRange(NebulaKeyUtils::firstKey(kvPre, 128), NebulaKeyUtils::lastKey(kvPre, 128));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 128? Is it a magic number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relax....it's not certain yet...

Copy link
Contributor

@critical27 critical27 Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to handle it …… For example, if we want to delete part 3's kv data. The prefix is 06 03 00 00 in hex, can we delete the range by [06 03 00 00, 06 03 00 01]? Perhaps need to do some test if all data can be deleted. (I am not sure we can delete data like 06 03 00 00 FF FF FF FF ...)

if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
VLOG(3) << idStr_ << "Failed to encode removeRange() when cleanup kvdata, error "
<< apache::thrift::util::enumNameSafe(ret);
return ret;
}

const auto& tagPre = NebulaKeyUtils::tagPrefix(partId_);
auto ret = batch->removeRange(NebulaKeyUtils::firstKey(tagPre, vIdLen_),
NebulaKeyUtils::lastKey(tagPre, vIdLen_));
ret = batch->removeRange(NebulaKeyUtils::firstKey(tagPre, vIdLen_),
NebulaKeyUtils::lastKey(tagPre, vIdLen_));
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
VLOG(3) << idStr_ << "Failed to encode removeRange() when cleanup tag, error "
<< apache::thrift::util::enumNameSafe(ret);
Expand Down