ddanielr commented on code in PR #4337:
URL: https://github.com/apache/accumulo/pull/4337#discussion_r1532272649


##########
core/src/main/java/org/apache/accumulo/core/util/Retry.java:
##########
@@ -381,6 +388,48 @@ public NeedsRetryDelay maxRetries(long max) {
       return this;
     }
 
+    @Override
+    public NeedsRetryDelay maxRetriesWithinDuration(Duration duration) {
+      checkState();
+      Preconditions.checkArgument(!duration.isNegative(),
+          "Duration for retries must not be negative");
+      this.retriesForDuration = duration;
+      return this;
+    }
+
+    /**
+     * Calculate the maximum number of retries that can occur within {@link 
#retriesForDuration}
+     */
+    private void calculateRetriesWithinDuration() {
+      long numberOfRetries = 0;
+      long cumulativeWaitTimeMillis = 0;
+      long currentWaitTimeMillis = initialWait.toMillis();
+      long retriesForDurationMillis = retriesForDuration.toMillis();
+
+      while (cumulativeWaitTimeMillis + currentWaitTimeMillis <= 
retriesForDurationMillis) {
+
+        cumulativeWaitTimeMillis += currentWaitTimeMillis;
+        numberOfRetries++;
+
+        if (backOffFactor > 1.0) {
+          currentWaitTimeMillis = (long) Math.ceil(currentWaitTimeMillis * 
backOffFactor);
+        } else {
+          currentWaitTimeMillis += waitIncrement.toMillis();
+        }
+
+        if (currentWaitTimeMillis > maxWait.toMillis()) {
+          currentWaitTimeMillis = maxWait.toMillis(); // Ensure wait time does 
not exceed maxWait
+        }
+
+        // prevent an infinite loop
+        if (numberOfRetries >= Integer.MAX_VALUE) {
+          break;
+        }

Review Comment:
   ```suggestion
           // ensure number is always positive to prevent infinite retries
           if (numberOfRetries >= Long.MAX_VALUE) {
             break;
           }
   ```
   Not sure if the comment wording is the best. Overall I think failing the 
calculation with a break is good since this failure will occur before the 
retry's code function is attempted.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to