MINOR: add test for kafka-consumer-groups.sh should not fail when partition offline#20235
Conversation
AndrewJSchofield
left a comment
There was a problem hiding this comment.
Thanks for the PR. A couple of small comments.
| cluster.createTopic(topic, 3, (short) 2); | ||
|
|
||
| try (ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args); | ||
| Admin admin = cluster.admin()) { |
There was a problem hiding this comment.
nit: The indentation here is a bit strange not being a multiple of 4 spaces. I wonder whether just concatenating this on the end of the previous line would be simplest.
There was a problem hiding this comment.
change to
try (Admin admin = cluster.admin(); ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args))
| } | ||
| } | ||
|
|
||
| @ClusterTest(brokers = 5) |
There was a problem hiding this comment.
I think we could just use 2 brokers for this test? 5 is overkill.
There was a problem hiding this comment.
Thanks for review.
I use 3 broker as default since we need to ensure __consumere_offset always have two brokers in any condition and we need to shutdown a broker.
If the replica of __consumer_offset is 1, we can't sure the leader is not shutdown broker.
There was a problem hiding this comment.
Can two brokers with two replicas fix the issue you mentioned?
There was a problem hiding this comment.
Change to two brokers and explicitly define min_insyn_replica equals one.
| } | ||
|
|
||
| @ClusterTest(brokers = 5) | ||
| public void testResetOffsetsWithOfflinePartition(ClusterInstance cluster) throws Exception { |
There was a problem hiding this comment.
To better distinguish this test from testResetOffsetsWithPartitionNoneLeader, maybe rename it to testResetOffsetsWithOfflinePartitionNotInResetTarget or something similar.
Yunyung
left a comment
There was a problem hiding this comment.
Thanks for the updates. Left two comments, one here: https://github.com/apache/kafka/pull/20168/files#r2228628205
| .stream() | ||
| .flatMap(entry -> entry.getValue().partitions().stream() | ||
| .filter(partitionInfo -> partitionInfo.leader() == null) | ||
| .filter(partitionInfo -> topicPartitions.contains(new TopicPartition(entry.getKey(), partitionInfo.partition())) && partitionInfo.leader() == null) |
There was a problem hiding this comment.
nit: check partitionInfo.leader() == null before creating the TopicPartition for performance.
There was a problem hiding this comment.
Good point, thanks.
| cluster.waitTopicCreation(topic, 2); | ||
|
|
||
| cluster.shutdownBroker(1); | ||
| TestUtils.waitForCondition(() -> !cluster.aliveBrokers().containsKey(1), |
There was a problem hiding this comment.
According to https://github.com/apache/kafka/pull/20168/files#r2228677312, I understand that shutdown() already waits until the shutdown is complete. So this can be removed as well.
| .flatMap(entry -> entry.getValue().partitions().stream() | ||
| .filter(partitionInfo -> partitionInfo.leader() == null) | ||
| .filter(partitionInfo -> partitionInfo.leader() == null && topicPartitions.contains(new TopicPartition(entry.getKey(), partitionInfo.partition()))) | ||
| .map(partitionInfo -> new TopicPartition(entry.getKey(), partitionInfo.partition()))) |
There was a problem hiding this comment.
Please add the filter after map to avoid creating extra TopicPartition object.
.filter(partitionInfo -> partitionInfo.leader() == null)
.map(partitionInfo -> new TopicPartition(entry.getKey(), partitionInfo.partition()))
.filter(topicPartitions::contains))| } | ||
|
|
||
| @ClusterTest( | ||
| brokers = 3, |
There was a problem hiding this comment.
It seems two brokers could work well for this test, right?
There was a problem hiding this comment.
Here is the reason I selected three brokers instead of two.
#20235 (comment)
| @ClusterConfigProperty(key = OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2"), | ||
| @ClusterConfigProperty(key = TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, value = "1") |
There was a problem hiding this comment.
Do we really need to set these properties? We can reproduce the failure without setting them.
There was a problem hiding this comment.
These settings can avoid flaky.
In my mind, if __consumer_offset is at broker 1 and we shutdown it, we don't have any __consumer_offset.
There was a problem hiding this comment.
The min.insync.replicas default value is 1, so we don't need to configure it explicitly?
kafka-consumer-groups.sh should not fail when partition offlinekafka-consumer-groups.sh should not fail when partition offline
|
@TaiJuWu please fix the build error |
Thanks for remaining me! |
AndrewJSchofield
left a comment
There was a problem hiding this comment.
Thanks for the PR. Looks good to me.
…artition offline (apache#20235) See: apache#20168 (comment) add follow test case: Given a topic with three partitions, where partition `t-2` is offline, if partitionsToReset contains only `t-1`, the method filterNoneLeaderPartitions incorrectly includes `t-2` in the result, leading to a failure in the tool. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Jhen-Yung Hsu <jhenyunghsu@gmail.com>, Ken Huang <s7133700@gmail.com>, Andrew Schofield <aschofield@confluent.io>
…artition offline (apache#20235) See: apache#20168 (comment) add follow test case: Given a topic with three partitions, where partition `t-2` is offline, if partitionsToReset contains only `t-1`, the method filterNoneLeaderPartitions incorrectly includes `t-2` in the result, leading to a failure in the tool. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Jhen-Yung Hsu <jhenyunghsu@gmail.com>, Ken Huang <s7133700@gmail.com>, Andrew Schofield <aschofield@confluent.io>
See: #20168 (comment)
add follow test case:
Given a topic with three partitions, where partition
t-2is offline,if partitionsToReset contains only
t-1, the methodfilterNoneLeaderPartitions incorrectly includes
t-2in the result,leading to a failure in the tool.
Reviewers: Chia-Ping Tsai chia7712@gmail.com, Jhen-Yung Hsu
jhenyunghsu@gmail.com, Ken Huang s7133700@gmail.com, Andrew
Schofield aschofield@confluent.io