Skip to content

Commit

Permalink
kvserver: schedule ready processing when the leaseholder changes
Browse files Browse the repository at this point in the history
Epic: CRDB-37515

Release note: None
  • Loading branch information
sumeerbhola committed Oct 7, 2024
1 parent 4920f6f commit 84c1dc4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/kv/kvserver/replica_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,8 @@ func (r *Replica) handleRaftReadyRaftMuLocked(
}
}

// Grab the known leaseholder before applying to the state machine.
startingLeaseholderID := r.shMu.state.Lease.Replica.ReplicaID
refreshReason := noReason
if hasMsg(msgStorageAppend) {
app := logstore.MakeMsgStorageAppend(msgStorageAppend)
Expand Down Expand Up @@ -1292,6 +1294,15 @@ func (r *Replica) handleRaftReadyRaftMuLocked(
return stats, errors.Wrap(err, "during advance")
}

if leaseholderID := r.shMu.state.Lease.Replica.ReplicaID; leaderID == r.replicaID &&
leaseholderID != startingLeaseholderID &&
leaseholderID != r.replicaID {
// Leader is this replica and leaseholder changed and is some other replica.
// RACv2 needs to know promptly about this in case it needs to force-flush the
// send-queue for the new leaseholder.
r.store.scheduler.EnqueueRaftReady(r.RangeID)
}

// NB: All early returns other than the one due to not having a ready
// which also makes the below call are due to fatal errors.
// We must also update the proposal quota when have a ready; consider the
Expand Down

0 comments on commit 84c1dc4

Please sign in to comment.