@@ -13,7 +13,6 @@ import (
1313 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvstorage"
1414 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/load"
1515 "github.com/cockroachdb/cockroach/pkg/roachpb"
16- "github.com/cockroachdb/cockroach/pkg/storage"
1716 "github.com/cockroachdb/cockroach/pkg/storage/enginepb"
1817 "github.com/cockroachdb/cockroach/pkg/util/hlc"
1918 "github.com/cockroachdb/cockroach/pkg/util/log"
@@ -29,7 +28,8 @@ import (
2928func splitPreApply (
3029 ctx context.Context ,
3130 r * Replica ,
32- readWriter storage.ReadWriter ,
31+ stateRW kvstorage.StateRW ,
32+ raftRW kvstorage.Raft ,
3333 split roachpb.SplitTrigger ,
3434 initClosedTS * hlc.Timestamp ,
3535) {
@@ -79,13 +79,17 @@ func splitPreApply(
7979 // on this Store, it doesn't have a RaftTruncatedState (which only initialized
8080 // replicas can have), so this deletion will not conflict with or corrupt it.
8181 //
82+ // NB: the key is cleared in stateRW rather than raftRW, deliberately. It
83+ // lives in the raft engine, but here we want to clear it from the state
84+ // engine batch, so that it doesn't make it to the state engine.
85+ //
8286 // TODO(#152847): remove this workaround when there are no historical
8387 // proposals with RaftTruncatedState, e.g. after a below-raft migration.
84- if ts , err := rsl .LoadRaftTruncatedState (ctx , readWriter ); err != nil {
88+ if ts , err := rsl .LoadRaftTruncatedState (ctx , stateRW ); err != nil {
8589 log .KvExec .Fatalf (ctx , "cannot load RaftTruncatedState: %v" , err )
8690 } else if ts == (kvserverpb.RaftTruncatedState {}) {
8791 // Common case. Do nothing.
88- } else if err := rsl .ClearRaftTruncatedState (readWriter ); err != nil {
92+ } else if err := rsl .ClearRaftTruncatedState (stateRW ); err != nil {
8993 log .KvExec .Fatalf (ctx , "cannot clear RaftTruncatedState: %v" , err )
9094 }
9195
@@ -122,7 +126,7 @@ func splitPreApply(
122126 }
123127 }
124128 if err := kvstorage .RemoveStaleRHSFromSplit (
125- ctx , readWriter , readWriter , split .RightDesc .RangeID , split .RightDesc .RSpan (),
129+ ctx , kvstorage . WrapState ( stateRW ) , split .RightDesc .RangeID , split .RightDesc .RSpan (),
126130 ); err != nil {
127131 log .KvExec .Fatalf (ctx , "failed to clear range data for removed rhs: %v" , err )
128132 }
@@ -138,10 +142,10 @@ func splitPreApply(
138142 //
139143 // [*] Note that uninitialized replicas may cast votes, and if they have, we
140144 // can't load the default Term and Vote values.
141- if err := rsl .SynthesizeRaftState (ctx , readWriter , kvstorage . TODORaft ( readWriter ) ); err != nil {
145+ if err := rsl .SynthesizeRaftState (ctx , stateRW , raftRW ); err != nil {
142146 log .KvExec .Fatalf (ctx , "%v" , err )
143147 }
144- if err := rsl .SetRaftTruncatedState (ctx , readWriter , & kvserverpb.RaftTruncatedState {
148+ if err := rsl .SetRaftTruncatedState (ctx , raftRW . WO , & kvserverpb.RaftTruncatedState {
145149 Index : kvstorage .RaftInitialLogIndex ,
146150 Term : kvstorage .RaftInitialLogTerm ,
147151 }); err != nil {
@@ -159,7 +163,7 @@ func splitPreApply(
159163 initClosedTS = & hlc.Timestamp {}
160164 }
161165 initClosedTS .Forward (r .GetCurrentClosedTimestamp (ctx ))
162- if err := rsl .SetClosedTimestamp (ctx , readWriter , * initClosedTS ); err != nil {
166+ if err := rsl .SetClosedTimestamp (ctx , stateRW , * initClosedTS ); err != nil {
163167 log .KvExec .Fatalf (ctx , "%s" , err )
164168 }
165169}
0 commit comments