AndrewJSchofield commented on code in PR #14111:
URL: https://github.com/apache/kafka/pull/14111#discussion_r1288667079


##########
clients/src/main/java/org/apache/kafka/clients/Metadata.java:
##########
@@ -119,20 +130,24 @@ public synchronized Cluster fetch() {
      * @return remaining time in ms till the cluster info can be updated again
      */
     public synchronized long timeToAllowUpdate(long nowMs) {
-        return Math.max(this.lastRefreshMs + this.refreshBackoffMs - nowMs, 0);
+        return Math.max(this.lastRefreshMs + 
this.refreshBackoff.backoff(this.attempts) - nowMs, 0);
     }
 
     /**
      * The next time to update the cluster info is the maximum of the time the 
current info will expire and the time the
-     * current info can be updated (i.e. backoff time has elapsed); If an 
update has been request then the expiry time
-     * is now
+     * current info can be updated (i.e. backoff time has elapsed). There are 
two calculations for backing off based on
+     * how many requests with backing off have been issued, and how many 
attempts to retrieve metadata have been made
+     * since the last successful response. The first of these allows backing 
off when there are errors to do with
+     * stale metadata, even though the metadata responses are clean.
      *
      * @param nowMs current time in ms
      * @return remaining time in ms till updating the cluster info
      */
     public synchronized long timeToNextUpdate(long nowMs) {
-        long timeToExpire = updateRequested() ? 0 : 
Math.max(this.lastSuccessfulRefreshMs + this.metadataExpireMs - nowMs, 0);
-        return Math.max(timeToExpire, timeToAllowUpdate(nowMs));
+        long timeToUpdateWithBackoff = Math.max(this.lastRefreshMs +
+                (this.backoffUpdateRequests > 0 ? 
this.refreshBackoff.backoff(this.backoffUpdateRequests - 1) : 0) - nowMs, 0);
+        long timeToExpire = Math.max(this.lastSuccessfulRefreshMs + 
this.metadataExpireMs - nowMs, 0);
+        return Math.max(updateRequested() ? timeToUpdateWithBackoff : 
timeToExpire, timeToAllowUpdate(nowMs));

Review Comment:
   Yes, I agree. I've spun it round to simplify it and added comments. Will 
push the commit soon.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to