@@ -45,66 +45,6 @@ func ClearRangeThresholdPointKeys() int {
4545 return clearRangeThresholdPointKeys
4646}
4747
48- // clearRangeDataOptions specify which parts of a Replica are to be destroyed.
49- type clearRangeDataOptions struct {
50- // clearReplicatedByRangeID indicates that replicated RangeID-based keys
51- // (abort span, etc) should be removed.
52- clearReplicatedByRangeID bool
53- // clearUnreplicatedByRangeID indicates that unreplicated RangeID-based keys
54- // (logstore state incl. HardState, etc) should be removed.
55- clearUnreplicatedByRangeID bool
56- // clearReplicatedBySpan causes the state machine data (i.e. the replicated state
57- // for the given RSpan) that is key-addressable (i.e. range descriptor, user keys,
58- // locks) to be removed. No data is removed if this is the zero span.
59- clearReplicatedBySpan roachpb.RSpan
60-
61- // If mustUseClearRange is true, a Pebble range tombstone will always be used
62- // to clear the key spans (unless empty). This is typically used when we need
63- // to write additional keys to an SST after this clear, e.g. a replica
64- // tombstone, since keys must be written in order. When this is false, a
65- // heuristic will be used instead.
66- mustUseClearRange bool
67- }
68-
69- // clearRangeData clears the data associated with a range descriptor selected
70- // by the provided options.
71- //
72- // TODO(tbg): could rename this to XReplica. The use of "Range" in both the
73- // "CRDB Range" and "storage.ClearRange" context in the setting of this method could
74- // be confusing.
75- func clearRangeData (
76- ctx context.Context ,
77- rangeID roachpb.RangeID ,
78- reader storage.Reader ,
79- writer storage.Writer ,
80- opts clearRangeDataOptions ,
81- ) error {
82- keySpans := rditer .Select (rangeID , rditer.SelectOpts {
83- Ranged : rditer.SelectRangedOptions {
84- RSpan : opts .clearReplicatedBySpan ,
85- SystemKeys : true ,
86- LockTable : true ,
87- UserKeys : true ,
88- },
89- ReplicatedByRangeID : opts .clearReplicatedByRangeID ,
90- UnreplicatedByRangeID : opts .clearUnreplicatedByRangeID ,
91- })
92-
93- pointKeyThreshold := ClearRangeThresholdPointKeys ()
94- if opts .mustUseClearRange {
95- pointKeyThreshold = 1
96- }
97-
98- for _ , keySpan := range keySpans {
99- if err := storage .ClearRangeWithHeuristic (
100- ctx , reader , writer , keySpan .Key , keySpan .EndKey , pointKeyThreshold ,
101- ); err != nil {
102- return err
103- }
104- }
105- return nil
106- }
107-
10848// DestroyReplicaTODO is the plan for splitting DestroyReplica into cross-engine
10949// writes.
11050//
@@ -175,18 +115,30 @@ func destroyReplicaImpl(
175115 }
176116
177117 _ = DestroyReplicaTODO // 2.1 + 2.2 + 3.1
178- // NB: if required, set mustUseClearRange to true. This call can be used for
179- // generating SSTables when ingesting a snapshot, which requires Clears and
180- // Puts to be written in key order. DestroyReplica sets RangeTombstoneKey
181- // after clearing the unreplicated span which may contain higher keys.
182- if err := clearRangeData (ctx , info .RangeID , reader , writer , clearRangeDataOptions {
183- clearReplicatedByRangeID : true ,
184- clearUnreplicatedByRangeID : true ,
185- clearReplicatedBySpan : info .Keys ,
186- mustUseClearRange : forceSortedKeys ,
187- }); err != nil {
188- return err
118+ // NB: if forceSortedKeys is true, disable the heuristic and force deletion by
119+ // range keys. This call can be used for generating SSTables when ingesting a
120+ // snapshot, which requires Clears and Puts to be written in key order. Since
121+ // we write RangeTombstoneKey further down, ensure that this is the only point
122+ // key here.
123+ pointKeyThreshold := ClearRangeThresholdPointKeys ()
124+ if forceSortedKeys {
125+ pointKeyThreshold = 1
189126 }
127+ // TODO(pav-kv): decompose this loop to delete raft and state machine keys
128+ // separately. The main challenge is the unreplicated span because it is
129+ // scattered across 2 engines.
130+ for _ , span := range rditer .Select (info .RangeID , rditer.SelectOpts {
131+ UnreplicatedByRangeID : true ,
132+ ReplicatedByRangeID : true ,
133+ Ranged : rditer .SelectAllRanged (info .Keys ),
134+ }) {
135+ if err := storage .ClearRangeWithHeuristic (
136+ ctx , reader , writer , span .Key , span .EndKey , pointKeyThreshold ,
137+ ); err != nil {
138+ return err
139+ }
140+ }
141+
190142 // Save a tombstone to ensure that replica IDs never get reused.
191143 _ = DestroyReplicaTODO // 2.3
192144 return sl .SetRangeTombstone (ctx , writer , kvserverpb.RangeTombstone {
0 commit comments