DomGarguilo commented on code in PR #4337:
URL: https://github.com/apache/accumulo/pull/4337#discussion_r1532608955
##########
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:
> What if we used something relative to time as the loop limit?
> Like `Duration.ofHours(1).toMillis()`? this would limit number of retries
to 3,600,000 or lower.
This makes a lot of sense. Good idea. Added in 2394559
--
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]