Skip to content

Commit

Permalink
Prevent intraL0 when L0L1 is ready but is blocked by intraL0
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuval-Ariel committed Mar 7, 2024
1 parent 69756e0 commit 4506ef9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions db/compaction/compaction_picker_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class LevelCompactionBuilder {
// Return true if a L0 trivial move is picked up.
bool TryPickL0TrivialMove();

bool IsL0L1ready();

// For L0->L0, picks the longest span of files that aren't currently
// undergoing compaction for which work-per-deleted-file decreases. The span
// always starts from the newest L0 file.
Expand Down Expand Up @@ -212,6 +214,11 @@ void LevelCompactionBuilder::SetupInitialFiles() {
start_level_inputs_.clear();
if (start_level_ == 0) {
skipped_l0_to_base = true;
// Dont start an IntraL0Compaction if L0L1 compaction will be blocked
// by it.
if (IsL0L1ready()) {
continue;
}
// L0->base_level may be blocked due to ongoing L0->base_level
// compactions. It may also be blocked by an ongoing compaction from
// base_level downwards.
Expand Down Expand Up @@ -857,6 +864,35 @@ bool LevelCompactionBuilder::PickFileToCompact() {
return start_level_inputs_.size() > 0;
}

bool LevelCompactionBuilder::IsL0L1ready() {
// L0L1 compaction is not ready to go when its score is lower than L1,
// or its already running.
int l0_score = 0;
int l1_score = 0;

for (int i = 0; i < compaction_picker_->NumberLevels() - 1; i++) {
int level = vstorage_->CompactionScoreLevel(i);
if (level == 0) {
l0_score = vstorage_->CompactionScore(i);
} else if (level == 1) {
l1_score = vstorage_->CompactionScore(i);
}
}
if (l1_score > l0_score) {
return false;
}

auto l0_compactions_in_progress =
compaction_picker_->level0_compactions_in_progress();
for (Compaction* c : *l0_compactions_in_progress) {
if (c->output_level() == vstorage_->base_level()) {
return false;
}
}

return true;
}

bool LevelCompactionBuilder::PickIntraL0Compaction() {
start_level_inputs_.clear();
const std::vector<FileMetaData*>& level_files =
Expand Down

0 comments on commit 4506ef9

Please sign in to comment.