@@ -164,7 +164,6 @@ type pickedCompactionMetrics struct {
164
164
// this struct, and is copied over into the compaction struct when that's
165
165
// created.
166
166
type pickedCompaction struct {
167
- cmp Compare
168
167
// score of the chosen compaction (candidateLevelInfo.score).
169
168
score float64
170
169
// kind indicates the kind of compaction.
@@ -239,7 +238,6 @@ func newPickedCompaction(
239
238
240
239
adjustedLevel := adjustedOutputLevel (outputLevel , baseLevel )
241
240
pc := & pickedCompaction {
242
- cmp : opts .Comparer .Compare ,
243
241
version : cur ,
244
242
l0Organizer : l0Organizer ,
245
243
baseLevel : baseLevel ,
@@ -319,7 +317,6 @@ func (pc *pickedCompaction) clone() *pickedCompaction {
319
317
// Quickly copy over fields that do not require special deep copy care, and
320
318
// set all fields that will require a deep copy to nil.
321
319
newPC := & pickedCompaction {
322
- cmp : pc .cmp ,
323
320
score : pc .score ,
324
321
kind : pc .kind ,
325
322
baseLevel : pc .baseLevel ,
@@ -365,7 +362,9 @@ func (pc *pickedCompaction) clone() *pickedCompaction {
365
362
// the candidate keys expand the key span. This avoids a bug for multi-level
366
363
// compactions: during the second call to setupInputs, the picked compaction's
367
364
// smallest and largest keys should not decrease the key span.
368
- func (pc * pickedCompaction ) maybeExpandBounds (smallest InternalKey , largest InternalKey ) {
365
+ func (pc * pickedCompaction ) maybeExpandBounds (
366
+ cmp base.Compare , smallest InternalKey , largest InternalKey ,
367
+ ) {
369
368
if len (smallest .UserKey ) == 0 && len (largest .UserKey ) == 0 {
370
369
return
371
370
}
@@ -374,10 +373,10 @@ func (pc *pickedCompaction) maybeExpandBounds(smallest InternalKey, largest Inte
374
373
pc .largest = largest
375
374
return
376
375
}
377
- if base .InternalCompare (pc . cmp , pc .smallest , smallest ) >= 0 {
376
+ if base .InternalCompare (cmp , pc .smallest , smallest ) >= 0 {
378
377
pc .smallest = smallest
379
378
}
380
- if base .InternalCompare (pc . cmp , pc .largest , largest ) <= 0 {
379
+ if base .InternalCompare (cmp , pc .largest , largest ) <= 0 {
381
380
pc .largest = largest
382
381
}
383
382
}
@@ -394,11 +393,13 @@ func (pc *pickedCompaction) setupInputs(
394
393
inputLevel * compactionLevel ,
395
394
problemSpans * problemspans.ByLevel ,
396
395
) bool {
396
+ cmp := opts .Comparer .Compare
397
397
if ! canCompactTables (inputLevel .files , inputLevel .level , problemSpans ) {
398
398
return false
399
399
}
400
400
401
- pc .maybeExpandBounds (manifest .KeyRange (pc .cmp , inputLevel .files .All ()))
401
+ sm , la := manifest .KeyRange (cmp , inputLevel .files .All ())
402
+ pc .maybeExpandBounds (cmp , sm , la )
402
403
403
404
// Setup output files and attempt to grow the inputLevel files with
404
405
// the expanded key range. No need to do this for intra-L0 compactions;
@@ -411,7 +412,8 @@ func (pc *pickedCompaction) setupInputs(
411
412
return false
412
413
}
413
414
414
- pc .maybeExpandBounds (manifest .KeyRange (pc .cmp , pc .outputLevel .files .All ()))
415
+ sm , la = manifest .KeyRange (cmp , pc .outputLevel .files .All ())
416
+ pc .maybeExpandBounds (cmp , sm , la )
415
417
416
418
// maxExpandedBytes is the maximum size of an expanded compaction. If
417
419
// growing a compaction results in a larger size, the original compaction
@@ -423,16 +425,17 @@ func (pc *pickedCompaction) setupInputs(
423
425
// Grow the sstables in inputLevel.level as long as it doesn't affect the number
424
426
// of sstables included from pc.outputLevel.level.
425
427
if pc .lcf != nil && inputLevel .level == 0 {
426
- pc .growL0ForBase (maxExpandedBytes )
427
- } else if pc .grow (pc .smallest , pc .largest , maxExpandedBytes , inputLevel , problemSpans ) {
428
+ pc .growL0ForBase (cmp , maxExpandedBytes )
429
+ } else if pc .grow (cmp , pc .smallest , pc .largest , maxExpandedBytes , inputLevel , problemSpans ) {
428
430
// inputLevel was expanded, adjust key range if necessary.
429
- pc .maybeExpandBounds (manifest .KeyRange (pc .cmp , inputLevel .files .All ()))
431
+ sm , la = manifest .KeyRange (cmp , inputLevel .files .All ())
432
+ pc .maybeExpandBounds (cmp , sm , la )
430
433
}
431
434
}
432
435
433
436
if inputLevel .level == 0 {
434
437
// If L0 is involved, it should always be the startLevel of the compaction.
435
- pc .startLevel .l0SublevelInfo = generateSublevelInfo (pc . cmp , pc .startLevel .files )
438
+ pc .startLevel .l0SublevelInfo = generateSublevelInfo (cmp , pc .startLevel .files )
436
439
}
437
440
438
441
return true
@@ -442,6 +445,7 @@ func (pc *pickedCompaction) setupInputs(
442
445
// pc.outputLevel files in the compaction, and returns whether the inputs grew. sm
443
446
// and la are the smallest and largest InternalKeys in all of the inputs.
444
447
func (pc * pickedCompaction ) grow (
448
+ cmp base.Compare ,
445
449
sm , la InternalKey ,
446
450
maxExpandedBytes uint64 ,
447
451
inputLevel * compactionLevel ,
@@ -465,7 +469,7 @@ func (pc *pickedCompaction) grow(
465
469
// expandedInputLevel's key range not fully cover all files currently in pc.outputLevel,
466
470
// since pc.outputLevel was created using the entire key range which includes higher levels.
467
471
expandedOutputLevel := pc .version .Overlaps (pc .outputLevel .level ,
468
- base .UserKeyBoundsFromInternal (manifest .KeyRange (pc . cmp , expandedInputLevel .All (), pc .outputLevel .files .All ())))
472
+ base .UserKeyBoundsFromInternal (manifest .KeyRange (cmp , expandedInputLevel .All (), pc .outputLevel .files .All ())))
469
473
if expandedOutputLevel .Len () != pc .outputLevel .files .Len () {
470
474
return false
471
475
}
@@ -493,7 +497,7 @@ func (pc *pickedCompaction) grow(
493
497
// will expand the compaction to include c-d and g-h from L0. The
494
498
// bounds passed in are exclusive; the compaction cannot be expanded
495
499
// to include files that "touch" it.
496
- func (pc * pickedCompaction ) growL0ForBase (maxExpandedBytes uint64 ) bool {
500
+ func (pc * pickedCompaction ) growL0ForBase (cmp base. Compare , maxExpandedBytes uint64 ) bool {
497
501
if invariants .Enabled {
498
502
if pc .startLevel .level != 0 {
499
503
panic (fmt .Sprintf ("pc.startLevel.level is %d, expected 0" , pc .startLevel .level ))
@@ -503,10 +507,10 @@ func (pc *pickedCompaction) growL0ForBase(maxExpandedBytes uint64) bool {
503
507
largestBaseKey := base .InvalidInternalKey
504
508
if pc .outputLevel .files .Empty () {
505
509
baseIter := pc .version .Levels [pc .outputLevel .level ].Iter ()
506
- if sm := baseIter .SeekLT (pc . cmp , pc .smallest .UserKey ); sm != nil {
510
+ if sm := baseIter .SeekLT (cmp , pc .smallest .UserKey ); sm != nil {
507
511
smallestBaseKey = sm .Largest ()
508
512
}
509
- if la := baseIter .SeekGE (pc . cmp , pc .largest .UserKey ); la != nil {
513
+ if la := baseIter .SeekGE (cmp , pc .largest .UserKey ); la != nil {
510
514
largestBaseKey = la .Smallest ()
511
515
}
512
516
} else {
@@ -543,7 +547,7 @@ func (pc *pickedCompaction) growL0ForBase(maxExpandedBytes uint64) bool {
543
547
}
544
548
545
549
pc .startLevel .files = manifest .NewLevelSliceSeqSorted (newStartLevelFiles )
546
- pc .smallest , pc .largest = manifest .KeyRange (pc . cmp ,
550
+ pc .smallest , pc .largest = manifest .KeyRange (cmp ,
547
551
pc .startLevel .files .All (), pc .outputLevel .files .All ())
548
552
return true
549
553
}
@@ -1373,7 +1377,7 @@ func (p *compactionPickerByScore) pickAutoScore(env compactionEnv) (pc *pickedCo
1373
1377
pc = pickL0 (env , p .opts , p .vers , p .latestVersionState .l0Organizer , p .baseLevel )
1374
1378
// Fail-safe to protect against compacting the same sstable
1375
1379
// concurrently.
1376
- if pc != nil && ! inputRangeAlreadyCompacting (env , pc ) {
1380
+ if pc != nil && ! inputRangeAlreadyCompacting (p . opts . Comparer . Compare , env , pc ) {
1377
1381
p .addScoresToPickedCompactionMetrics (pc , scores )
1378
1382
pc .score = info .score
1379
1383
if false {
@@ -1393,7 +1397,7 @@ func (p *compactionPickerByScore) pickAutoScore(env compactionEnv) (pc *pickedCo
1393
1397
1394
1398
pc := pickAutoLPositive (env , p .opts , p .vers , p .latestVersionState .l0Organizer , * info , p .baseLevel )
1395
1399
// Fail-safe to protect against compacting the same sstable concurrently.
1396
- if pc != nil && ! inputRangeAlreadyCompacting (env , pc ) {
1400
+ if pc != nil && ! inputRangeAlreadyCompacting (p . opts . Comparer . Compare , env , pc ) {
1397
1401
p .addScoresToPickedCompactionMetrics (pc , scores )
1398
1402
pc .score = info .score
1399
1403
if false {
@@ -1579,10 +1583,10 @@ func (p *compactionPickerByScore) pickedCompactionFromCandidateFile(
1579
1583
startLevel , outputLevel , p .baseLevel )
1580
1584
pc .kind = kind
1581
1585
pc .startLevel .files = inputs
1582
- pc .smallest , pc .largest = manifest .KeyRange (pc . cmp , pc .startLevel .files .All ())
1586
+ pc .smallest , pc .largest = manifest .KeyRange (p . opts . Comparer . Compare , pc .startLevel .files .All ())
1583
1587
1584
1588
// Fail-safe to protect against compacting the same sstable concurrently.
1585
- if inputRangeAlreadyCompacting (env , pc ) {
1589
+ if inputRangeAlreadyCompacting (p . opts . Comparer . Compare , env , pc ) {
1586
1590
return nil
1587
1591
}
1588
1592
@@ -1881,7 +1885,7 @@ func pickL0(
1881
1885
}
1882
1886
// A single-file intra-L0 compaction is unproductive.
1883
1887
if iter := pc .startLevel .files .Iter (); iter .First () != nil && iter .Next () != nil {
1884
- pc .smallest , pc .largest = manifest .KeyRange (pc . cmp , pc .startLevel .files .All ())
1888
+ pc .smallest , pc .largest = manifest .KeyRange (opts . Comparer . Compare , pc .startLevel .files .All ())
1885
1889
return pc
1886
1890
}
1887
1891
} else {
@@ -1946,7 +1950,7 @@ func newPickedManualCompaction(
1946
1950
}
1947
1951
}
1948
1952
// Fail-safe to protect against compacting the same sstable concurrently.
1949
- if inputRangeAlreadyCompacting (env , pc ) {
1953
+ if inputRangeAlreadyCompacting (opts . Comparer . Compare , env , pc ) {
1950
1954
return nil , true
1951
1955
}
1952
1956
return pc , false
@@ -1984,7 +1988,7 @@ func pickDownloadCompaction(
1984
1988
panic ("pebble: download compaction picked unexpected output level" )
1985
1989
}
1986
1990
// Fail-safe to protect against compacting the same sstable concurrently.
1987
- if inputRangeAlreadyCompacting (env , pc ) {
1991
+ if inputRangeAlreadyCompacting (opts . Comparer . Compare , env , pc ) {
1988
1992
return nil
1989
1993
}
1990
1994
return pc
@@ -2030,7 +2034,7 @@ func pickReadTriggeredCompactionHelper(
2030
2034
if ! pc .setupInputs (p .opts , env .diskAvailBytes , pc .startLevel , env .problemSpans ) {
2031
2035
return nil
2032
2036
}
2033
- if inputRangeAlreadyCompacting (env , pc ) {
2037
+ if inputRangeAlreadyCompacting (p . opts . Comparer . Compare , env , pc ) {
2034
2038
return nil
2035
2039
}
2036
2040
pc .kind = compactionKindRead
@@ -2055,7 +2059,7 @@ func (p *compactionPickerByScore) forceBaseLevel1() {
2055
2059
p .baseLevel = 1
2056
2060
}
2057
2061
2058
- func inputRangeAlreadyCompacting (env compactionEnv , pc * pickedCompaction ) bool {
2062
+ func inputRangeAlreadyCompacting (cmp base. Compare , env compactionEnv , pc * pickedCompaction ) bool {
2059
2063
for _ , cl := range pc .inputs {
2060
2064
for f := range cl .files .All () {
2061
2065
if f .IsCompacting () {
@@ -2097,8 +2101,8 @@ func inputRangeAlreadyCompacting(env compactionEnv, pc *pickedCompaction) bool {
2097
2101
if pc .outputLevel .level != c .outputLevel {
2098
2102
continue
2099
2103
}
2100
- if base .InternalCompare (pc . cmp , c .largest , pc .smallest ) < 0 ||
2101
- base .InternalCompare (pc . cmp , c .smallest , pc .largest ) > 0 {
2104
+ if base .InternalCompare (cmp , c .largest , pc .smallest ) < 0 ||
2105
+ base .InternalCompare (cmp , c .smallest , pc .largest ) > 0 {
2102
2106
continue
2103
2107
}
2104
2108
0 commit comments