showuon commented on a change in pull request #10552:
URL: https://github.com/apache/kafka/pull/10552#discussion_r615229332



##########
File path: 
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java
##########
@@ -527,12 +615,23 @@ private int getBalanceScore(Map<String, 
List<TopicPartition>> assignment) {
      * Sort valid partitions so they are processed in the potential 
reassignment phase in the proper order
      * that causes minimal partition movement among consumers (hence honoring 
maximal stickiness)
      *
-     * @param partition2AllPotentialConsumers a mapping of partitions to their 
potential consumers
+     * @param topic2AllPotentialConsumers a mapping of partitions to their 
potential consumers
+     * @param partitionsPerTopic The number of partitions for each subscribed 
topic
      * @return  an ascending sorted list of topic partitions based on how many 
consumers can potentially use them
      */
-    private List<TopicPartition> sortPartitions(Map<TopicPartition, 
List<String>> partition2AllPotentialConsumers) {
-        List<TopicPartition> sortedPartitions = new 
ArrayList<>(partition2AllPotentialConsumers.keySet());
-        Collections.sort(sortedPartitions, new 
PartitionComparator(partition2AllPotentialConsumers));
+    private List<TopicPartition> sortPartitions(Map<String, List<String>> 
topic2AllPotentialConsumers,
+                                                Map<String, Integer> 
partitionsPerTopic) {
+        List<TopicPartition> sortedPartitions = new ArrayList<>();
+        List<String> allTopics = new 
ArrayList<>(topic2AllPotentialConsumers.keySet());
+        Collections.sort(allTopics, new 
TopicComparator(topic2AllPotentialConsumers));
+
+        // since allTopics are sorted, we can loop through allTopics to create 
the sortedPartitions

Review comment:
       refactor 4: To have `sortPartitions` list, we used to sort all of the 
partitions. To improve it, I sort all topics first(only 500 topics to sort, 
compared to the original 1 million partitions to sort), and then add the 
partitions by looping all sorted topics.




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

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


Reply via email to