You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by dl...@apache.org on 2023/05/23 13:08:56 UTC
[accumulo] branch 2.1 updated: Fix Long overflow in Retry when backoff factor > 1.0 (#3422)
This is an automated email from the ASF dual-hosted git repository.
dlmarion pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new 487f2a34f1 Fix Long overflow in Retry when backoff factor > 1.0 (#3422)
487f2a34f1 is described below
commit 487f2a34f126dad45d8c32465e74d19a357bbf4c
Author: Dave Marion <dl...@apache.org>
AuthorDate: Tue May 23 09:08:50 2023 -0400
Fix Long overflow in Retry when backoff factor > 1.0 (#3422)
Closes #3414
---
.../src/main/java/org/apache/accumulo/core/util/Retry.java | 6 ++++--
.../test/java/org/apache/accumulo/core/util/RetryTest.java | 14 ++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Retry.java b/core/src/main/java/org/apache/accumulo/core/util/Retry.java
index 57260a593b..952d9803cd 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Retry.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Retry.java
@@ -185,8 +185,10 @@ public class Retry {
if (backOffFactor == 1) {
currentWait = Math.min(maxWait, currentWait + waitIncrement);
} else if (backOffFactor > 1.0) {
- waitIncrement = (long) Math.ceil(waitFactor * this.initialWait);
- currentWait = Math.min(maxWait, initialWait + waitIncrement);
+ if (currentWait < maxWait) {
+ waitIncrement = (long) Math.ceil(waitFactor * this.initialWait);
+ currentWait = Math.min(maxWait, initialWait + waitIncrement);
+ }
}
}
diff --git a/core/src/test/java/org/apache/accumulo/core/util/RetryTest.java b/core/src/test/java/org/apache/accumulo/core/util/RetryTest.java
index f58b9dbb7f..ce1933324b 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/RetryTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/RetryTest.java
@@ -330,4 +330,18 @@ public class RetryTest {
assertEquals(logInterval, retry.getLogInterval());
}
+ @Test
+ public void testInfiniteRetryWithBackoff() throws InterruptedException {
+ Retry retry = Retry.builder().infiniteRetries().retryAfter(100, MILLISECONDS)
+ .incrementBy(100, MILLISECONDS).maxWait(500, MILLISECONDS).backOffFactor(1.5)
+ .logInterval(3, MINUTES).createRetry();
+ for (int i = 0; i < 100; i++) {
+ try {
+ retry.waitForNextAttempt(log, i + "");
+ } catch (IllegalArgumentException e) {
+ log.error("Failed on iteration: {}", i);
+ throw e;
+ }
+ }
+ }
}