Skip to content

Commit b0534c0

Browse files
nithinsujirchingor13
authored andcommitted
---
yaml --- r: 14995 b: refs/heads/autosynth-bigquerydatatransfer c: 90f8c98 h: refs/heads/master i: 14993: 3287990 14991: 975cd11
1 parent 50cfbc6 commit b0534c0

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

  • branches/autosynth-bigquerydatatransfer/google-cloud-clients/google-cloud-spanner/src

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b
124124
refs/tags/v0.69.0: 78f67a29e8b9c46ba01de566a2eae0fd1c03edea
125125
refs/heads/autosynth-asset: cd8251de8c40e239ad24dcf9ed93ea2708a3eed5
126126
refs/heads/autosynth-automl: cced2f56bbef0499609073edbca6253e1df5e535
127-
refs/heads/autosynth-bigquerydatatransfer: 97b1efc4cd24639d84cab1de244bc03fb23e2a3e
127+
refs/heads/autosynth-bigquerydatatransfer: 90f8c98e5720186cc24e01ce1d427ee235312416
128128
refs/heads/autosynth-bigquerystorage: 99aee05df348f39d98b6fb23c292006f1d2a6c28
129129
refs/heads/autosynth-bigtable: fa0d1de9e264d7ecac8a3abc3de7a8364cfaf427
130130
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca

branches/autosynth-bigquerydatatransfer/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ private <T> T runInternal(TransactionCallable<T> callable) {
13191319
shouldRollback = false;
13201320
} catch (Exception e) {
13211321
txnLogger.log(Level.FINE, "User-provided TransactionCallable raised exception", e);
1322-
if (txn.isAborted()) {
1322+
if (txn.isAborted() || (e instanceof AbortedException)) {
13231323
span.addAnnotation(
13241324
"Transaction Attempt Aborted in user operation. Retrying",
13251325
ImmutableMap.of("Attempt", AttributeValue.longAttributeValue(attempt)));

branches/autosynth-bigquerydatatransfer/google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITDMLTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020
import static org.junit.Assert.fail;
2121

22+
import com.google.cloud.spanner.AbortedException;
2223
import com.google.cloud.spanner.Database;
2324
import com.google.cloud.spanner.DatabaseClient;
2425
import com.google.cloud.spanner.ErrorCode;
@@ -30,6 +31,7 @@
3031
import com.google.cloud.spanner.Mutation;
3132
import com.google.cloud.spanner.ResultSet;
3233
import com.google.cloud.spanner.SpannerException;
34+
import com.google.cloud.spanner.SpannerExceptionFactory;
3335
import com.google.cloud.spanner.Statement;
3436
import com.google.cloud.spanner.TimestampBound;
3537
import com.google.cloud.spanner.TransactionContext;
@@ -59,6 +61,8 @@ public final class ITDMLTest {
5961
private static final String DELETE_DML = "DELETE FROM T WHERE T.K like 'boo%';";
6062
private static final long DML_COUNT = 4;
6163

64+
private static boolean throwAbortOnce = false;
65+
6266
@BeforeClass
6367
public static void setUpDatabase() {
6468
db =
@@ -82,6 +86,12 @@ private void executeUpdate(long expectedCount, final String... stmts) {
8286
public Long run(TransactionContext transaction) {
8387
long rowCount = 0;
8488
for (String stmt : stmts) {
89+
if (throwAbortOnce) {
90+
throwAbortOnce = false;
91+
throw SpannerExceptionFactory.newSpannerException(
92+
ErrorCode.ABORTED, "Abort in test");
93+
}
94+
8595
rowCount += transaction.executeUpdate(Statement.of(stmt));
8696
}
8797
return rowCount;
@@ -92,6 +102,17 @@ public Long run(TransactionContext transaction) {
92102
assertThat(rowCount).isEqualTo(expectedCount);
93103
}
94104

105+
@Test
106+
public void abortOnceShouldSucceedAfterRetry() {
107+
try {
108+
throwAbortOnce = true;
109+
executeUpdate(DML_COUNT, INSERT_DML);
110+
assertThat(throwAbortOnce).isFalse();
111+
} catch (AbortedException e) {
112+
fail("Abort Exception not caught and retried");
113+
}
114+
}
115+
95116
@Test
96117
public void partitionedDML() {
97118
executeUpdate(DML_COUNT, INSERT_DML);

0 commit comments

Comments
 (0)