@@ -185,9 +185,9 @@ interface SessionConsumer {
185
185
186
186
// SessionClient is created long before a DatabaseClientImpl is created,
187
187
// as batch sessions are firstly created then later attached to each Client.
188
- private static AtomicInteger NTH_ID = new AtomicInteger (0 );
189
- private final int nthId ;
190
- private final AtomicInteger nthRequest ;
188
+ private static final AtomicInteger NTH_ID = new AtomicInteger (0 );
189
+ private final int nthId = NTH_ID . incrementAndGet () ;
190
+ private final AtomicInteger nthRequest = new AtomicInteger ( 0 ) ;
191
191
192
192
@ GuardedBy ("this" )
193
193
private volatile long sessionChannelCounter ;
@@ -201,8 +201,6 @@ interface SessionConsumer {
201
201
this .executorFactory = executorFactory ;
202
202
this .executor = executorFactory .get ();
203
203
this .commonAttributes = spanner .getTracer ().createCommonAttributes (db );
204
- this .nthId = SessionClient .NTH_ID .incrementAndGet ();
205
- this .nthRequest = new AtomicInteger (0 );
206
204
}
207
205
208
206
@ Override
@@ -220,7 +218,8 @@ DatabaseId getDatabaseId() {
220
218
221
219
@ Override
222
220
public XGoogSpannerRequestId nextRequestId (long channelId , int attempt ) {
223
- return XGoogSpannerRequestId .of (this .nthId , this .nthRequest .incrementAndGet (), channelId , 1 );
221
+ return XGoogSpannerRequestId .of (
222
+ this .nthId , this .nthRequest .incrementAndGet (), channelId , attempt );
224
223
}
225
224
226
225
/** Create a single session. */
@@ -287,6 +286,9 @@ SessionImpl createMultiplexedSession() {
287
286
spanner
288
287
.getTracer ()
289
288
.spanBuilder (SpannerImpl .CREATE_MULTIPLEXED_SESSION , this .commonAttributes );
289
+ // MultiplexedSession doesn't use a channelId hence this hard-coded value.
290
+ int channelId = 0 ;
291
+ XGoogSpannerRequestId reqId = nextRequestId (channelId , 1 );
290
292
try (IScope s = spanner .getTracer ().withSpan (span )) {
291
293
com .google .spanner .v1 .Session session =
292
294
spanner
@@ -295,7 +297,7 @@ SessionImpl createMultiplexedSession() {
295
297
db .getName (),
296
298
spanner .getOptions ().getDatabaseRole (),
297
299
spanner .getOptions ().getSessionLabels (),
298
- null ,
300
+ createRequestOptions ( channelId , reqId ) ,
299
301
true );
300
302
SessionImpl sessionImpl =
301
303
new SessionImpl (
0 commit comments