Skip to content

Commit 842c8ef

Browse files
committed
internal/manifest: remove base.Compare from B-Tree
The base.Compare is now passed in the only only site that requires it.
1 parent cb31369 commit 842c8ef

File tree

6 files changed

+17
-21
lines changed

6 files changed

+17
-21
lines changed

internal/manifest/annotator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,16 @@ func (a *Annotator[T]) MultiLevelAnnotation(lms []LevelMetadata) *T {
280280
// [lowerBound, upperBound). A pointer to the Annotator is used as the key for
281281
// pre-calculated values, so the same Annotator must be used to avoid duplicate
282282
// computation.
283-
func (a *Annotator[T]) LevelRangeAnnotation(lm LevelMetadata, bounds base.UserKeyBounds) *T {
283+
func (a *Annotator[T]) LevelRangeAnnotation(
284+
cmp base.Compare, lm LevelMetadata, bounds base.UserKeyBounds,
285+
) *T {
284286
if lm.Empty() {
285287
return a.Aggregator.Zero(nil)
286288
}
287289

288290
var dst *T
289291
dst = a.Aggregator.Zero(dst)
290-
dst = a.accumulateRangeAnnotation(lm.tree.root, lm.tree.cmp, bounds, false, false, dst)
292+
dst = a.accumulateRangeAnnotation(lm.tree.root, cmp, bounds, false, false, dst)
291293
return dst
292294
}
293295

internal/manifest/annotator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func randomBounds(rng *rand.Rand, count int) base.UserKeyBounds {
8888

8989
func requireMatchOverlaps(t *testing.T, v *Version, bounds base.UserKeyBounds) {
9090
overlaps := v.Overlaps(6, bounds)
91-
numFiles := *NumFilesAnnotator.LevelRangeAnnotation(v.Levels[6], bounds)
91+
numFiles := *NumFilesAnnotator.LevelRangeAnnotation(v.cmp.Compare, v.Levels[6], bounds)
9292
require.EqualValues(t, overlaps.length, numFiles)
9393
}
9494

@@ -150,7 +150,7 @@ func BenchmarkNumFilesRangeAnnotation(b *testing.B) {
150150
toDelete := rng.IntN(count)
151151
v.Levels[6].tree.Delete(files[toDelete], ignoreObsoleteFiles{})
152152

153-
NumFilesAnnotator.LevelRangeAnnotation(v.Levels[6], b)
153+
NumFilesAnnotator.LevelRangeAnnotation(v.cmp.Compare, v.Levels[6], b)
154154

155155
v.Levels[6].tree.Insert(files[toDelete])
156156
}

internal/manifest/btree.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"unsafe"
1515

1616
"github.com/cockroachdb/errors"
17-
"github.com/cockroachdb/pebble/internal/base"
1817
"github.com/cockroachdb/pebble/internal/invariants"
1918
)
2019

@@ -690,7 +689,6 @@ func (n *node[M]) verifyInvariants() {
690689
// goroutines, but Read operations are.
691690
type btree[M fileMetadata] struct {
692691
root *node[M]
693-
cmp base.Compare
694692
bcmp btreeCmp[M]
695693
}
696694

internal/manifest/l0_sublevels.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func newL0Sublevels(
321321
// Construct a parallel slice of sublevel B-Trees.
322322
// TODO(jackson): Consolidate and only use the B-Trees.
323323
for _, sublevelFiles := range s.levelFiles {
324-
ls := makeLevelSlice(cmp, btreeCmpSmallestKey(cmp), sublevelFiles)
324+
ls := makeLevelSlice(btreeCmpSmallestKey(cmp), sublevelFiles)
325325
s.Levels = append(s.Levels, ls)
326326
}
327327

@@ -635,7 +635,7 @@ func (s *l0Sublevels) addL0Files(
635635
// Construct a parallel slice of sublevel B-Trees.
636636
// TODO(jackson): Consolidate and only use the B-Trees.
637637
for _, sublevel := range updatedSublevels {
638-
ls := makeLevelSlice(newVal.cmp, btreeCmpSmallestKey(newVal.cmp), newVal.levelFiles[sublevel])
638+
ls := makeLevelSlice(btreeCmpSmallestKey(newVal.cmp), newVal.levelFiles[sublevel])
639639
if sublevel == len(newVal.Levels) {
640640
newVal.Levels = append(newVal.Levels, ls)
641641
} else {

internal/manifest/level_metadata.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func MakeLevelMetadata(cmp Compare, level int, files []*TableMetadata) LevelMeta
5252
}
5353
var lm LevelMetadata
5454
lm.level = level
55-
lm.tree = makeBTree(cmp, bcmp, files)
55+
lm.tree = makeBTree(bcmp, files)
5656
for _, f := range files {
5757
lm.totalTableSize += f.Size
5858
lm.totalRefSize += f.EstimatedReferenceSize()
@@ -64,10 +64,8 @@ func MakeLevelMetadata(cmp Compare, level int, files []*TableMetadata) LevelMeta
6464
return lm
6565
}
6666

67-
func makeBTree(
68-
cmp base.Compare, bcmp btreeCmp[*TableMetadata], files []*TableMetadata,
69-
) btree[*TableMetadata] {
70-
t := btree[*TableMetadata]{cmp: cmp, bcmp: bcmp}
67+
func makeBTree(bcmp btreeCmp[*TableMetadata], files []*TableMetadata) btree[*TableMetadata] {
68+
t := btree[*TableMetadata]{bcmp: bcmp}
7169
for _, f := range files {
7270
if err := t.Insert(f); err != nil {
7371
panic(err)
@@ -76,10 +74,8 @@ func makeBTree(
7674
return t
7775
}
7876

79-
func makeLevelSlice(
80-
cmp base.Compare, bcmp btreeCmp[*TableMetadata], files []*TableMetadata,
81-
) LevelSlice {
82-
t := makeBTree(cmp, bcmp, files)
77+
func makeLevelSlice(bcmp btreeCmp[*TableMetadata], files []*TableMetadata) LevelSlice {
78+
t := makeBTree(bcmp, files)
8379
slice := newLevelSlice(tableMetadataIter(&t))
8480
slice.verifyInvariants()
8581
// We can release the tree because the nodes that are referenced by the
@@ -190,23 +186,23 @@ func (lf LevelFile) Slice() LevelSlice {
190186
// TODO(jackson): Can we improve this interface or avoid needing to export
191187
// a slice constructor like this?
192188
func NewLevelSliceSeqSorted(files []*TableMetadata) LevelSlice {
193-
return makeLevelSlice(nil, btreeCmpSeqNum, files)
189+
return makeLevelSlice(btreeCmpSeqNum, files)
194190
}
195191

196192
// NewLevelSliceKeySorted constructs a LevelSlice over the provided files,
197193
// sorted by the files smallest keys.
198194
// TODO(jackson): Can we improve this interface or avoid needing to export
199195
// a slice constructor like this?
200196
func NewLevelSliceKeySorted(cmp base.Compare, files []*TableMetadata) LevelSlice {
201-
return makeLevelSlice(cmp, btreeCmpSmallestKey(cmp), files)
197+
return makeLevelSlice(btreeCmpSmallestKey(cmp), files)
202198
}
203199

204200
// NewLevelSliceSpecificOrder constructs a LevelSlice over the provided files,
205201
// ordering the files by their order in the provided slice. It's used in
206202
// tests.
207203
// TODO(jackson): Update tests to avoid requiring this and remove it.
208204
func NewLevelSliceSpecificOrder(files []*TableMetadata) LevelSlice {
209-
slice := makeLevelSlice(nil, btreeCmpSpecificOrder(files), files)
205+
slice := makeLevelSlice(btreeCmpSpecificOrder(files), files)
210206
slice.verifyInvariants()
211207
return slice
212208
}

internal/manifest/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ func NewVersionForTesting(
13341334
// order to test consistency checking, etc. Once we've constructed the
13351335
// initial B-Tree, we swap out the btreeCmp for the correct one.
13361336
// TODO(jackson): Adjust or remove the tests and remove this.
1337-
v.Levels[l].tree = makeBTree(comparer.Compare, btreeCmpSpecificOrder(files[l]), files[l])
1337+
v.Levels[l].tree = makeBTree(btreeCmpSpecificOrder(files[l]), files[l])
13381338
v.Levels[l].level = l
13391339
if l == 0 {
13401340
v.Levels[l].tree.bcmp = btreeCmpSeqNum

0 commit comments

Comments
 (0)