philipnee commented on code in PR #13550:
URL: https://github.com/apache/kafka/pull/13550#discussion_r1177895473
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:
##########
@@ -149,47 +148,51 @@ private boolean allSubscriptionsEqual(Set<String>
allTopics,
}
MemberData memberData = memberData(subscription);
+ maxGeneration = Math.max(maxGeneration,
memberData.generation.orElse(DEFAULT_GENERATION));
List<TopicPartition> ownedPartitions = new ArrayList<>();
consumerToOwnedPartitions.put(consumer, ownedPartitions);
- // Only consider this consumer's owned partitions as valid if it
is a member of the current highest
- // generation, or it's generation is not present but we have not
seen any known generation so far
- if (memberData.generation.isPresent() &&
memberData.generation.get() >= maxGeneration
- || !memberData.generation.isPresent() && maxGeneration ==
DEFAULT_GENERATION) {
-
- // If the current member's generation is higher, all the
previously owned partitions are invalid
- if (memberData.generation.isPresent() &&
memberData.generation.get() > maxGeneration) {
- allPreviousPartitionsToOwner.clear();
- partitionsWithMultiplePreviousOwners.clear();
- for (String droppedOutConsumer :
membersOfCurrentHighestGeneration) {
-
consumerToOwnedPartitions.get(droppedOutConsumer).clear();
- }
-
- membersOfCurrentHighestGeneration.clear();
- maxGeneration = memberData.generation.get();
- }
+ // the member has a valid generation, so we can consider its owned
partitions if it has the highest
+ // generation amongst
+ for (final TopicPartition tp : memberData.partitions) {
+ if (allTopics.contains(tp.topic())) {
+ String otherConsumer =
allPreviousPartitionsToOwner.put(tp, consumer);
+ if (otherConsumer == null) {
+ // this partition is not owned by other consumer in
the same generation
+ ownedPartitions.add(tp);
+ } else {
+ final int memberGeneration =
memberData.generation.orElse(DEFAULT_GENERATION);
+ final int otherMemberGeneration =
subscriptions.get(otherConsumer).generationId().orElse(DEFAULT_GENERATION);
+
+ if (memberGeneration == otherMemberGeneration) {
+ if
(subscriptions.get(otherConsumer).generationId().orElse(DEFAULT_GENERATION) ==
memberData.generation.orElse(DEFAULT_GENERATION)) {
+ log.error("Found multiple consumers {} and {}
claiming the same TopicPartition {} in the "
+ + "same generation {}, this will be
invalidated and removed from their previous assignment.",
+ consumer, otherConsumer, tp,
memberGeneration);
+ partitionsWithMultiplePreviousOwners.add(tp);
+ }
+
consumerToOwnedPartitions.get(otherConsumer).remove(tp);
+ allPreviousPartitionsToOwner.put(tp, consumer);
+ continue;
Review Comment:
It could be. I got into the habit of returning early, I thought it makes it
easier to read.
--
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]