KAFKA-19500: kafka-consumer-groups.sh should fail quickly if the partition leader is unavailable#20168
Conversation
|
The all methods which depend on
And they are all called in method |
AndrewJSchofield
left a comment
There was a problem hiding this comment.
Thanks for the PR. Just one minor comment.
| private void checkAllTopicPartitionsHaveLeader(Collection<TopicPartition> partitionsToReset) { | ||
| List<TopicPartition> partitionsWithoutLeader = filterNoneLeaderPartitions(partitionsToReset); | ||
| if (!partitionsWithoutLeader.isEmpty()) { | ||
| // append the TopicPartition list string |
There was a problem hiding this comment.
nit: You could do this string concatenation much more neatly with something like
String partitionStr = partitionsWithoutLeader.stream().map(TopicPartition::toString).collect(Collectors.joining(","));
There was a problem hiding this comment.
@AndrewJSchofield Thanks very much for CR, it's indeed much neater. I have fixed it, PTAL
| assertThrows(OptionException.class, () -> getConsumerGroupService(cgcArgs)); | ||
| } | ||
|
|
||
| @Timeout(60) |
There was a problem hiding this comment.
Nit: No need to add @Timeout here, @ClusterTest already includes a timeout setting.
There was a problem hiding this comment.
@m1a2st Thanks very much, the @Timeout is redundant, and I have remove it, PTAL
AndrewJSchofield
left a comment
There was a problem hiding this comment.
I think this could do with a little more work. If I create a topic T1 with 1 partition, the following command bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --reset-offsets --group CG1 --to-earliest --topic T1:1 --execute still hangs for a long time, even though it has called Admin.describeTopics.
I think it can be improved for the case of a non-existent topic of an existing topic. Seems like it's worth fixing this at the same time.
Good find! It's indeed hangs when a non-existent TopicPartition of an existing topic. I have added some logic to determine whether the target TopicPartitions actually exists, PTAL |
AndrewJSchofield
left a comment
There was a problem hiding this comment.
Thanks for the updates. Just a few minor comments now.
| List<TopicPartition> partitionsNotExistList = filterNotExistPartitions(partitionsToReset); | ||
| if (!partitionsNotExistList.isEmpty()) { | ||
| String partitionStr = partitionsNotExistList.stream().map(TopicPartition::toString).collect(Collectors.joining(",")); | ||
| throw new UnknownTopicOrPartitionException("The partitions \"" + partitionStr + "\" does not exist"); |
There was a problem hiding this comment.
nit: Grammar "do not exist" I think.
| } | ||
| } | ||
|
|
||
| private List<TopicPartition> filterNotExistPartitions(Collection<TopicPartition> topicPartitions) { |
There was a problem hiding this comment.
nit: filterNonExistentPartitions is probably a bit better.
| .toList(); | ||
|
|
||
| return topicPartitions.stream().filter(element -> !existPartitions.contains(element)).toList(); | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
For consistency, we tend to catch (InterruptedException | ExecutionException e) in this source file.
|
Also please merge latest changes from trunk. Hopefully you'll get a clean test run then. |
|
@AndrewJSchofield Thanks for the code review, and I have fixed them and merged the latest changes from trunk, PTAL |
AndrewJSchofield
left a comment
There was a problem hiding this comment.
Thanks for the PR. Looks good to me.
| } | ||
|
|
||
| // check the partitions have leader | ||
| List<TopicPartition> partitionsWithoutLeader = filterNoneLeaderPartitions(partitionsToReset); |
There was a problem hiding this comment.
if there is a topic having three partitions, and the t-2 partition is offline, then if partitionsToReset is t-0,t-1, filterNoneLeaderPartitions will return t-2, causing the tool to fail. Is it expected?
There was a problem hiding this comment.
I think it's fair enough.
There was a problem hiding this comment.
chia7712@chia7712-ubuntu:~/project/kafka$ ./bin/kafka-consumer-groups.sh \
--bootstrap-server 172.20.10.2:20001 \
--reset-offsets \
--to-earliest \
--execute \
--group perf-consumer-19460 \
--topic chia:1
Error: Executing consumer group command failed due to The partitions "chia-2" have no leader
org.apache.kafka.common.errors.LeaderNotAvailableException: The partitions "chia-2" have no leader
It is indeed a bug that unrelated topic partitions could fail the tool.
There was a problem hiding this comment.
filterNoneLeaderPartitions needs to get fixed since it could return unrelated topic partitions.
There was a problem hiding this comment.
Yes, that's a very good point. Thanks for finding it.
| produceConsumeAndShutdown(cluster, topic, group, 2, GroupProtocol.CLASSIC); | ||
| assertDoesNotThrow(() -> resetOffsets(service)); | ||
| // shutdown a broker to make some partitions missing leader | ||
| cluster.shutdownBroker(0); |
There was a problem hiding this comment.
Should we wait to ensure it has shut down correctly?
There was a problem hiding this comment.
The shutdown already has a 5-minute timeout by default.
…artition offline (#20235) See: #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>
…rtition leader is unavailable (apache#20168) 1. Add check leader missing logic in method `ConsumerGroupCommand.ConsumerGroupService#prepareOffsetsToReset` in order to fail quickly 2. Add some tests Reviewers: TaiJuWu <tjwu1217@gmail.com>, Lan Ding <isDing_L@163.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>
ConsumerGroupCommand.ConsumerGroupService#prepareOffsetsToResetinorder to fail quickly
Reviewers: TaiJuWu tjwu1217@gmail.com, Lan Ding isDing_L@163.com,
Ken Huang s7133700@gmail.com, Andrew Schofield
aschofield@confluent.io