Skip to content

Commit 5023631

Browse files
nithinsujirchingor13
authored andcommitted
---
yaml --- r: 15743 b: refs/heads/autosynth-dialogflow c: 90f8c98 h: refs/heads/master i: 15741: 9f31124 15739: 1c6811a 15735: 861fdd7 15727: 8a6d600 15711: 47ebf6d 15679: 0c4fd23 15615: 20d461f
1 parent 1b061fb commit 5023631

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ refs/heads/autosynth-bigtable: 2fbcb15847e0e89e79d6dc07420e28d7dfcea894
130130
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
131131
refs/heads/autosynth-containeranalysis: 039ca5b8db725c76c16a965ff26b2774322b8ef8
132132
refs/heads/autosynth-datastore: 9acd400b484d6691a080c9152a331d88d24fefc1
133-
refs/heads/autosynth-dialogflow: 97b1efc4cd24639d84cab1de244bc03fb23e2a3e
133+
refs/heads/autosynth-dialogflow: 90f8c98e5720186cc24e01ce1d427ee235312416
134134
refs/heads/autosynth-errorreporting: 3d0566d6bebcc187f148bbed463b5a8e75b1edf6
135135
refs/heads/autosynth-firestore: 92b27fbc8855c9902168695abb0a8f1f433b750b
136136
refs/heads/autosynth-iot: 9d732be07d99843d8cb53d34ec0837328a807fce

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