Skip to content

Commit 6e459be

Browse files
authored
Change retries 2.1 builder param to nullable (#6927)
This will allow us to better track opt-in behavior in the UA.
1 parent a682952 commit 6e459be

5 files changed

Lines changed: 38 additions & 30 deletions

File tree

core/aws-core/src/main/java/software/amazon/awssdk/awscore/retry/AwsRetryStrategy.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static RetryStrategy forRetryMode(RetryMode mode) {
8282
* @param newRetries2026Enabled Whether retries 2.1 behavior is enabled.
8383
* @return A retry strategy for the given retry mode.
8484
*/
85-
public static RetryStrategy forRetryMode(RetryMode mode, boolean newRetries2026Enabled) {
85+
public static RetryStrategy forRetryMode(RetryMode mode, Boolean newRetries2026Enabled) {
8686
switch (mode) {
8787
case STANDARD:
8888
return standardRetryStrategy(newRetries2026Enabled);
@@ -135,7 +135,7 @@ public static StandardRetryStrategy standardRetryStrategy() {
135135
* @param newRetries2026Enabled Whether retries 2.1 behavior is enabled.
136136
* @return A {@link StandardRetryStrategy} with AWS-specific conditions added.
137137
*/
138-
public static StandardRetryStrategy standardRetryStrategy(boolean newRetries2026Enabled) {
138+
public static StandardRetryStrategy standardRetryStrategy(Boolean newRetries2026Enabled) {
139139
StandardRetryStrategy.Builder builder = SdkDefaultRetryStrategy.standardRetryStrategyBuilder(newRetries2026Enabled);
140140
return configure(builder, newRetries2026Enabled).build();
141141
}
@@ -167,7 +167,7 @@ public static AdaptiveRetryStrategy adaptiveRetryStrategy() {
167167
* @param newRetries2026Enabled Whether retries 2.1 behavior is enabled.
168168
* @return An {@link AdaptiveRetryStrategy} with AWS-specific conditions added.
169169
*/
170-
public static AdaptiveRetryStrategy adaptiveRetryStrategy(boolean newRetries2026Enabled) {
170+
public static AdaptiveRetryStrategy adaptiveRetryStrategy(Boolean newRetries2026Enabled) {
171171
AdaptiveRetryStrategy.Builder builder = SdkDefaultRetryStrategy.adaptiveRetryStrategyBuilder(newRetries2026Enabled);
172172
return configure(builder, newRetries2026Enabled)
173173
.build();
@@ -191,9 +191,9 @@ public static AdaptiveRetryStrategy adaptiveRetryStrategy(boolean newRetries2026
191191
* @param <T> The type of the builder extending {@link RetryStrategy.Builder}
192192
* @return The given builder
193193
*/
194-
private static <T extends RetryStrategy.Builder<T, ?>> T configure(T builder, boolean newRetries2026Enabled) {
194+
private static <T extends RetryStrategy.Builder<T, ?>> T configure(T builder, Boolean newRetries2026Enabled) {
195195
builder.retryOnException(AwsRetryStrategy::retryOnAwsRetryableErrors);
196-
if (newRetries2026Enabled) {
196+
if (Boolean.TRUE.equals(newRetries2026Enabled)) {
197197
builder.retryOnException(AwsRetryStrategy::isLimitExceededErrorCode);
198198
builder.treatAsThrottling(AwsRetryStrategy::treatAsThrottlingV21);
199199
}

core/retries/src/main/java/software/amazon/awssdk/retries/AdaptiveRetryStrategy.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,19 @@ static AdaptiveRetryStrategy.Builder builder() {
7171
/**
7272
* Create a new {@link AdaptiveRetryStrategy.Builder} with v2.0 or v2.1 retry constants.
7373
*
74-
* @param retries2026Enabled when {@code true}, uses v2.1 constants (50ms base delay, differentiated token costs);
75-
* when {@code false}, uses v2.0 constants (100ms base delay, uniform token costs)
74+
* @param retries2026Enabled when {@code true}, uses v2.1 constants (50ms base delay, differentiated token costs); when
75+
* {@code false}, uses v2.0 constants (100ms base delay, uniform token costs)
7676
*/
77-
static AdaptiveRetryStrategy.Builder builder(boolean retries2026Enabled) {
78-
Duration baseDelay = retries2026Enabled ? DefaultRetryStrategy.Standard.BASE_DELAY_V21
79-
: DefaultRetryStrategy.Standard.BASE_DELAY_V20;
80-
int exceptionCost = retries2026Enabled ? DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V21
81-
: DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V20;
77+
static AdaptiveRetryStrategy.Builder builder(Boolean retries2026Enabled) {
78+
boolean retries21 = Boolean.TRUE.equals(retries2026Enabled);
79+
80+
Duration baseDelay = retries21 ? DefaultRetryStrategy.Standard.BASE_DELAY_V21
81+
: DefaultRetryStrategy.Standard.BASE_DELAY_V20;
82+
int exceptionCost = retries21 ? DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V21
83+
: DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V20;
8284
// v2.0 does not treat throttling exceptions differently from others
83-
int throttlingCost = retries2026Enabled ? DefaultRetryStrategy.Standard.THROTTLING_EXCEPTION_TOKEN_COST_V21
84-
: exceptionCost;
85+
int throttlingCost = retries21 ? DefaultRetryStrategy.Standard.THROTTLING_EXCEPTION_TOKEN_COST_V21
86+
: exceptionCost;
8587
return DefaultAdaptiveRetryStrategy
8688
.builder()
8789
.maxAttempts(DefaultRetryStrategy.Adaptive.MAX_ATTEMPTS)

core/retries/src/main/java/software/amazon/awssdk/retries/DefaultRetryStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static StandardRetryStrategy.Builder standardStrategyBuilder() {
6767
*
6868
* @param retries2026Enabled Whether retries 2.1 behavior is used.
6969
*/
70-
public static StandardRetryStrategy.Builder standardStrategyBuilder(boolean retries2026Enabled) {
70+
public static StandardRetryStrategy.Builder standardStrategyBuilder(Boolean retries2026Enabled) {
7171
return StandardRetryStrategy.builder(retries2026Enabled);
7272
}
7373

@@ -117,7 +117,7 @@ public static AdaptiveRetryStrategy.Builder adaptiveStrategyBuilder() {
117117
*
118118
* @param retries2026Enabled Whether retries 2.1 behavior is used.
119119
*/
120-
public static AdaptiveRetryStrategy.Builder adaptiveStrategyBuilder(boolean retries2026Enabled) {
120+
public static AdaptiveRetryStrategy.Builder adaptiveStrategyBuilder(Boolean retries2026Enabled) {
121121
return AdaptiveRetryStrategy.builder(retries2026Enabled);
122122
}
123123

core/retries/src/main/java/software/amazon/awssdk/retries/StandardRetryStrategy.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ static Builder builder() {
6363
/**
6464
* Create a new {@link StandardRetryStrategy.Builder} with v2.0 or v2.1 retry constants.
6565
*
66-
* @param retries2026Enabled when {@code true}, uses v2.1 constants (50ms base delay, differentiated token costs);
67-
* when {@code false}, uses v2.0 constants (100ms base delay, uniform token costs)
66+
* @param retries2026Enabled when {@code true}, uses v2.1 constants (50ms base delay, differentiated token costs); when
67+
* {@code false}, uses v2.0 constants (100ms base delay, uniform token costs)
6868
*/
69-
static Builder builder(boolean retries2026Enabled) {
70-
Duration baseDelay = retries2026Enabled ? DefaultRetryStrategy.Standard.BASE_DELAY_V21
71-
: DefaultRetryStrategy.Standard.BASE_DELAY_V20;
72-
int exceptionCost = retries2026Enabled ? DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V21
73-
: DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V20;
69+
static Builder builder(Boolean retries2026Enabled) {
70+
boolean retries21 = Boolean.TRUE.equals(retries2026Enabled);
71+
72+
Duration baseDelay = retries21 ? DefaultRetryStrategy.Standard.BASE_DELAY_V21
73+
: DefaultRetryStrategy.Standard.BASE_DELAY_V20;
74+
int exceptionCost = retries21 ? DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V21
75+
: DefaultRetryStrategy.Standard.DEFAULT_EXCEPTION_TOKEN_COST_V20;
7476
// v2.0 does not treat throttling exceptions differently from others
75-
int throttlingCost = retries2026Enabled ? DefaultRetryStrategy.Standard.THROTTLING_EXCEPTION_TOKEN_COST_V21
76-
: exceptionCost;
77+
int throttlingCost = retries21 ? DefaultRetryStrategy.Standard.THROTTLING_EXCEPTION_TOKEN_COST_V21
78+
: exceptionCost;
7779
return DefaultStandardRetryStrategy
7880
.builder()
7981
.retries2026Enabled(retries2026Enabled)

core/retries/src/main/java/software/amazon/awssdk/retries/internal/DefaultStandardRetryStrategy.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public final class DefaultStandardRetryStrategy
3030
extends BaseRetryStrategy implements StandardRetryStrategy {
3131
private static final Logger LOG = Logger.loggerFor(DefaultStandardRetryStrategy.class);
3232
private static final Duration FIVE_SECONDS = Duration.ofSeconds(5);
33-
private final boolean retries2026Enabled;
33+
private final Boolean retries2026Enabled;
3434

3535
DefaultStandardRetryStrategy(Builder builder) {
3636
super(LOG, builder);
@@ -48,7 +48,7 @@ public static Builder builder() {
4848

4949
@Override
5050
protected Duration computeAcquireFailureBackoff(RefreshRetryTokenRequest request) {
51-
if (!retries2026Enabled || !request.isLongPolling()) {
51+
if (!isRetries2026Enabled() || !request.isLongPolling()) {
5252
return super.computeAcquireFailureBackoff(request);
5353
}
5454

@@ -60,7 +60,7 @@ protected Duration computeAcquireFailureBackoff(RefreshRetryTokenRequest request
6060

6161
@Override
6262
protected Duration computeBackoff(RefreshRetryTokenRequest request, DefaultRetryToken token) {
63-
if (!retries2026Enabled) {
63+
if (!isRetries2026Enabled()) {
6464
return super.computeBackoff(request, token);
6565
}
6666

@@ -90,8 +90,12 @@ protected Duration computeBackoff(RefreshRetryTokenRequest request, DefaultRetry
9090
return backoff;
9191
}
9292

93+
private boolean isRetries2026Enabled() {
94+
return Boolean.TRUE.equals(retries2026Enabled);
95+
}
96+
9397
public static class Builder extends BaseRetryStrategy.Builder implements StandardRetryStrategy.Builder {
94-
private boolean retries2026Enabled;
98+
private Boolean retries2026Enabled;
9599

96100
Builder() {
97101
}
@@ -160,7 +164,7 @@ public Builder useClientDefaults(boolean useClientDefaults) {
160164
/**
161165
* Whether retries 2.1 behavior is enabled.
162166
*/
163-
public Builder retries2026Enabled(boolean retries2026Enabled) {
167+
public Builder retries2026Enabled(Boolean retries2026Enabled) {
164168
this.retries2026Enabled = retries2026Enabled;
165169
return this;
166170
}

0 commit comments

Comments
 (0)