@@ -590,12 +590,24 @@ private static GcpManagedChannelOptions grpcGcpOptionsWithMetrics(SpannerOptions
590590 if (metricsOptions .getNamePrefix ().equals ("" )) {
591591 metricsOptionsBuilder .withNamePrefix ("cloud.google.com/java/spanner/gcp-channel-pool/" );
592592 }
593- GcpChannelPoolOptions .Builder channelPoolOptionsBuilder =
594- GcpChannelPoolOptions .newBuilder ().setDynamicScaling (0 , 100 , Duration .ofMinutes (30L ));
595- return GcpManagedChannelOptions .newBuilder (grpcGcpOptions )
596- .withMetricsOptions (metricsOptionsBuilder .build ())
597- .withChannelPoolOptions (channelPoolOptionsBuilder .build ())
598- .build ();
593+ GcpManagedChannelOptions .Builder channelOptionsBuilder =
594+ GcpManagedChannelOptions .newBuilder (grpcGcpOptions )
595+ .withMetricsOptions (metricsOptionsBuilder .build ());
596+
597+ boolean isMultiplexedSessionEnabledForAllTransactions =
598+ options .getSessionPoolOptions ().getUseMultiplexedSession ()
599+ && options .getSessionPoolOptions ().getUseMultiplexedSessionForRW ()
600+ && options .getSessionPoolOptions ().getUseMultiplexedSessionPartitionedOps ();
601+ if (isMultiplexedSessionEnabledForAllTransactions ) {
602+ // When multiplexed session is enabled for all the transactions then enable dynamic channel
603+ // pooling by default.
604+ // TODO: What if backend throws an unimplemented error and the transactions fallback to using
605+ // regular sessions? Is there a way to disable dynamic scaling on the fly?
606+ GcpChannelPoolOptions .Builder channelPoolOptionsBuilder =
607+ GcpChannelPoolOptions .newBuilder ().setDynamicScaling (0 , 100 , Duration .ofMinutes (30L ));
608+ channelOptionsBuilder .withChannelPoolOptions (channelPoolOptionsBuilder .build ());
609+ }
610+ return channelOptionsBuilder .build ();
599611 }
600612
601613 @ SuppressWarnings ("rawtypes" )
0 commit comments