@@ -319,7 +319,7 @@ public CommitResponse writeAtLeastOnceWithOptions(
319319 private XGoogSpannerRequestId reqIdOrFresh (Options options ) {
320320 XGoogSpannerRequestId reqId = options .reqId ();
321321 if (reqId == null ) {
322- reqId = this .getRequestIdCreator ().nextRequestId (1 /* TODO: channelId */ , 1 );
322+ reqId = this .getRequestIdCreator ().nextRequestId (this . getChannel () , 1 );
323323 }
324324 return reqId ;
325325 }
@@ -464,17 +464,15 @@ public AsyncTransactionManagerImpl transactionManagerAsync(TransactionOption...
464464
465465 @ Override
466466 public ApiFuture <Empty > asyncClose () {
467- XGoogSpannerRequestId reqId =
468- this .getRequestIdCreator ().nextRequestId (1 /* TODO: channelId */ , 0 );
467+ XGoogSpannerRequestId reqId = this .getRequestIdCreator ().nextRequestId (this .getChannel (), 0 );
469468 return spanner .getRpc ().asyncDeleteSession (getName (), reqId .withOptions (getOptions ()));
470469 }
471470
472471 @ Override
473472 public void close () {
474473 ISpan span = tracer .spanBuilder (SpannerImpl .DELETE_SESSION );
475474 try (IScope s = tracer .withSpan (span )) {
476- XGoogSpannerRequestId reqId =
477- this .getRequestIdCreator ().nextRequestId (1 /* TODO: channelId */ , 0 );
475+ XGoogSpannerRequestId reqId = this .getRequestIdCreator ().nextRequestId (this .getChannel (), 0 );
478476 spanner .getRpc ().deleteSession (getName (), reqId .withOptions (getOptions ()));
479477 } catch (RuntimeException e ) {
480478 span .setStatus (e );
@@ -505,8 +503,7 @@ ApiFuture<Transaction> beginTransactionAsync(
505503 }
506504 final BeginTransactionRequest request = requestBuilder .build ();
507505 final ApiFuture <Transaction > requestFuture ;
508- XGoogSpannerRequestId reqId =
509- this .getRequestIdCreator ().nextRequestId (1 /* TODO: channelId */ , 1 );
506+ XGoogSpannerRequestId reqId = this .getRequestIdCreator ().nextRequestId (this .getChannel (), 1 );
510507 try (IScope ignore = tracer .withSpan (span )) {
511508 requestFuture =
512509 spanner
@@ -597,4 +594,12 @@ public void setRequestIdCreator(XGoogSpannerRequestId.RequestIdCreator creator)
597594 public XGoogSpannerRequestId .RequestIdCreator getRequestIdCreator () {
598595 return this .requestIdCreator ;
599596 }
597+
598+ int getChannel () {
599+ if (getIsMultiplexed ()) {
600+ return 0 ;
601+ }
602+ Long channelHint = (Long ) this .getOptions ().get (SpannerRpc .Option .CHANNEL_HINT );
603+ return (int ) (channelHint % this .spanner .getOptions ().getNumChannels ());
604+ }
600605}
0 commit comments