Skip to content

Commit 5ffaa9e

Browse files
committed
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
1 parent 9a2be97 commit 5ffaa9e

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

pkg/kv/kvserver/replica_range_lease.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,13 +772,24 @@ func (r *Replica) requestLeaseLocked(
772772
// trying to move leases away elsewhere). But if we're the leader, we don't
773773
// really have a choice and we take the lease - there might not be any other
774774
// replica available to take this lease (perhaps they're all draining).
775-
if r.store.IsDraining() && (r.raftBasicStatusRLocked().RaftState != raft.StateLeader) {
776-
// TODO(andrei): If we start refusing to take leases on followers elsewhere,
777-
// this code can go away.
778-
log.VEventf(ctx, 2, "refusing to take the lease because we're draining")
779-
return r.mu.pendingLeaseRequest.newResolvedHandle(roachpb.NewError(
780-
newNotLeaseHolderError(roachpb.Lease{}, r.store.StoreID(), r.mu.state.Desc,
781-
"refusing to take the lease; node is draining")))
775+
if r.store.IsDraining() {
776+
// NB: Replicas that are not the Raft leader will not take leases anyway
777+
// (see the check inside propBuf.FlushLockedWithRaftGroup()), so we don't
778+
// really need any special behavior for draining nodes here. This check
779+
// serves mostly as a means to get more granular logging and as a defensive
780+
// precaution.
781+
if r.raftBasicStatusRLocked().RaftState != raft.StateLeader {
782+
log.VEventf(ctx, 2, "refusing to take the lease because we're draining")
783+
return r.mu.pendingLeaseRequest.newResolvedHandle(
784+
roachpb.NewError(
785+
newNotLeaseHolderError(
786+
roachpb.Lease{}, r.store.StoreID(), r.mu.state.Desc,
787+
"refusing to take the lease; node is draining",
788+
),
789+
),
790+
)
791+
}
792+
log.Info(ctx, "trying to take the lease while we're draining since we're the raft leader")
782793
}
783794

784795
// Propose a Raft command to get a lease for this replica.

0 commit comments

Comments
 (0)