DomGarguilo commented on code in PR #4337:
URL: https://github.com/apache/accumulo/pull/4337#discussion_r1531952689
##########
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:
This just makes sure that if an infinite loop occurs for some reason
(`numberOfRetries` is incremented at every iteration) the loop will break after
a very large number. I am not sure this is the best approach and more or less
picked the value to check against at random.
--
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]