@@ -8,7 +8,6 @@ package kvstorage
88import (
99 "context"
1010
11- "github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1211 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
1312 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/logstore"
1413 "github.com/cockroachdb/cockroach/pkg/roachpb"
@@ -128,16 +127,10 @@ func (s StateLoader) Save(
128127 return enginepb.MVCCStats {}, err
129128 }
130129 }
131- if err := s .SetRangeAppliedState (
132- ctx ,
133- stateRW ,
134- state .RaftAppliedIndex ,
135- state .LeaseAppliedIndex ,
136- state .RaftAppliedIndexTerm ,
137- ms ,
138- state .RaftClosedTimestamp ,
139- nil ,
140- ); err != nil {
130+ state .Stats = ms // no-op, just an acknowledgement that the stats were updated
131+
132+ as := state .ToRangeAppliedState ()
133+ if err := s .SetRangeAppliedState (ctx , stateRW , & as ); err != nil {
141134 return enginepb.MVCCStats {}, err
142135 }
143136 return * ms , nil
@@ -216,26 +209,8 @@ func (s StateLoader) LoadMVCCStats(
216209// keys. We now deem those keys to be "legacy" because they have been replaced
217210// by the range applied state key.
218211func (s StateLoader ) SetRangeAppliedState (
219- ctx context.Context ,
220- stateRW StateRW ,
221- appliedIndex kvpb.RaftIndex ,
222- leaseAppliedIndex kvpb.LeaseAppliedIndex ,
223- appliedIndexTerm kvpb.RaftTerm ,
224- newMS * enginepb.MVCCStats ,
225- raftClosedTimestamp hlc.Timestamp ,
226- asAlloc * kvserverpb.RangeAppliedState , // optional
212+ ctx context.Context , stateRW StateRW , as * kvserverpb.RangeAppliedState ,
227213) error {
228- if asAlloc == nil {
229- asAlloc = new (kvserverpb.RangeAppliedState )
230- }
231- as := asAlloc
232- * as = kvserverpb.RangeAppliedState {
233- RaftAppliedIndex : appliedIndex ,
234- LeaseAppliedIndex : leaseAppliedIndex ,
235- RangeStats : kvserverpb .MVCCPersistentStats (* newMS ),
236- RaftClosedTimestamp : raftClosedTimestamp ,
237- RaftAppliedIndexTerm : appliedIndexTerm ,
238- }
239214 // The RangeAppliedStateKey is not included in stats. This is also reflected
240215 // in ComputeStats.
241216 ms := (* enginepb .MVCCStats )(nil )
@@ -253,10 +228,8 @@ func (s StateLoader) SetMVCCStats(
253228 if err != nil {
254229 return err
255230 }
256- alloc := as // reuse
257- return s .SetRangeAppliedState (
258- ctx , stateRW , as .RaftAppliedIndex , as .LeaseAppliedIndex , as .RaftAppliedIndexTerm , newMS ,
259- as .RaftClosedTimestamp , alloc )
231+ as .RangeStats = kvserverpb .MVCCPersistentStats (* newMS )
232+ return s .SetRangeAppliedState (ctx , stateRW , as )
260233}
261234
262235// SetClosedTimestamp overwrites the closed timestamp.
@@ -267,10 +240,8 @@ func (s StateLoader) SetClosedTimestamp(
267240 if err != nil {
268241 return err
269242 }
270- alloc := as // reuse
271- return s .SetRangeAppliedState (
272- ctx , stateRW , as .RaftAppliedIndex , as .LeaseAppliedIndex , as .RaftAppliedIndexTerm ,
273- as .RangeStats .ToStatsPtr (), closedTS , alloc )
243+ as .RaftClosedTimestamp = closedTS
244+ return s .SetRangeAppliedState (ctx , stateRW , as )
274245}
275246
276247// LoadGCThreshold loads the GC threshold.
0 commit comments