Skip to content

Commit

Permalink
kvserver: update tests that failed to persist ReplicaID
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
tbg committed Dec 16, 2022
1 parent 32484ff commit 4c4f26d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pkg/kv/kvserver/split_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/config/zonepb"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/logstore"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand Down Expand Up @@ -96,7 +97,10 @@ func TestSplitQueueShouldQueue(t *testing.T) {
cpy := *tc.repl.Desc()
cpy.StartKey = test.start
cpy.EndKey = test.end
repl, err := newReplica(ctx, &cpy, tc.store, cpy.Replicas().VoterDescriptors()[0].ReplicaID)
replicaID := cpy.Replicas().VoterDescriptors()[0].ReplicaID
require.NoError(t,
logstore.NewStateLoader(cpy.RangeID).SetRaftReplicaID(ctx, tc.store.engine, replicaID))
repl, err := newReplica(ctx, &cpy, tc.store, replicaID)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/kv/kvserver/store_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/storepool"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/logstore"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/replicastats"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
Expand Down Expand Up @@ -216,7 +217,11 @@ func TestStorePoolUpdateLocalStoreBeforeGossip(t *testing.T) {
NextReplicaID: 1,
}
rg.AddReplica(1, 1, roachpb.VOTER_FULL)
replica, err := newReplica(ctx, &rg, store, 1)

const replicaID = 1
require.NoError(t,
logstore.NewStateLoader(rg.RangeID).SetRaftReplicaID(ctx, store.engine, replicaID))
replica, err := newReplica(ctx, &rg, store, replicaID)
if err != nil {
t.Fatalf("make replica error : %+v", err)
}
Expand Down
17 changes: 14 additions & 3 deletions pkg/kv/kvserver/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/logstore"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/rditer"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/stateloader"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/txnwait"
Expand Down Expand Up @@ -521,6 +522,7 @@ func TestInitializeEngineErrors(t *testing.T) {
// deprecated; new tests should create replicas by splitting from a
// properly-bootstrapped initial range.
func createReplica(s *Store, rangeID roachpb.RangeID, start, end roachpb.RKey) *Replica {
ctx := context.Background()
desc := &roachpb.RangeDescriptor{
RangeID: rangeID,
StartKey: start,
Expand All @@ -532,9 +534,15 @@ func createReplica(s *Store, rangeID roachpb.RangeID, start, end roachpb.RKey) *
}},
NextReplicaID: 2,
}
r, err := newReplica(context.Background(), desc, s, 1)
const replicaID = 1
if err := stateloader.WriteInitialRangeState(
ctx, s.engine, *desc, replicaID, clusterversion.TestingClusterVersion.Version,
); err != nil {
panic(err)
}
r, err := newReplica(ctx, desc, s, replicaID)
if err != nil {
log.Fatalf(context.Background(), "%v", err)
panic(err)
}
return r
}
Expand Down Expand Up @@ -825,7 +833,10 @@ func TestMaybeMarkReplicaInitialized(t *testing.T) {
RangeID: newRangeID,
}

r, err := newReplica(ctx, desc, store, 1)
const replicaID = 1
require.NoError(t,
logstore.NewStateLoader(desc.RangeID).SetRaftReplicaID(ctx, store.engine, replicaID))
r, err := newReplica(ctx, desc, store, replicaID)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/kv/kvserver/stores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/logstore"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/testutils"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/require"
)

func newStores(ambientCtx log.AmbientContext, clock *hlc.Clock) *Stores {
Expand Down Expand Up @@ -153,6 +155,8 @@ func TestStoresGetReplicaForRangeID(t *testing.T) {
},
}

require.NoError(t,
logstore.NewStateLoader(desc.RangeID).SetRaftReplicaID(ctx, store.engine, replicaID))
replica, err := newReplica(ctx, desc, store, replicaID)
if err != nil {
t.Fatalf("unexpected error when creating replica: %+v", err)
Expand Down

0 comments on commit 4c4f26d

Please sign in to comment.