dongnuo123 commented on code in PR #24187:
URL: https://github.com/apache/kafka/pull/24187#discussion_r4539378314


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/consumer/ConsumerGroup.java:
##########
@@ -1226,54 +1226,67 @@ public static ConsumerGroup fromClassicGroup(
         consumerGroup.setGroupEpoch(classicGroup.generationId());
         consumerGroup.setTargetAssignmentMetadata(classicGroup.generationId(), 
0L);
 
-        classicGroup.allMembers().forEach(classicGroupMember -> {
-            // The assigned partition can be empty if the member just joined 
and has never synced.
-            // We should accept the empty assignment.
-            Map<Uuid, Set<Integer>> assignedPartitions;
-            if (Arrays.equals(classicGroupMember.assignment(), 
EMPTY_ASSIGNMENT)) {
-                assignedPartitions = Map.of();
-            } else {
-                ConsumerProtocolAssignment assignment = 
ConsumerProtocol.deserializeConsumerProtocolAssignment(
-                    ByteBuffer.wrap(classicGroupMember.assignment())
-                );
-                if (assignment.userData() != null && 
assignment.userData().hasRemaining()) {
-                    throw new UnsupportedVersionException("userData from a 
custom assignor would be lost");
+        // A classic group reaches the online conversion without members when 
its last member left
+        // while a member that got MEMBER_ID_REQUIRED had not rejoined yet. It 
is then still in
+        // PreparingRebalance rather than Empty, and it has no member metadata 
to parse.
+        if (classicGroup.numMembers() > 0) {
+            // The members are parsed with the selected protocol if they all 
support it. Otherwise,
+            // when no protocol is selected yet or a member that does not 
support it has joined,
+            // they are parsed with the protocol that the next generation 
would select.
+            String protocol = classicGroup.protocolName()
+                .filter(name -> 
classicGroup.supportedProtocols().getOrDefault(name, 0) == 
classicGroup.numMembers())
+                .orElseGet(classicGroup::selectProtocol);
+
+            classicGroup.allMembers().forEach(classicGroupMember -> {
+                // The assigned partition can be empty if the member just 
joined and has never
+                // synced. We should accept the empty assignment.
+                Map<Uuid, Set<Integer>> assignedPartitions;
+                if (Arrays.equals(classicGroupMember.assignment(), 
EMPTY_ASSIGNMENT)) {
+                    assignedPartitions = Map.of();
+                } else {
+                    ConsumerProtocolAssignment assignment = 
ConsumerProtocol.deserializeConsumerProtocolAssignment(
+                        ByteBuffer.wrap(classicGroupMember.assignment())
+                    );
+                    if (assignment.userData() != null && 
assignment.userData().hasRemaining()) {
+                        throw new UnsupportedVersionException("userData from a 
custom assignor would be lost");
+                    }
+                    assignedPartitions = toTopicPartitionMap(assignment, 
metadataImage);
                 }
-                assignedPartitions = toTopicPartitionMap(assignment, 
metadataImage);
-            }
 
-            // Every member is guaranteed to have metadata set when it joins,
-            // so we don't check for empty subscription here.
-            ConsumerProtocolSubscription subscription = 
ConsumerProtocol.deserializeConsumerProtocolSubscription(
-                
ByteBuffer.wrap(classicGroupMember.metadata(classicGroup.protocolName().get()))
-            );
+                // Every member is guaranteed to have metadata set when it 
joins,
+                // so we don't check for empty subscription here.
+                ConsumerProtocolSubscription subscription = 
ConsumerProtocol.deserializeConsumerProtocolSubscription(
+                    ByteBuffer.wrap(classicGroupMember.metadata(protocol))

Review Comment:
   Why don't we just pick a random protocol in 
`classicGroupMember.supportedProtocols()`? We only care about the 
subscription's rack Id and topics which should be the same in any protocol's 
metadata?



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