aliehsaeedii commented on code in PR #24228:
URL: https://github.com/apache/kafka/pull/24228#discussion_r4589881891


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java:
##########
@@ -1565,6 +1558,23 @@ private long pollPhase() {
         return pollLatency;
     }
 
+    /**
+     * Sets the end offset of each partition this poll returned records for, 
or advanced the position of, to the main
+     * consumer's position plus its current lag: the high watermark, or the 
last stable offset under read_committed, of
+     * the partition's latest fetch response. The position can pass the last 
returned record, as control records and
+     * aborted transactions are skipped.
+     */
+    private void updateTaskEndOffsets(final ConsumerRecords<byte[], byte[]> 
records) {
+        final Set<TopicPartition> partitions = new 
HashSet<>(records.partitions());
+        partitions.addAll(records.nextOffsets().keySet());
+        for (final TopicPartition partition : partitions) {
+            final OptionalLong lag = mainConsumer.currentLag(partition);
+            if (lag.isPresent()) {
+                taskManager.updateTaskEndMetadata(partition, 
mainConsumer.position(partition) + lag.getAsLong());

Review Comment:
   `position()` needs a *valid* position, but `currentLag()` only needs a 
non-null one. If a fetch response with a leader change lands right after 
`poll()`, the partition goes to AWAIT_VALIDATION, and `position()` then blocks 
on validation (up to `default.api.timeout.ms`) or throws. That throw is outside 
the `InvalidOffsetException` handler in `pollRequests()`, so it kills the 
thread. Could we use `records.nextOffsets().get(partition).offset() + lag` 
instead, so there's no second consumer call?



-- 
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