rreddy-22 commented on code in PR #15785:
URL: https://github.com/apache/kafka/pull/15785#discussion_r1583450532


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/consumer/ConsumerGroup.java:
##########
@@ -966,6 +982,61 @@ 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> updateSubscribedTopicNames(
+        ConsumerGroupMember oldMember,
+        ConsumerGroupMember newMember
+    ) {
+        Map<String, Integer> subscribedTopicCount = new 
HashMap<>(this.subscribedTopicNames);
+        if (oldMember != null) {
+            oldMember.subscribedTopicNames().forEach(topicName ->
+                subscribedTopicCount.compute(topicName, 
ConsumerGroup::decValue)
+            );
+        }
+
+        if (newMember != null) {
+            newMember.subscribedTopicNames().forEach(topicName ->
+                subscribedTopicCount.compute(topicName, 
ConsumerGroup::incValue)
+            );
+        }
+
+        return subscribedTopicCount;
+    }
+
+    /**
+     * Compute the subscription type of the consumer group.
+     *
+     * If all members are subscribed to the same set of topics, the type is 
homogeneous.
+     * Otherwise, it is heterogeneous.
+     *
+     * @param subscribedTopicNames      A map of topic names to the count of 
members subscribed to each topic.
+     * @param numOfMembers              The total number of members in the 
group.
+     * @param subscriptionType          The current subscription type of the 
group.
+     * @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,
+        int numOfMembers,
+        SubscriptionType subscriptionType
+    ) {
+        if (subscribedTopicNames.isEmpty()) return subscriptionType;

Review Comment:
   discussed offline



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