Skip to content

Commit f2cbc1a

Browse files
fix(spanner): Fixes possible missed fallback initiation when multiple Transactions are running in parallel.
1 parent 0cc7653 commit f2cbc1a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private static class BatchReadOnlyTransactionImpl extends MultiUseReadOnlyTransa
165165
private String sessionName;
166166
private final Map<SpannerRpc.Option, ?> options;
167167
private final SessionClient sessionClient;
168+
private final AtomicBoolean fallbackInitiated = new AtomicBoolean(false);
168169

169170
BatchReadOnlyTransactionImpl(
170171
MultiUseReadOnlyTransaction.Builder builder,
@@ -332,16 +333,16 @@ private List<Partition> partitionQuery(
332333
}
333334

334335
boolean maybeMarkUnimplementedForPartitionedOps(SpannerException spannerException) {
335-
synchronized (session) {
336-
if (MultiplexedSessionDatabaseClient.verifyErrorMessage(
337-
spannerException,
338-
"Partitioned operations are not supported with multiplexed sessions")) {
339-
if (!unimplementedForPartitionedOps.get()) {
336+
if (MultiplexedSessionDatabaseClient.verifyErrorMessage(
337+
spannerException, "Partitioned operations are not supported with multiplexed sessions")) {
338+
synchronized (fallbackInitiated) {
339+
if (!fallbackInitiated.get()) {
340340
session.setFallbackSessionReference(
341341
sessionClient.createSession().getSessionReference());
342342
sessionName = session.getName();
343343
initFallbackTransaction();
344344
unimplementedForPartitionedOps.set(true);
345+
fallbackInitiated.set(true);
345346
}
346347
return true;
347348
}

0 commit comments

Comments
 (0)