Skip to content

Commit

Permalink
[Enhancement] reduce tablet shard read lock holding time when calc pe…
Browse files Browse the repository at this point in the history
…rsistent index compact score (StarRocks#38299)

Signed-off-by: luohaha <18810541851@163.com>
  • Loading branch information
luohaha authored Jan 3, 2024
1 parent e9ec5b1 commit efcb2d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions be/src/storage/olap_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,11 @@ void* StorageEngine::_pk_index_major_compaction_thread_callback(void* arg) {
while (!_bg_worker_stopped.load(std::memory_order_consume)) {
SLEEP_IN_BG_WORKER(1);
// schedule persistent index compaction
_update_manager->get_pindex_compaction_mgr()->schedule([&]() {
return StorageEngine::instance()->tablet_manager()->pick_tablets_to_do_pk_index_major_compaction();
});
if (config::enable_pindex_minor_compaction) {
_update_manager->get_pindex_compaction_mgr()->schedule([&]() {
return StorageEngine::instance()->tablet_manager()->pick_tablets_to_do_pk_index_major_compaction();
});
}
}

return nullptr;
Expand Down
18 changes: 11 additions & 7 deletions be/src/storage/tablet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ TabletSharedPtr TabletManager::find_best_tablet_to_compaction(CompactionType com
std::vector<TabletAndScore> TabletManager::pick_tablets_to_do_pk_index_major_compaction() {
std::vector<TabletAndScore> pick_tablets;
// 1. pick valid tablet, which score is larger than 0
std::vector<TabletSharedPtr> tablet_ptr_list;
for (const auto& tablets_shard : _tablets_shards) {
std::shared_lock rlock(tablets_shard.lock);
for (const auto& [tablet_id, tablet_ptr] : tablets_shard.tablet_map) {
Expand All @@ -716,15 +717,18 @@ std::vector<TabletAndScore> TabletManager::pick_tablets_to_do_pk_index_major_com
continue;
}

double score = tablet_ptr->updates()->get_pk_index_write_amp_score();
if (score <= 0) {
// score == 0 means this tablet's pk index doesn't need major compaction
continue;
}

pick_tablets.emplace_back(tablet_ptr, score);
tablet_ptr_list.push_back(tablet_ptr);
}
}
for (const auto& tablet_ptr : tablet_ptr_list) {
double score = tablet_ptr->updates()->get_pk_index_write_amp_score();
if (score <= 0) {
// score == 0 means this tablet's pk index doesn't need major compaction
continue;
}

pick_tablets.emplace_back(tablet_ptr, score);
}
// 2. sort tablet by score, by ascending order.
std::sort(pick_tablets.begin(), pick_tablets.end(), [](TabletAndScore& a, TabletAndScore& b) {
// We try to compact tablet with small write amplification score first,
Expand Down

0 comments on commit efcb2d5

Please sign in to comment.