squah-confluent commented on code in PR #24315:
URL: https://github.com/apache/kafka/pull/24315#discussion_r4708750492


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/consumer/ConsumerGroup.java:
##########
@@ -1299,7 +1299,21 @@ public static ConsumerGroup fromClassicGroup(
     ) {
         String groupId = classicGroup.groupId();
         ConsumerGroup consumerGroup = new ConsumerGroup(logContext, 
snapshotRegistry, groupId);
-        consumerGroup.setGroupEpoch(classicGroup.generationId());
+        int groupEpoch = switch (classicGroup.currentState()) {
+            case EMPTY, DEAD -> classicGroup.generationId();
+            case PREPARING_REBALANCE -> classicGroup.generationId() + 1; // We 
are expecting a new assignment.
+            case COMPLETING_REBALANCE -> {
+                // We are expecting a new assignment. The generation was 
already bumped when the join
+                // phase completed, but the members have not received its 
assignment yet. The members
+                // may have already observed the bumped generation id in their 
JoinGroup responses and
+                // will send it in their SyncGroup and Heartbeat requests. We 
must keep the generation id
+                // as their member epoch and the target assignment epoch, and 
bump the group epoch again
+                // to compute a new target assignment.
+                yield classicGroup.generationId() + 1;
+            }
+            case STABLE -> classicGroup.generationId();
+        };
+        consumerGroup.setGroupEpoch(groupEpoch);
         consumerGroup.setTargetAssignmentMetadata(classicGroup.generationId(), 
0L);

Review Comment:
   I brought the KAFKA-21584 fix forward into this PR.
   
   The `PREPARING_REBALANCE ` and `COMPLETING_REBALANCE` switch cases are 
intentionally separated to make the double epoch bump in `COMPLETING_REBALANCE` 
very visible, since one might naively expect both states from the same 
rebalance to end up at the same epoch number.



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

Reply via email to