dajac commented on code in PR #18020:
URL: https://github.com/apache/kafka/pull/18020#discussion_r1869513717


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/consumer/ConsumerGroup.java:
##########
@@ -791,6 +819,60 @@ private void validateMemberEpoch(
         }
     }
 
+    /**
+     * Computes the subscription type based on the provided information.
+     *
+     * @param subscribedRegularExpressions  The subscribed regular expression 
count.
+     * @param subscribedTopicNames          The subscribed topic name count.
+     * @param numberOfMembers               The number of members in the group.
+     *
+     * @return The subscription type.
+     */
+    public static SubscriptionType subscriptionType(
+        Map<String, Integer> subscribedRegularExpressions,
+        Map<String, Integer> subscribedTopicNames,
+        int numberOfMembers
+    ) {
+        if (subscribedRegularExpressions.isEmpty()) {
+            // If the members do not use regular expressions, the subscription 
is
+            // considered as homogeneous if all the members are subscribed to 
the
+            // same topics. Otherwise, it is considered as heterogeneous.
+            for (int subscriberCount : subscribedTopicNames.values()) {
+                if (subscriberCount != numberOfMembers) {
+                    return HETEROGENEOUS;
+                }
+            }
+            return HOMOGENEOUS;
+        } else {
+            int count = 
subscribedRegularExpressions.values().iterator().next();
+            if (count == numberOfMembers) {
+                // If all the members are subscribed to a single regular 
expressions
+                // and none of them are subscribed to topic names, the 
subscription
+                // is considered as homogeneous. If some members are 
subscribed to
+                // topic names too, the subscription is considered as 
heterogeneous.
+                for (int subscriberCount : subscribedTopicNames.values()) {
+                    if (subscriberCount != 1) {
+                        return HETEROGENEOUS;
+                    }
+                }
+                return HOMOGENEOUS;

Review Comment:
   @squah-confluent I updated the PR to address it. I opted for tracking the 
number of subscribed names and of subscribed regexes separately in order to 
avoid it. Let me know what you think.



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