@@ -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