8
8
"bytes"
9
9
"context"
10
10
"fmt"
11
- "iter"
12
11
"math"
13
12
"runtime/pprof"
14
13
"slices"
@@ -263,8 +262,7 @@ type compaction struct {
263
262
bytesWritten atomic.Int64
264
263
265
264
// The boundaries of the input data.
266
- smallest InternalKey
267
- largest InternalKey
265
+ bounds base.UserKeyBounds
268
266
269
267
// A list of fragment iterators to close when the compaction finishes. Used by
270
268
// input iteration to keep rangeDelIters open for the lifetime of the
@@ -364,10 +362,6 @@ func (c *compaction) makeInfo(jobID JobID) CompactionInfo {
364
362
return info
365
363
}
366
364
367
- func (c * compaction ) userKeyBounds () base.UserKeyBounds {
368
- return base .UserKeyBoundsFromInternal (c .smallest , c .largest )
369
- }
370
-
371
365
type getValueSeparation func (JobID , * compaction , sstable.TableFormat ) compact.ValueSeparation
372
366
373
367
// newCompaction constructs a compaction from the provided picked compaction.
@@ -390,8 +384,7 @@ func newCompaction(
390
384
comparer : opts .Comparer ,
391
385
formatKey : opts .Comparer .FormatKey ,
392
386
inputs : pc .inputs ,
393
- smallest : pc .smallest ,
394
- largest : pc .largest ,
387
+ bounds : pc .bounds ,
395
388
logger : opts .Logger ,
396
389
version : pc .version ,
397
390
beganAt : beganAt ,
@@ -434,10 +427,10 @@ func newCompaction(
434
427
// Compute the set of outputLevel+1 files that overlap this compaction (these
435
428
// are the grandparent sstables).
436
429
if c .outputLevel .level + 1 < numLevels {
437
- c .grandparents = c .version .Overlaps (c .outputLevel .level + 1 , c .userKeyBounds () )
430
+ c .grandparents = c .version .Overlaps (c .outputLevel .level + 1 , c .bounds )
438
431
}
439
432
c .delElision , c .rangeKeyElision = compact .SetupTombstoneElision (
440
- c .cmp , c .version , pc .l0Organizer , c .outputLevel .level , base . UserKeyBoundsFromInternal ( c . smallest , c . largest ) ,
433
+ c .cmp , c .version , pc .l0Organizer , c .outputLevel .level , c . bounds ,
441
434
)
442
435
c .kind = pc .kind
443
436
@@ -568,11 +561,10 @@ func newDeleteOnlyCompaction(
568
561
c .version .Ref ()
569
562
570
563
// Set c.smallest, c.largest.
571
- files := make ([]iter. Seq [ * manifest. TableMetadata ], 0 , len ( inputs ))
564
+ cmp := opts . Comparer . Compare
572
565
for _ , in := range inputs {
573
- files = append ( files , in .files .All ())
566
+ c . bounds = manifest . ExtendKeyRange ( cmp , c . bounds , in .files .All ())
574
567
}
575
- c .smallest , c .largest = manifest .KeyRange (opts .Comparer .Compare , files ... )
576
568
return c
577
569
}
578
570
@@ -713,20 +705,15 @@ func newFlush(
713
705
714
706
c .l0Limits = l0Organizer .FlushSplitKeys ()
715
707
716
- smallestSet , largestSet := false , false
717
708
updatePointBounds := func (iter internalIterator ) {
718
709
if kv := iter .First (); kv != nil {
719
- if ! smallestSet ||
720
- base .InternalCompare (c .cmp , c .smallest , kv .K ) > 0 {
721
- smallestSet = true
722
- c .smallest = kv .K .Clone ()
710
+ if c .bounds .Start == nil || c .cmp (c .bounds .Start , kv .K .UserKey ) > 0 {
711
+ c .bounds .Start = slices .Clone (kv .K .UserKey )
723
712
}
724
713
}
725
714
if kv := iter .Last (); kv != nil {
726
- if ! largestSet ||
727
- base .InternalCompare (c .cmp , c .largest , kv .K ) < 0 {
728
- largestSet = true
729
- c .largest = kv .K .Clone ()
715
+ if c .bounds .End .Key == nil || ! c .bounds .End .IsUpperBoundForInternalKey (c .cmp , kv .K ) {
716
+ c .bounds .End = base .UserKeyExclusiveIf (slices .Clone (kv .K .UserKey ), kv .K .IsExclusiveSentinel ())
730
717
}
731
718
}
732
719
}
@@ -738,20 +725,12 @@ func newFlush(
738
725
if s , err := iter .First (); err != nil {
739
726
return err
740
727
} else if s != nil {
741
- if key := s .SmallestKey (); ! smallestSet ||
742
- base .InternalCompare (c .cmp , c .smallest , key ) > 0 {
743
- smallestSet = true
744
- c .smallest = key .Clone ()
745
- }
728
+ c .bounds = c .bounds .Union (c .cmp , s .Bounds ().Clone ())
746
729
}
747
730
if s , err := iter .Last (); err != nil {
748
731
return err
749
732
} else if s != nil {
750
- if key := s .LargestKey (); ! largestSet ||
751
- base .InternalCompare (c .cmp , c .largest , key ) < 0 {
752
- largestSet = true
753
- c .largest = key .Clone ()
754
- }
733
+ c .bounds = c .bounds .Union (c .cmp , s .Bounds ().Clone ())
755
734
}
756
735
return nil
757
736
}
@@ -776,7 +755,7 @@ func newFlush(
776
755
if opts .FlushSplitBytes > 0 {
777
756
c .maxOutputFileSize = uint64 (opts .Levels [0 ].TargetFileSize )
778
757
c .maxOverlapBytes = maxGrandparentOverlapBytes (opts , 0 )
779
- c .grandparents = c .version .Overlaps (baseLevel , c .userKeyBounds () )
758
+ c .grandparents = c .version .Overlaps (baseLevel , c .bounds )
780
759
adjustGrandparentOverlapBytesForFlush (c , flushingBytes )
781
760
}
782
761
@@ -1665,6 +1644,7 @@ func (d *DB) flush1() (bytesFlushed uint64, err error) {
1665
1644
// c.kind == compactionKindIngestedFlushable && we could have deleted files due
1666
1645
// to ingest-time splits or excises.
1667
1646
ingestFlushable := c .flushing [0 ].flushable .(* ingestedFlushable )
1647
+ exciseBounds := ingestFlushable .exciseSpan .UserKeyBounds ()
1668
1648
for c2 := range d .mu .compact .inProgress {
1669
1649
// Check if this compaction overlaps with the excise span. Note that just
1670
1650
// checking if the inputs individually overlap with the excise span
@@ -1673,7 +1653,7 @@ func (d *DB) flush1() (bytesFlushed uint64, err error) {
1673
1653
// doing a [c,d) excise at the same time as this compaction, we will have
1674
1654
// to error out the whole compaction as we can't guarantee it hasn't/won't
1675
1655
// write a file overlapping with the excise span.
1676
- if ingestFlushable . exciseSpan . OverlapsInternalKeyRange (d .cmp , c2 . smallest , c2 . largest ) {
1656
+ if c2 . bounds . Overlaps (d .cmp , & exciseBounds ) {
1677
1657
c2 .cancel .Store (true )
1678
1658
}
1679
1659
}
@@ -2452,7 +2432,7 @@ func (d *DB) compactionPprofLabels(c *compaction) pprof.LabelSet {
2452
2432
level = fmt .Sprintf ("L%d" , c .outputLevel .level )
2453
2433
}
2454
2434
if kc := d .opts .Experimental .UserKeyCategories ; kc .Len () > 0 {
2455
- cat := kc .CategorizeKeyRange (c .smallest . UserKey , c .largest . UserKey )
2435
+ cat := kc .CategorizeKeyRange (c .bounds . Start , c .bounds . End . Key )
2456
2436
return pprof .Labels ("pebble" , activity , "output-level" , level , "key-type" , cat )
2457
2437
}
2458
2438
return pprof .Labels ("pebble" , activity , "output-level" , level )
@@ -3270,7 +3250,7 @@ func (d *DB) compactAndWrite(
3270
3250
iter := compact .NewIter (cfg , pointIter , rangeDelIter , rangeKeyIter )
3271
3251
3272
3252
runnerCfg := compact.RunnerConfig {
3273
- CompactionBounds : base . UserKeyBoundsFromInternal ( c . smallest , c . largest ) ,
3253
+ CompactionBounds : c . bounds ,
3274
3254
L0SplitKeys : c .l0Limits ,
3275
3255
Grandparents : c .grandparents ,
3276
3256
MaxGrandparentOverlapBytes : c .maxOverlapBytes ,
0 commit comments