99 "bytes"
1010 "context"
1111 "time"
12+ "unsafe"
1213
1314 "github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1415 "github.com/cockroachdb/cockroach/pkg/roachpb"
@@ -223,8 +224,6 @@ func (i *CatchUpSnapshot) CatchUpScan(
223224 var meta enginepb.MVCCMetadata
224225 iter .SeekGE (storage.MVCCKey {Key : i .span .Key })
225226
226- var keyCount uint64
227-
228227 for {
229228 if ok , err := iter .Valid (); err != nil {
230229 return err
@@ -240,7 +239,6 @@ func (i *CatchUpSnapshot) CatchUpScan(
240239 unsafeKey := iter .UnsafeKey ()
241240 sameKey := bytes .Equal (unsafeKey .Key , lastKey )
242241 if ! sameKey {
243- keyCount ++
244242
245243 // If so, output events for the last key encountered.
246244 if err := outputEvents (); err != nil {
@@ -263,7 +261,15 @@ func (i *CatchUpSnapshot) CatchUpScan(
263261 // proved a bit slow.
264262 forceRecreateUnderTest := false
265263 if util .RaceEnabled {
266- forceRecreateUnderTest = keyCount % 10 == 0
264+ // Hash the pointer of the current iterator into the range [0, 3] to
265+ // give us a ~25% chance of recreating the iterator.
266+ //
267+ // unsafe.Pointer's documentation implies that this uintptr is not
268+ // technically guaranteed to be stable across multiple calls. So, we
269+ // could make a different decision for the same iterator. That's OK, the
270+ // goal here is to force recreation occasionally, nothing more.
271+ ptr := uintptr (unsafe .Pointer (& iter ))
272+ forceRecreateUnderTest = util .FibHash (uint64 (ptr ), 2 ) == 0
267273 }
268274
269275 // We sample the current time only when readmitted is true, to avoid
0 commit comments