Skip to content

Commit 6eec91f

Browse files
committed
db: don't smoothe compaction picker compensated fill factor
When deciding whether a level is even eligible for compaction picking, we consider the 'compensated fill factor': a statistic about the size of a level plus its garbage relative to the level's ideal size given the level multiplier and database size. Currently, we consider a level eligible to be the input level of a compaction if the compensated fill factor is > 1.0 AND the compensated fill factor divided by the next level's fill factor is also > 1.0. We've preserved this behavior for historical consistency but have no clear justification for it. Experimentally, we've observed instances where the LSM is known to contain significant garbage (>14%) but no compactions are pursued because most of the data is in L6 and L6's fill factor is positive (see cockroachdb/cockroach#151633). This commit removes the separate concept of a 'compensated score,' instead allowing the compaction picker to pursue a compaction out of a level so long as its compensated fill factor is > 1.0.
1 parent d143b0d commit 6eec91f

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

compaction_picker.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,30 +1038,25 @@ func (p *compactionPickerByScore) calculateLevelScores(
10381038
continue
10391039
}
10401040
const compensatedFillFactorThreshold = 1.0
1041+
// The level requires compaction iff the compensatedFillFactor is >= 1.0.
10411042
if scores[level].compensatedFillFactor < compensatedFillFactorThreshold {
10421043
// No need to compact this level; score stays 0.
10431044
continue
10441045
}
10451046
score := scores[level].fillFactor
1046-
compensatedScore := scores[level].compensatedFillFactor
10471047
if level < numLevels-1 {
10481048
nextLevel := scores[level].outputLevel
10491049
// Avoid absurdly large scores by placing a floor on the factor that we'll
10501050
// adjust a level by. The value of 0.01 was chosen somewhat arbitrarily.
10511051
denominator := max(0.01, scores[nextLevel].fillFactor)
10521052
score /= denominator
1053-
compensatedScore /= denominator
1054-
}
1055-
// The level requires compaction iff both compensatedFillFactor and
1056-
// compensatedScore are >= 1.0.
1057-
//
1058-
// TODO(radu): this seems ad-hoc. In principle, the state of other levels
1059-
// should not come into play when we're determining this level's eligibility
1060-
// for compaction. The score should take care of correctly prioritizing the
1061-
// levels.
1062-
const compensatedScoreThreshold = 1.0
1063-
if compensatedScore < compensatedScoreThreshold {
1064-
// No need to compact this level; score stays 0.
1053+
}
1054+
// L0 doesn't get compensated, so its compensated and uncompensated fill
1055+
// factors are equal. We avoid compacting L0 if its score (the value
1056+
// after dividing by the next level's fill factor) is less than 1.0.
1057+
// This helps avoid over eager L0 compaction picking (and intra L0
1058+
// compactions) when LBase is large.
1059+
if level == 0 && score < 1.0 {
10651060
continue
10661061
}
10671062
scores[level].score = score

0 commit comments

Comments
 (0)