@@ -699,7 +699,10 @@ private void appendLoop() {
699699 hasMessageInWaitingQueue .await (100 , TimeUnit .MILLISECONDS );
700700 // Check whether we should error out the current append loop.
701701 if (inflightRequestQueue .size () > 0 ) {
702- throwIfWaitCallbackTooLong (inflightRequestQueue .getFirst ().requestCreationTimeStamp );
702+ Instant sendInstant = inflightRequestQueue .getFirst ().requestSendTimeStamp ;
703+ if (sendInstant != null ) {
704+ throwIfWaitCallbackTooLong (sendInstant );
705+ }
703706 }
704707
705708 // Copy the streamConnectionIsConnected guarded by lock to a local variable.
@@ -711,7 +714,9 @@ private void appendLoop() {
711714 // from inflightRequestQueue and prepent them onto the waitinRequestQueue. They need to be
712715 // prepended as they need to be sent before new requests.
713716 while (!inflightRequestQueue .isEmpty ()) {
714- waitingRequestQueue .addFirst (inflightRequestQueue .pollLast ());
717+ AppendRequestAndResponse requestWrapper = inflightRequestQueue .pollLast ();
718+ requestWrapper .requestSendTimeStamp = null ;
719+ waitingRequestQueue .addFirst (requestWrapper );
715720 }
716721
717722 // If any of the inflight messages were meant to be ignored during requestCallback, they
@@ -721,7 +726,6 @@ private void appendLoop() {
721726 while (!this .waitingRequestQueue .isEmpty ()) {
722727 AppendRequestAndResponse requestWrapper = this .waitingRequestQueue .pollFirst ();
723728 waitForBackoffIfNecessary (requestWrapper );
724- requestWrapper .trySetRequestInsertQueueTime ();
725729 this .inflightRequestQueue .add (requestWrapper );
726730 localQueue .addLast (requestWrapper );
727731 }
@@ -760,6 +764,7 @@ private void appendLoop() {
760764 firstRequestForTableOrSchemaSwitch = true ;
761765 }
762766 while (!localQueue .isEmpty ()) {
767+ localQueue .peekFirst ().setRequestSendQueueTime ();
763768 AppendRowsRequest originalRequest = localQueue .pollFirst ().message ;
764769 AppendRowsRequest .Builder originalRequestBuilder = originalRequest .toBuilder ();
765770 // Always respect the first writer schema seen by the loop.
@@ -1217,6 +1222,7 @@ private void doneCallback(Throwable finalStatus) {
12171222 private AppendRequestAndResponse pollInflightRequestQueue (boolean pollLast ) {
12181223 AppendRequestAndResponse requestWrapper =
12191224 pollLast ? inflightRequestQueue .pollLast () : inflightRequestQueue .poll ();
1225+ requestWrapper .requestSendTimeStamp = null ;
12201226 --this .inflightRequests ;
12211227 this .inflightBytes -= requestWrapper .messageSize ;
12221228 this .inflightReduced .signal ();
@@ -1256,7 +1262,9 @@ static final class AppendRequestAndResponse {
12561262
12571263 TimedAttemptSettings attemptSettings ;
12581264
1259- Instant requestCreationTimeStamp ;
1265+ // Time at which request was last sent over the network.
1266+ // If a response is no longer expected this is set back to null.
1267+ Instant requestSendTimeStamp ;
12601268
12611269 AppendRequestAndResponse (
12621270 AppendRowsRequest message , StreamWriter streamWriter , RetrySettings retrySettings ) {
@@ -1276,11 +1284,8 @@ static final class AppendRequestAndResponse {
12761284 }
12771285 }
12781286
1279- void trySetRequestInsertQueueTime () {
1280- // Only set the first time the caller tries to set the timestamp.
1281- if (requestCreationTimeStamp == null ) {
1282- requestCreationTimeStamp = Instant .now ();
1283- }
1287+ void setRequestSendQueueTime () {
1288+ requestSendTimeStamp = Instant .now ();
12841289 }
12851290 }
12861291
0 commit comments