diff --git a/pkg/kv/kvserver/replica_test.go b/pkg/kv/kvserver/replica_test.go index a93e2433ba15..b2312e3a9515 100644 --- a/pkg/kv/kvserver/replica_test.go +++ b/pkg/kv/kvserver/replica_test.go @@ -286,15 +286,7 @@ func (tc *testContext) StartWithStoreConfigAndVersion( if realRange { if tc.bootstrapMode == bootstrapRangeOnly { testDesc := testRangeDescriptor() - if _, err := stateloader.WriteInitialState( - ctx, - tc.store.Engine(), - enginepb.MVCCStats{}, - *testDesc, - roachpb.Lease{}, - hlc.Timestamp{}, - stateloader.TruncatedStateUnreplicated, - ); err != nil { + if err := stateloader.WriteInitialRangeState(ctx, tc.store.Engine(), *testDesc); err != nil { t.Fatal(err) } repl, err := newReplica(ctx, testDesc, tc.store, 1) diff --git a/pkg/kv/kvserver/stateloader/initial.go b/pkg/kv/kvserver/stateloader/initial.go index 51002edcc6d6..9fd76fa8568e 100644 --- a/pkg/kv/kvserver/stateloader/initial.go +++ b/pkg/kv/kvserver/stateloader/initial.go @@ -33,7 +33,7 @@ const ( // WriteInitialReplicaState sets up a new Range, but without writing an // associated Raft state (which must be written separately via -// synthesizeRaftState before instantiating a Replica). The main task is to +// SynthesizeRaftState before instantiating a Replica). The main task is to // persist a ReplicaState which does not start from zero but presupposes a few // entries already having applied. The supplied MVCCStats are used for the Stats // field after adjusting for persisting the state itself, and the updated stats @@ -82,26 +82,23 @@ func WriteInitialReplicaState( return newMS, nil } -// WriteInitialState calls WriteInitialReplicaState followed by -// SynthesizeRaftState. It is typically called during bootstrap. The supplied -// MVCCStats are used for the Stats field after adjusting for persisting the -// state itself, and the updated stats are returned. -func WriteInitialState( - ctx context.Context, - readWriter storage.ReadWriter, - ms enginepb.MVCCStats, - desc roachpb.RangeDescriptor, - lease roachpb.Lease, - gcThreshold hlc.Timestamp, - truncStateType TruncatedStateType, -) (enginepb.MVCCStats, error) { - newMS, err := WriteInitialReplicaState( - ctx, readWriter, ms, desc, lease, gcThreshold, truncStateType) - if err != nil { - return enginepb.MVCCStats{}, err +// WriteInitialRangeState writes the initial range state. It's called during +// bootstrap. +func WriteInitialRangeState( + ctx context.Context, readWriter storage.ReadWriter, desc roachpb.RangeDescriptor, +) error { + initialLease := roachpb.Lease{} + initialGCThreshold := hlc.Timestamp{} + initialTruncStateType := TruncatedStateUnreplicated + initialMS := enginepb.MVCCStats{} + + if _, err := WriteInitialReplicaState( + ctx, readWriter, initialMS, desc, initialLease, initialGCThreshold, initialTruncStateType, + ); err != nil { + return err } if err := Make(desc.RangeID).SynthesizeRaftState(ctx, readWriter); err != nil { - return enginepb.MVCCStats{}, err + return err } - return newMS, nil + return nil } diff --git a/pkg/kv/kvserver/stateloader/stateloader.go b/pkg/kv/kvserver/stateloader/stateloader.go index d03b5d8173b8..3230b064314b 100644 --- a/pkg/kv/kvserver/stateloader/stateloader.go +++ b/pkg/kv/kvserver/stateloader/stateloader.go @@ -619,7 +619,7 @@ func (rsl StateLoader) SetHardState( // SynthesizeRaftState creates a Raft state which synthesizes both a HardState // and a lastIndex from pre-seeded data in the engine (typically created via -// writeInitialReplicaState and, on a split, perhaps the activity of an +// WriteInitialReplicaState and, on a split, perhaps the activity of an // uninitialized Raft group) func (rsl StateLoader) SynthesizeRaftState( ctx context.Context, readWriter storage.ReadWriter, diff --git a/pkg/kv/kvserver/store_init.go b/pkg/kv/kvserver/store_init.go index 7dc9ec747632..00679438e04b 100644 --- a/pkg/kv/kvserver/store_init.go +++ b/pkg/kv/kvserver/store_init.go @@ -233,20 +233,9 @@ func WriteInitialClusterData( } } - truncStateType := stateloader.TruncatedStateUnreplicated - lease := roachpb.Lease{} - _, err := stateloader.WriteInitialState( - ctx, batch, - enginepb.MVCCStats{}, - *desc, - lease, - hlc.Timestamp{}, /* gcThreshold */ - truncStateType, - ) - if err != nil { + if err := stateloader.WriteInitialRangeState(ctx, batch, *desc); err != nil { return err } - computedStats, err := rditer.ComputeStatsForRange(desc, batch, now.WallTime) if err != nil { return err diff --git a/pkg/kv/kvserver/store_test.go b/pkg/kv/kvserver/store_test.go index b8ef7409d59a..dfaaa735c021 100644 --- a/pkg/kv/kvserver/store_test.go +++ b/pkg/kv/kvserver/store_test.go @@ -1424,10 +1424,7 @@ func splitTestRange(store *Store, key, splitKey roachpb.RKey, t *testing.T) *Rep rangeID, splitKey, repl.Desc().EndKey, repl.Desc().Replicas()) // Minimal amount of work to keep this deprecated machinery working: Write // some required Raft keys. - _, err = stateloader.WriteInitialState( - ctx, store.engine, enginepb.MVCCStats{}, *rhsDesc, roachpb.Lease{}, - hlc.Timestamp{}, stateloader.TruncatedStateUnreplicated, - ) + err = stateloader.WriteInitialRangeState(ctx, store.engine, *rhsDesc) require.NoError(t, err) newRng, err := newReplica(ctx, rhsDesc, store, repl.ReplicaID()) require.NoError(t, err) @@ -2932,10 +2929,7 @@ func TestStoreRemovePlaceholderOnRaftIgnored(t *testing.T) { } uninitDesc := roachpb.RangeDescriptor{RangeID: repl1.Desc().RangeID} - if _, err := stateloader.WriteInitialState( - ctx, s.Engine(), enginepb.MVCCStats{}, uninitDesc, roachpb.Lease{}, - hlc.Timestamp{}, stateloader.TruncatedStateUnreplicated, - ); err != nil { + if err := stateloader.WriteInitialRangeState(ctx, s.Engine(), uninitDesc); err != nil { t.Fatal(err) } uninitRepl1, err := newReplica(ctx, &uninitDesc, s, 2)