@@ -20,6 +20,14 @@ import (
20
20
"github.com/cockroachdb/errors"
21
21
)
22
22
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
+
23
31
// snapWriteBuilder contains the data needed to prepare the on-disk state for a
24
32
// snapshot.
25
33
type snapWriteBuilder struct {
@@ -29,10 +37,10 @@ type snapWriteBuilder struct {
29
37
sl stateloader.StateLoader
30
38
writeSST func (context.Context , func (context.Context , storage.Writer ) error ) error
31
39
32
- truncState kvserverpb.RaftTruncatedState
33
- hardState raftpb.HardState
34
- desc * roachpb.RangeDescriptor
35
- subsumedDescs [] * roachpb. RangeDescriptor
40
+ truncState kvserverpb.RaftTruncatedState
41
+ hardState raftpb.HardState
42
+ desc * roachpb.RangeDescriptor
43
+ subsume [] destroyReplicaInfo
36
44
37
45
// cleared contains the spans that this snapshot application clears before
38
46
// writing new state on top.
@@ -115,7 +123,7 @@ func (s *snapWriteBuilder) clearSubsumedReplicaDiskData(ctx context.Context) err
115
123
}
116
124
keySpans := getKeySpans (s .desc )
117
125
totalKeySpans := append ([]roachpb.Span (nil ), keySpans ... )
118
- for _ , subDesc := range s .subsumedDescs {
126
+ for _ , sub := range s .subsume {
119
127
// We have to create an SST for the subsumed replica's range-id local keys.
120
128
if err := s .writeSST (ctx , func (ctx context.Context , w storage.Writer ) error {
121
129
// NOTE: We set mustClearRange to true because we are setting
@@ -126,16 +134,16 @@ func (s *snapWriteBuilder) clearSubsumedReplicaDiskData(ctx context.Context) err
126
134
ClearUnreplicatedByRangeID : true ,
127
135
MustUseClearRange : true ,
128
136
}
129
- s .cleared = append (s .cleared , rditer .Select (subDesc .RangeID , rditer.SelectOpts {
137
+ s .cleared = append (s .cleared , rditer .Select (sub . id .RangeID , rditer.SelectOpts {
130
138
ReplicatedByRangeID : opts .ClearReplicatedByRangeID ,
131
139
UnreplicatedByRangeID : opts .ClearUnreplicatedByRangeID ,
132
140
})... )
133
- return kvstorage .DestroyReplica (ctx , subDesc . RangeID , reader , w , mergedTombstoneReplicaID , opts )
141
+ return kvstorage .DestroyReplica (ctx , sub . id , reader , w , mergedTombstoneReplicaID , opts )
134
142
}); err != nil {
135
143
return err
136
144
}
137
145
138
- srKeySpans := getKeySpans (subDesc )
146
+ srKeySpans := getKeySpans (sub . desc )
139
147
// Compute the total key space covered by the current replica and all
140
148
// subsumed replicas.
141
149
for i := range srKeySpans {
0 commit comments