-
Notifications
You must be signed in to change notification settings - Fork 814
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
New API for the retries module #3769
New API for the retries module #3769
Conversation
This new module includes the interfaces and classes that will be used to implement the new retry logic within the SDK.
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.
Left some initial comments, still going through the PR.
core/retries-api/pom.xml
Outdated
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> |
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.
Let's remove junit4 and use junit5 for all tests in this module.
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.
Sure, I will change it.
/** | ||
* Strategy that waits for a period of time equal to the provided delay. | ||
*/ | ||
final class FixedDelayWithoutJitter implements BackoffStrategy { |
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.
Can we create separate classes for them?
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.
Sure, I can move those into their own files.
* Configure the strategy to retry the root cause of a failure (the final cause) a failure exception is an instance of to | ||
* the provided class (includes subtypes). | ||
*/ | ||
default Builder retryOnRootCauseInstanceOf(Class<? extends Throwable> throwable) { |
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.
I wonder if we should expose so many retryXXX methods. Too many APIs could make this harder to understand and use.
The number of APIs will be doubled if we add varargs overloads.
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.
I guess that some of these conditions are subtle and error prone, having these spell out with proper names make the API easier to use and understand, but I can remove some of these. Which ones do you think it will be worth keeping and which ones do you think we can go without?
* Configure the strategy to retry when a failure exception class is an instance of the provided class (includes | ||
* subtypes). | ||
*/ | ||
default Builder retryOnExceptionInstanceOf(Class<? extends Throwable> throwable) { |
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.
Should we create APIs to allow users to pass a list of exceptions?
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.
I guess the argument in favor would be that it will make some expressions easier but the same can be accomplish by calling this method for each. Since I'm not quite sure that this will add much I think it would be better to do that when and if the need araises.
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.retriesapi; |
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.
Should it be software.amazon.awssdk.retries.api
?
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.
I just realized that the original plan was to use instead software.amazon.awssdk.api.retries
, I can go either way but I like the original idea better, thoughts?
@SdkPublicApi | ||
@ThreadSafe | ||
public interface BackoffStrategy { | ||
Duration BASE_DELAY_CEILING = Duration.ofMillis(Integer.MAX_VALUE); // Around ~24.8 days |
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.
These constants seem to be implementation details, should we move them to the classes that use them? If they are shared between classes, should we move them to a constant class?
* Exception thrown by {@link RetryStrategy} when a new token cannot be acquired. | ||
*/ | ||
@SdkPublicApi | ||
public final class TokenAcquisitionFailedException extends RuntimeException { |
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.
I wonder if it should extend SdkClientException to make it easier for customers to handle
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.
I guess we could depend on core
, but not sure if we want to complect those. This package for now only depends on annotations
and utils
and I feel that adding sdk-core
will make it a lot less easier to reuse outside the SDK.
Also, moved the backoff strategies out of the interface class an into their own clasess and remove the constants from the interface into its own class.
* Move the namespace from api.retries to retries.api to make it consistent with the identity module * Remove the backoff implementations and static methods from the interface, those classes will be living in the implementation package.
core/retries-api/pom.xml
Outdated
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>software.amazon.awssdk.retriesapi</Automatic-Module-Name> |
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.
This needs to match with the top-level package name.
SonarCloud Quality Gate failed. |
* New API for the retries module (#3769) This new module includes the interfaces and classes that will be used to implement the new retry logic within the SDK. * Add default backoff strategies (#3906) * Add default backoff strategies * Moved the backoff strategires to the SPI package * Use AssertJ instead of Hamcrest * Add standard retry strategy (#3931) * Add standard retry strategy * Fix the AcquireInitialTokenRequestImpl API annotation Also add the package to the test/tests-coverage-reporting/pom.xml to get coverage reporting * Add adaptive retry strategy (#3975) * Add adaptive retry strategy * Address pull request comments * Address PR comments * Address PR comments * Update retries and retries-api to snapshot version: 2.20.64-SNAPSHOT * Fix SonarCloud code smells (#3991) * Fix SonarCloud code smells * Move AdaptiveRetryStrategyResourceConstrainedTest to an integration test This change is to workaround the SonarCloud code smell of the Sleep usage in this test * Add legacy retry strategy (#3988) * Add legacy retry strategy * Remove public modifiers from test classes to make SonarCloud happy * Fix another SonarCloud code smell * WIP * Address PR comments * Rename all the strategies to use Default prefix instead of Impl suffix * Address PR comments * Remove those tests that are now part of a different class * Update version after merge from master * Refactor retry strategies (#4039) * Refactor the retry strategies This change uses a single class to implement the core logic of all the retries strategies and adds extension points to tailor the behavior when needed. * Rename to BaseRetryStrategy and make it abstract * Remove previous implementations and rename the new ones * Update sdk version * Fix the retry condition to just look for the initial cause * Add new sync and async retryable stages (#4062) * Add new sync and async retryable stages * Address PR comments * Update sdk version * Change uses of RetryPolicy to RetryStrategy (#4125) * Update sdk version * Deprecate legacy classes and use new when possible (#4154) * Deprecate legacy classes and use new when possible * Fix checkstyle and add some more validation * Add missing @deprecated annotation * Add missing dependency to the retries-api module * Fix minor logging issues * Update sdk version * Add support for retryable trait (#4170) * Merge master * Update to support plugins * Add support for AWS retryable conditions * Use the correct token bucket exception cost value * Add ADAPTIVE_V2 retry mode to support the legacy behavior (#5123) * Add a new ADAPTIVE2 mode to support the legacy behavior * Fix dynamodb test to use adaptive2 mode * Fixes and tests for the expected behaviors * Rename the new adaptive mode to ADAPTIVE_V2 * More fixes related to the rename from adaptive2 to adaptive_v2 * Fix dynamodb retry resolver logic for adaptive mode * Properly clean up the test state * Address PR comments * Remove a small typo * Dumy commit * Dummy commit to kick the internal build * Rename retries-api to retries-spi * Add retry packages to brazil (#5215) * Add retry packages to brazil * Update pom's as per the new module checklist * Remove type params from RetryStrategy, but keep them in RetryStrategy… (#5262) * Remove type params from RetryStrategy, but keep them in RetryStrategy.Builder * Rename from `none` to `doNotRetry` to clarify the behavior * External names used for retry modes only support 'adaptive' (#5265) * Externally named retry modes only support 'adaptive' Behind the scenes this will be mapped to RetryMode.ADAPTIVE_V2 which makes it a non-backwards compatible behavioral change. * Sneak in a fix from the previous PR * Fix a test that expects adaptive to map to `RetryMode.ADAPTIVE` * Fix typos in the comments * Retries release (#5280) * Bump version to 2.26.0-SNAPSHOT * Add retry release changlog entry * Add missing deprecation annotation and javadoc tag * Archive the last changelog from the 2.25 series --------- Co-authored-by: John Viegas <70235430+joviegas@users.noreply.github.com>
* New API for the retries module (aws#3769) This new module includes the interfaces and classes that will be used to implement the new retry logic within the SDK. * Add default backoff strategies (aws#3906) * Add default backoff strategies * Moved the backoff strategires to the SPI package * Use AssertJ instead of Hamcrest * Add standard retry strategy (aws#3931) * Add standard retry strategy * Fix the AcquireInitialTokenRequestImpl API annotation Also add the package to the test/tests-coverage-reporting/pom.xml to get coverage reporting * Add adaptive retry strategy (aws#3975) * Add adaptive retry strategy * Address pull request comments * Address PR comments * Address PR comments * Update retries and retries-api to snapshot version: 2.20.64-SNAPSHOT * Fix SonarCloud code smells (aws#3991) * Fix SonarCloud code smells * Move AdaptiveRetryStrategyResourceConstrainedTest to an integration test This change is to workaround the SonarCloud code smell of the Sleep usage in this test * Add legacy retry strategy (aws#3988) * Add legacy retry strategy * Remove public modifiers from test classes to make SonarCloud happy * Fix another SonarCloud code smell * WIP * Address PR comments * Rename all the strategies to use Default prefix instead of Impl suffix * Address PR comments * Remove those tests that are now part of a different class * Update version after merge from master * Refactor retry strategies (aws#4039) * Refactor the retry strategies This change uses a single class to implement the core logic of all the retries strategies and adds extension points to tailor the behavior when needed. * Rename to BaseRetryStrategy and make it abstract * Remove previous implementations and rename the new ones * Update sdk version * Fix the retry condition to just look for the initial cause * Add new sync and async retryable stages (aws#4062) * Add new sync and async retryable stages * Address PR comments * Update sdk version * Change uses of RetryPolicy to RetryStrategy (aws#4125) * Update sdk version * Deprecate legacy classes and use new when possible (aws#4154) * Deprecate legacy classes and use new when possible * Fix checkstyle and add some more validation * Add missing @deprecated annotation * Add missing dependency to the retries-api module * Fix minor logging issues * Update sdk version * Add support for retryable trait (aws#4170) * Merge master * Update to support plugins * Add support for AWS retryable conditions * Use the correct token bucket exception cost value * Add ADAPTIVE_V2 retry mode to support the legacy behavior (aws#5123) * Add a new ADAPTIVE2 mode to support the legacy behavior * Fix dynamodb test to use adaptive2 mode * Fixes and tests for the expected behaviors * Rename the new adaptive mode to ADAPTIVE_V2 * More fixes related to the rename from adaptive2 to adaptive_v2 * Fix dynamodb retry resolver logic for adaptive mode * Properly clean up the test state * Address PR comments * Remove a small typo * Dumy commit * Dummy commit to kick the internal build * Rename retries-api to retries-spi * Add retry packages to brazil (aws#5215) * Add retry packages to brazil * Update pom's as per the new module checklist * Remove type params from RetryStrategy, but keep them in RetryStrategy… (aws#5262) * Remove type params from RetryStrategy, but keep them in RetryStrategy.Builder * Rename from `none` to `doNotRetry` to clarify the behavior * External names used for retry modes only support 'adaptive' (aws#5265) * Externally named retry modes only support 'adaptive' Behind the scenes this will be mapped to RetryMode.ADAPTIVE_V2 which makes it a non-backwards compatible behavioral change. * Sneak in a fix from the previous PR * Fix a test that expects adaptive to map to `RetryMode.ADAPTIVE` * Fix typos in the comments * Retries release (aws#5280) * Bump version to 2.26.0-SNAPSHOT * Add retry release changlog entry * Add missing deprecation annotation and javadoc tag * Archive the last changelog from the 2.25 series --------- Co-authored-by: John Viegas <70235430+joviegas@users.noreply.github.com>
This new module includes the interfaces and classes that will be used to implement the new retry logic within the SDK.
Motivation and Context
As part of the Smithy Reference Architecture this change adds a new module for retries. This change adds only the API part.
Modifications
No modifications to existing code were made. We will make those changes in follow up pull requests.
Testing
RetryStrategy.Builder
interface that create lambdas to be used to decide if an exception should be retried.ExponentialDelayWithJitter
andFixedDelayWithJitterTest
similar to the tests present for its equivalent class hereScreenshots (if appropriate)
N/A
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License