Skip to content

Commit f948c7f

Browse files
[Enhancement] update persistent index size statistic when do major compaction (backport #62195) (#62200)
Signed-off-by: luohaha <18810541851@163.com> Co-authored-by: Yixin Luo <18810541851@163.com>
1 parent 1dd1b1e commit f948c7f

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

be/src/storage/persistent_index.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5069,7 +5069,8 @@ Status PersistentIndex::TEST_major_compaction(PersistentIndexMetaPB& index_meta)
50695069
// 1. load current l2 vec
50705070
// 2. merge l2 files to new l2 file
50715071
// 3. modify PersistentIndexMetaPB and make this step atomic.
5072-
Status PersistentIndex::major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex) {
5072+
Status PersistentIndex::major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex,
5073+
IOStat* stat) {
50735074
if (_cancel_major_compaction) {
50745075
return Status::InternalError("cancel major compaction");
50755076
}
@@ -5128,6 +5129,9 @@ Status PersistentIndex::major_compaction(DataDir* data_dir, int64_t tablet_id, s
51285129
l0_version, _l1_version,
51295130
_l2_versions.size() > 0 ? _l2_versions[0] : EditVersionWithMerge(INT64_MAX, INT64_MAX, true)));
51305131
_calc_memory_usage();
5132+
if (stat != nullptr) {
5133+
stat->total_file_size = (_l0 ? _l0->file_size() : 0) + _l1_l2_file_size();
5134+
}
51315135
}
51325136
(void)_delete_major_compaction_tmp_index_file();
51335137
return Status::OK();

be/src/storage/persistent_index.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ class PersistentIndex {
783783
// just for unit test
784784
bool has_bf() { return _l1_vec.empty() ? false : _l1_vec[0]->has_bf(); }
785785

786-
Status major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex);
786+
Status major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex,
787+
IOStat* stat = nullptr);
787788

788789
Status TEST_major_compaction(PersistentIndexMetaPB& index_meta);
789790

be/src/storage/primary_index.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,15 +1572,16 @@ std::unique_ptr<PrimaryIndex> TEST_create_primary_index(const Schema& pk_schema)
15721572
return std::make_unique<PrimaryIndex>(pk_schema);
15731573
}
15741574

1575-
Status PrimaryIndex::major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex) {
1575+
Status PrimaryIndex::major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex,
1576+
IOStat* stat) {
15761577
// `_persistent_index` could be reset when call `unload()`, so we need to fetch reference first.
15771578
std::shared_ptr<PersistentIndex> pindex;
15781579
{
15791580
std::lock_guard<std::mutex> lg(_lock);
15801581
pindex = _persistent_index;
15811582
}
15821583
if (pindex != nullptr) {
1583-
return pindex->major_compaction(data_dir, tablet_id, mutex);
1584+
return pindex->major_compaction(data_dir, tablet_id, mutex, stat);
15841585
} else {
15851586
return Status::OK();
15861587
}

be/src/storage/primary_index.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class PrimaryIndex {
131131

132132
Status on_commited();
133133

134-
Status major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex);
134+
Status major_compaction(DataDir* data_dir, int64_t tablet_id, std::shared_timed_mutex* mutex,
135+
IOStat* stat = nullptr);
135136

136137
Status abort();
137138

be/src/storage/tablet_updates.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4773,10 +4773,12 @@ Status TabletUpdates::pk_index_major_compaction() {
47734773
}
47744774
});
47754775
manager->index_cache().update_object_size(index_entry, index.memory_usage());
4776-
st = index.major_compaction(_tablet.data_dir(), _tablet.tablet_id(), _tablet.updates()->get_index_lock());
4776+
IOStat stat;
4777+
st = index.major_compaction(_tablet.data_dir(), _tablet.tablet_id(), _tablet.updates()->get_index_lock(), &stat);
47774778
if (st.ok()) {
47784779
// reset score after major compaction finish
47794780
_pk_index_write_amp_score.store(0.0);
4781+
_extra_file_size_cache.pindex_size.store(stat.total_file_size);
47804782
}
47814783
return st;
47824784
}

0 commit comments

Comments
 (0)