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


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractMembershipManager.java:
##########
@@ -1135,7 +1134,9 @@ CompletableFuture<Void> 
revokePartitions(Set<TopicPartition> partitionsToRevoke)
         // Ensure the set of partitions to revoke are still assigned
         Set<TopicPartition> revokedPartitions = new 
HashSet<>(partitionsToRevoke);
         revokedPartitions.retainAll(subscriptions.assignedPartitions());
-        log.info("Revoking previously assigned partitions {}", 
revokedPartitions.stream().map(TopicPartition::toString).collect(Collectors.joining(",
 ")));
+
+        if (log.isInfoEnabled())
+            log.info("Revoking previously assigned partitions {}", 
Utils.sortedTopicPartitions(revokedPartitions));

Review Comment:
   This is actually sorting the list of partitions whereas it previously was 
not. That seems accidental in a PR that is trying to reduce CPU usage.



##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/Utils.java:
##########
@@ -20,12 +20,41 @@
 import org.apache.kafka.common.TopicPartition;
 
 import java.io.Serializable;
+import java.util.Collection;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 public final class Utils {
 
+    public static String sortedTopicPartitions(Collection<TopicPartition> 
partitions) {
+        SortedSet<TopicPartition> sortedPartitions;
+
+        if (partitions instanceof SortedSet) {
+            sortedPartitions = (SortedSet<TopicPartition>) partitions;
+        } else {
+            sortedPartitions = new TreeSet<>(new TopicPartitionComparator());
+            sortedPartitions.addAll(partitions);
+        }
+
+        return join(sortedPartitions);
+    }
+
+    private static String join(SortedSet<?> elements) {
+        StringBuilder b = new StringBuilder();

Review Comment:
   If you constructed an implementation of `Iterator` which executed 
`Object.toString()` on its elements, you could then use `String.join` directly. 
I wonder what you think about using the Java library to do the string 
concatenation.



##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/TopicMetadataRequestManager.java:
##########
@@ -84,16 +84,21 @@ public TopicMetadataRequestManager(final LogContext 
context, final Time time, fi
     @Override
     public NetworkClientDelegate.PollResult poll(final long currentTimeMs) {
         // Prune any requests which have timed out
-        List<TopicMetadataRequestState> expiredRequests = 
inflightRequests.stream()
-                .filter(TimedRequestState::isExpired)
-                .collect(Collectors.toList());
+        List<TopicMetadataRequestState> expiredRequests = new ArrayList<>();
+
+        for (TopicMetadataRequestState requestState : inflightRequests) {
+            if (requestState.isExpired())
+                expiredRequests.add(requestState);
+        }
+
         expiredRequests.forEach(TopicMetadataRequestState::expire);

Review Comment:
   Couldn't you just not build `expiredRequests` and call 
`requestState.expire()` at L91?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to