You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/06/04 19:14:38 UTC

[GitHub] [kafka] d8tltanc commented on a change in pull request #8421: KAFKA-9800: [KIP-580] Admin Client Exponential Backoff Implementation

d8tltanc commented on a change in pull request #8421:
URL: https://github.com/apache/kafka/pull/8421#discussion_r435492178



##########
File path: clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java
##########
@@ -683,21 +686,65 @@ public Node provide() {
         }
     }
 
+    /**
+     * Provides context which the retry may refer to
+     */
+    class CallRetryContext {
+
+        private int tries = 0;
+        private long nextAllowedTryMs = 0;
+        private final double JITTER_MIN = 0.8;
+        private final double JITTER_MAX = 1.2;
+
+        public int tries() {
+            return tries;
+        }
+
+        public long nextAllowedTryMs() {
+            return nextAllowedTryMs;
+        }
+
+        private void updateTries(int currentTries) {
+            this.tries = currentTries + 1;
+        }
+
+        private void updateNextAllowTryMs() {
+            double jitter = Math.random() * (JITTER_MAX - JITTER_MIN) + JITTER_MIN;
+            int failures = tries - 1;
+            double exp = Math.pow(2, failures);
+            this.nextAllowedTryMs = time.milliseconds() +
+                    (long) Math.min(retryBackoffMaxMs, jitter * exp * retryBackoffMs);
+            // TODO: Remove the line below
+            System.out.println("nextAllow = " +  (long) Math.min(retryBackoffMaxMs, jitter * exp * retryBackoffMs));
+        }

Review comment:
       Make sense. Will extract it to a util class in my KIP-601 implementation.




----------------------------------------------------------------
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.

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