chia7712 commented on code in PR #24141:
URL: https://github.com/apache/kafka/pull/24141#discussion_r4578825698
##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupMetadataManagerTest.java:
##########
@@ -6997,6 +6997,130 @@ public void
testLastJoiningMembersAreKickedOutWhenRejoiningGroupWithMaxSize() {
.forEach(memberId -> assertTrue(group.hasMember(memberId)));
}
+ @Test
+ public void
testJoinPhaseCompletesWhenLastRejoiningMembersAreRejectedWithGroupMaxSize() {
Review Comment:
Would you mind adding an integration test? We could restart the brokers with
a lower limit and check if the rebalance gets completed in time
```java
@ClusterTest
public void
testClassicGroupIsShrunkWhenCoordinatorLoadsItWithSmallerMaxGroupSize() throws
Exception {
String group = "group-max-size-shrink-test";
String topic = "group-max-size-shrink-test";
int newMaxGroupSize = 2;
int consumerCount = newMaxGroupSize + 1;
int partitionCount = consumerCount * 2;
// The rebalance timeout of the classic protocol is
max.poll.interval.ms.
long rebalanceTimeoutMs = 30000L;
Map<String, String> consumerConfig = new HashMap<>();
consumerConfig.put(ConsumerConfig.GROUP_PROTOCOL_CONFIG,
GroupProtocol.CLASSIC.name);
consumerConfig.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG,
Long.toString(rebalanceTimeoutMs));
consumerConfig.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG,
"1000");
consumerConfig.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,
"false");
clusterInstance.createTopic(topic, partitionCount, (short)
BROKER_COUNT);
Set<TopicPartition> partitions = new HashSet<>();
for (int i = 0; i < partitionCount; ++i)
partitions.add(new TopicPartition(topic, i));
// The group fits in the initial max size (MAX_GROUP_SIZE).
addConsumersToGroupAndWaitForGroupAssignment(
consumerCount,
List.of(topic),
partitions,
group,
consumerConfig
);
// Roll all the brokers with the smaller max size. The current
coordinator goes last so that
// the group is loaded by a broker which already has the new config
when the coordinator moves.
int coordinatorId =
findCoordinators(List.of(group)).iterator().next();
List<Integer> brokerIds = new
ArrayList<>(clusterInstance.brokers().keySet());
brokerIds.remove(Integer.valueOf(coordinatorId));
brokerIds.add(coordinatorId);
Map<String, Object> newConfig = Map.of(
GroupCoordinatorConfig.GROUP_MAX_SIZE_CONFIG,
Integer.toString(newMaxGroupSize));
for (int brokerId : brokerIds) {
clusterInstance.restartBroker(brokerId, newConfig);
clusterInstance.waitForReadyBrokers();
// Do not restart the next broker until this one has caught up,
so the group metadata is never lost.
waitForGroupMetadataTopicFullyReplicated();
}
// The group is over capacity, so the coordinator forces a rebalance
and rejects the last member to rejoin.
TestUtils.waitForCondition(
() -> consumerPollers.stream().anyMatch(poller ->
poller.getThrownException().isPresent()),
30000L,
"No consumer was removed from the group after the max group
size was reduced"
);
List<ConsumerAssignmentPoller> rejectedPollers =
consumerPollers.stream()
.filter(poller -> poller.getThrownException().isPresent())
.toList();
consumerPollers.removeAll(rejectedPollers);
// The remaining members have all rejoined, so the rebalance must
complete right after the rejection.
// Waiting for less than the rebalance timeout fails the test if the
coordinator only completes
// the rebalance when the rebalance timeout expires.
validateGroupAssignment(
consumerPollers,
partitions,
Optional.of("The rebalance did not complete right after the
over-capacity member was rejected"),
rebalanceTimeoutMs / 2,
List.of()
);
assertEquals(newMaxGroupSize, consumerPollers.size());
assertTrue(consumerPollers.stream().noneMatch(poller ->
poller.getThrownException().isPresent()),
"More consumers than expected were removed from the group");
assertEquals(1, rejectedPollers.size());
assertInstanceOf(GroupMaxSizeReachedException.class,
rejectedPollers.get(0).getThrownException().get());
try (Admin admin = clusterInstance.admin()) {
assertEquals(newMaxGroupSize,
admin.describeConsumerGroups(List.of(group)).describedGroups().get(group).get().members().size());
}
}
private void waitForGroupMetadataTopicFullyReplicated() throws
InterruptedException {
try (Admin admin = clusterInstance.admin()) {
TestUtils.waitForCondition(() -> {
try {
TopicDescription description =
admin.describeTopics(List.of(Topic.GROUP_METADATA_TOPIC_NAME))
.allTopicNames().get().get(Topic.GROUP_METADATA_TOPIC_NAME);
return description.partitions().stream()
.allMatch(info -> info.leader() != null &&
info.isr().size() == BROKER_COUNT);
} catch (ExecutionException e) {
return false;
}
}, 30000L, Topic.GROUP_METADATA_TOPIC_NAME + " did not become
fully replicated");
}
}
```
--
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]