chia7712 commented on code in PR #23532:
URL: https://github.com/apache/kafka/pull/23532#discussion_r4092540866
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareFetch.java:
##########
@@ -67,25 +67,28 @@ private ShareFetch(Map<TopicIdPartition,
List<ShareInFlightBatch<K, V>>> batches
*/
public void add(TopicIdPartition partition, ShareInFlightBatch<K, V>
batch) {
Objects.requireNonNull(batch);
- batches.computeIfAbsent(partition, k -> new LinkedList<>()).add(batch);
+ batches.computeIfAbsent(partition, k -> new ArrayList<>()).add(batch);
if (batch.getAcquisitionLockTimeoutMs().isPresent()) {
acquisitionLockTimeoutMs = batch.getAcquisitionLockTimeoutMs();
}
}
/**
- * @return all the non-control messages for this fetch, grouped by
partition
+ * @return all the non-control messages for this fetch, grouped by
partition. Partitions with no
+ * in-flight records (such as those whose acquired offsets were all
control records) are omitted.
*/
public Map<TopicPartition, List<ConsumerRecord<K, V>>> records() {
- final LinkedHashMap<TopicPartition, List<ConsumerRecord<K, V>>> result
= new LinkedHashMap<>();
+ final HashMap<TopicPartition, List<ConsumerRecord<K, V>>> result = new
HashMap<>(batches.size());
batches.forEach((tip, batchList) -> {
List<ConsumerRecord<K, V>> records = new ArrayList<>();
for (ShareInFlightBatch<K, V> batch : batchList) {
records.addAll(batch.getInFlightRecords());
}
- result.put(tip.topicPartition(), records);
+ if (!records.isEmpty()) {
Review Comment:
Nice guard, and I noticed that we didn't document that in `ConsumerRecords`.
I have opened https://issues.apache.org/jira/browse/KAFKA-21155 to handle it.
--
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]