This is an automated email from the ASF dual-hosted git repository.
vsarathy1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 6eb19a80ac [NO ISSUE]: Avoid potential overflows
6eb19a80ac is described below
commit 6eb19a80acb6a24989138b7a7a8d2fbc79b91c2f
Author: Savyasach Reddy <[email protected]>
AuthorDate: Fri Jan 31 10:03:06 2025 +0530
[NO ISSUE]: Avoid potential overflows
- user model changes: no
- storage format changes: no
- interface changes: no
details:
- delay might overflow if maxRetries > 50
Change-Id: Icdc500f49ac9b90e169182930489ec6c5fee7552
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19378
Integration-Tests: Jenkins <[email protected]>
Tested-by: Jenkins <[email protected]>
Reviewed-by: Ritik Raj <[email protected]>
---
.../java/org/apache/hyracks/util/ExponentialRetryPolicy.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git
a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ExponentialRetryPolicy.java
b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ExponentialRetryPolicy.java
index a5255ab303..b332a2de14 100644
---
a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ExponentialRetryPolicy.java
+++
b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ExponentialRetryPolicy.java
@@ -25,11 +25,11 @@ public class ExponentialRetryPolicy implements IRetryPolicy
{
private static final int DEFAULT_MAX_RETRIES = 10;
private static final long DEFAULT_INITIAL_DELAY_IN_MILLIS = 100;
- private static final long DEFAULT_MAX_DELAY_IN_MILLIS = Long.MAX_VALUE;
+ private static final long DEFAULT_MAX_DELAY_IN_MILLIS = Long.MAX_VALUE - 1;
private final int maxRetries;
- private final long initialDelay;
private final long maxDelay;
private int attempt = 0;
+ private long delay;
/**
* Default constructor for ExponentialRetryPolicy.
@@ -48,8 +48,8 @@ public class ExponentialRetryPolicy implements IRetryPolicy {
*/
public ExponentialRetryPolicy(int maxRetries, long initialDelay, long
maxDelay) {
this.maxRetries = maxRetries;
- this.initialDelay = initialDelay;
- this.maxDelay = maxDelay;
+ this.maxDelay = Long.min(maxDelay, DEFAULT_MAX_DELAY_IN_MILLIS);
+ this.delay = Long.min(initialDelay, this.maxDelay);
}
/**
@@ -77,12 +77,12 @@ public class ExponentialRetryPolicy implements IRetryPolicy
{
public boolean retry(Throwable failure) {
if (attempt < maxRetries) {
try {
- long delay = initialDelay * (1L << attempt);
-
TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextLong(1 +
Long.min(delay, maxDelay)));
+
TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextLong(1 + delay));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
attempt++;
+ delay = delay > maxDelay / 2 ? maxDelay : delay * 2;
return true;
}
return false;