dajac commented on PR #24315:
URL: https://github.com/apache/kafka/pull/24315#issuecomment-7135563131

   This also fixes a second trigger, besides the static member replacement: an 
upgrade during a rebalance after a member changed its subscription, by a member 
that doesn't bump the group epoch.
   
   - Classic members 1 and 2 are Stable and subscribed to foo and bar. Member 1 
rejoins subscribed to foo only, which starts a rebalance.
   - A consumer-protocol member joins with a regex that matches no topic and 
upgrades the group. Its join doesn't bump the group epoch: it brings no topic 
names, and the regex resolves to nothing.
   - On trunk, `fromClassicGroup` takes member 1's new subscription but its 
last assignment. The target keeps bar-0 for member 1, which no longer 
subscribes to it, so member 1 rejoins in a loop and bar-0 isn't consumed. 
Member 1's rejoin doesn't bump the epoch either, because its subscription is 
the one that the conversion took.
   
   With this PR, the group epoch is bumped and the target follows the current 
subscriptions. The test below fails on trunk in both states and passes on 
76a8540a94. Could you add it next to the other upgrade tests? KAFKA-21582 only 
names the static member replacement, so it may be worth mentioning this case 
there too.
   
   <details>
   
<summary>testConsumerGroupHeartbeatWithRebalancingClassicGroupAfterSubscriptionChange</summary>
   
   ```java
       @ParameterizedTest
       @EnumSource(value = ClassicGroupState.class, names = 
{"PREPARING_REBALANCE", "COMPLETING_REBALANCE"})
       public void 
testConsumerGroupHeartbeatWithRebalancingClassicGroupAfterSubscriptionChange(ClassicGroupState
 state) throws Exception {
           String groupId = "group-id";
           String memberId1 = "member-id-1";
           String memberId2 = "member-id-2";
           String memberId3 = "member-id-3";
           Uuid fooTopicId = Uuid.randomUuid();
           String fooTopicName = "foo";
           Uuid barTopicId = Uuid.randomUuid();
           String barTopicName = "bar";
   
           CoordinatorMetadataImage metadataImage = new MetadataImageBuilder()
               .addTopic(fooTopicId, fooTopicName, 2)
               .addTopic(barTopicId, barTopicName, 2)
               .buildCoordinatorMetadataImage();
   
           GroupMetadataManagerTestContext context = new 
GroupMetadataManagerTestContext.Builder()
               
.withConfig(GroupCoordinatorConfig.CONSUMER_GROUP_MIGRATION_POLICY_CONFIG, 
ConsumerGroupMigrationPolicy.UPGRADE.toString())
               
.withConfig(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNOR_OFFLOAD_ENABLE_CONFIG,
 false)
               
.withConfig(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(new 
RangeAssignor()))
               .withMetadataImage(metadataImage)
               .build();
   
           JoinGroupRequestProtocolCollection protocols = 
GroupMetadataManagerTestContext.toConsumerProtocol(
               List.of(fooTopicName, barTopicName),
               List.of()
           );
           Map<String, byte[]> assignments = Map.of(
               memberId1, 
Utils.toArray(ConsumerProtocol.serializeAssignment(new 
ConsumerPartitionAssignor.Assignment(List.of(
                   new TopicPartition(fooTopicName, 0),
                   new TopicPartition(barTopicName, 0)
               )))),
               memberId2, 
Utils.toArray(ConsumerProtocol.serializeAssignment(new 
ConsumerPartitionAssignor.Assignment(List.of(
                   new TopicPartition(fooTopicName, 1),
                   new TopicPartition(barTopicName, 1)
               ))))
           );
   
           // Create a stable classic group at generation 1 with members 1 and 
2 subscribed to foo and bar.
           ClassicGroup group = context.createClassicGroup(groupId);
           group.add(
               new ClassicGroupMember(
                   memberId1,
                   Optional.empty(),
                   "client-id",
                   "client-host",
                   10000,
                   5000,
                   "consumer",
                   protocols,
                   assignments.get(memberId1)
               )
           );
           group.add(
               new ClassicGroupMember(
                   memberId2,
                   Optional.empty(),
                   "client-id",
                   "client-host",
                   10000,
                   5000,
                   "consumer",
                   protocols,
                   assignments.get(memberId2)
               )
           );
           group.transitionTo(PREPARING_REBALANCE);
           group.initNextGeneration();
           group.transitionTo(STABLE);
   
           
context.replay(GroupCoordinatorRecordHelpers.newGroupMetadataRecord(group, 
assignments));
           context.commit();
           group = 
context.groupMetadataManager.getOrMaybeCreateClassicGroup(groupId, false);
   
           // Member 1 rejoins subscribed to foo only, triggering a rebalance.
           context.sendClassicGroupJoin(
               new GroupMetadataManagerTestContext.JoinGroupRequestBuilder()
                   .withGroupId(groupId)
                   .withMemberId(memberId1)
                   
.withProtocols(GroupMetadataManagerTestContext.toConsumerProtocol(List.of(fooTopicName),
 List.of()))
                   .withSessionTimeoutMs(5000)
                   .withRebalanceTimeoutMs(10000)
                   .build()
           );
   
           if (state == COMPLETING_REBALANCE) {
               // Member 2 rejoins with the same subscription, completing the 
join phase.
               context.sendClassicGroupJoin(
                   new GroupMetadataManagerTestContext.JoinGroupRequestBuilder()
                       .withGroupId(groupId)
                       .withMemberId(memberId2)
                       .withProtocols(protocols)
                       .withSessionTimeoutMs(5000)
                       .withRebalanceTimeoutMs(10000)
                       .build()
               );
           }
           assertTrue(group.isInState(state));
           int generationId = group.generationId();
   
           // Member 3 joins with a regex that matches no topic, triggering the 
upgrade.
           CoordinatorResult<ConsumerGroupHeartbeatResponseData, 
CoordinatorRecord> result = context.consumerGroupHeartbeat(
               new ConsumerGroupHeartbeatRequestData()
                   .setGroupId(groupId)
                   .setMemberId(memberId3)
                   .setMemberEpoch(0)
                   .setRebalanceTimeoutMs(5000)
                   .setSubscribedTopicRegex("baz")
                   .setTopicPartitions(List.of())
           );
   
           // The target assignment follows the current subscriptions, so bar 
goes to member 2 only.
           assertEquals(
               Map.of(
                   memberId1, new Assignment(mkAssignment(
                       mkTopicAssignment(fooTopicId, 0)
                   )),
                   memberId2, new Assignment(mkAssignment(
                       mkTopicAssignment(fooTopicId, 1),
                       mkTopicAssignment(barTopicId, 0, 1)
                   )),
                   memberId3, new Assignment(Map.of())
               ),
               
Map.copyOf(context.groupMetadataManager.consumerGroup(groupId).targetAssignment())
           );
           assertResponseEquals(
               new ConsumerGroupHeartbeatResponseData()
                   .setMemberId(memberId3)
                   .setMemberEpoch(generationId + 1)
                   .setHeartbeatIntervalMs(5000)
                   .setAssignment(new 
ConsumerGroupHeartbeatResponseData.Assignment()),
               result.response()
           );
       }
   ```
   
   </details>
   


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