@@ -10,7 +10,6 @@ import (
1010 "context"
1111 "fmt"
1212 "math"
13- "math/rand"
1413 "reflect"
1514 "sort"
1615 "strings"
@@ -62,15 +61,13 @@ import (
6261 "github.com/cockroachdb/cockroach/pkg/util/log"
6362 "github.com/cockroachdb/cockroach/pkg/util/metric"
6463 "github.com/cockroachdb/cockroach/pkg/util/protoutil"
65- "github.com/cockroachdb/cockroach/pkg/util/randutil"
6664 "github.com/cockroachdb/cockroach/pkg/util/retry"
6765 "github.com/cockroachdb/cockroach/pkg/util/stop"
6866 "github.com/cockroachdb/cockroach/pkg/util/timeutil"
6967 "github.com/cockroachdb/cockroach/pkg/util/tracing"
7068 "github.com/cockroachdb/cockroach/pkg/util/uuid"
7169 "github.com/cockroachdb/errors"
7270 "github.com/cockroachdb/redact"
73- "github.com/kr/pretty"
7471 "github.com/stretchr/testify/assert"
7572 "github.com/stretchr/testify/require"
7673 "golang.org/x/exp/slices"
@@ -343,131 +340,6 @@ func createTestStoreWithConfig(
343340 return store
344341}
345342
346- // TestIterateIDPrefixKeys lays down a number of tombstones (at keys.RangeTombstoneKey) interspersed
347- // with other irrelevant keys (both chosen randomly). It then verifies that IterateIDPrefixKeys
348- // correctly returns only the relevant keys and values.
349- func TestIterateIDPrefixKeys (t * testing.T ) {
350- defer leaktest .AfterTest (t )()
351- defer log .Scope (t ).Close (t )
352-
353- ctx := context .Background ()
354- stopper := stop .NewStopper ()
355- defer stopper .Stop (ctx )
356-
357- eng := storage .NewDefaultInMemForTesting ()
358- stopper .AddCloser (eng )
359-
360- seed := randutil .NewPseudoSeed ()
361- // const seed = -1666367124291055473
362- t .Logf ("seed is %d" , seed )
363- rng := rand .New (rand .NewSource (seed ))
364-
365- ops := []func (rangeID roachpb.RangeID ) roachpb.Key {
366- keys .RaftHardStateKey , // unreplicated; sorts after tombstone
367- // Replicated key-anchored local key (i.e. not one we should care about).
368- // Will be written at zero timestamp, but that's ok.
369- func (rangeID roachpb.RangeID ) roachpb.Key {
370- return keys .RangeDescriptorKey ([]byte (fmt .Sprintf ("fakerange%d" , rangeID )))
371- },
372- func (rangeID roachpb.RangeID ) roachpb.Key {
373- return roachpb .Key (fmt .Sprintf ("fakeuserkey%d" , rangeID ))
374- },
375- }
376-
377- const rangeCount = 10
378- rangeIDFn := func () roachpb.RangeID {
379- return 1 + roachpb .RangeID (rng .Intn (10 * rangeCount )) // spread rangeIDs out
380- }
381-
382- // Write a number of keys that should be irrelevant to the iteration in this test.
383- for i := 0 ; i < rangeCount ; i ++ {
384- rangeID := rangeIDFn ()
385-
386- // Grab between one and all ops, randomly.
387- for _ , opIdx := range rng .Perm (len (ops ))[:rng .Intn (1 + len (ops ))] {
388- key := ops [opIdx ](rangeID )
389- t .Logf ("writing op=%d rangeID=%d" , opIdx , rangeID )
390- if _ , err := storage .MVCCPut (
391- ctx ,
392- eng ,
393- key ,
394- hlc.Timestamp {},
395- roachpb .MakeValueFromString ("fake value for " + key .String ()),
396- storage.MVCCWriteOptions {},
397- ); err != nil {
398- t .Fatal (err )
399- }
400- }
401- }
402-
403- type seenT struct {
404- rangeID roachpb.RangeID
405- tombstone kvserverpb.RangeTombstone
406- }
407-
408- // Next, write the keys we're planning to see again.
409- var wanted []seenT
410- {
411- used := make (map [roachpb.RangeID ]struct {})
412- for {
413- rangeID := rangeIDFn ()
414- if _ , ok := used [rangeID ]; ok {
415- // We already wrote this key, so roll the dice again.
416- continue
417- }
418-
419- tombstone := kvserverpb.RangeTombstone {
420- NextReplicaID : roachpb .ReplicaID (rng .Int31n (100 )),
421- }
422-
423- used [rangeID ] = struct {}{}
424- wanted = append (wanted , seenT {rangeID : rangeID , tombstone : tombstone })
425-
426- t .Logf ("writing tombstone at rangeID=%d" , rangeID )
427- require .NoError (t , kvstorage .MakeStateLoader (rangeID ).SetRangeTombstone (ctx , eng , tombstone ))
428-
429- if len (wanted ) >= rangeCount {
430- break
431- }
432- }
433- }
434-
435- sort .Slice (wanted , func (i , j int ) bool {
436- return wanted [i ].rangeID < wanted [j ].rangeID
437- })
438-
439- var seen []seenT
440- var tombstone kvserverpb.RangeTombstone
441-
442- handleTombstone := func (rangeID roachpb.RangeID ) error {
443- seen = append (seen , seenT {rangeID : rangeID , tombstone : tombstone })
444- return nil
445- }
446-
447- if err := kvstorage .IterateIDPrefixKeys (ctx , eng , keys .RangeTombstoneKey , & tombstone , handleTombstone ); err != nil {
448- t .Fatal (err )
449- }
450- placeholder := seenT {
451- rangeID : roachpb .RangeID (9999 ),
452- }
453-
454- if len (wanted ) != len (seen ) {
455- t .Errorf ("wanted %d results, got %d" , len (wanted ), len (seen ))
456- }
457-
458- for len (wanted ) < len (seen ) {
459- wanted = append (wanted , placeholder )
460- }
461- for len (seen ) < len (wanted ) {
462- seen = append (seen , placeholder )
463- }
464-
465- if diff := pretty .Diff (wanted , seen ); len (diff ) > 0 {
466- pretty .Ldiff (t , wanted , seen )
467- t .Fatal ("diff(wanted, seen) is nonempty" )
468- }
469- }
470-
471343// TestStoreConfigSetDefaults checks that StoreConfig.SetDefaults() sets proper
472344// defaults based on numStores.
473345func TestStoreConfigSetDefaultsNumStores (t * testing.T ) {
0 commit comments