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: use default retry settings for aborted transactions #48

Merged
merged 1 commit into from Jan 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,7 +22,10 @@
import com.google.api.gax.retrying.TimedAttemptSettings;
import com.google.cloud.RetryHelper;
import com.google.cloud.RetryHelper.RetryHelperException;
import com.google.cloud.spanner.v1.stub.SpannerStub;
import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
import com.google.common.base.Throwables;
import com.google.spanner.v1.RollbackRequest;
import io.grpc.Context;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
Expand All @@ -34,12 +37,19 @@
* a cap on the number of retries.
*/
class SpannerRetryHelper {

/**
* Use the same {@link RetrySettings} for retrying an aborted transaction as for retrying a {@link
* RollbackRequest}. The {@link RollbackRequest} automatically uses the default retry settings
* defined for the {@link SpannerStub}. By referencing these settings, the retry settings for
* retrying aborted transactions will also automatically be updated if the default retry settings
* are updated.
*
* <p>These default {@link RetrySettings} are only used if no retry information is returned by the
* {@link AbortedException}.
*/
private static final RetrySettings txRetrySettings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(1000L))
.setMaxRetryDelay(Duration.ofMillis(32000L))
.setTotalTimeout(Duration.ofMillis(Integer.MAX_VALUE))
.build();
SpannerStubSettings.newBuilder().rollbackSettings().getRetrySettings();

/** Executes the {@link Callable} and retries if it fails with an {@link AbortedException}. */
static <T> T runTxWithRetriesOnAborted(Callable<T> callable) {
Expand Down