@@ -20,14 +20,6 @@ import (
2020 "github.com/cockroachdb/errors"
2121)
2222
23- // destroyReplicaInfo contains the replica's metadata needed for its removal
24- // from storage.
25- // TODO(pav-kv): for WAG, add the truncated state and applied index. See #152845.
26- type destroyReplicaInfo struct {
27- id roachpb.FullReplicaID
28- desc * roachpb.RangeDescriptor
29- }
30-
3123// snapWriteBuilder contains the data needed to prepare the on-disk state for a
3224// snapshot.
3325type snapWriteBuilder struct {
@@ -41,9 +33,8 @@ type snapWriteBuilder struct {
4133 hardState raftpb.HardState
4234 desc * roachpb.RangeDescriptor // corresponds to the range descriptor in the snapshot
4335 origDesc * roachpb.RangeDescriptor // pre-snapshot range descriptor
44- // NB: subsume, if set, must be in sorted (by destroyReplicaInfo.desc start
45- // key) order.
46- subsume []destroyReplicaInfo
36+ // NB: subsume must be in sorted order by DestroyReplicaInfo start key.
37+ subsume []kvstorage.DestroyReplicaInfo
4738
4839 // cleared contains the spans that this snapshot application clears before
4940 // writing new state on top.
@@ -112,7 +103,7 @@ func (s *snapWriteBuilder) rewriteRaftState(ctx context.Context, w storage.Write
112103// the Reader reflects the latest I/O each of the subsumed replicas has done
113104// (i.e. Reader was instantiated after all raftMu were acquired).
114105//
115- // NB: does nothing if s.subsumedDescs is empty .
106+ // NB: does nothing if there are no subsumed replicas .
116107func (s * snapWriteBuilder ) clearSubsumedReplicaDiskData (ctx context.Context ) error {
117108 if len (s .subsume ) == 0 {
118109 return nil // no subsumed replicas to speak of; early return
@@ -123,10 +114,10 @@ func (s *snapWriteBuilder) clearSubsumedReplicaDiskData(ctx context.Context) err
123114 // the left implies that either we merged "to the left" (we don't), or that
124115 // we're applying a snapshot for another range (we don't do that either).
125116 // Something is severely wrong for this to happen, so perform a sanity check.
126- if s .subsume [0 ].desc . StartKey .Compare (s .desc .StartKey ) < 0 { // subsumedDescs are sorted by StartKey
117+ if s .subsume [0 ].Keys . Key .Compare (s .desc .StartKey ) < 0 { // subsume is sorted by start key
127118 log .KvDistribution .Fatalf (ctx ,
128119 "subsuming replica to our left; subsumed desc start key: %v; snapshot desc start key %v" ,
129- s .subsume [0 ].desc . StartKey , s .desc .StartKey ,
120+ s .subsume [0 ].Keys . Key , s .desc .StartKey ,
130121 )
131122 }
132123
@@ -167,12 +158,12 @@ func (s *snapWriteBuilder) clearSubsumedReplicaDiskData(ctx context.Context) err
167158 ClearUnreplicatedByRangeID : true ,
168159 MustUseClearRange : true ,
169160 }
170- s .cleared = append (s .cleared , rditer .Select (sub .id . RangeID , rditer.SelectOpts {
161+ s .cleared = append (s .cleared , rditer .Select (sub .RangeID , rditer.SelectOpts {
171162 ReplicatedByRangeID : opts .ClearReplicatedByRangeID ,
172163 UnreplicatedByRangeID : opts .ClearUnreplicatedByRangeID ,
173164 })... )
174165 // NB: Actually clear RangeID local key spans.
175- return kvstorage .DestroyReplica (ctx , sub . id , reader , w , mergedTombstoneReplicaID , opts )
166+ return kvstorage .DestroyReplica (ctx , reader , w , sub , mergedTombstoneReplicaID , opts )
176167 }); err != nil {
177168 return err
178169 }
@@ -223,23 +214,22 @@ func (s *snapWriteBuilder) clearResidualDataOnNarrowSnapshot(ctx context.Context
223214 return nil
224215 }
225216
226- rightMostDesc := s .origDesc
217+ endKey := s .origDesc . EndKey
227218 if len (s .subsume ) != 0 {
228219 // NB: s.subsume are non-overlapping and sorted by start key. Pick the last
229220 // one to determine whether the snapshot is narrowing the keyspace or not.
230- rightMostDesc = s .subsume [len (s .subsume )- 1 ].desc
221+ endKey = s .subsume [len (s .subsume )- 1 ].Keys . EndKey
231222 }
232223
233- if rightMostDesc . EndKey .Compare (s .desc .EndKey ) <= 0 {
224+ if endKey .Compare (s .desc .EndKey ) <= 0 {
234225 return nil // we aren't narrowing anything; no-op
235226 }
236227
237228 // TODO(sep-raft-log): read from the state machine engine here.
238229 reader := storage .Reader (s .todoEng )
239230 for _ , span := range rditer .Select (0 , rditer.SelectOpts {
240- Ranged : rditer.SelectRangedOptions {RSpan : roachpb.RSpan {
241- Key : s .desc .EndKey , EndKey : rightMostDesc .EndKey ,
242- },
231+ Ranged : rditer.SelectRangedOptions {
232+ RSpan : roachpb.RSpan {Key : s .desc .EndKey , EndKey : endKey },
243233 SystemKeys : true ,
244234 LockTable : true ,
245235 UserKeys : true ,
0 commit comments