ableegoldman commented on a change in pull request #11057:
URL: https://github.com/apache/kafka/pull/11057#discussion_r675163448



##########
File path: 
clients/src/main/java/org/apache/kafka/clients/consumer/KafkaConsumer.java
##########
@@ -2237,7 +2237,21 @@ public OptionalLong currentLag(TopicPartition 
topicPartition) {
         acquireAndEnsureOpen();
         try {
             final Long lag = subscriptions.partitionLag(topicPartition, 
isolationLevel);
-            return lag == null ? OptionalLong.empty() : OptionalLong.of(lag);
+
+            // if the log end offset is not known and hence cannot return lag,
+            // issue a list offset request for that partition so that next time
+            // we may get the answer; we do not need to wait for the return 
value
+            // since we would not try to poll the network client synchronously
+            if (lag == null) {
+                if (subscriptions.partitionEndOffset(topicPartition, 
isolationLevel) == null) {
+                    log.info("Requesting the log end offset for {} in order to 
compute lag", topicPartition);
+                    fetcher.endOffsets(Collections.singleton(topicPartition), 
time.timer(0L));

Review comment:
       Ah sorry, I overlooked that we passed in a timeout of 0 (originally 
thought that would throw a TimeoutException but I see now it would just return 
-- nevermind this then)
   
   However I do think it's probably worth taking care not to fire off a million 
requests per second (possible slight over-exaggeration) when we're just waiting 
on the same partition(s). It shouldn't be too complicated to avoid sending 
duplicated requests so imo it's not over-optimization...thoughts?




-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to