Make Partitioner.RequiresConsistency vary per-message #1112
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.
This is a little bit speculative, but it was about as easy to write the patch as it was to write the proposal, so this seemed easier. I don't have any particular commitment to any aspect of the implementation, so I'm interested in hearing feedback.
One of the useful features of the random partitioner is that it will only partition messages onto partitions that are currently online. In theory, hash partitioner is capable of exhibiting the same behavior for messages where the key is unset, but it can't because RequiresConsistency is a constant for the partitioner. It's also not feasible to add methods to the Partitioner interface, since that's part of the public API.
Therefore, this introduces a new interface, ExtendedPartitioner, which includes an additional method: MessageRequiresConsistency. This lets the partitioner make a per-message determination for whether consistency is required (and therefore whether it's acceptable to publish to partitions which are offline). The producer library will use this method if it's available, and fall back on the existing RequiresConsistency method otherwise.
Since hash partitioners are the only ones which have different consistency requirements per-message, for now they are the only partitioner to implement MessageRequiresConsistency.