diff --git a/src/common/utils/NebulaKeyUtils.cpp b/src/common/utils/NebulaKeyUtils.cpp index ff1c60ba8bd..4e155f084aa 100644 --- a/src/common/utils/NebulaKeyUtils.cpp +++ b/src/common/utils/NebulaKeyUtils.cpp @@ -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(NebulaKeyType::kKeyValue); + std::string key; + key.reserve(sizeof(PartitionID)); + key.append(reinterpret_cast(&item), sizeof(PartitionID)); + return key; +} + // static std::string NebulaKeyUtils::tagPrefix(size_t vIdLen, PartitionID partId, @@ -237,6 +245,7 @@ std::vector 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 } diff --git a/src/common/utils/NebulaKeyUtils.h b/src/common/utils/NebulaKeyUtils.h index 6d07383e4dd..985cfe8959e 100644 --- a/src/common/utils/NebulaKeyUtils.h +++ b/src/common/utils/NebulaKeyUtils.h @@ -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 diff --git a/src/kvstore/Part.cpp b/src/kvstore/Part.cpp index 767f1e853ed..d08b060c192 100644 --- a/src/kvstore/Part.cpp +++ b/src/kvstore/Part.cpp @@ -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)); + 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);