@@ -57,9 +57,11 @@ type applyCommittedEntriesStats struct {
57
57
// side-effects of each command is applied to the Replica's in-memory state.
58
58
type replicaStateMachine struct {
59
59
r * Replica
60
- // batch is returned from NewBatch.
60
+ // batch is returned from NewBatch. It is non-zero between NewBatch() and the
61
+ // corresponding Close() call.
61
62
batch replicaAppBatch
62
- // ephemeralBatch is returned from NewEphemeralBatch.
63
+ // ephemeralBatch is returned from NewEphemeralBatch. It is non-zero between
64
+ // NewEphemeralBatch() and the corresponding Close() call.
63
65
ephemeralBatch ephemeralReplicaAppBatch
64
66
// stats are updated during command application and reset by moveStats.
65
67
applyStats applyCommittedEntriesStats
@@ -128,6 +130,8 @@ func replicaApplyTestingFilters(
128
130
func (sm * replicaStateMachine ) NewEphemeralBatch () apply.EphemeralBatch {
129
131
r := sm .r
130
132
mb := & sm .ephemeralBatch
133
+ // NB: the batch struct is zero-initialized, which is guaranteed by the fact
134
+ // that its previous use ended with ephemeralReplicaAppBatch.Close().
131
135
mb .r = r
132
136
r .raftMu .AssertHeld ()
133
137
mb .state = r .shMu .state
@@ -138,9 +142,8 @@ func (sm *replicaStateMachine) NewEphemeralBatch() apply.EphemeralBatch {
138
142
func (sm * replicaStateMachine ) NewBatch () apply.Batch {
139
143
r := sm .r
140
144
b := & sm .batch
141
- // TODO(pav-kv): replicaAppBatch initialization below is bug-prone, we need to
142
- // not forget resetting the fields that are local to one batch. Find a way to
143
- // make it safer.
145
+ // NB: the batch struct is zero-initialized, which is guaranteed by the fact
146
+ // that its previous use ended with replicaAppBatch.Close().
144
147
b .r = r
145
148
b .applyStats = & sm .applyStats
146
149
// TODO(#144627): most commands do not need to read. Use NewWriteBatch because
@@ -154,9 +157,6 @@ func (sm *replicaStateMachine) NewBatch() apply.Batch {
154
157
* b .state .Stats = * r .shMu .state .Stats
155
158
b .closedTimestampSetter = r .mu .closedTimestampSetter
156
159
r .mu .RUnlock ()
157
- b .changeRemovesReplica = false
158
- b .changeTruncatesSideloadedFiles = false
159
- // TODO(pav-kv): what about b.ab and b.followerStoreWriteBytes?
160
160
b .start = timeutil .Now ()
161
161
return b
162
162
}
0 commit comments