-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated retryWith values and added salting to match compute/.NET behavior #24619
Changes from 5 commits
5271bdd
4bcf079
652f177
85f0086
3124606
581384e
3840506
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Random; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull; | ||
|
||
|
@@ -36,6 +38,7 @@ public class GoneAndRetryWithRetryPolicy implements IRetryPolicy { | |
|
||
private volatile RetryWithException lastRetryWithException; | ||
private RetryContext retryContext; | ||
static final ThreadLocalRandom random = ThreadLocalRandom.current(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private |
||
|
||
public GoneAndRetryWithRetryPolicy(RxDocumentServiceRequest request, Integer waitTimeInSeconds) { | ||
this.retryContext = BridgeInternal.getRetryContext(request.requestContext.cosmosDiagnostics); | ||
|
@@ -171,7 +174,6 @@ public Mono<ShouldRetryResult> shouldRetry(Exception exception) { | |
Duration timeout; | ||
boolean forceRefreshAddressCache; | ||
if (isNonRetryableException(exception)) { | ||
|
||
logger.debug("Operation will NOT be retried. Current attempt {}, Exception: ", this.attemptCount, | ||
exception); | ||
return Mono.just(ShouldRetryResult.noRetryOnNonRelatedException()); | ||
|
@@ -291,9 +293,10 @@ private Pair<Mono<ShouldRetryResult>, Boolean> handleInvalidPartitionException(I | |
|
||
class RetryWithRetryPolicy implements IRetryPolicy { | ||
private final static int DEFAULT_WAIT_TIME_IN_SECONDS = 30; | ||
private final static int MAXIMUM_BACKOFF_TIME_IN_MS = 15000; | ||
private final static int MAXIMUM_BACKOFF_TIME_IN_MS = 1000; | ||
private final static int INITIAL_BACKOFF_TIME_MS = 10; | ||
private final static int BACK_OFF_MULTIPLIER = 2; | ||
private final static int RANDOM_SALT_IN_MS = 5; | ||
|
||
private volatile int attemptCount = 1; | ||
private volatile int currentBackoffMilliseconds = RetryWithRetryPolicy.INITIAL_BACKOFF_TIME_MS; | ||
|
@@ -334,7 +337,7 @@ public Mono<ShouldRetryResult> shouldRetry(Exception exception) { | |
|
||
backoffTime = Duration.ofMillis( | ||
Math.min( | ||
Math.min(this.currentBackoffMilliseconds, remainingMilliseconds), | ||
Math.min(this.currentBackoffMilliseconds + random.nextInt(RANDOM_SALT_IN_MS), remainingMilliseconds), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it include both positive and negative salt value ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
RetryWithRetryPolicy.MAXIMUM_BACKOFF_TIME_IN_MS)); | ||
this.currentBackoffMilliseconds *= RetryWithRetryPolicy.BACK_OFF_MULTIPLIER; | ||
logger.debug("BackoffTime: {} ms.", backoffTime.toMillis()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this unused import? if so remove