dajac commented on code in PR #15785:
URL: https://github.com/apache/kafka/pull/15785#discussion_r1587222161
##########
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:
We don't allow subscribing with no topic names with the consumer protocol so
this logic works in this case. However, thinking about
https://github.com/apache/kafka/pull/15798, it may not be true when the classic
protocol is used to join a consumer group. @dongnuo123 Do you confirm?
--
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]