Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: use default retry settings for aborted tx (#48)
  • Loading branch information
olavloite committed Jan 30, 2020
1 parent 63b33e9 commit 6709552
Showing 1 changed file with 15 additions and 5 deletions.
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

0 comments on commit 6709552

Please sign in to comment.