squah-confluent commented on code in PR #18020:
URL: https://github.com/apache/kafka/pull/18020#discussion_r1868494415
##########
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:
I'm a little confused about this. Won't we return `HOMOGENEOUS` when all
members are subscribed to the same regex, but one member is additionally
subscribed to a topic outside the scope of the regex?
eg. all members subscribe to regex "foo*" and one member also subscribes to
topic "bar".
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]