Skip to content

Commit

Permalink
[feat][store] Record region size when auto split
Browse files Browse the repository at this point in the history
  • Loading branch information
visualYJD authored and rock-git committed Dec 4, 2024
1 parent 8c722c8 commit b4a4467
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
23 changes: 13 additions & 10 deletions src/split/split_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ void MergedIterator::Next(IteratorPtr iter, int iter_pos) {

// base physics key, contain key of multi version.
std::string HalfSplitChecker::SplitKey(store::RegionPtr region, const pb::common::Range& range,
const std::vector<std::string>& cf_names, uint32_t& count) {
const std::vector<std::string>& cf_names, uint32_t& count, int64_t& size) {
MergedIterator iter(raw_engine_, cf_names, range.end_key());
iter.Seek(range.start_key());

int64_t size = 0;
int64_t chunk_size = 0;
std::string prev_key;
std::vector<std::string> keys;
Expand Down Expand Up @@ -136,11 +135,10 @@ std::string HalfSplitChecker::SplitKey(store::RegionPtr region, const pb::common

// base physics key, contain key of multi version.
std::string SizeSplitChecker::SplitKey(store::RegionPtr region, const pb::common::Range& range,
const std::vector<std::string>& cf_names, uint32_t& count) {
const std::vector<std::string>& cf_names, uint32_t& count, int64_t& size) {
MergedIterator iter(raw_engine_, cf_names, range.end_key());
iter.Seek(range.start_key());

int64_t size = 0;
std::string prev_key;
std::string split_key;
bool is_split = false;
Expand Down Expand Up @@ -168,11 +166,10 @@ std::string SizeSplitChecker::SplitKey(store::RegionPtr region, const pb::common

// base logic key, ignore key of multi version.
std::string KeysSplitChecker::SplitKey(store::RegionPtr region, const pb::common::Range& range,
const std::vector<std::string>& cf_names, uint32_t& count) {
const std::vector<std::string>& cf_names, uint32_t& count, int64_t& size) {
MergedIterator iter(raw_engine_, cf_names, range.end_key());
iter.Seek(range.start_key());

int64_t size = 0;
int64_t split_key_count = 0;
std::string prev_key;
std::string split_key;
Expand Down Expand Up @@ -264,7 +261,8 @@ void SplitCheckTask::SplitCheck() {
DINGO_LOG(INFO) << fmt::format("[split.check][region({})] Will check SplitKey for raw_range{} cf_names({})",
region_->Id(), Helper::RangeToString(plain_range), Helper::VectorToString(cf_names));
uint32_t key_count = 0;
std::string encode_split_key = split_checker_->SplitKey(region_, encode_range, cf_names, key_count);
int64_t size = 0;
std::string encode_split_key = split_checker_->SplitKey(region_, encode_range, cf_names, key_count, size);

int64_t ts = 0;
std::string plain_split_key;
Expand All @@ -273,9 +271,14 @@ void SplitCheckTask::SplitCheck() {
}

// Update region key count metrics.
if (region_metrics_ != nullptr && key_count > 0) {
region_metrics_->SetKeyCount(key_count);
region_metrics_->SetNeedUpdateKeyCount(false);
if (region_metrics_ != nullptr) {
if (key_count > 0) {
region_metrics_->SetKeyCount(key_count);
region_metrics_->SetNeedUpdateKeyCount(false);
}
if (size > 0) {
region_metrics_->SetRegionSize(size);
}
}

bool need_split = true;
Expand Down
8 changes: 4 additions & 4 deletions src/split/split_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SplitChecker {

// Calculate region split key.
virtual std::string SplitKey(store::RegionPtr region, const pb::common::Range& range,
const std::vector<std::string>& cf_names, uint32_t& count) = 0;
const std::vector<std::string>& cf_names, uint32_t& count, int64_t& size) = 0;

private:
Policy policy_;
Expand All @@ -103,7 +103,7 @@ class HalfSplitChecker : public SplitChecker {

// base physics key, contain key of multi version.
std::string SplitKey(store::RegionPtr region, const pb::common::Range& range,
const std::vector<std::string>& cf_names, uint32_t& count) override;
const std::vector<std::string>& cf_names, uint32_t& count, int64_t& size) override;

private:
// Split region when exceed the split_threshold_size.
Expand All @@ -125,7 +125,7 @@ class SizeSplitChecker : public SplitChecker {

// base physics key, contain key of multi version.
std::string SplitKey(store::RegionPtr region, const pb::common::Range& range,
const std::vector<std::string>& cf_names, uint32_t& count) override;
const std::vector<std::string>& cf_names, uint32_t& count, int64_t& size) override;

private:
// Split when region exceed the split_size.
Expand All @@ -147,7 +147,7 @@ class KeysSplitChecker : public SplitChecker {

// base logic key, ignore key of multi version.
std::string SplitKey(store::RegionPtr region, const pb::common::Range& range,
const std::vector<std::string>& cf_names, uint32_t& count) override;
const std::vector<std::string>& cf_names, uint32_t& count, int64_t& size) override;

private:
// Split when region key number exceed split_key_number.
Expand Down

0 comments on commit b4a4467

Please sign in to comment.