From 690295eded612108261642176ae4b23cba894dde Mon Sep 17 00:00:00 2001 From: Aayush Shah Date: Sun, 3 Apr 2022 15:27:15 -0400 Subject: [PATCH] kvserver: log when acquiring lease as a draining node Generally, draining nodes are not allowed to acquire leases. Additionally, replicas that are not Raft leaders are not allowed to acquire leases. This means that draining nodes have to be permitted to acquire leases for replicas that they are the Raft leaders for. This commit adds a verbose log event when a draining store acquires a lease because it is the Raft leader. Release note: none --- pkg/kv/kvserver/replica_range_lease.go | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/kv/kvserver/replica_range_lease.go b/pkg/kv/kvserver/replica_range_lease.go index 6aad6682d460..ff70503f15f4 100644 --- a/pkg/kv/kvserver/replica_range_lease.go +++ b/pkg/kv/kvserver/replica_range_lease.go @@ -772,13 +772,26 @@ func (r *Replica) requestLeaseLocked( // trying to move leases away elsewhere). But if we're the leader, we don't // really have a choice and we take the lease - there might not be any other // replica available to take this lease (perhaps they're all draining). - if r.store.IsDraining() && (r.raftBasicStatusRLocked().RaftState != raft.StateLeader) { - // TODO(andrei): If we start refusing to take leases on followers elsewhere, - // this code can go away. - log.VEventf(ctx, 2, "refusing to take the lease because we're draining") - return r.mu.pendingLeaseRequest.newResolvedHandle(roachpb.NewError( - newNotLeaseHolderError(roachpb.Lease{}, r.store.StoreID(), r.mu.state.Desc, - "refusing to take the lease; node is draining"))) + if r.store.IsDraining() { + // NB: Replicas that are not the Raft leader will not take leases anyway + // (see the check inside propBuf.FlushLockedWithRaftGroup()), so we don't + // really need any special behavior for draining nodes here. This check + // serves mostly as a means to get more granular logging and as a defensive + // precaution. + if r.raftBasicStatusRLocked().RaftState != raft.StateLeader { + log.VEventf(ctx, 2, "refusing to take the lease because we're draining") + return r.mu.pendingLeaseRequest.newResolvedHandle( + roachpb.NewError( + newNotLeaseHolderError( + roachpb.Lease{}, r.store.StoreID(), r.mu.state.Desc, + "refusing to take the lease; node is draining", + ), + ), + ) + } + log.VEventf( + ctx, 2, "trying to take the lease while we're draining since we're the raft leader", + ) } // Propose a Raft command to get a lease for this replica.