You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ch...@apache.org on 2025/10/29 13:21:06 UTC

(kafka) branch trunk updated: KAFKA-19820 remove the unnecessary copy from AbstractFetch#fetchablePartitions (#20745)

This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 0072bd9277b KAFKA-19820 remove the unnecessary copy from AbstractFetch#fetchablePartitions (#20745)
0072bd9277b is described below

commit 0072bd9277bf9c622df9fd0982117bcbd55389bf
Author: TaiJuWu <tj...@gmail.com>
AuthorDate: Wed Oct 29 21:20:59 2025 +0800

    KAFKA-19820 remove the unnecessary copy from AbstractFetch#fetchablePartitions (#20745)
    
    Remove the redundant copy and change the return type to List.  This
    change also align `ShareConsumer`
    
    Reviewers: Kirk True <ki...@kirktrue.pro>, Ken Huang
     <s7...@gmail.com>, Chia-Ping Tsai <ch...@gmail.com>
---
 .../apache/kafka/clients/consumer/internals/AbstractFetch.java    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java
index e3e52f7525d..27f7fce1fab 100644
--- a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java
+++ b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java
@@ -341,15 +341,15 @@ public abstract class AbstractFetch implements Closeable {
      * until the previously-fetched data has been processed.
      *
      * @param buffered The set of partitions we have in our buffer
-     * @return {@link Set} of {@link TopicPartition topic partitions} for which we should fetch data
+     * @return {@link List} of {@link TopicPartition topic partitions} for which we should fetch data
      */
-    private Set<TopicPartition> fetchablePartitions(Set<TopicPartition> buffered) {
+    private List<TopicPartition> fetchablePartitions(Set<TopicPartition> buffered) {
         // This is the test that returns true if the partition is *not* buffered
         Predicate<TopicPartition> isNotBuffered = tp -> !buffered.contains(tp);
 
         // Return all partitions that are in an otherwise fetchable state *and* for which we don't already have some
         // messages sitting in our buffer.
-        return new HashSet<>(subscriptions.fetchablePartitions(isNotBuffered));
+        return subscriptions.fetchablePartitions(isNotBuffered);
     }
 
     /**
@@ -430,7 +430,7 @@ public abstract class AbstractFetch implements Closeable {
         Set<TopicPartition> buffered = Collections.unmodifiableSet(fetchBuffer.bufferedPartitions());
 
         // This is the set of partitions that do not have buffered data
-        Set<TopicPartition> unbuffered = fetchablePartitions(buffered);
+        List<TopicPartition> unbuffered = fetchablePartitions(buffered);
 
         if (unbuffered.isEmpty()) {
             // If there are no partitions that don't already have data locally buffered, there's no need to issue