Skip to content

Commit 59e7a03

Browse files
committed
kvserver: reset some fields of replicaAppBatch
This commit fixes a bug in replicaAppBatch initialization. Some fields were not reset, and would be carried across batches. For example, the changeTruncatesSideloadedFiles field, once set to true, would be true forever, and cause Pebble sync on every command application. Epic: none Release note: none
1 parent 97313dc commit 59e7a03

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/kv/kvserver/replica_application_state_machine.go

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func (sm *replicaStateMachine) NewEphemeralBatch() apply.EphemeralBatch {
139139
func (sm *replicaStateMachine) NewBatch() apply.Batch {
140140
r := sm.r
141141
b := &sm.batch
142+
// TODO(pav-kv): replicaAppBatch initialization below is bug-prone, we need to
143+
// not forget resetting the fields that are local to one batch. Find a way to
144+
// make it safer.
142145
b.r = r
143146
b.applyStats = &sm.applyStats
144147
b.batch = r.store.TODOEngine().NewBatch()
@@ -148,6 +151,9 @@ func (sm *replicaStateMachine) NewBatch() apply.Batch {
148151
*b.state.Stats = *r.mu.state.Stats
149152
b.closedTimestampSetter = r.mu.closedTimestampSetter
150153
r.mu.RUnlock()
154+
b.changeRemovesReplica = false
155+
b.changeTruncatesSideloadedFiles = false
156+
// TODO(pav-kv): what about b.ab and b.followerStoreWriteBytes?
151157
b.start = timeutil.Now()
152158
return b
153159
}

0 commit comments

Comments
 (0)