@@ -457,30 +457,22 @@ void initTransaction() {
457457 }
458458
459459 private void initTransactionInternal (BeginTransactionRequest request ) {
460- XGoogSpannerRequestId reqId =
461- session .getRequestIdCreator ().nextRequestId (session .getChannel (), 1 );
462460 try {
463461 Transaction transaction =
464- rpc .beginTransaction (
465- request , reqId .withOptions (getTransactionChannelHint ()), isRouteToLeader ());
462+ rpc .beginTransaction (request , getTransactionChannelHint (), isRouteToLeader ());
466463 if (!transaction .hasReadTimestamp ()) {
467464 throw SpannerExceptionFactory .newSpannerException (
468- ErrorCode .INTERNAL ,
469- "Missing expected transaction.read_timestamp metadata field" ,
470- reqId );
465+ ErrorCode .INTERNAL , "Missing expected transaction.read_timestamp metadata field" );
471466 }
472467 if (transaction .getId ().isEmpty ()) {
473468 throw SpannerExceptionFactory .newSpannerException (
474- ErrorCode .INTERNAL , "Missing expected transaction.id metadata field" , reqId );
469+ ErrorCode .INTERNAL , "Missing expected transaction.id metadata field" );
475470 }
476471 try {
477472 timestamp = Timestamp .fromProto (transaction .getReadTimestamp ());
478473 } catch (IllegalArgumentException e ) {
479474 throw SpannerExceptionFactory .newSpannerException (
480- ErrorCode .INTERNAL ,
481- "Bad value in transaction.read_timestamp metadata field" ,
482- e ,
483- reqId );
475+ ErrorCode .INTERNAL , "Bad value in transaction.read_timestamp metadata field" , e );
484476 }
485477 transactionId = transaction .getId ();
486478 span .addAnnotation (
@@ -816,7 +808,8 @@ ResultSet executeQueryInternalWithOptions(
816808 @ Override
817809 CloseableIterator <PartialResultSet > startStream (
818810 @ Nullable ByteString resumeToken ,
819- AsyncResultSet .StreamMessageListener streamListener ) {
811+ AsyncResultSet .StreamMessageListener streamListener ,
812+ XGoogSpannerRequestId requestId ) {
820813 GrpcStreamIterator stream =
821814 new GrpcStreamIterator (
822815 statement ,
@@ -839,20 +832,12 @@ CloseableIterator<PartialResultSet> startStream(
839832 if (selector != null ) {
840833 request .setTransaction (selector );
841834 }
842- this .ensureNonNullXGoogRequestId ();
843- this .incrementXGoogRequestIdAttempt ();
844- Map <SpannerRpc .Option , ?> txChannelHint = getTransactionChannelHint ();
845- if (txChannelHint != null && txChannelHint .get (Option .CHANNEL_HINT ) != null ) {
846- long channelHint = Option .CHANNEL_HINT .getLong (txChannelHint );
847- this .xGoogRequestId .setChannelId (channelHint );
848- } else {
849- this .xGoogRequestId .setChannelId (session .getChannel ());
850- }
851835 SpannerRpc .StreamingCall call =
852836 rpc .executeQuery (
853837 request .build (),
854838 stream .consumer (),
855- this .xGoogRequestId .withOptions (getTransactionChannelHint ()),
839+ getTransactionChannelHint (),
840+ requestId ,
856841 isRouteToLeader ());
857842 session .markUsed (clock .instant ());
858843 stream .setCall (call , request .getTransaction ().hasBegin ());
@@ -868,7 +853,7 @@ boolean prepareIteratorForRetryOnDifferentGrpcChannel() {
868853 stream , this , options .hasDecodeMode () ? options .decodeMode () : defaultDecodeMode );
869854 }
870855
871- Map <SpannerRpc .Option , ?> getChannelHintOptions (
856+ static Map <SpannerRpc .Option , ?> getChannelHintOptions (
872857 Map <SpannerRpc .Option , ?> channelHintForSession , Long channelHintForTransaction ) {
873858 if (channelHintForSession != null ) {
874859 return channelHintForSession ;
@@ -1038,7 +1023,8 @@ ResultSet readInternalWithOptions(
10381023 @ Override
10391024 CloseableIterator <PartialResultSet > startStream (
10401025 @ Nullable ByteString resumeToken ,
1041- AsyncResultSet .StreamMessageListener streamListener ) {
1026+ AsyncResultSet .StreamMessageListener streamListener ,
1027+ XGoogSpannerRequestId requestId ) {
10421028 GrpcStreamIterator stream =
10431029 new GrpcStreamIterator (
10441030 lastStatement , prefetchChunks , cancelQueryWhenClientIsClosed );
@@ -1056,13 +1042,12 @@ CloseableIterator<PartialResultSet> startStream(
10561042 builder .setTransaction (selector );
10571043 }
10581044 builder .setRequestOptions (buildRequestOptions (readOptions ));
1059- this .incrementXGoogRequestIdAttempt ();
1060- this .xGoogRequestId .setChannelId (session .getChannel ());
10611045 SpannerRpc .StreamingCall call =
10621046 rpc .read (
10631047 builder .build (),
10641048 stream .consumer (),
1065- this .xGoogRequestId .withOptions (getTransactionChannelHint ()),
1049+ getTransactionChannelHint (),
1050+ requestId ,
10661051 isRouteToLeader ());
10671052 session .markUsed (clock .instant ());
10681053 stream .setCall (call , /* withBeginTransaction= */ builder .getTransaction ().hasBegin ());
0 commit comments