Skip to content

Commit 3f8bf42

Browse files
nithinsujirchingor13
authored andcommitted
---
yaml --- r: 17699 b: refs/heads/autosynth-trace c: 90f8c98 h: refs/heads/master i: 17697: d488489 17695: ae80d7a
1 parent 3e1de1f commit 3f8bf42

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
@@ -144,7 +144,7 @@ refs/heads/autosynth-spanner: 9bff86d057df31e04c76d72865e8e073ac5794fb
144144
refs/heads/autosynth-speech: 75d6c62a9d07d3a3642980502a25d07fbde0f232
145145
refs/heads/autosynth-tasks: b0cdb991f3f75345151a3f68db1aab273dfc069b
146146
refs/heads/autosynth-texttospeech: 2dcc5dc22be0f456caa1b6a8a4bcdace2641239c
147-
refs/heads/autosynth-trace: 97b1efc4cd24639d84cab1de244bc03fb23e2a3e
147+
refs/heads/autosynth-trace: 90f8c98e5720186cc24e01ce1d427ee235312416
148148
refs/heads/autosynth-websecurityscanner: d4febbffb6c648b74faec62fe90e20adadc9a7d3
149149
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64
150150
refs/heads/elharo-patch-1: ce159ef828d3c545991ff78e7b6e0d912a9453e9

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