Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: tombstone density compaction picking is O(n log(n)) #4179

Open
jbowens opened this issue Nov 25, 2024 · 0 comments
Open

db: tombstone density compaction picking is O(n log(n)) #4179

jbowens opened this issue Nov 25, 2024 · 0 comments

Comments

@jbowens
Copy link
Collaborator

jbowens commented Nov 25, 2024

Picking a tombstone density compaction is likely too expensive in LSMs with high sstable counts. For every level, we traverse over all n sstables and for any eligible sstables search the lower level for overlaps:

pebble/compaction_picker.go

Lines 1528 to 1553 in 3ec779d

for l := numLevels - 2; l >= 0; l-- {
iter := p.vers.Levels[l].Iter()
for f := iter.First(); f != nil; f = iter.Next() {
if f.IsCompacting() || !f.StatsValid() || f.Size == 0 {
continue
}
if f.Stats.TombstoneDenseBlocksRatio < p.opts.Experimental.TombstoneDenseCompactionThreshold {
continue
}
overlaps := p.vers.Overlaps(lastNonEmptyLevel, f.UserKeyBounds())
if float64(overlaps.SizeSum())/float64(f.Size) > maxOverlappingRatio {
continue
}
if candidate == nil || candidate.Stats.TombstoneDenseBlocksRatio < f.Stats.TombstoneDenseBlocksRatio {
candidate = f
level = l
}
}
// We prefer lower level (ie. L5) candidates over higher level (ie. L4) ones.
if candidate != nil {
break
}
if !p.vers.Levels[l].Empty() {
lastNonEmptyLevel = l
}
}

We did this to enable a write-amp calculation based on overlap in fcb941e There's likely an algorithmic improvement we can make.

Jira issue: PEBBLE-309

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Incoming
Development

No branches or pull requests

1 participant