Skip to content

kAFKA-9651:Handle edge case when partition metadata contains zero partitions#21609

Open
nileshkumar3 wants to merge 4 commits intoapache:trunkfrom
nileshkumar3:KAFKA-9651-fix-partitioner
Open

kAFKA-9651:Handle edge case when partition metadata contains zero partitions#21609
nileshkumar3 wants to merge 4 commits intoapache:trunkfrom
nileshkumar3:KAFKA-9651-fix-partitioner

Conversation

@nileshkumar3
Copy link

@nileshkumar3 nileshkumar3 commented Mar 1, 2026

Handle edge case where partition metadata contains zero partitions.
Add a defensive check in the producer partition selection path to avoid operating on an empty partition list.
This improves robustness during transient metadata states.

@github-actions github-actions bot added triage PRs from the community producer clients small Small PRs labels Mar 1, 2026
@nileshkumar3
Copy link
Author

@tombentley Can you review this

Copy link
Member

@showuon showuon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@showuon
Copy link
Member

showuon commented Mar 2, 2026

@nileshkumar3 , thanks for the PR! Please help change the PR title to prefix with MINOR: or KAFKA-xxxx. You can check what others did: https://github.com/apache/kafka/pulls?page=2&q=is%3Apr+is%3Aopen

Also, please make the PR description format correct and clear. Thanks.

@showuon
Copy link
Member

showuon commented Mar 2, 2026

Note: Although the producer side already has validated the partition size is > 0, the stream side (like here) I cannot see all places have the partition size validation. Adding a validation in the partitionFor makes sense to me to avoid missing validation. When we have a fail use case reported, I think we should fix in the root to have re-fetch metadata mechanism or something.

@github-actions github-actions bot removed the triage PRs from the community label Mar 2, 2026
@nileshkumar3 nileshkumar3 changed the title handling 0 partitions kafka-9651:handling 0 partitions Mar 4, 2026
@nileshkumar3 nileshkumar3 changed the title kafka-9651:handling 0 partitions kAFKA-9651:handling 0 partitions Mar 4, 2026
@nileshkumar3
Copy link
Author

@nileshkumar3 , thanks for the PR! Please help change the PR title to prefix with MINOR: or KAFKA-xxxx. You can check what others did: https://github.com/apache/kafka/pulls?page=2&q=is%3Apr+is%3Aopen

Also, please make the PR description format correct and clear. Thanks.
@showuon done

@nileshkumar3
Copy link
Author

Note: Although the producer side already has validated the partition size is > 0, the stream side (like here) I cannot see all places have the partition size validation. Adding a validation in the partitionFor makes sense to me to avoid missing validation. When we have a fail use case reported, I think we should fix in the root to have re-fetch metadata mechanism or something.

@showuon Added validation in StreamsMetadataState.

@nileshkumar3 nileshkumar3 changed the title kAFKA-9651:handling 0 partitions kAFKA-9651:Handle edge case when partition metadata contains zero partitions Mar 4, 2026
@showuon
Copy link
Member

showuon commented Mar 4, 2026

Note: Although the producer side already has validated the partition size is > 0, the stream side (like here) I cannot see all places have the partition size validation. Adding a validation in the partitionFor makes sense to me to avoid missing validation. When we have a fail use case reported, I think we should fix in the root to have re-fetch metadata mechanism or something.

@showuon Added validation in StreamsMetadataState.

Is this really needed? Let's say, if you don't have the change in the commit: 86511ce , the shouldFailWhenSourceTopicHasNoPartitionsInMetadata test can still pass because the IllegalStateException will be thrown in the partitionForKey method, right? I mean, if possible, we should fix from the root, instead of adding validation here and there, but still fail the application. WDYT?

@nileshkumar3
Copy link
Author

Note: Although the producer side already has validated the partition size is > 0, the stream side (like here) I cannot see all places have the partition size validation. Adding a validation in the partitionFor makes sense to me to avoid missing validation. When we have a fail use case reported, I think we should fix in the root to have re-fetch metadata mechanism or something.

@showuon Added validation in StreamsMetadataState.

Is this really needed? Let's say, if you don't have the change in the commit: 86511ce , the shouldFailWhenSourceTopicHasNoPartitionsInMetadata test can still pass because the IllegalStateException will be thrown in the partitionForKey method, right? I mean, if possible, we should fix from the root, instead of adding validation here and there, but still fail the application. WDYT?

yes what you think make sense. we should add validation at the root. before streamsMetadataState.onChange in StreamThread and StreamsPartitionAssginor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants