Skip to content

Commit

Permalink
internal/manifest: incrementally generate L0Sublevels for L0 additions
Browse files Browse the repository at this point in the history
NewL0Sublevels is an expensive method to call, and it's called every time
there's a change to L0. This commit adds a faster, incremental generation
method for cases when there are only additions to L0 and no deletions from
it. This lets us reuse most of the slices in NewL0Sublevels and merge new
fileIntervals into it instead of starting from scratch.

Fixes cockroachdb#1406.
  • Loading branch information
itsbilal committed Feb 7, 2022
1 parent 788ef98 commit b7b78b1
Show file tree
Hide file tree
Showing 6 changed files with 671 additions and 87 deletions.
4 changes: 2 additions & 2 deletions compaction_picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func newPickedCompactionFromL0(
files := make([]*manifest.FileMetadata, 0, len(lcf.Files))
iter := vers.Levels[0].Iter()
for j, f := 0, iter.First(); f != nil; j, f = j+1, iter.Next() {
if lcf.FilesIncluded[j] {
if lcf.FilesIncluded[f.L0Index] {
files = append(files, f)
}
}
Expand Down Expand Up @@ -277,7 +277,7 @@ func (pc *pickedCompaction) setupInputs(opts *Options, diskAvailBytes uint64) bo
iter := pc.version.Levels[0].Iter()
var sizeSum uint64
for j, f := 0, iter.First(); f != nil; j, f = j+1, iter.Next() {
if pc.lcf.FilesIncluded[j] {
if pc.lcf.FilesIncluded[f.L0Index] {
newStartLevelFiles = append(newStartLevelFiles, f)
sizeSum += f.Size
}
Expand Down
Loading

0 comments on commit b7b78b1

Please sign in to comment.