Skip to content
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

[FLINK-34995] flink kafka connector source stuck when partition leade… #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Set<TopicPartition> getSubscribedTopicPartitions(AdminClient adminClient)

for (TopicPartition subscribedPartition : this.subscribedPartitions) {
if (topicMetadata.containsKey(subscribedPartition.topic())
&& partitionExistsInTopic(
&& partitionExistsInTopicAndValid(
subscribedPartition, topicMetadata.get(subscribedPartition.topic()))) {
existingSubscribedPartitions.add(subscribedPartition);
} else {
Expand All @@ -70,7 +70,9 @@ && partitionExistsInTopic(
return existingSubscribedPartitions;
}

private boolean partitionExistsInTopic(TopicPartition partition, TopicDescription topic) {
return topic.partitions().size() > partition.partition();
private boolean partitionExistsInTopicAndValid(
TopicPartition partition, TopicDescription topic) {
return topic.partitions().stream()
.anyMatch(p -> p.leader() != null && p.partition() == partition.partition());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public Set<TopicPartition> getSubscribedTopicPartitions(AdminClient adminClient)
Set<TopicPartition> subscribedPartitions = new HashSet<>();
for (TopicDescription topic : topicMetadata.values()) {
for (TopicPartitionInfo partition : topic.partitions()) {
subscribedPartitions.add(new TopicPartition(topic.name(), partition.partition()));
if (partition.leader() != null) {
subscribedPartitions.add(
new TopicPartition(topic.name(), partition.partition()));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public Set<TopicPartition> getSubscribedTopicPartitions(AdminClient adminClient)
(topicName, topicDescription) -> {
if (topicPattern.matcher(topicName).matches()) {
for (TopicPartitionInfo partition : topicDescription.partitions()) {
subscribedTopicPartitions.add(
new TopicPartition(
topicDescription.name(), partition.partition()));
if (partition.leader() != null) {
subscribedTopicPartitions.add(
new TopicPartition(
topicDescription.name(), partition.partition()));
}
}
}
});
Expand Down