Skip to content

Commit 2db7ff7

Browse files
docs: update retry guide to use java.time.Duration (#11518)
1 parent 9149c04 commit 2db7ff7

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

docs/client_retries.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Client libraries have two types of retry parameters to configure:
1313

1414
### Default RPC Retry Configuration Location
1515
The default retry configurations are defined in the generated `{Client}StubSettings` file. Using the ExportAssets RPC in
16-
Java-Asset v3.41.0 as an example, the default retry configurations are defined in the following places:
16+
Java-Asset v3.64.0 as an example, the default retry configurations are defined in the following places:
1717
<br>
1818
- Retry Status Codes are configured [here](https://github.com/googleapis/google-cloud-java/blob/d9da511b4b56302e509abe8b2d919a15ea7dcae7/java-asset/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java#L1058-L1082). Example:
1919
```java
@@ -23,23 +23,23 @@ Java-Asset v3.41.0 as an example, the default retry configurations are defined i
2323
RETRYABLE_CODE_DEFINITIONS = definitions.build();
2424
```
2525

26-
- Retry parameters are configured [here](https://github.com/googleapis/google-cloud-java/blob/d9da511b4b56302e509abe8b2d919a15ea7dcae7/java-asset/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java#L1086-L1155). Example:
26+
- Retry parameters are configured [here](https://github.com/googleapis/google-cloud-java/blob/40ca7a8a267ca29837f9a6eceb3933c73551ac11/java-asset/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java#L1105-L1172). Example:
2727
```java
2828
ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();
2929
RetrySettings settings = null;
3030
settings =
3131
RetrySettings.newBuilder()
32-
.setInitialRpcTimeout(Duration.ofMillis(60000L))
32+
.setInitialRpcTimeoutDuration(Duration.ofMillis(60000L))
3333
.setRpcTimeoutMultiplier(1.0)
34-
.setMaxRpcTimeout(Duration.ofMillis(60000L))
35-
.setTotalTimeout(Duration.ofMillis(60000L))
34+
.setMaxRpcTimeoutDuration(Duration.ofMillis(60000L))
35+
.setTotalTimeoutDuration(Duration.ofMillis(60000L))
3636
.build();
3737
definitions.put("no_retry_0_params", settings);
3838
// ... More RetrySettings configurations
3939
RETRY_PARAM_DEFINITIONS = definitions.build();
4040
```
4141

42-
- The configurations above are mapped to the RPC [here](https://github.com/googleapis/google-cloud-java/blob/d9da511b4b56302e509abe8b2d919a15ea7dcae7/java-asset/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java#L1306-L1474). Example:
42+
- The configurations above are mapped to the RPC [here](https://github.com/googleapis/google-cloud-java/blob/40ca7a8a267ca29837f9a6eceb3933c73551ac11/java-asset/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java#L1325-L1491). Example:
4343
```java
4444
builder
4545
.exportAssetsSettings()
@@ -56,29 +56,29 @@ Take a sample RetrySettings configuration
5656
```java
5757
settings =
5858
RetrySettings.newBuilder()
59-
.setInitialRetryDelay(Duration.ofMillis(100L))
59+
.setInitialRetryDelayDuration(Duration.ofMillis(100L))
6060
.setRetryDelayMultiplier(1.3)
61-
.setMaxRetryDelay(Duration.ofMillis(60000L))
62-
.setInitialRpcTimeout(Duration.ofMillis(60000L))
61+
.setMaxRetryDelayDuration(Duration.ofMillis(60000L))
62+
.setInitialRpcTimeoutDuration(Duration.ofMillis(60000L))
6363
.setRpcTimeoutMultiplier(1.0)
64-
.setMaxRpcTimeout(Duration.ofMillis(60000L))
65-
.setTotalTimeout(Duration.ofMillis(60000L))
64+
.setMaxRpcTimeoutDuration(Duration.ofMillis(60000L))
65+
.setTotalTimeoutDuration(Duration.ofMillis(60000L))
6666
.build();
6767
```
6868
The configuration above modifies the retry settings for both an RPC's attempt and operation. An RPC attempt is the
6969
individual attempt made and an RPC operation is collection of all attempts made. A single RPC invocation will
7070
have one or more attempts in a single operation.
7171
7272
Individual RPC Bounds (an attempt) are controlled by the following settings:
73-
- [setInitialRetryDelay](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setInitialRetryDelay_org_threeten_bp_Duration_): Delay before the first attempt
73+
- [setInitialRetryDelayDuration](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setInitialRetryDelayDuration_java_time_Duration_): Delay before the first attempt
7474
- [setRetryDelayMultiplier](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setRetryDelayMultiplier_double_) - Delay multiplier applied between each attempt
75-
- [setMaxRetryDelay](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setMaxRetryDelay_org_threeten_bp_Duration_) - Max Delay possible for an attempt
76-
- [setInitialRpcTimeout](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setInitialRpcTimeout_org_threeten_bp_Duration_) - Timeout for the first attempt
75+
- [setMaxRetryDelayDuration](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setMaxRetryDelayDuration_java_time_Duration_) - Max Delay possible for an attempt
76+
- [setInitialRpcTimeoutDuration](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setInitialRpcTimeoutDuration_java_time_Duration_) - Timeout for the first attempt
7777
- [setRpcTimeoutMultiplier](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setRpcTimeoutMultiplier_double_) - Timeout multiplier applied between each attempt
78-
- [setMaxRpcTimeout](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setMaxRpcTimeout_org_threeten_bp_Duration_) - Max Timeout possible for an attempt
78+
- [setMaxRpcTimeoutDuration](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setMaxRpcTimeoutDuration_java_time_Duration_) - Max Timeout possible for an attempt
7979
8080
Total RPC Bounds (an operation) are controlled by the following settings:
81-
- [setTotalTimeout](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setTotalTimeout_org_threeten_bp_Duration_) - Total timeout allowed the entire operation
81+
- [setTotalTimeout](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setTotalTimeoutDuration_java_time_Duration_) - Total timeout allowed the entire operation
8282
- [setMaxAttempts](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings.Builder#com_google_api_gax_retrying_RetrySettings_Builder_setMaxAttempts_int_) - Max number of attempts allowed
8383
8484
### When is an RPC retried
@@ -153,7 +153,7 @@ value at the end of each attempt.
153153
RetrySettings defaultNoRetrySettings =
154154
RetrySettings.newBuilder()
155155
// Use the default configurations for other settings
156-
.setTotalTimeout(Duration.ofMillis(5000L))
156+
.setTotalTimeoutDuration(Duration.ofMillis(5000L))
157157
// Explicitly set retries as disabled (maxAttempts == 1)
158158
.setMaxAttempts(1)
159159
.build();
@@ -162,7 +162,7 @@ Alternatively, this same behavior can be configured with
162162
```java
163163
RetrySettings defaultNoRetrySettings =
164164
RetrySettings.newBuilder()
165-
.setLogicalTimeout(Duration.ofMillis(5000L))
165+
.setLogicalTimeoutDuration(Duration.ofMillis(5000L))
166166
.build();
167167
```
168168

@@ -176,13 +176,13 @@ The following table shows the attempts:
176176
#### Example 1
177177
```java
178178
RetrySettings.newBuilder()
179-
.setInitialRetryDelay(Duration.ofMillis(200L))
179+
.setInitialRetryDelayDuration(Duration.ofMillis(200L))
180180
.setRetryDelayMultiplier(2.0)
181-
.setMaxRetryDelay(Duration.ofMillis(500L))
182-
.setInitialRpcTimeout(Duration.ofMillis(1500L))
181+
.setMaxRetryDelayDuration(Duration.ofMillis(500L))
182+
.setInitialRpcTimeoutDuration(Duration.ofMillis(1500L))
183183
.setRpcTimeoutMultiplier(2.0)
184-
.setMaxRpcTimeout(Duration.ofMillis(3000L))
185-
.setTotalTimeout(Duration.ofMillis(5000L))
184+
.setMaxRpcTimeoutDuration(Duration.ofMillis(3000L))
185+
.setTotalTimeoutDuration(Duration.ofMillis(5000L))
186186
.build();
187187
```
188188

@@ -201,13 +201,13 @@ This example is similar to Example #1, but has a longer total timeout to showcas
201201
retry attempt and the capped RPC Timeout for the last retry attempt.
202202
```java
203203
RetrySettings.newBuilder()
204-
.setInitialRetryDelay(Duration.ofMillis(200L))
204+
.setInitialRetryDelayDuration(Duration.ofMillis(200L))
205205
.setRetryDelayMultiplier(2.0)
206-
.setMaxRetryDelay(Duration.ofMillis(500L))
207-
.setInitialRpcTimeout(Duration.ofMillis(1500L))
206+
.setMaxRetryDelayDuration(Duration.ofMillis(500L))
207+
.setInitialRpcTimeoutDuration(Duration.ofMillis(1500L))
208208
.setRpcTimeoutMultiplier(2.0)
209-
.setMaxRpcTimeout(Duration.ofMillis(3000L))
210-
.setTotalTimeout(Duration.ofMillis(10000L))
209+
.setMaxRpcTimeoutDuration(Duration.ofMillis(3000L))
210+
.setTotalTimeoutDuration(Duration.ofMillis(10000L))
211211
.build();
212212
```
213213

@@ -227,13 +227,13 @@ exceed the Total Timeout and is reduced to be the "time left" (10000 - 5100 = 49
227227
```java
228228
RetrySettings defaultRetrySettings =
229229
RetrySettings.newBuilder()
230-
.setInitialRetryDelay(Duration.ofMillis(200L))
230+
.setInitialRetryDelayDuration(Duration.ofMillis(200L))
231231
.setRetryDelayMultiplier(2.0)
232-
.setMaxRetryDelay(Duration.ofMillis(500L))
233-
.setInitialRpcTimeout(Duration.ofMillis(500L))
232+
.setMaxRetryDelayDuration(Duration.ofMillis(500L))
233+
.setInitialRpcTimeoutDuration(Duration.ofMillis(500L))
234234
.setRpcTimeoutMultiplier(2.0)
235-
.setMaxRpcTimeout(Duration.ofMillis(2000L))
236-
.setTotalTimeout(Duration.ofMillis(4000L))
235+
.setMaxRpcTimeoutDuration(Duration.ofMillis(2000L))
236+
.setTotalTimeoutDuration(Duration.ofMillis(4000L))
237237
.build();
238238
```
239239

0 commit comments

Comments
 (0)