AndrewJSchofield commented on code in PR #23499:
URL: https://github.com/apache/kafka/pull/23499#discussion_r4060570250


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareFetch.java:
##########
@@ -81,7 +78,13 @@ public void add(TopicIdPartition partition, 
ShareInFlightBatch<K, V> batch) {
      */
     public Map<TopicPartition, List<ConsumerRecord<K, V>>> records() {
         final LinkedHashMap<TopicPartition, List<ConsumerRecord<K, V>>> result 
= new LinkedHashMap<>();
-        batches.forEach((tip, batch) -> result.put(tip.topicPartition(), 
batch.getInFlightRecords()));
+        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);
+        });
         return Map.copyOf(result);

Review Comment:
   Yes, I agree. This does revert to the older `Collections.unmodifiableMap` 
but it does avoid the copy.



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