@@ -11,6 +11,7 @@ import (
1111 "testing"
1212 "time"
1313
14+ "github.com/RaduBerinde/btreemap"
1415 "github.com/cockroachdb/cockroach/pkg/roachpb"
1516 "github.com/cockroachdb/cockroach/pkg/storage/enginepb"
1617 "github.com/cockroachdb/cockroach/pkg/testutils"
@@ -21,7 +22,6 @@ import (
2122 "github.com/cockroachdb/cockroach/pkg/util/syncutil"
2223 "github.com/cockroachdb/cockroach/pkg/util/timeutil"
2324 "github.com/cockroachdb/errors"
24- "github.com/google/btree"
2525)
2626
2727func makeAmbCtx () log.AmbientContext {
@@ -31,16 +31,15 @@ func makeAmbCtx() log.AmbientContext {
3131// Test implementation of a range set backed by btree.BTree.
3232type testRangeSet struct {
3333 syncutil.Mutex
34- replicasByKey * btree. BTreeG [ * Replica ]
34+ replicasByKey * btreemap. BTreeMap [roachpb. RKey , * Replica ]
3535 visited int
3636}
3737
3838// newTestRangeSet creates a new range set that has the count number of ranges.
3939func newTestRangeSet (count int , t * testing.T ) * testRangeSet {
40- lessFn := func ( a , b * Replica ) bool {
41- return a . startKey . Less ( b . startKey )
40+ rs := & testRangeSet {
41+ replicasByKey : btreemap . New [roachpb. RKey , * Replica ]( 64 /* degree */ , roachpb . RKey . Compare ),
4242 }
43- rs := & testRangeSet {replicasByKey : btree .NewG [* Replica ](64 /* degree */ , lessFn )}
4443 for i := 0 ; i < count ; i ++ {
4544 desc := & roachpb.RangeDescriptor {
4645 RangeID : roachpb .RangeID (i ),
@@ -59,7 +58,7 @@ func newTestRangeSet(count int, t *testing.T) *testRangeSet {
5958 }
6059 repl .shMu .state .Desc = desc
6160 repl .startKey = desc .StartKey // actually used by replicasByKey
62- if exRngItem , _ := rs .replicasByKey .ReplaceOrInsert (repl ); exRngItem != nil {
61+ if _ , exRngItem , _ := rs .replicasByKey .ReplaceOrInsert (repl . startKey , repl ); exRngItem != nil {
6362 t .Fatalf ("failed to insert range %s" , repl )
6463 }
6564 }
@@ -70,12 +69,15 @@ func (rs *testRangeSet) Visit(visitor func(*Replica) bool) {
7069 rs .Lock ()
7170 defer rs .Unlock ()
7271 rs .visited = 0
73- rs .replicasByKey .Ascend (func (r * Replica ) bool {
74- rs .visited ++
75- rs .Unlock ()
76- defer rs .Lock ()
77- return visitor (r )
78- })
72+ rs .replicasByKey .AscendFunc (
73+ btreemap .Min [roachpb.RKey ](), btreemap .Max [roachpb.RKey ](),
74+ func (_ roachpb.RKey , r * Replica ) bool {
75+ rs .visited ++
76+ rs .Unlock ()
77+ defer rs .Lock ()
78+ return visitor (r )
79+ },
80+ )
7981}
8082
8183func (rs * testRangeSet ) EstimatedCount () int {
@@ -93,7 +95,7 @@ func (rs *testRangeSet) remove(index int, t *testing.T) *Replica {
9395 endKey := roachpb .RKey (fmt .Sprintf ("%03d" , index + 1 ))
9496 rs .Lock ()
9597 defer rs .Unlock ()
96- repl , _ := rs .replicasByKey .Delete (& Replica { startKey : endKey } )
98+ _ , repl , _ := rs .replicasByKey .Delete (endKey )
9799 if repl == nil {
98100 t .Fatalf ("failed to delete range of end key %s" , endKey )
99101 }
0 commit comments