@@ -370,6 +370,9 @@ const (
370370 // The maximum number of times a replica is retried when it repeatedly returns
371371 // stale lease info.
372372 sameReplicaRetryLimit = 10
373+ // InLeaseTransferBackoffTraceMessage is traced when DistSender backs off as a
374+ // result of a NotLeaseholderError. It is exported for testing.
375+ InLeaseTransferBackoffTraceMessage = "backing off due to NotLeaseHolderErr with stale info"
373376)
374377
375378var rangeDescriptorCacheSize = settings .RegisterIntSetting (
@@ -2899,6 +2902,7 @@ func (ds *DistSender) sendToReplicas(
28992902 // If we get a gRPC error against the leaseholder, we don't want to
29002903 // backoff and keep trying the request against the same leaseholder.
29012904 if lh := routing .Leaseholder (); lh != nil && lh .IsSame (curReplica ) {
2905+ log .VEventf (ctx , 2 , "RPC error and lh %s != curReplica %s; marking leaseholder as unavailable" , lh , curReplica )
29022906 leaseholderUnavailable = true
29032907 }
29042908 } else {
@@ -3008,6 +3012,7 @@ func (ds *DistSender) sendToReplicas(
30083012 // error out when the transport is exhausted even if multiple replicas
30093013 // return NLHEs to different replicas all returning RUEs.
30103014 replicaUnavailableError = br .Error .GoError ()
3015+ log .VEventf (ctx , 2 , "got RUE from lh and lh equals curReplica; marking as leaseholderUnavailable" )
30113016 leaseholderUnavailable = true
30123017 } else if replicaUnavailableError == nil {
30133018 // This is the first time we see a RUE. Record it, such that we'll
@@ -3054,6 +3059,8 @@ func (ds *DistSender) sendToReplicas(
30543059 // prevents accidentally returning a replica unavailable
30553060 // error too aggressively.
30563061 if updatedLeaseholder {
3062+ log .VEventf (ctx , 2 ,
3063+ "updated leaseholder; resetting leaseholderUnavailable and routing to leaseholder" )
30573064 leaseholderUnavailable = false
30583065 routeToLeaseholder = true
30593066 // If we changed the leaseholder, reset the transport to try all the
@@ -3130,7 +3137,10 @@ func (ds *DistSender) sendToReplicas(
31303137 shouldBackoff := ! updatedLeaseholder && ! intentionallySentToFollower && ! leaseholderUnavailable
31313138 if shouldBackoff {
31323139 ds .metrics .InLeaseTransferBackoffs .Inc (1 )
3133- log .VErrEventf (ctx , 2 , "backing off due to NotLeaseHolderErr with stale info" )
3140+ log .VErrEventf (ctx , 2 ,
3141+ InLeaseTransferBackoffTraceMessage +
3142+ " (updatedLH=%t intentionallySentToFollower=%t leaseholderUnavailable=%t)" ,
3143+ updatedLeaseholder , intentionallySentToFollower , leaseholderUnavailable )
31343144 } else {
31353145 inTransferRetry .Reset () // The following Next() call will not block.
31363146 }
0 commit comments