-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(bigquery): wrap default ResultRetryAlgorithm to retry transient HTTP errors #13416
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |||||||||||||||||||||
| */ | ||||||||||||||||||||||
| package com.google.cloud.bigquery; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import com.google.api.client.http.HttpResponseException; | ||||||||||||||||||||||
| import com.google.api.core.ApiClock; | ||||||||||||||||||||||
| import com.google.api.gax.retrying.DirectRetryingExecutor; | ||||||||||||||||||||||
| import com.google.api.gax.retrying.ExponentialRetryAlgorithm; | ||||||||||||||||||||||
|
|
@@ -23,6 +24,7 @@ | |||||||||||||||||||||
| import com.google.api.gax.retrying.RetrySettings; | ||||||||||||||||||||||
| import com.google.api.gax.retrying.RetryingExecutor; | ||||||||||||||||||||||
| import com.google.api.gax.retrying.RetryingFuture; | ||||||||||||||||||||||
| import com.google.api.gax.retrying.TimedAttemptSettings; | ||||||||||||||||||||||
| import com.google.api.gax.retrying.TimedRetryAlgorithm; | ||||||||||||||||||||||
| import com.google.cloud.RetryHelper; | ||||||||||||||||||||||
| import io.opentelemetry.api.trace.Span; | ||||||||||||||||||||||
|
|
@@ -69,6 +71,9 @@ public static <V> V runWithRetries( | |||||||||||||||||||||
| // implementation does not use response at all, so ignoring its type is ok. | ||||||||||||||||||||||
| @SuppressWarnings("unchecked") | ||||||||||||||||||||||
| ResultRetryAlgorithm<V> algorithm = (ResultRetryAlgorithm<V>) resultRetryAlgorithm; | ||||||||||||||||||||||
| if (algorithm == BigQueryBaseService.DEFAULT_BIGQUERY_EXCEPTION_HANDLER) { | ||||||||||||||||||||||
| algorithm = wrapDefaultAlgorithm(algorithm); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return run( | ||||||||||||||||||||||
| callable, | ||||||||||||||||||||||
| new ExponentialRetryAlgorithm(retrySettings, clock), | ||||||||||||||||||||||
|
|
@@ -119,6 +124,28 @@ private static <V> V run( | |||||||||||||||||||||
| return retryingFuture.get(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private static <V> ResultRetryAlgorithm<V> wrapDefaultAlgorithm( | ||||||||||||||||||||||
| ResultRetryAlgorithm<V> defaultAlgorithm) { | ||||||||||||||||||||||
| return new ResultRetryAlgorithm<V>() { | ||||||||||||||||||||||
| @Override | ||||||||||||||||||||||
| public TimedAttemptSettings createNextAttempt( | ||||||||||||||||||||||
| Throwable previousThrowable, V previousResponse, TimedAttemptSettings previousSettings) { | ||||||||||||||||||||||
| return null; // Delegate timing to TimedRetryAlgorithm | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+130
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of hardcoding
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Override | ||||||||||||||||||||||
| public boolean shouldRetry(Throwable previousThrowable, V previousResponse) { | ||||||||||||||||||||||
| if (previousThrowable instanceof HttpResponseException) { | ||||||||||||||||||||||
| int statusCode = ((HttpResponseException) previousThrowable).getStatusCode(); | ||||||||||||||||||||||
| if (statusCode == 500 || statusCode == 502 || statusCode == 503 || statusCode == 504) { | ||||||||||||||||||||||
| return true; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return defaultAlgorithm.shouldRetry(previousThrowable, previousResponse); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public static class BigQueryRetryHelperException extends RuntimeException { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private static final long serialVersionUID = -8519852520090965314L; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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 these changes be made on the specific RPCs that we want to add it to? I'm worried that this would retry on some non-query RPCs (e.g. createJob or something) which we may not want to retry.