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


##########
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:
   The break here prevents the while loop in `calculateRetriesWithinDuration()` 
from being infinite not the retry process itself. I think its a good idea to 
change it to Long.MAX_VALUE but unless I am misinterpreting something I don't 
think the comment fits here. The comment could probably be refined to specify 
that it is referring too the while loop it is in as opposed to the retry 
process.



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