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


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareFetch.java:
##########
@@ -91,17 +94,17 @@ public Map<TopicPartition, List<ConsumerRecord<K, V>>> 
records() {
     public int numRecords() {
         int numRecords = 0;
         if (!batches.isEmpty()) {
-            Iterator<Map.Entry<TopicIdPartition, ShareInFlightBatch<K, V>>> 
iterator = batches.entrySet().iterator();
+            Iterator<Map.Entry<TopicIdPartition, List<ShareInFlightBatch<K, 
V>>>> iterator = batches.entrySet().iterator();
             while (iterator.hasNext()) {
-                Map.Entry<TopicIdPartition, ShareInFlightBatch<K, V>> entry = 
iterator.next();
-                ShareInFlightBatch<K, V> batch = entry.getValue();
-                if (batch.isEmpty()) {
-                    if (!batch.hasRenewals()) {
-                        iterator.remove();
-                    }
-                } else {
+                Map.Entry<TopicIdPartition, List<ShareInFlightBatch<K, V>>> 
entry = iterator.next();
+                List<ShareInFlightBatch<K, V>> batchList = entry.getValue();
+                batchList.removeIf(batch -> batch.isEmpty() && 
!batch.hasRenewals());

Review Comment:
   It's because calling this method has the side-effect of cleaning up batches 
which are no longer required. In the prior code, it was just a check whether 
the batch was empty and had no renewals. So, this is analogous I think. There's 
a larger refactor due here I think.



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