@@ -13,31 +13,37 @@ import (
1313 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/rditer"
1414 "github.com/cockroachdb/cockroach/pkg/roachpb"
1515 "github.com/cockroachdb/cockroach/pkg/storage"
16+ "github.com/cockroachdb/cockroach/pkg/util/buildutil"
1617 "github.com/cockroachdb/errors"
1718)
1819
19- const (
20- // ClearRangeThresholdPointKeys is the threshold (as number of point keys)
21- // beyond which we'll clear range data using a Pebble range tombstone rather
22- // than individual Pebble point tombstones.
23- //
24- // It is expensive for there to be many Pebble range tombstones in the same
25- // sstable because all of the tombstones in an sstable are loaded whenever the
26- // sstable is accessed. So we avoid using range deletion unless there is some
27- // minimum number of keys. The value here was pulled out of thin air. It might
28- // be better to make this dependent on the size of the data being deleted. Or
29- // perhaps we should fix Pebble to handle large numbers of range tombstones in
30- // an sstable better.
31- ClearRangeThresholdPointKeys = 64
32-
33- // MergedTombstoneReplicaID is the replica ID written into the RangeTombstone
34- // for replicas of a range which is known to have been merged. This value
35- // should prevent any messages from stale replicas of that range from ever
36- // resurrecting merged replicas. Whenever merging or subsuming a replica we
37- // know new replicas can never be created so this value is used even if we
38- // don't know the current replica ID.
39- MergedTombstoneReplicaID roachpb.ReplicaID = math .MaxInt32
40- )
20+ // MergedTombstoneReplicaID is the replica ID written into the RangeTombstone
21+ // for replicas of a range which is known to have been merged. This value
22+ // should prevent any messages from stale replicas of that range from ever
23+ // resurrecting merged replicas. Whenever merging or subsuming a replica we
24+ // know new replicas can never be created so this value is used even if we
25+ // don't know the current replica ID.
26+ const MergedTombstoneReplicaID roachpb.ReplicaID = math .MaxInt32
27+
28+ // clearRangeThresholdPointKeys is the value of ClearRangeThresholdPointKeys().
29+ // Can be overridden only in tests, in order to deterministically force using
30+ // ClearRawRange instead of point clears, when destroying replicas.
31+ var clearRangeThresholdPointKeys = 64
32+
33+ // ClearRangeThresholdPointKeys returns the threshold (as number of point keys)
34+ // beyond which we'll clear range data using a Pebble range tombstone rather
35+ // than individual Pebble point tombstones.
36+ //
37+ // It is expensive for there to be many Pebble range tombstones in the same
38+ // sstable because all of the tombstones in an sstable are loaded whenever the
39+ // sstable is accessed. So we avoid using range deletion unless there is some
40+ // minimum number of keys. The value here was pulled out of thin air. It might
41+ // be better to make this dependent on the size of the data being deleted. Or
42+ // perhaps we should fix Pebble to handle large numbers of range tombstones in
43+ // an sstable better.
44+ func ClearRangeThresholdPointKeys () int {
45+ return clearRangeThresholdPointKeys
46+ }
4147
4248// clearRangeDataOptions specify which parts of a Replica are to be destroyed.
4349type clearRangeDataOptions struct {
@@ -84,7 +90,7 @@ func clearRangeData(
8490 UnreplicatedByRangeID : opts .clearUnreplicatedByRangeID ,
8591 })
8692
87- pointKeyThreshold := ClearRangeThresholdPointKeys
93+ pointKeyThreshold := ClearRangeThresholdPointKeys ()
8894 if opts .mustUseClearRange {
8995 pointKeyThreshold = 1
9096 }
@@ -252,3 +258,21 @@ func RemoveStaleRHSFromSplit(
252258 clearUnreplicatedByRangeID : true ,
253259 })
254260}
261+
262+ // TestingForceClearRange changes the value of ClearRangeThresholdPointKeys to
263+ // 1, which effectively forces ClearRawRange in the replica destruction path,
264+ // instead of point deletions. This can be used for making the storage
265+ // operations in tests deterministic.
266+ //
267+ // The caller must call the returned function at the end of the test, to restore
268+ // the default value.
269+ func TestingForceClearRange () func () {
270+ if ! buildutil .CrdbTestBuild {
271+ panic ("test-only function" )
272+ }
273+ old := clearRangeThresholdPointKeys
274+ clearRangeThresholdPointKeys = 1 // forces ClearRawRange
275+ return func () {
276+ clearRangeThresholdPointKeys = old
277+ }
278+ }
0 commit comments