Skip to content
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

fix: Modify client lib retry policy for CreateWriteStream with longer backoff, more error code and longer overall time #1679

Merged
merged 4 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ public BigQueryReadStub getStub() {
* @param maxStreamCount Max initial number of streams. If unset or zero, the server will provide
* a value of streams so as to produce reasonable throughput. Must be non-negative. The number
* of streams may be lower than the requested number, depending on the amount parallelism that
* is reasonable for the table. Error will be returned if the max count is greater than the
* current system max limit of 1,000.
* <p>Streams must be read starting from offset 0.
* is reasonable for the table. There is a default system max limit of 1,000.
* <p>This must be greater than or equal to preferred_min_stream_count. Typically, clients
* should either leave this unset to let the system to determine an upper bound OR set this a
* size for the maximum "units of work" it can gracefully handle.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ReadSession createReadSession(
Expand Down Expand Up @@ -243,9 +244,10 @@ public final ReadSession createReadSession(
* @param maxStreamCount Max initial number of streams. If unset or zero, the server will provide
* a value of streams so as to produce reasonable throughput. Must be non-negative. The number
* of streams may be lower than the requested number, depending on the amount parallelism that
* is reasonable for the table. Error will be returned if the max count is greater than the
* current system max limit of 1,000.
* <p>Streams must be read starting from offset 0.
* is reasonable for the table. There is a default system max limit of 1,000.
* <p>This must be greater than or equal to preferred_min_stream_count. Typically, clients
* should either leave this unset to let the system to determine an upper bound OR set this a
* size for the maximum "units of work" it can gracefully handle.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ReadSession createReadSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,20 @@ public static class Builder extends StubSettings.Builder<BigQueryWriteStubSettin
ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =
ImmutableMap.builder();
definitions.put(
"retry_policy_4_codes",
"retry_policy_5_codes",
ImmutableSet.copyOf(
Lists.<StatusCode.Code>newArrayList(
StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
StatusCode.Code.DEADLINE_EXCEEDED,
StatusCode.Code.UNAVAILABLE,
StatusCode.Code.RESOURCE_EXHAUSTED)));
definitions.put(
"retry_policy_3_codes",
ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList(StatusCode.Code.UNAVAILABLE)));
definitions.put(
"retry_policy_4_codes",
ImmutableSet.copyOf(
Lists.<StatusCode.Code>newArrayList(
StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
RETRYABLE_CODE_DEFINITIONS = definitions.build();
}

Expand All @@ -260,15 +267,15 @@ public static class Builder extends StubSettings.Builder<BigQueryWriteStubSettin
RetrySettings settings = null;
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(100L))
.setInitialRetryDelay(Duration.ofMillis(10000L))
.setRetryDelayMultiplier(1.3)
.setMaxRetryDelay(Duration.ofMillis(60000L))
.setInitialRpcTimeout(Duration.ofMillis(600000L))
.setMaxRetryDelay(Duration.ofMillis(120000L))
.setInitialRpcTimeout(Duration.ofMillis(1200000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(600000L))
.setTotalTimeout(Duration.ofMillis(600000L))
.setMaxRpcTimeout(Duration.ofMillis(1200000L))
.setTotalTimeout(Duration.ofMillis(1200000L))
.build();
definitions.put("retry_policy_4_params", settings);
definitions.put("retry_policy_5_params", settings);
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(100L))
Expand All @@ -280,6 +287,17 @@ public static class Builder extends StubSettings.Builder<BigQueryWriteStubSettin
.setTotalTimeout(Duration.ofMillis(86400000L))
.build();
definitions.put("retry_policy_3_params", settings);
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(100L))
.setRetryDelayMultiplier(1.3)
.setMaxRetryDelay(Duration.ofMillis(60000L))
.setInitialRpcTimeout(Duration.ofMillis(600000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(600000L))
.setTotalTimeout(Duration.ofMillis(600000L))
.build();
definitions.put("retry_policy_4_params", settings);
RETRY_PARAM_DEFINITIONS = definitions.build();
}

Expand Down Expand Up @@ -342,8 +360,8 @@ private static Builder createDefault() {
private static Builder initDefaults(Builder builder) {
builder
.createWriteStreamSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_4_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_4_params"));
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_5_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_5_params"));

builder
.getWriteStreamSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ public void createWriteStreamExceptionTest2() throws Exception {
@Test
public void appendRowsTest() throws Exception {
AppendRowsResponse expectedResponse =
AppendRowsResponse.newBuilder().setUpdatedSchema(TableSchema.newBuilder().build()).build();
AppendRowsResponse.newBuilder()
.setUpdatedSchema(TableSchema.newBuilder().build())
.addAllRowErrors(new ArrayList<RowError>())
.build();
mockBigQueryWrite.addResponse(expectedResponse);
AppendRowsRequest request =
AppendRowsRequest.newBuilder()
Expand Down
Loading