Skip to content

Commit b4a4467

Browse files
visualYJDrock-git
authored andcommitted
[feat][store] Record region size when auto split
1 parent 8c722c8 commit b4a4467

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/split/split_checker.cc

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ void MergedIterator::Next(IteratorPtr iter, int iter_pos) {
9898

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

105-
int64_t size = 0;
106105
int64_t chunk_size = 0;
107106
std::string prev_key;
108107
std::vector<std::string> keys;
@@ -136,11 +135,10 @@ std::string HalfSplitChecker::SplitKey(store::RegionPtr region, const pb::common
136135

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

143-
int64_t size = 0;
144142
std::string prev_key;
145143
std::string split_key;
146144
bool is_split = false;
@@ -168,11 +166,10 @@ std::string SizeSplitChecker::SplitKey(store::RegionPtr region, const pb::common
168166

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

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

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

275273
// Update region key count metrics.
276-
if (region_metrics_ != nullptr && key_count > 0) {
277-
region_metrics_->SetKeyCount(key_count);
278-
region_metrics_->SetNeedUpdateKeyCount(false);
274+
if (region_metrics_ != nullptr) {
275+
if (key_count > 0) {
276+
region_metrics_->SetKeyCount(key_count);
277+
region_metrics_->SetNeedUpdateKeyCount(false);
278+
}
279+
if (size > 0) {
280+
region_metrics_->SetRegionSize(size);
281+
}
279282
}
280283

281284
bool need_split = true;

src/split/split_checker.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SplitChecker {
8585

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

9090
private:
9191
Policy policy_;
@@ -103,7 +103,7 @@ class HalfSplitChecker : public SplitChecker {
103103

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

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

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

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

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

152152
private:
153153
// Split when region key number exceed split_key_number.

0 commit comments

Comments
 (0)