Skip to content

Commit 67909b2

Browse files
nithinsujirchingor13
authored andcommitted
---
yaml --- r: 13477 b: refs/heads/autosynth-dlp c: 90f8c98 h: refs/heads/master i: 13475: 51bdf8a
1 parent 6d94195 commit 67909b2

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ refs/tags/v0.60.0: 4cd518d0612329f8a8e53484eef4cd1651e32855
104104
refs/tags/v0.61.0: e4b526656bb1bf5eefd0ee578b7405147821225e
105105
refs/tags/v0.62.0: bbede7385d48ba08f487bdd29ec10668ace96396
106106
refs/heads/0.60.0-alpha: 10939381ffe0b8da32db4fe3087c86e3aa7f3e55
107-
refs/heads/autosynth-dlp: 97b1efc4cd24639d84cab1de244bc03fb23e2a3e
107+
refs/heads/autosynth-dlp: 90f8c98e5720186cc24e01ce1d427ee235312416
108108
refs/heads/autosynth-logging: f8794c50a64f62b167cddf42513d133547679e01
109109
refs/heads/dupes: 3478c5d81fd242d0e985656645a679420a2060c2
110110
refs/tags/v0.63.0: 94f19b71d40f46b36120e7b9d78a1a3d41bfcbd6

branches/autosynth-dlp/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-dlp/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)