@@ -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,12 +832,12 @@ CloseableIterator<PartialResultSet> startStream(
839832 if (selector != null ) {
840833 request .setTransaction (selector );
841834 }
842- this .ensureNonNullXGoogRequestId ();
843835 SpannerRpc .StreamingCall call =
844836 rpc .executeQuery (
845837 request .build (),
846838 stream .consumer (),
847- this .xGoogRequestId .withOptions (getTransactionChannelHint ()),
839+ getTransactionChannelHint (),
840+ requestId ,
848841 isRouteToLeader ());
849842 session .markUsed (clock .instant ());
850843 stream .setCall (call , request .getTransaction ().hasBegin ());
@@ -860,7 +853,7 @@ boolean prepareIteratorForRetryOnDifferentGrpcChannel() {
860853 stream , this , options .hasDecodeMode () ? options .decodeMode () : defaultDecodeMode );
861854 }
862855
863- Map <SpannerRpc .Option , ?> getChannelHintOptions (
856+ static Map <SpannerRpc .Option , ?> getChannelHintOptions (
864857 Map <SpannerRpc .Option , ?> channelHintForSession , Long channelHintForTransaction ) {
865858 if (channelHintForSession != null ) {
866859 return channelHintForSession ;
@@ -1030,7 +1023,8 @@ ResultSet readInternalWithOptions(
10301023 @ Override
10311024 CloseableIterator <PartialResultSet > startStream (
10321025 @ Nullable ByteString resumeToken ,
1033- AsyncResultSet .StreamMessageListener streamListener ) {
1026+ AsyncResultSet .StreamMessageListener streamListener ,
1027+ XGoogSpannerRequestId requestId ) {
10341028 GrpcStreamIterator stream =
10351029 new GrpcStreamIterator (
10361030 lastStatement , prefetchChunks , cancelQueryWhenClientIsClosed );
@@ -1048,13 +1042,12 @@ CloseableIterator<PartialResultSet> startStream(
10481042 builder .setTransaction (selector );
10491043 }
10501044 builder .setRequestOptions (buildRequestOptions (readOptions ));
1051- this .incrementXGoogRequestIdAttempt ();
1052- this .xGoogRequestId .setChannelId (session .getChannel ());
10531045 SpannerRpc .StreamingCall call =
10541046 rpc .read (
10551047 builder .build (),
10561048 stream .consumer (),
1057- this .xGoogRequestId .withOptions (getTransactionChannelHint ()),
1049+ getTransactionChannelHint (),
1050+ requestId ,
10581051 isRouteToLeader ());
10591052 session .markUsed (clock .instant ());
10601053 stream .setCall (call , /* withBeginTransaction= */ builder .getTransaction ().hasBegin ());
0 commit comments