From 84c1dc498a6fb45757ea077b72ea8b98d1a83b7e Mon Sep 17 00:00:00 2001 From: sumeerbhola Date: Mon, 7 Oct 2024 19:46:43 -0400 Subject: [PATCH] kvserver: schedule ready processing when the leaseholder changes Epic: CRDB-37515 Release note: None --- pkg/kv/kvserver/replica_raft.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/kv/kvserver/replica_raft.go b/pkg/kv/kvserver/replica_raft.go index 3b87a2583854..f19dba9963f2 100644 --- a/pkg/kv/kvserver/replica_raft.go +++ b/pkg/kv/kvserver/replica_raft.go @@ -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) @@ -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