Current state: Under Discussion
Discussion thread: here
JIRA: - KAFKA-4835Getting issue details... STATUS
- KAFKA-10844Getting issue details... STATUS
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Each key changing operation in Kafka Streams (
transform, etc.) now leads to automatic repartition before an aggregation.
But there is quite a large class of key mappings that do not require repartition: every mapping that gives different result for different source partition does not require repartitioning to keep the data locally (see the picture below):
In tickets KAFKA-4835 and KAFKA-10844 the option for canceling the unneeded repartition is being requested. Repartition canceling is also needed for efficient usage of
distinct() operator proposed in KIP-655:
groupBy(...).windowedBy(...).distinct() will always repartition by default, while in practice this is not always needed.
In accordance with KStreams DSL Grammar, we introduce a new parameterless
DSLOperation cancelRepartition() on
KStream, which resets
keyChangingOperation flag for the upstream node.
Introducing a new parameterless method on
KStream rather than adding parameters to all the key changing operations will lead to minimum changes in public APIs.
- This operation is unsafe: wrong usage can lead to undefined behaviour. Thus it should be used with care for performance tuning only. This warning should be given in the documentation.
- The usage of this operation complicates the usage of IQ. Without repartitioning, the mapped key does not contain the information of the correct partition anymore, since the hash of the mapped key might compute to a wrong instance. However, if we use cancelRepartition correctly, it is always possible to provide the 'reverse mapping' for the key that restores the original key, which then can be used for obtaining the metadata.
Compatibility, Deprecation, and Migration Plan
- No impact on existing users, no migration is needed.
If we don't want to introduce an unsafe operation, we might discuss introducing composite keys as an alternative.
CompositeKey<H, P>consists of a head and a postfix, and the partition of a composite key is always defined by its 'head' only.
CompositeKey(k, v)must have the same partition for each
- We will need to introduce
selectCompositeKeyoperation which will not lead to repartition.
CompositeKey usage will be safe both from pov of data locality and IQ, however it is questionable, whether it will be convenient to use it.