From 03858486a4117bbc2a93f1a5901a606826066c9e Mon Sep 17 00:00:00 2001 From: Arul Ajmani Date: Thu, 14 Nov 2024 19:15:31 +0000 Subject: [PATCH] kvserver: add logging if a lease {request, transfer} is not applied It's interesting when a lease request or lease transfer is thrown away and not applied. Log these. Informs cockroachdb#134640 Release note: None --- pkg/kv/kvserver/kvserverbase/forced_error.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/kv/kvserver/kvserverbase/forced_error.go b/pkg/kv/kvserver/kvserverbase/forced_error.go index 2562dfc11308..5bae23dac931 100644 --- a/pkg/kv/kvserver/kvserverbase/forced_error.go +++ b/pkg/kv/kvserver/kvserverbase/forced_error.go @@ -14,6 +14,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/util/log" + "github.com/cockroachdb/redact" ) // ProposalRejectionType indicates how to handle a proposal that was @@ -72,7 +73,22 @@ func CheckForcedErr( raftCmd *kvserverpb.RaftCommand, isLocal bool, replicaState *kvserverpb.ReplicaState, -) ForcedErrResult { +) (res ForcedErrResult) { + isLeaseRequest := raftCmd.ReplicatedEvalResult.IsLeaseRequest + + defer func() { + if res.ForcedError != nil && + raftCmd.ReplicatedEvalResult.State != nil && + raftCmd.ReplicatedEvalResult.State.Lease != nil { + op := redact.SafeString("transfer") + if isLeaseRequest { + op = "request" + } + log.Infof(ctx, "rejected lease %s %s; current lease %s; err: %s", + op, raftCmd.ReplicatedEvalResult.State.Lease, replicaState.Lease, res.ForcedError) + } + }() + if raftCmd.ReplicatedEvalResult.IsProbe { // A Probe is handled by forcing an error during application (which // avoids a separate "success" code path for this type of request) @@ -84,7 +100,6 @@ func CheckForcedErr( } } leaseIndex := replicaState.LeaseAppliedIndex - isLeaseRequest := raftCmd.ReplicatedEvalResult.IsLeaseRequest var requestedLease roachpb.Lease if isLeaseRequest { requestedLease = *raftCmd.ReplicatedEvalResult.State.Lease