kirktrue commented on code in PR #17353:
URL: https://github.com/apache/kafka/pull/17353#discussion_r1805613969
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java:
##########
@@ -1072,12 +1073,10 @@ public Map<TopicPartition, OffsetAndTimestamp>
offsetsForTimes(Map<TopicPartitio
}
try {
- return applicationEventHandler.addAndGet(listOffsetsEvent)
- .entrySet()
- .stream()
- .collect(Collectors.toMap(
- Map.Entry::getKey,
- entry -> entry.getValue().buildOffsetAndTimestamp()));
+ Map<TopicPartition, OffsetAndTimestampInternal> offsets =
applicationEventHandler.addAndGet(listOffsetsEvent);
+ Map<TopicPartition, OffsetAndTimestamp> results = new
HashMap<>(offsets.size());
+ offsets.forEach((k, v) -> results.put(k, v != null ?
v.buildOffsetAndTimestamp() : null));
Review Comment:
Because of the existing logic, it's not possible for the set of partitions
passed to `beginningOffsets()` and `endOffsets()` to include partitions that
are not in the returned set.
For example, if a topic has two partitions (0 and 1), attempting to search
for partitions 0, 1, **and** 2 does not work. Wrong or right, both consumers
will enter a loop, attempting to determine the leader for partition 2.
In that case, when the user calls `beginningOffsets()` or `endOffsets()`
with a timeout, a `TimeoutException` will eventually be thrown. If no timeout
is provided, those API calls hang forever looking for the leader 😱
--
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]