Skip to content

Commit 8157be0

Browse files
nithinsujirchingor13
authored andcommitted
---
yaml --- r: 12999 b: refs/heads/autosynth-securitycenter c: 90f8c98 h: refs/heads/master i: 12997: 645b9cb 12995: 742cd18 12991: 8ae2314
1 parent 26b3df4 commit 8157be0

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ refs/heads/autosynth-language: 8972866b016473559702424205ce5569de47b34d
139139
refs/heads/autosynth-os-login: daa910328b954bbe87068f684a3088ed910f1ddf
140140
refs/heads/autosynth-redis: 4c68cb0fbc599124e717ab3f24bd8a8a5d085ca9
141141
refs/heads/autosynth-scheduler: 2f0fe714a8541dc72f88b45bddd8748e5f21cf29
142-
refs/heads/autosynth-securitycenter: 97b1efc4cd24639d84cab1de244bc03fb23e2a3e
142+
refs/heads/autosynth-securitycenter: 90f8c98e5720186cc24e01ce1d427ee235312416
143143
refs/heads/autosynth-spanner: 1804eb46dd34a05b47163758d376a7fac49188f1
144144
refs/heads/autosynth-speech: 631df42a628621fe42eb4974c9eb725b2fe8e473
145145
refs/heads/autosynth-tasks: afc9f4da54964dea5e7f3a9b164db282fc35db5c

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