adikou commented on code in PR #24330:
URL: https://github.com/apache/kafka/pull/24330#discussion_r4649555487
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
Review Comment:
Nit: I noticed this block comment is incomplete
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -146,9 +147,10 @@ private boolean allSubscriptionsEqual(Set<String>
allTopics,
final String consumer = subscriptionEntry.getKey();
final Subscription subscription = subscriptionEntry.getValue();
- // initialize the subscribed topics set if this is the first
subscription
- if (subscribedTopics.isEmpty()) {
- subscribedTopics.addAll(subscription.topics());
+ // initialize the subscribed topics set if this is the first
subscription. It may be empty, so
+ // check for null and not for an empty set
+ if (subscribedTopics == null) {
Review Comment:
Why use the state of the collection itself for detecting the set of
subscribed topics? How about a boolean to track the initialisation out of band?
This way we don't have to reason about null/empty.
This may be my own gap in knowledge: is there anything special about just
the first `Subscription`? What about the first 2/3/N/all entries being empty?
Something like pick the first non-empty collection for subscribed topics?
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -146,9 +147,10 @@ private boolean allSubscriptionsEqual(Set<String>
allTopics,
final String consumer = subscriptionEntry.getKey();
final Subscription subscription = subscriptionEntry.getValue();
- // initialize the subscribed topics set if this is the first
subscription
- if (subscribedTopics.isEmpty()) {
- subscribedTopics.addAll(subscription.topics());
+ // initialize the subscribed topics set if this is the first
subscription. It may be empty, so
+ // check for null and not for an empty set
+ if (subscribedTopics == null) {
+ subscribedTopics = new HashSet<>(subscription.topics());
} else if (isAllSubscriptionsEqual &&
!(subscription.topics().size() == subscribedTopics.size()
Review Comment:
`s.size() == s2.size() && s.containsAll(s2) ` is basically `s.equals(s2)`
(or Objects.equals if you want)
--
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]