Skip to content

Commit e8d6f70

Browse files
committed
storage: enable multilevel compactions by default with a cluster setting
Reenable multilevel compactions, with more constraints. ML compactions will run according to a write amp heuristic, along with the following rules: - At most 1 ML compaction is running at any time. - The db must have >= 2 maximum compaction slots. Closes: cockroachdb/pebble#4139
1 parent e30bcbf commit e8d6f70

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pkg/storage/pebble.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ var readaheadModeSpeculative = settings.RegisterEnumSetting(
167167
},
168168
)
169169

170+
var enableMultiLevelWriteAmpHeuristic = settings.RegisterBoolSetting(
171+
settings.ApplicationLevel,
172+
"storage.multi_level_compaction_write_amp_heuristic.enabled",
173+
"enables multi-level compactions using the write amplification heuristic",
174+
true,
175+
)
176+
170177
// SSTableCompressionProfile is an enumeration of compression algorithms
171178
// available for compressing SSTables (e.g. for backup or transport).
172179
type SSTableCompressionProfile int64
@@ -564,11 +571,6 @@ func DefaultPebbleOptions() *pebble.Options {
564571
policy.ValueStoragePolicy = pebble.ValueStorageLowReadLatency
565572
return policy, lockTableEndKey, nil
566573
}
567-
568-
// Disable multi-level compaction heuristic for now. See #134423
569-
// for why this was disabled, and what needs to be changed to reenable it.
570-
// This issue tracks re-enablement: https://github.com/cockroachdb/pebble/issues/4139
571-
opts.Experimental.MultiLevelCompactionHeuristic = pebble.NoMultiLevel{}
572574
opts.Experimental.UserKeyCategories = userKeyCategories
573575

574576
opts.Levels[0] = pebble.LevelOptions{
@@ -924,6 +926,14 @@ func newPebble(ctx context.Context, cfg engineConfig) (p *Pebble, err error) {
924926
TargetGarbageRatio: float64(valueSeparationCompactionGarbageThreshold.Get(&cfg.settings.SV)) / 100.0,
925927
}
926928
}
929+
cfg.opts.Experimental.MultiLevelCompactionHeuristic = func() pebble.MultiLevelHeuristic {
930+
if enableMultiLevelWriteAmpHeuristic.Get(&cfg.settings.SV) {
931+
// Use the default write amp heuristic, which adds no propensity towards
932+
// multi-level compactions and disallows multi-level compactions involving L0.
933+
return pebble.OptionWriteAmpHeuristic()
934+
}
935+
return pebble.OptionNoMultiLevel()
936+
}
927937

928938
auxDir := cfg.opts.FS.PathJoin(cfg.env.Dir, base.AuxiliaryDir)
929939
if !cfg.env.IsReadOnly() {

0 commit comments

Comments
 (0)