AndrewJSchofield commented on code in PR #23014:
URL: https://github.com/apache/kafka/pull/23014#discussion_r3804039595


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/FetchRequestManager.java:
##########
@@ -69,6 +74,25 @@ protected void maybeThrowAuthFailure(Node node) {
         networkClientDelegate.maybeThrowAuthFailure(node);
     }
 
+    /**
+     * {@inheritDoc}
+     *
+     * If any request is in flight, its completion will wake the application 
thread regardless of the outcome, so
+     * no separate bound is needed. Otherwise, if any fetchable partition is 
still not buffered, it was skipped for a
+     * transient reason, such as reconnect backoff or an unknown leader. Since 
nothing else will wake the application
+     * thread in that case, its wait is bounded by {@code retryBackoffMs}.
+     */
+    @Override
+    public long maximumTimeToWait(long currentTimeMs) {
+        if (!nodesWithPendingFetchRequests.isEmpty()) {
+            return Long.MAX_VALUE;
+        }
+
+        Set<TopicPartition> buffered = fetchBuffer.bufferedPartitions();
+        boolean hasUnbufferedFetchablePartition = 
!subscriptions.fetchablePartitions(tp -> !buffered.contains(tp)).isEmpty();
+        return hasUnbufferedFetchablePartition ? retryBackoffMs : 
Long.MAX_VALUE;

Review Comment:
   One of the principles of the AsyncKafkaConsumer is that it tries to 
eliminate sharing of state between the application and network threads. 
Clearly, it didn't quite manage that, but the principle is still largely 
intact. It seems to me that the PR code as it stands is doing a much improved 
job of clearly setting out the various cases for adjusting timeouts, notifying 
the fetch buffer and building requests to send. I'd like to see a more 
comprehensive refactor, but probably not right now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to