-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MINOR: add test for kafka-consumer-groups.sh should not fail when partition offline
#20235
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
Changes from 5 commits
13c821c
a0fdb86
f7a4b03
a18d896
c2a24c9
b0e292f
391326a
e1cfa54
e13bc80
05b504b
ca27cea
7cd0703
cbe8138
3406b22
b843e4e
ae74eb4
5d1c22d
1a9e642
cda748f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -653,7 +653,7 @@ private List<TopicPartition> filterNoneLeaderPartitions(Collection<TopicPartitio | |
| return adminClient.describeTopics(topics).allTopicNames().get().entrySet() | ||
| .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) | ||
| .map(partitionInfo -> new TopicPartition(entry.getKey(), partitionInfo.partition()))) | ||
|
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. Please add the filter after .filter(partitionInfo -> partitionInfo.leader() == null)
.map(partitionInfo -> new TopicPartition(entry.getKey(), partitionInfo.partition()))
.filter(topicPartitions::contains)) |
||
| .toList(); | ||
| } catch (Exception e) { | ||
|
|
@@ -1054,7 +1054,7 @@ private List<TopicPartition> filterNonExistentPartitions(Collection<TopicPartiti | |
| .map(partitionInfo -> new TopicPartition(entry.getKey(), partitionInfo.partition()))) | ||
| .toList(); | ||
|
|
||
| return topicPartitions.stream().filter(element -> !existPartitions.contains(element)).toList(); | ||
| return topicPartitions.stream().filter(tp -> !existPartitions.contains(tp)).toList(); | ||
|
TaiJuWu marked this conversation as resolved.
Outdated
|
||
| } catch (InterruptedException | ExecutionException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| package org.apache.kafka.tools.consumer.group; | ||
|
|
||
| import org.apache.kafka.clients.admin.Admin; | ||
| import org.apache.kafka.clients.admin.NewPartitionReassignment; | ||
| import org.apache.kafka.clients.admin.NewTopic; | ||
| import org.apache.kafka.clients.consumer.GroupProtocol; | ||
| import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
|
@@ -26,7 +27,9 @@ | |
| import org.apache.kafka.clients.producer.Producer; | ||
| import org.apache.kafka.clients.producer.ProducerRecord; | ||
| import org.apache.kafka.common.GroupState; | ||
| import org.apache.kafka.common.Node; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.TopicPartitionInfo; | ||
| import org.apache.kafka.common.errors.LeaderNotAvailableException; | ||
| import org.apache.kafka.common.errors.UnknownTopicOrPartitionException; | ||
| import org.apache.kafka.common.serialization.ByteArraySerializer; | ||
|
|
@@ -51,7 +54,9 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.function.Function; | ||
| import java.util.function.Supplier; | ||
|
|
@@ -153,6 +158,33 @@ public void testResetOffsetsNotExistingGroup(ClusterInstance cluster) throws Exc | |
| } | ||
| } | ||
|
|
||
| @ClusterTest(brokers = 5) | ||
|
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. I think we could just use 2 brokers for this test? 5 is overkill.
Collaborator
Author
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. Thanks for review. If the replica of
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. Can two brokers with two replicas fix the issue you mentioned?
Collaborator
Author
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. Change to two brokers and explicitly define min_insyn_replica equals one. |
||
| public void testResetOffsetsWithOfflinePartition(ClusterInstance cluster) throws Exception { | ||
|
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. To better distinguish this test from |
||
| String topic = generateRandomTopic(); | ||
| String group = "new.group"; | ||
| String[] args = buildArgsForGroup(cluster, group, "--to-earliest", "--execute", "--topic", topic + ":1"); | ||
| cluster.createTopic(topic, 3, (short) 2); | ||
|
|
||
| try (ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args); | ||
| Admin admin = cluster.admin()) { | ||
|
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. 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.
Collaborator
Author
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. change to |
||
| admin.alterPartitionReassignments(Map.of(new TopicPartition(topic, 2), | ||
| Optional.of(new NewPartitionReassignment(List.of(3, 4))))); | ||
|
|
||
| TestUtils.waitForCondition(() -> { | ||
| List<TopicPartitionInfo> partInfo = admin.describeTopics(List.of(topic)).topicNameValues().get(topic).get().partitions(); | ||
| return partInfo.get(2).replicas().stream().map(Node::id).collect(Collectors.toUnmodifiableSet()).equals(Set.of(3, 4)); | ||
| }, "Partitions did not complete reassignment to the target broker(s) within the expected time."); | ||
|
|
||
| cluster.shutdownBroker(3); | ||
| cluster.shutdownBroker(4); | ||
| TestUtils.waitForCondition(() -> !cluster.aliveBrokers().keySet().containsAll(Set.of(3, 4)), | ||
| "The cluster did not shut down the broker within the expected time."); | ||
|
|
||
| Map<TopicPartition, OffsetAndMetadata> resetOffsets = service.resetOffsets().get(group); | ||
| assertEquals(Set.of(new TopicPartition(topic, 1)), resetOffsets.keySet()); | ||
| } | ||
| } | ||
|
|
||
| @ClusterTest | ||
| public void testResetOffsetsExistingTopic(ClusterInstance cluster) { | ||
| String topic = generateRandomTopic(); | ||
|
|
||
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.
nit: check
partitionInfo.leader() == nullbefore creating theTopicPartitionfor performance.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.
Good point, thanks.