-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Retry overhaul #4718
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
Merged
Merged
Retry overhaul #4718
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
f727b25
Move BatchOptions into models package.
conniey 6a6e38f
Move tests into their respective folders.
conniey f0553dc
Add RetryOptions and RetryMode.
conniey 88237af
Add test for RetryOptions.
conniey 2917b48
Rename Retry -> RetryPolicy
conniey 7017142
Update names for RetryOptions.
conniey b77deaf
Update RetryPolicy and ExponentialRetryPolicy to use new interface.
conniey 5209b38
Add test cases for equality. And fixing ExponentialRetryPolicy tests.
conniey 5579ef3
Fixing documentation error.
conniey 3e40f85
Fix SpotBugs issue.
conniey 1c61e79
Add @inheritDocs
conniey efe958b
Updating RetryPolicy, adding FixedRetry and ExponentialRetry.
conniey a605954
Adding documentation to RetryPolicy.
conniey c983b51
Fix test cases for ExponentialRetryPolicy
conniey 5b879b3
Adding documentation for RetryPolicy.
conniey 045b61c
Add final
conniey 9a136ab
Remove RemainingTime from RetryPolicy. Only works in Send, but not ge…
conniey c4bad4c
Adding tests for FixedRetryPolicy.
conniey 9d6e66e
Add RetryOptionsUtil and TimeoutHandler.
conniey 7894261
Update tests to use RetryOptions and RetryUtil for retry with timeouts.
conniey 8614786
Fixing test.
conniey 48828a2
Remove unneeded logging.
conniey b56d79e
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
conniey 4a4b368
Fix import.
conniey 6a54a8c
Fixing imports
conniey 119adeb
Fixing tests.
conniey 96127d4
Removing Cloneable interface and replacing with concrete implementation.
conniey 64f3fab
If Retry is longer than maximum duration, return that.
conniey d1a1db2
Replacing Cloneable interface.
conniey 5f69a00
Naming changes.
conniey cf1b86c
Add test case for RetryOptionsTest
conniey f3d6b66
Fixing warnings.
conniey b3871f5
Adding RetryUtilTests.
conniey 87bb014
Move into core package.
conniey 6757e0b
Using parallel scheduler. Remove redundant casts.
conniey 05b8ee8
Fix checkstyle error.
conniey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 0 additions & 103 deletions
103
sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/ExponentialRetry.java
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/ExponentialRetryPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.amqp; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
|
|
||
| /** | ||
| * A policy to govern retrying of messaging operations in which the delay between retries will grow in an exponential | ||
| * manner, allowing more time to recover as the number of retries increases. | ||
| */ | ||
| public final class ExponentialRetryPolicy extends RetryPolicy { | ||
| private final double retryFactor; | ||
|
|
||
| /** | ||
| * Creates a new instance with a minimum and maximum retry period in addition to maximum number of retry attempts. | ||
| * | ||
| * @param retryOptions The options to apply to this retry policy. | ||
| * @throws NullPointerException if {@code retryOptions} is {@code null}. | ||
| */ | ||
| public ExponentialRetryPolicy(RetryOptions retryOptions) { | ||
| super(retryOptions); | ||
|
|
||
| this.retryFactor = computeRetryFactor(); | ||
| } | ||
|
|
||
| /** | ||
| * Calculates the retry delay using exponential backoff. | ||
| * | ||
| * @param retryCount The number of attempts that have been made, including the initial attempt before any | ||
| * retries. | ||
| * @param baseDelay The delay to use for the basis of the exponential backoff. | ||
| * @param baseJitter The duration to use for the basis of the random jitter value. | ||
| * @param random The random number generator used to calculate the jitter. | ||
| * @return The duration to delay before retrying a request. | ||
| */ | ||
| @Override | ||
| protected Duration calculateRetryDelay(int retryCount, Duration baseDelay, Duration baseJitter, | ||
| ThreadLocalRandom random) { | ||
| final double jitterSeconds = random.nextDouble() * baseJitter.getSeconds(); | ||
| final double nextRetrySeconds = Math.pow(retryFactor, (double) retryCount); | ||
| final Double nextRetryNanos = (jitterSeconds + nextRetrySeconds) * NANOS_PER_SECOND; | ||
|
|
||
| return baseDelay.plus(Duration.ofNanos(nextRetryNanos.longValue())); | ||
conniey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public int hashCode() { | ||
| return super.hashCode(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
|
|
||
| return obj instanceof ExponentialRetryPolicy | ||
| && super.equals(obj); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a clone of this instance. | ||
| * | ||
| * @return A clone of the {@link ExponentialRetryPolicy} instance. | ||
| */ | ||
| @Override | ||
| public RetryPolicy clone() { | ||
| final RetryOptions cloned = getRetryOptions().clone(); | ||
| return new ExponentialRetryPolicy(cloned); | ||
| } | ||
|
|
||
| private double computeRetryFactor() { | ||
| final RetryOptions options = getRetryOptions(); | ||
| final Duration maxBackoff = options.maxDelay(); | ||
| final Duration minBackoff = options.delay(); | ||
| final int maximumRetries = options.maxRetries(); | ||
| final long deltaBackoff = maxBackoff.minus(minBackoff).getSeconds(); | ||
|
|
||
| if (deltaBackoff <= 0 || maximumRetries <= 0) { | ||
| return 0; | ||
| } | ||
|
|
||
| return Math.log(deltaBackoff) / Math.log(maximumRetries); | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/FixedRetryPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.amqp; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
|
|
||
| /** | ||
| * A policy to govern retrying of messaging operations in which the base delay between retries remains the same. | ||
| */ | ||
| public final class FixedRetryPolicy extends RetryPolicy { | ||
| /** | ||
| * Creates an instance with the given retry options. | ||
| * | ||
| * @param retryOptions The options to set on this retry policy. | ||
| */ | ||
| public FixedRetryPolicy(RetryOptions retryOptions) { | ||
| super(retryOptions); | ||
| } | ||
|
|
||
| /** | ||
| * Calculates the delay for a fixed backoff. | ||
| * | ||
| * @param retryCount The number of attempts that have been made, including the initial attempt before any | ||
| * retries. | ||
| * @param baseDelay The delay to use for the fixed backoff. | ||
| * @param baseJitter The duration to use for the basis of the random jitter value. | ||
| * @param random The random number generator used to calculate the jitter. | ||
| * @return The duration to delay before retrying a request. | ||
| */ | ||
| @Override | ||
| protected Duration calculateRetryDelay(int retryCount, Duration baseDelay, Duration baseJitter, ThreadLocalRandom random) { | ||
| final Double jitterNanos = random.nextDouble() * baseJitter.getSeconds() * RetryPolicy.NANOS_PER_SECOND; | ||
| final Duration jitter = Duration.ofNanos(jitterNanos.longValue()); | ||
|
|
||
| return baseDelay.plus(jitter); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public int hashCode() { | ||
| return super.hashCode(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
|
|
||
| return obj instanceof FixedRetryPolicy | ||
| && super.equals(obj); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a clone of this instance. | ||
| * | ||
| * @return A clone of the {@link FixedRetryPolicy} instance. | ||
| */ | ||
| @Override | ||
| public RetryPolicy clone() { | ||
| final RetryOptions cloned = getRetryOptions().clone(); | ||
| return new FixedRetryPolicy(cloned); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.