@@ -454,23 +454,45 @@ func IterateReplicaKeySpans(
454
454
}
455
455
456
456
// IterateReplicaKeySpansShared is a shared-replicate version of
457
- // IterateReplicaKeySpans. See definitions of this method for how it is
458
- // implemented.
457
+ // IterateReplicaKeySpans. IterateReplicaKeySpansShared iterates over the
458
+ // range's user key span, skipping any keys present in shared files. It calls
459
+ // the appropriate visitor function for the type of key visited, namely, point
460
+ // keys, range deletes and range keys. Shared files that are skipped during this
461
+ // iteration are also surfaced through a dedicated visitor. Note that this
462
+ // method only iterates over a range's user key span; IterateReplicaKeySpans
463
+ // must be called to iterate over the other key spans.
459
464
//
460
- // The impl of this method along with a comment is in
461
- // engineccl/shared_storage.go.
462
- var IterateReplicaKeySpansShared func (
465
+ // If this method returns pebble.ErrInvalidSkipSharedIteration, only the shared
466
+ // external visitors may have been invoked. In particular, no local data has
467
+ // been visited yet. The above contract appears true for the current
468
+ // implementation of this method, but is likely untested.
469
+ //
470
+ // Must use a reader with consistent iterators.
471
+ func IterateReplicaKeySpansShared (
463
472
ctx context.Context ,
464
473
desc * roachpb.RangeDescriptor ,
465
474
st * cluster.Settings ,
466
- clusterID uuid.UUID ,
475
+ _ uuid.UUID ,
467
476
reader storage.Reader ,
468
477
visitPoint func (key * pebble.InternalKey , val pebble.LazyValue , info pebble.IteratorLevel ) error ,
469
478
visitRangeDel func (start , end []byte , seqNum pebble.SeqNum ) error ,
470
479
visitRangeKey func (start , end []byte , keys []rangekey.Key ) error ,
471
480
visitSharedFile func (sst * pebble.SharedSSTMeta ) error ,
472
481
visitExternalFile func (sst * pebble.ExternalFile ) error ,
473
- ) error
482
+ ) error {
483
+ if ! reader .ConsistentIterators () {
484
+ panic ("reader must provide consistent iterators" )
485
+ }
486
+ spans := Select (desc .RangeID , SelectOpts {
487
+ Ranged : SelectRangedOptions {
488
+ RSpan : desc .RSpan (),
489
+ UserKeys : true ,
490
+ },
491
+ })
492
+ span := spans [0 ]
493
+ return reader .ScanInternal (ctx , span .Key , span .EndKey , visitPoint , visitRangeDel ,
494
+ visitRangeKey , visitSharedFile , visitExternalFile )
495
+ }
474
496
475
497
// IterateOptions instructs how points and ranges should be presented to visitor
476
498
// and if iterators should be visited in forward or reverse order.
0 commit comments