diff --git a/compaction_picker.go b/compaction_picker.go index 49b23c678d..7f2e061ee0 100644 --- a/compaction_picker.go +++ b/compaction_picker.go @@ -717,6 +717,7 @@ func (p *compactionPickerByScore) initLevelMaxBytes(inProgressCompactions []comp p.estimatedMaxWAmp = float64(numLevels-p.baseLevel) * (smoothedLevelMultiplier + 1) levelSize := float64(baseBytesMax) + p.levelMaxBytes[0] = baseBytesMax for level := p.baseLevel; level < numLevels; level++ { if level > p.baseLevel && levelSize > 0 { levelSize *= smoothedLevelMultiplier @@ -770,15 +771,25 @@ func (p *compactionPickerByScore) calculateScores( scores[i].level = i scores[i].outputLevel = i + 1 } - scores[0] = p.calculateL0Score(inProgressCompactions) - sizeAdjust := calculateSizeAdjust(inProgressCompactions) - for level := 1; level < numLevels; level++ { + for level := 0; level < numLevels; level++ { levelSize := int64(levelCompensatedSize(p.vers.Levels[level])) + sizeAdjust[level] scores[level].score = float64(levelSize) / float64(p.levelMaxBytes[level]) scores[level].origScore = scores[level].score } + // Calculate a L0 score based on the sublevel count. The base vs intra-L0 + // compaction determination happens in pickAuto, not here. If the + // sublevel-based score is higher than the size-based score, use the + // sublevel-based score. + sublevelScore := float64(2*p.vers.L0Sublevels.MaxDepthAfterOngoingCompactions()) / + float64(p.opts.L0CompactionThreshold) + if sublevelScore > scores[0].score { + scores[0].score = sublevelScore + scores[0].origScore = sublevelScore + } + scores[0].outputLevel = p.baseLevel + // Adjust each level's score by the score of the next level. If the next // level has a high score, and is thus a priority for compaction, this // reduces the priority for compacting the current level. If the next level @@ -819,20 +830,6 @@ func (p *compactionPickerByScore) calculateScores( return scores } -func (p *compactionPickerByScore) calculateL0Score( - inProgressCompactions []compactionInfo, -) candidateLevelInfo { - var info candidateLevelInfo - info.outputLevel = p.baseLevel - - // If L0Sublevels are present, we use the sublevel count as opposed to - // the L0 file count to score this level. The base vs intra-L0 - // compaction determination happens in pickAuto, not here. - info.score = float64(2*p.vers.L0Sublevels.MaxDepthAfterOngoingCompactions()) / - float64(p.opts.L0CompactionThreshold) - return info -} - func (p *compactionPickerByScore) pickFile( level, outputLevel int, earliestSnapshotSeqNum uint64, ) (manifest.LevelFile, bool) { diff --git a/testdata/compaction_picker_target_level b/testdata/compaction_picker_target_level index a1bb053254..ba6de4ca9d 100644 --- a/testdata/compaction_picker_target_level +++ b/testdata/compaction_picker_target_level @@ -195,7 +195,7 @@ L4->L5: 7.7 pick ongoing=(5,6) ---- -no compaction +L0->L4: 1.0 pick ongoing=(0,4) ---- @@ -224,11 +224,11 @@ base: 4 queue ---- -L0->L4: 1000.0 +L0->L4: 2000.0 pick ---- -L0->L4: 1000.0 +L0->L4: 2000.0 pick ongoing=(0,4) ---- @@ -249,7 +249,7 @@ base: 4 queue ---- -L0->L4: 1000.0 +L0->L4: 2000.0 pick ongoing=(0,4,4,5) ---- @@ -257,7 +257,7 @@ no compaction pick ongoing=(4,5) ---- -L0->L4: 1000.0 +L0->L4: 2000.0 # Verify we can start concurrent Ln->Ln+1 compactions given sufficient # priority.