Copilot commented on code in PR #24228:
URL: https://github.com/apache/kafka/pull/24228#discussion_r4598339705
##########
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);
Review Comment:
With `group.protocol=streams`, `AsyncKafkaConsumer.currentLag()` waits for
the consumer network thread through `ApplicationEventHandler.addAndGet(...)`.
Calling it separately for each partition adds serial cross-thread round trips
before records reach tasks, increasing processing latency for polls spanning
many partitions. Use cached fetch end offsets or a batched, nonblocking lookup
instead.
##########
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:
After a leader change, `ClassicKafkaConsumer.poll()` can mark positions for
leader-epoch validation just before returning, so this `position()` call can
still time out. The uncaught `TimeoutException` then escapes `pollPhase()` and
terminates the stream thread solely while refreshing metadata. Use a
zero-timeout position lookup and skip timed-out updates, following the
timeout-handling pattern in `StreamTask.commitNeeded()`.
##########
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:
Please add a regression test with nonzero consumer lag, such as position 1
and lag 9 yielding end offset 10. Both integration-test assertions check the
metadata only after the consumer has caught up, so an implementation that
reports just the consumer position or `nextOffsets()` would also pass. A
focused `StreamThreadTest` case with explicit position and lag values would
protect the distinction between the consumed position and the partition's end
offset.
--
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]