@@ -198,14 +198,11 @@ type compaction struct {
198
198
// compactionKindRewrite.
199
199
isDownload bool
200
200
201
- cmp Compare
202
- equal Equal
203
- comparer * base.Comparer
204
- formatKey base.FormatKey
205
- logger Logger
206
- version * manifest.Version
207
- stats base.InternalIteratorStats
208
- beganAt time.Time
201
+ comparer * base.Comparer
202
+ logger Logger
203
+ version * manifest.Version
204
+ stats base.InternalIteratorStats
205
+ beganAt time.Time
209
206
// versionEditApplied is set to true when a compaction has completed and the
210
207
// resulting version has been installed (if successful), but the compaction
211
208
// goroutine is still cleaning up (eg, deleting obsolete files).
@@ -379,10 +376,7 @@ func newCompaction(
379
376
) * compaction {
380
377
c := & compaction {
381
378
kind : compactionKindDefault ,
382
- cmp : opts .Comparer .Compare ,
383
- equal : opts .Comparer .Equal ,
384
379
comparer : opts .Comparer ,
385
- formatKey : opts .Comparer .FormatKey ,
386
380
inputs : pc .inputs ,
387
381
bounds : pc .bounds ,
388
382
logger : opts .Logger ,
@@ -430,7 +424,7 @@ func newCompaction(
430
424
c .grandparents = c .version .Overlaps (c .outputLevel .level + 1 , c .bounds )
431
425
}
432
426
c .delElision , c .rangeKeyElision = compact .SetupTombstoneElision (
433
- c .cmp , c .version , pc .l0Organizer , c .outputLevel .level , c .bounds ,
427
+ c .comparer . Compare , c .version , pc .l0Organizer , c .outputLevel .level , c .bounds ,
434
428
)
435
429
c .kind = pc .kind
436
430
@@ -533,10 +527,7 @@ func newDeleteOnlyCompaction(
533
527
) * compaction {
534
528
c := & compaction {
535
529
kind : compactionKindDeleteOnly ,
536
- cmp : opts .Comparer .Compare ,
537
- equal : opts .Comparer .Equal ,
538
530
comparer : opts .Comparer ,
539
- formatKey : opts .Comparer .FormatKey ,
540
531
logger : opts .Logger ,
541
532
version : cur ,
542
533
beganAt : beganAt ,
@@ -658,10 +649,7 @@ func newFlush(
658
649
) (* compaction , error ) {
659
650
c := & compaction {
660
651
kind : compactionKindFlush ,
661
- cmp : opts .Comparer .Compare ,
662
- equal : opts .Comparer .Equal ,
663
652
comparer : opts .Comparer ,
664
- formatKey : opts .Comparer .FormatKey ,
665
653
logger : opts .Logger ,
666
654
version : cur ,
667
655
beganAt : beganAt ,
@@ -705,14 +693,15 @@ func newFlush(
705
693
706
694
c .l0Limits = l0Organizer .FlushSplitKeys ()
707
695
696
+ cmp := c .comparer .Compare
708
697
updatePointBounds := func (iter internalIterator ) {
709
698
if kv := iter .First (); kv != nil {
710
- if c .bounds .Start == nil || c . cmp (c .bounds .Start , kv .K .UserKey ) > 0 {
699
+ if c .bounds .Start == nil || cmp (c .bounds .Start , kv .K .UserKey ) > 0 {
711
700
c .bounds .Start = slices .Clone (kv .K .UserKey )
712
701
}
713
702
}
714
703
if kv := iter .Last (); kv != nil {
715
- if c .bounds .End .Key == nil || ! c .bounds .End .IsUpperBoundForInternalKey (c . cmp , kv .K ) {
704
+ if c .bounds .End .Key == nil || ! c .bounds .End .IsUpperBoundForInternalKey (cmp , kv .K ) {
716
705
c .bounds .End = base .UserKeyExclusiveIf (slices .Clone (kv .K .UserKey ), kv .K .IsExclusiveSentinel ())
717
706
}
718
707
}
@@ -725,12 +714,12 @@ func newFlush(
725
714
if s , err := iter .First (); err != nil {
726
715
return err
727
716
} else if s != nil {
728
- c .bounds = c .bounds .Union (c . cmp , s .Bounds ().Clone ())
717
+ c .bounds = c .bounds .Union (cmp , s .Bounds ().Clone ())
729
718
}
730
719
if s , err := iter .Last (); err != nil {
731
720
return err
732
721
} else if s != nil {
733
- c .bounds = c .bounds .Union (c . cmp , s .Bounds ().Clone ())
722
+ c .bounds = c .bounds .Union (cmp , s .Bounds ().Clone ())
734
723
}
735
724
return nil
736
725
}
@@ -785,9 +774,9 @@ func (c *compaction) errorOnUserKeyOverlap(ve *manifest.VersionEdit) error {
785
774
meta := ve .NewTables [n - 1 ].Meta
786
775
prevMeta := ve .NewTables [n - 2 ].Meta
787
776
if ! prevMeta .Largest ().IsExclusiveSentinel () &&
788
- c .cmp (prevMeta .Largest ().UserKey , meta .Smallest ().UserKey ) >= 0 {
777
+ c .comparer . Compare (prevMeta .Largest ().UserKey , meta .Smallest ().UserKey ) >= 0 {
789
778
return errors .Errorf ("pebble: compaction split user key across two sstables: %s in %s and %s" ,
790
- prevMeta .Largest ().Pretty (c .formatKey ),
779
+ prevMeta .Largest ().Pretty (c .comparer . FormatKey ),
791
780
prevMeta .TableNum ,
792
781
meta .TableNum )
793
782
}
@@ -819,17 +808,19 @@ func (c *compaction) newInputIters(
819
808
rangeDelIter , rangeKeyIter keyspan.FragmentIterator ,
820
809
retErr error ,
821
810
) {
811
+ cmp := c .comparer .Compare
812
+
822
813
// Validate the ordering of compaction input files for defense in depth.
823
814
if len (c .flushing ) == 0 {
824
815
if c .startLevel .level >= 0 {
825
- err := manifest .CheckOrdering (c .cmp , c . formatKey ,
826
- manifest . Level ( c . startLevel . level ), c .startLevel .files .Iter ())
816
+ err := manifest .CheckOrdering (c .comparer , manifest . Level ( c . startLevel . level ) ,
817
+ c .startLevel .files .Iter ())
827
818
if err != nil {
828
819
return nil , nil , nil , err
829
820
}
830
821
}
831
- err := manifest .CheckOrdering (c .cmp , c . formatKey ,
832
- manifest . Level ( c . outputLevel . level ), c .outputLevel .files .Iter ())
822
+ err := manifest .CheckOrdering (c .comparer , manifest . Level ( c . outputLevel . level ) ,
823
+ c .outputLevel .files .Iter ())
833
824
if err != nil {
834
825
return nil , nil , nil , err
835
826
}
@@ -838,8 +829,7 @@ func (c *compaction) newInputIters(
838
829
panic ("l0SublevelInfo not created for compaction out of L0" )
839
830
}
840
831
for _ , info := range c .startLevel .l0SublevelInfo {
841
- err := manifest .CheckOrdering (c .cmp , c .formatKey ,
842
- info .sublevel , info .Iter ())
832
+ err := manifest .CheckOrdering (c .comparer , info .sublevel , info .Iter ())
843
833
if err != nil {
844
834
return nil , nil , nil , err
845
835
}
@@ -850,8 +840,8 @@ func (c *compaction) newInputIters(
850
840
panic ("n>2 multi level compaction not implemented yet" )
851
841
}
852
842
interLevel := c .extraLevels [0 ]
853
- err := manifest .CheckOrdering (c .cmp , c . formatKey ,
854
- manifest . Level ( interLevel . level ), interLevel .files .Iter ())
843
+ err := manifest .CheckOrdering (c .comparer , manifest . Level ( interLevel . level ) ,
844
+ interLevel .files .Iter ())
855
845
if err != nil {
856
846
return nil , nil , nil , err
857
847
}
@@ -996,7 +986,7 @@ func (c *compaction) newInputIters(
996
986
return noCloseIter , err
997
987
}
998
988
li := keyspanimpl .NewLevelIter (
999
- context .Background (), keyspan.SpanIterOptions {}, c . cmp ,
989
+ context .Background (), keyspan.SpanIterOptions {}, cmp ,
1000
990
newRangeKeyIterWrapper , level .files .Iter (), l , manifest .KeyTypeRange ,
1001
991
)
1002
992
rangeKeyIters = append (rangeKeyIters , li )
@@ -1030,7 +1020,7 @@ func (c *compaction) newInputIters(
1030
1020
// iter.
1031
1021
pointIter = iters [0 ]
1032
1022
if len (iters ) > 1 {
1033
- pointIter = newMergingIter (c .logger , & c .stats , c . cmp , nil , iters ... )
1023
+ pointIter = newMergingIter (c .logger , & c .stats , cmp , nil , iters ... )
1034
1024
}
1035
1025
1036
1026
// In normal operation, levelIter iterates over the point operations in a
@@ -2723,10 +2713,14 @@ func (d *DB) runCopyCompaction(
2723
2713
SyntheticPrefixAndSuffix : inputMeta .SyntheticPrefixAndSuffix ,
2724
2714
}
2725
2715
if inputMeta .HasPointKeys {
2726
- newMeta .ExtendPointKeyBounds (c .cmp , inputMeta .PointKeyBounds .Smallest (), inputMeta .PointKeyBounds .Largest ())
2716
+ newMeta .ExtendPointKeyBounds (c .comparer .Compare ,
2717
+ inputMeta .PointKeyBounds .Smallest (),
2718
+ inputMeta .PointKeyBounds .Largest ())
2727
2719
}
2728
2720
if inputMeta .HasRangeKeys {
2729
- newMeta .ExtendRangeKeyBounds (c .cmp , inputMeta .RangeKeyBounds .Smallest (), inputMeta .RangeKeyBounds .Largest ())
2721
+ newMeta .ExtendRangeKeyBounds (c .comparer .Compare ,
2722
+ inputMeta .RangeKeyBounds .Smallest (),
2723
+ inputMeta .RangeKeyBounds .Largest ())
2730
2724
}
2731
2725
newMeta .TableNum = d .mu .versions .getNextTableNum ()
2732
2726
if objMeta .IsExternal () {
@@ -3393,13 +3387,19 @@ func (c *compaction) makeVersionEdit(result compact.Result) (*manifest.VersionEd
3393
3387
)
3394
3388
3395
3389
if t .WriterMeta .HasPointKeys {
3396
- fileMeta .ExtendPointKeyBounds (c .cmp , t .WriterMeta .SmallestPoint , t .WriterMeta .LargestPoint )
3390
+ fileMeta .ExtendPointKeyBounds (c .comparer .Compare ,
3391
+ t .WriterMeta .SmallestPoint ,
3392
+ t .WriterMeta .LargestPoint )
3397
3393
}
3398
3394
if t .WriterMeta .HasRangeDelKeys {
3399
- fileMeta .ExtendPointKeyBounds (c .cmp , t .WriterMeta .SmallestRangeDel , t .WriterMeta .LargestRangeDel )
3395
+ fileMeta .ExtendPointKeyBounds (c .comparer .Compare ,
3396
+ t .WriterMeta .SmallestRangeDel ,
3397
+ t .WriterMeta .LargestRangeDel )
3400
3398
}
3401
3399
if t .WriterMeta .HasRangeKeys {
3402
- fileMeta .ExtendRangeKeyBounds (c .cmp , t .WriterMeta .SmallestRangeKey , t .WriterMeta .LargestRangeKey )
3400
+ fileMeta .ExtendRangeKeyBounds (c .comparer .Compare ,
3401
+ t .WriterMeta .SmallestRangeKey ,
3402
+ t .WriterMeta .LargestRangeKey )
3403
3403
}
3404
3404
3405
3405
ve .NewTables [i ] = manifest.NewTableEntry {
@@ -3425,10 +3425,10 @@ func (c *compaction) makeVersionEdit(result compact.Result) (*manifest.VersionEd
3425
3425
3426
3426
// Sanity check that the tables are ordered and don't overlap.
3427
3427
for i := 1 ; i < len (ve .NewTables ); i ++ {
3428
- if ve .NewTables [i - 1 ].Meta .UserKeyBounds ().End . IsUpperBoundFor (c .cmp , ve .NewTables [i ].Meta .Smallest ().UserKey ) {
3428
+ if ve .NewTables [i - 1 ].Meta .Largest ().IsUpperBoundFor (c .comparer . Compare , ve .NewTables [i ].Meta .Smallest ().UserKey ) {
3429
3429
return nil , base .AssertionFailedf ("pebble: compaction output tables overlap: %s and %s" ,
3430
- ve .NewTables [i - 1 ].Meta .DebugString (c .formatKey , true ),
3431
- ve .NewTables [i ].Meta .DebugString (c .formatKey , true ),
3430
+ ve .NewTables [i - 1 ].Meta .DebugString (c .comparer . FormatKey , true ),
3431
+ ve .NewTables [i ].Meta .DebugString (c .comparer . FormatKey , true ),
3432
3432
)
3433
3433
}
3434
3434
}
0 commit comments