From ecdf544fc8b8c1f3087d67cf477a5a34bc957779 Mon Sep 17 00:00:00 2001 From: Andrew Baptist Date: Thu, 9 May 2024 10:46:54 -0400 Subject: [PATCH] kvserver: move maybeRefreshProposals to own method Allows the use of deferred unlock. Release note: None Part of: #105366 --- pkg/kv/kvserver/replica_raft.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/kv/kvserver/replica_raft.go b/pkg/kv/kvserver/replica_raft.go index 66a06142dfa9..a6f3d791cd3c 100644 --- a/pkg/kv/kvserver/replica_raft.go +++ b/pkg/kv/kvserver/replica_raft.go @@ -1141,11 +1141,7 @@ func (r *Replica) handleRaftReadyRaftMuLocked( if r.store.TestingKnobs().EnableUnconditionalRefreshesInRaftReady { refreshReason = reasonNewLeaderOrConfigChange } - if refreshReason != noReason { - r.mu.Lock() - r.refreshProposalsLocked(ctx, 0 /* refreshAtDelta */, refreshReason) - r.mu.Unlock() - } + r.maybeRefreshProposals(ctx, refreshReason) // NB: if we just processed a command which removed this replica from the // raft group we will early return before this point. This, combined with @@ -1199,6 +1195,14 @@ func (r *Replica) handleRaftReadyRaftMuLocked( return stats, nil } +func (r *Replica) maybeRefreshProposals(ctx context.Context, refreshReason refreshRaftReason) { + if refreshReason != noReason { + r.mu.Lock() + defer r.mu.Unlock() + r.refreshProposalsLocked(ctx, 0 /* refreshAtDelta */, refreshReason) + } +} + // asyncReady encapsulates the messages that are ready to be sent to other peers // or to be sent to local storage routines when async storage writes are enabled. // All fields in asyncReady are read-only.