-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-19500: kafka-consumer-groups.sh should fail quickly if the partition leader is unavailable
#20168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
KAFKA-19500: kafka-consumer-groups.sh should fail quickly if the partition leader is unavailable
#20168
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ | |
| import org.apache.kafka.clients.producer.ProducerRecord; | ||
| import org.apache.kafka.common.GroupState; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.errors.LeaderNotAvailableException; | ||
| import org.apache.kafka.common.errors.UnknownTopicOrPartitionException; | ||
| import org.apache.kafka.common.serialization.ByteArraySerializer; | ||
| import org.apache.kafka.common.serialization.StringDeserializer; | ||
| import org.apache.kafka.common.test.ClusterInstance; | ||
|
|
@@ -81,6 +83,7 @@ | |
| import static org.apache.kafka.coordinator.group.GroupCoordinatorConfig.OFFSETS_TOPIC_PARTITIONS_CONFIG; | ||
| import static org.apache.kafka.coordinator.group.GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG; | ||
| import static org.apache.kafka.test.TestUtils.DEFAULT_MAX_WAIT_MS; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
@@ -659,6 +662,41 @@ public void testResetWithUnrecognizedNewConsumerOption(ClusterInstance cluster) | |
| assertThrows(OptionException.class, () -> getConsumerGroupService(cgcArgs)); | ||
| } | ||
|
|
||
| @ClusterTest(brokers = 3, serverProperties = {@ClusterConfigProperty(key = OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")}) | ||
| public void testResetOffsetsWithPartitionNoneLeader(ClusterInstance cluster) throws Exception { | ||
| String group = generateRandomGroupId(); | ||
| String topic = generateRandomTopic(); | ||
| String[] args = buildArgsForGroup(cluster, group, "--topic", topic + ":0,1,2", | ||
| "--to-earliest", "--execute"); | ||
|
|
||
| try (Admin admin = cluster.admin(); | ||
| ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args)) { | ||
|
|
||
| admin.createTopics(singleton(new NewTopic(topic, 3, (short) 1))).all().get(); | ||
| produceConsumeAndShutdown(cluster, topic, group, 2, GroupProtocol.CLASSIC); | ||
| assertDoesNotThrow(() -> resetOffsets(service)); | ||
| // shutdown a broker to make some partitions missing leader | ||
| cluster.shutdownBroker(0); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we wait to ensure it has shut down correctly?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The shutdown already has a 5-minute timeout by default. |
||
| assertThrows(LeaderNotAvailableException.class, () -> resetOffsets(service)); | ||
| } | ||
| } | ||
|
|
||
| @ClusterTest | ||
| public void testResetOffsetsWithPartitionNotExist(ClusterInstance cluster) throws Exception { | ||
| String group = generateRandomGroupId(); | ||
| String topic = generateRandomTopic(); | ||
| String[] args = buildArgsForGroup(cluster, group, "--topic", topic + ":2,3", | ||
| "--to-earliest", "--execute"); | ||
|
|
||
| try (Admin admin = cluster.admin(); | ||
| ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args)) { | ||
|
|
||
| admin.createTopics(singleton(new NewTopic(topic, 1, (short) 1))).all().get(); | ||
| produceConsumeAndShutdown(cluster, topic, group, 2, GroupProtocol.CLASSIC); | ||
| assertThrows(UnknownTopicOrPartitionException.class, () -> resetOffsets(service)); | ||
| } | ||
| } | ||
|
|
||
| private String generateRandomTopic() { | ||
| return TOPIC_PREFIX + TestUtils.randomString(10); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is a topic having three partitions, and the
t-2partition is offline, then ifpartitionsToResetist-0,t-1,filterNoneLeaderPartitionswill returnt-2, causing the tool to fail. Is it expected?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed a bug that unrelated topic partitions could fail the tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterNoneLeaderPartitionsneeds to get fixed since it could return unrelated topic partitions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a very good point. Thanks for finding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file #20235 to fix it.