-
Notifications
You must be signed in to change notification settings - Fork 84
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
feat: retry certain RESOURCE_EXHAUSTED errors observed during ReadRows and report retry attempts #1257
feat: retry certain RESOURCE_EXHAUSTED errors observed during ReadRows and report retry attempts #1257
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 |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
import com.google.api.gax.retrying.TimedAttemptSettings; | ||
import com.google.api.gax.rpc.ApiException; | ||
import com.google.cloud.bigquery.storage.util.Errors; | ||
import com.google.cloud.bigquery.storage.v1.BigQueryReadSettings; | ||
import io.grpc.Metadata; | ||
import io.grpc.Status; | ||
import org.threeten.bp.Duration; | ||
|
||
|
@@ -30,17 +32,41 @@ public class ApiResultRetryAlgorithm<ResponseT> implements ResultRetryAlgorithm< | |
// Duration to sleep on if the error is DEADLINE_EXCEEDED. | ||
public static final Duration DEADLINE_SLEEP_DURATION = Duration.ofMillis(1); | ||
|
||
private final BigQueryReadSettings.RetryAttemptListener retryAttemptListener; | ||
|
||
public ApiResultRetryAlgorithm() { | ||
this(null); | ||
} | ||
|
||
public ApiResultRetryAlgorithm(BigQueryReadSettings.RetryAttemptListener retryAttemptListener) { | ||
super(); | ||
this.retryAttemptListener = retryAttemptListener; | ||
} | ||
|
||
@Override | ||
public TimedAttemptSettings createNextAttempt( | ||
Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { | ||
if (prevThrowable != null) { | ||
Status status = Status.fromThrowable(prevThrowable); | ||
if (Errors.isRetryableInternalStatus(status)) { | ||
Metadata metadata = Status.trailersFromThrowable(prevThrowable); | ||
Errors.IsRetryableStatusResult result = Errors.isRetryableStatus(status, metadata); | ||
if (result.isRetryable) { | ||
// If result.retryDelay isn't null, we know exactly how long we must wait, so both regular | ||
// and randomized delays are the same. | ||
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. Should there still be variance for the randomized delay? result.retryDelay + jitter? Looks like the previous impl didn't jitter either so likely can be ignored if its not been a source of issues. 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. I don't think it is needed in this case. |
||
Duration retryDelay = result.retryDelay; | ||
Duration randomizedRetryDelay = result.retryDelay; | ||
if (retryDelay == null) { | ||
retryDelay = prevSettings.getRetryDelay(); | ||
randomizedRetryDelay = DEADLINE_SLEEP_DURATION; | ||
} | ||
if (retryAttemptListener != null) { | ||
retryAttemptListener.onRetryAttempt(status, metadata); | ||
} | ||
return TimedAttemptSettings.newBuilder() | ||
.setGlobalSettings(prevSettings.getGlobalSettings()) | ||
.setRetryDelay(prevSettings.getRetryDelay()) | ||
.setRetryDelay(retryDelay) | ||
.setRpcTimeout(prevSettings.getRpcTimeout()) | ||
.setRandomizedRetryDelay(DEADLINE_SLEEP_DURATION) | ||
.setRandomizedRetryDelay(randomizedRetryDelay) | ||
.setAttemptCount(prevSettings.getAttemptCount() + 1) | ||
.setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) | ||
.build(); | ||
|
@@ -53,7 +79,8 @@ public TimedAttemptSettings createNextAttempt( | |
public boolean shouldRetry(Throwable prevThrowable, ResponseT prevResponse) { | ||
if (prevThrowable != null) { | ||
Status status = Status.fromThrowable(prevThrowable); | ||
if (Errors.isRetryableInternalStatus(status)) { | ||
Metadata metadata = Status.trailersFromThrowable(prevThrowable); | ||
if (Errors.isRetryableStatus(status, metadata).isRetryable) { | ||
return true; | ||
} | ||
} | ||
|
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.
Interesting, we'll need to see if we have compatible key resolvers for other langs. I've not seen this before, but apparently its descriptor fullname and a "-bin" suffix?
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.
That's exactly what it does. I'm having a hard time finding external docs about why it is supposed to be like that, but you can find other libraries interacting with gcp services using the same keys, e.g. https://github.com/googleapis/google-cloud-go/blob/master/spanner/retry.go#L33