dongnuo123 commented on code in PR #15785:
URL: https://github.com/apache/kafka/pull/15785#discussion_r1587655470


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/consumer/ConsumerGroup.java:
##########
@@ -966,6 +979,53 @@ private static void maybeUpdateSubscribedTopicNames(
         }
     }
 
+    /**
+     * Updates the subscription count.
+     *
+     * @param oldMember             The old member.
+     * @param newMember             The new member.
+     *
+     * @return Copy of the map of topics to the count of number of subscribers.
+     */
+    public Map<String, Integer> computeSubscribedTopicNames(
+        ConsumerGroupMember oldMember,
+        ConsumerGroupMember newMember
+    ) {
+        Map<String, Integer> subscribedTopicNames = new 
HashMap<>(this.subscribedTopicNames);
+        maybeUpdateSubscribedTopicNames(
+            subscribedTopicNames,
+            oldMember,
+            newMember
+        );
+        return subscribedTopicNames;
+    }
+
+    /**
+     * Compute the subscription type of the consumer group.
+     *
+     * @param subscribedTopicNames      A map of topic names to the count of 
members subscribed to each topic.
+     *
+     * @return {@link SubscriptionType#HOMOGENEOUS} if all members are 
subscribed to exactly the same topics;
+     *         otherwise, {@link SubscriptionType#HETEROGENEOUS}.
+     */
+    public static SubscriptionType subscriptionType(
+        Map<String, Integer> subscribedTopicNames
+    ) {
+        if (subscribedTopicNames.isEmpty()) {
+            return HOMOGENEOUS;
+        }
+
+        // Take the subscriber count of the first topic as the reference.
+        int referenceCount = subscribedTopicNames.values().iterator().next();

Review Comment:
   > thinking about https://github.com/apache/kafka/pull/15798, it may not be 
true
   
   Yes this isn't true. I can add a check to prevent empty subscribed topic 
list form joining.



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