@@ -36,8 +36,6 @@ type levelIter struct {
36
36
ctx context.Context
37
37
logger Logger
38
38
comparer * Comparer
39
- cmp Compare
40
- split Split
41
39
// The lower/upper bounds for iteration as specified at creation or the most
42
40
// recent call to SetBounds.
43
41
lower []byte
@@ -161,8 +159,6 @@ func (l *levelIter) init(
161
159
l .tableOpts .layer = l .layer
162
160
l .tableOpts .snapshotForHideObsoletePoints = opts .snapshotForHideObsoletePoints
163
161
l .comparer = comparer
164
- l .cmp = comparer .Compare
165
- l .split = comparer .Split
166
162
l .iterFile = nil
167
163
l .newIters = newIters
168
164
l .files = files
@@ -204,11 +200,11 @@ func (l *levelIter) maybeTriggerCombinedIteration(file *manifest.TableMetadata,
204
200
return
205
201
}
206
202
207
- if l .upper != nil && l .cmp (file .RangeKeyBounds .SmallestUserKey (), l .upper ) >= 0 {
203
+ if l .upper != nil && l .comparer . Compare (file .RangeKeyBounds .SmallestUserKey (), l .upper ) >= 0 {
208
204
// Range key bounds are above the upper iteration bound.
209
205
return
210
206
}
211
- if l .lower != nil && l .cmp (file .RangeKeyBounds .LargestUserKey (), l .lower ) <= 0 {
207
+ if l .lower != nil && l .comparer . Compare (file .RangeKeyBounds .LargestUserKey (), l .lower ) <= 0 {
212
208
// Range key bounds are below the lower iteration bound.
213
209
return
214
210
}
@@ -238,14 +234,14 @@ func (l *levelIter) maybeTriggerCombinedIteration(file *manifest.TableMetadata,
238
234
if ! l .combinedIterState .triggered {
239
235
l .combinedIterState .triggered = true
240
236
l .combinedIterState .key = file .RangeKeyBounds .SmallestUserKey ()
241
- } else if l .cmp (l .combinedIterState .key , file .RangeKeyBounds .SmallestUserKey ()) > 0 {
237
+ } else if l .comparer . Compare (l .combinedIterState .key , file .RangeKeyBounds .SmallestUserKey ()) > 0 {
242
238
l .combinedIterState .key = file .RangeKeyBounds .SmallestUserKey ()
243
239
}
244
240
case - 1 :
245
241
if ! l .combinedIterState .triggered {
246
242
l .combinedIterState .triggered = true
247
243
l .combinedIterState .key = file .RangeKeyBounds .LargestUserKey ()
248
- } else if l .cmp (l .combinedIterState .key , file .RangeKeyBounds .LargestUserKey ()) < 0 {
244
+ } else if l .comparer . Compare (l .combinedIterState .key , file .RangeKeyBounds .LargestUserKey ()) < 0 {
249
245
l .combinedIterState .key = file .RangeKeyBounds .LargestUserKey ()
250
246
}
251
247
}
@@ -315,7 +311,7 @@ func (l *levelIter) findFileGE(key []byte, flags base.SeekGEFlags) *manifest.Tab
315
311
if nextInsteadOfSeek {
316
312
m = l .iterFile
317
313
} else {
318
- m = l .files .SeekGE (l .cmp , key )
314
+ m = l .files .SeekGE (l .comparer . Compare , key )
319
315
}
320
316
// The below loop has a bit of an unusual organization. There are several
321
317
// conditions under which we need to Next to a later file. If none of those
@@ -348,14 +344,14 @@ func (l *levelIter) findFileGE(key []byte, flags base.SeekGEFlags) *manifest.Tab
348
344
//
349
345
// If the file does not contain point keys ≥ `key`, next to continue
350
346
// looking for a file that does.
351
- if (m .HasRangeKeys || nextInsteadOfSeek ) && l .cmp (m .PointKeyBounds .LargestUserKey (), key ) < 0 {
347
+ if (m .HasRangeKeys || nextInsteadOfSeek ) && l .comparer . Compare (m .PointKeyBounds .LargestUserKey (), key ) < 0 {
352
348
// If nextInsteadOfSeek is set and nextsUntilSeek is non-negative,
353
349
// the iterator has been nexting hoping to discover the relevant
354
350
// file without seeking. It's exhausted the allotted nextsUntilSeek
355
351
// and should seek to the sought key.
356
352
if nextInsteadOfSeek && nextsUntilSeek == 0 {
357
353
nextInsteadOfSeek = false
358
- m = l .files .SeekGE (l .cmp , key )
354
+ m = l .files .SeekGE (l .comparer . Compare , key )
359
355
continue
360
356
} else if nextsUntilSeek > 0 {
361
357
nextsUntilSeek --
@@ -374,7 +370,7 @@ func (l *levelIter) findFileGE(key []byte, flags base.SeekGEFlags) *manifest.Tab
374
370
// a table which can't possibly contain the target key and is required
375
371
// for correctness by mergingIter.SeekGE (see the comment in that
376
372
// function).
377
- if m .PointKeyBounds .Largest ().IsExclusiveSentinel () && l .cmp (m .PointKeyBounds .LargestUserKey (), key ) == 0 {
373
+ if m .PointKeyBounds .Largest ().IsExclusiveSentinel () && l .comparer . Compare (m .PointKeyBounds .LargestUserKey (), key ) == 0 {
378
374
m = l .files .Next ()
379
375
continue
380
376
}
@@ -406,7 +402,7 @@ func (l *levelIter) findFileLT(key []byte, flags base.SeekLTFlags) *manifest.Tab
406
402
if prevInsteadOfSeek {
407
403
m = l .iterFile
408
404
} else {
409
- m = l .files .SeekLT (l .cmp , key )
405
+ m = l .files .SeekLT (l .comparer . Compare , key )
410
406
}
411
407
// The below loop has a bit of an unusual organization. There are several
412
408
// conditions under which we need to Prev to a previous file. If none of
@@ -439,7 +435,7 @@ func (l *levelIter) findFileLT(key []byte, flags base.SeekLTFlags) *manifest.Tab
439
435
//
440
436
// If the file does not contain point keys < `key`, prev to continue
441
437
// looking for a file that does.
442
- if (m .HasRangeKeys || prevInsteadOfSeek ) && l .cmp (m .PointKeyBounds .SmallestUserKey (), key ) >= 0 {
438
+ if (m .HasRangeKeys || prevInsteadOfSeek ) && l .comparer . Compare (m .PointKeyBounds .SmallestUserKey (), key ) >= 0 {
443
439
m = l .files .Prev ()
444
440
continue
445
441
}
@@ -456,11 +452,11 @@ func (l *levelIter) findFileLT(key []byte, flags base.SeekLTFlags) *manifest.Tab
456
452
func (l * levelIter ) initTableBounds (f * manifest.TableMetadata ) int {
457
453
l .tableOpts .LowerBound = l .lower
458
454
if l .tableOpts .LowerBound != nil {
459
- if l .cmp (f .PointKeyBounds .LargestUserKey (), l .tableOpts .LowerBound ) < 0 {
455
+ if l .comparer . Compare (f .PointKeyBounds .LargestUserKey (), l .tableOpts .LowerBound ) < 0 {
460
456
// The largest key in the sstable is smaller than the lower bound.
461
457
return - 1
462
458
}
463
- if l .cmp (l .tableOpts .LowerBound , f .PointKeyBounds .SmallestUserKey ()) <= 0 {
459
+ if l .comparer . Compare (l .tableOpts .LowerBound , f .PointKeyBounds .SmallestUserKey ()) <= 0 {
464
460
// The lower bound is smaller or equal to the smallest key in the
465
461
// table. Iteration within the table does not need to check the lower
466
462
// bound.
@@ -469,12 +465,12 @@ func (l *levelIter) initTableBounds(f *manifest.TableMetadata) int {
469
465
}
470
466
l .tableOpts .UpperBound = l .upper
471
467
if l .tableOpts .UpperBound != nil {
472
- if l .cmp (f .PointKeyBounds .SmallestUserKey (), l .tableOpts .UpperBound ) >= 0 {
468
+ if l .comparer . Compare (f .PointKeyBounds .SmallestUserKey (), l .tableOpts .UpperBound ) >= 0 {
473
469
// The smallest key in the sstable is greater than or equal to the upper
474
470
// bound.
475
471
return 1
476
472
}
477
- if l .cmp (l .tableOpts .UpperBound , f .PointKeyBounds .LargestUserKey ()) > 0 {
473
+ if l .comparer . Compare (l .tableOpts .UpperBound , f .PointKeyBounds .LargestUserKey ()) > 0 {
478
474
// The upper bound is greater than the largest key in the
479
475
// table. Iteration within the table does not need to check the upper
480
476
// bound. NB: tableOpts.UpperBound is exclusive and f.PointKeyBounds.Largest() is
@@ -564,7 +560,7 @@ func (l *levelIter) loadFile(file *manifest.TableMetadata, dir int) loadFileRetu
564
560
// any keys within the iteration prefix. Loading the next file is
565
561
// unnecessary. This has been observed in practice on slow shared
566
562
// storage. See #3575.
567
- if l .prefix != nil && l .cmp (l .split .Prefix (file .PointKeyBounds .SmallestUserKey ()), l .prefix ) > 0 {
563
+ if l .prefix != nil && l .comparer . Compare (l .comparer . Split .Prefix (file .PointKeyBounds .SmallestUserKey ()), l .prefix ) > 0 {
568
564
// Note that because l.iter is nil, a subsequent call to
569
565
// SeekPrefixGE with TrySeekUsingNext()=true will load the file
570
566
// (returning newFileLoaded) and disable TrySeekUsingNext before
@@ -625,18 +621,18 @@ func (l *levelIter) verify(kv *base.InternalKV) *base.InternalKV {
625
621
// We allow returning a boundary key that is outside of the lower/upper
626
622
// bounds as such keys are always range tombstones which will be skipped
627
623
// by the Iterator.
628
- if l .lower != nil && kv != nil && ! kv .K .IsExclusiveSentinel () && l .cmp (kv .K .UserKey , l .lower ) < 0 {
624
+ if l .lower != nil && kv != nil && ! kv .K .IsExclusiveSentinel () && l .comparer . Compare (kv .K .UserKey , l .lower ) < 0 {
629
625
l .logger .Fatalf ("levelIter %s: lower bound violation: %s < %s\n %s" , l .layer , kv , l .lower , debug .Stack ())
630
626
}
631
- if l .upper != nil && kv != nil && ! kv .K .IsExclusiveSentinel () && l .cmp (kv .K .UserKey , l .upper ) > 0 {
627
+ if l .upper != nil && kv != nil && ! kv .K .IsExclusiveSentinel () && l .comparer . Compare (kv .K .UserKey , l .upper ) > 0 {
632
628
l .logger .Fatalf ("levelIter %s: upper bound violation: %s > %s\n %s" , l .layer , kv , l .upper , debug .Stack ())
633
629
}
634
630
}
635
631
return kv
636
632
}
637
633
638
634
func (l * levelIter ) SeekGE (key []byte , flags base.SeekGEFlags ) * base.InternalKV {
639
- if invariants .Enabled && l .lower != nil && l .cmp (key , l .lower ) < 0 {
635
+ if invariants .Enabled && l .lower != nil && l .comparer . Compare (key , l .lower ) < 0 {
640
636
panic (errors .AssertionFailedf ("levelIter SeekGE to key %q violates lower bound %q" , key , l .lower ))
641
637
}
642
638
@@ -662,7 +658,7 @@ func (l *levelIter) SeekGE(key []byte, flags base.SeekGEFlags) *base.InternalKV
662
658
}
663
659
664
660
func (l * levelIter ) SeekPrefixGE (prefix , key []byte , flags base.SeekGEFlags ) * base.InternalKV {
665
- if invariants .Enabled && l .lower != nil && l .cmp (key , l .lower ) < 0 {
661
+ if invariants .Enabled && l .lower != nil && l .comparer . Compare (key , l .lower ) < 0 {
666
662
panic (errors .AssertionFailedf ("levelIter SeekGE to key %q violates lower bound %q" , key , l .lower ))
667
663
}
668
664
l .err = nil // clear cached iteration error
@@ -691,7 +687,7 @@ func (l *levelIter) SeekPrefixGE(prefix, key []byte, flags base.SeekGEFlags) *ba
691
687
}
692
688
693
689
func (l * levelIter ) SeekLT (key []byte , flags base.SeekLTFlags ) * base.InternalKV {
694
- if invariants .Enabled && l .upper != nil && l .cmp (key , l .upper ) > 0 {
690
+ if invariants .Enabled && l .upper != nil && l .comparer . Compare (key , l .upper ) > 0 {
695
691
panic (errors .AssertionFailedf ("levelIter SeekLT to key %q violates upper bound %q" , key , l .upper ))
696
692
}
697
693
@@ -853,7 +849,7 @@ func (l *levelIter) skipEmptyFileForward() *base.InternalKV {
853
849
// subsequent SeekPrefixGE with TrySeekUsingNext could mistakenly skip
854
850
// the file's relevant keys.
855
851
if l .prefix != nil {
856
- if l .cmp (l .split .Prefix (l .iterFile .PointKeyBounds .LargestUserKey ()), l .prefix ) > 0 {
852
+ if l .comparer . Compare (l .comparer . Split .Prefix (l .iterFile .PointKeyBounds .LargestUserKey ()), l .prefix ) > 0 {
857
853
l .exhaustedForward ()
858
854
return nil
859
855
}
0 commit comments