Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Status

Current state: Vote in progress Accepted (vote thread)

Discussion thread: here

...

There is one new method exposed on the partitioner interface.


Code Block
languagejava
   /**
 * Computes a partition* basedExecutes on relevant data. Knows whether right before a new batch will be created. forFor the record.
 * 
 * @param topic The topic name
 * @param key The key to partition on (or null if no key)
 * @param keyBytes The serialized key to partition on( or null if no key)
 * @param value The value to partition on or null
 * @param valueBytes The serialized value to partition on or null
 example, if a sticky partitioner is used,
   * this method can change the chosen sticky partition for the new batch. 
   * @param topic The topic name
   * @param cluster The current cluster metadata
 * @param isNewBatch A* boolean@param toprevPartition specifyThe whetherpartition aof newthe batch that willwas bejust createdcompleted
 * @return The record's computed partition
 */
  default intpublic void computePartitiononNewBatch(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster, booleanint isNewBatchprevPartition) {
    return partition(topic, key, keyBytes, value, valueBytes, cluster);
}


The method computePartition will replace partition in the KafkaProducer. It will return an int to represent the new partitiononNewBatch will execute code right before a new batch is created. The sticky partitioner will define this method to update the sticky partition when a new batch is about to be created. This includes changing the sticky partition even when there will be a new batch on a keyed value. Test results show that this change will not significantly affect latency in the keyed value case.

The default of this method will result in no change to the current partitioning behavior for other user-defined partitioners. If a user wants to implement a sticky partitioner in their own partitioner class, this method can be overridden.Attempting to call the partition method in the DefaultPartitioner will throw an error, as this method will be deprecated and no longer return a partition. computePartition has replaced its functionality. 

Proposed Changes

Change the behavior of the default partitioner in the no explicit partition, key = null case. Choose the “sticky” partition for the given topic. The “sticky” partition is changed when the record accumulator is allocating a new batch for a topic on a given partition.

These changes will slightly modify the code path for records that have keys as well, but the changes will not affect latency significantly.

If the DefaultPartitioner's partition method is called, it will no longer return the partition and instead throw an error.

A new partitioner called StickyRoundRobinPartitioner UniformStickyPartitioner will be created to allow sticky partitioning on all records, even those that have non-null keys. This will mirror how the RoundRobinPartitioner uses the round robin partitioning strategy for all records, including those with keys.

...

EC2 Instance

m3.xlarge

Disk Type

SSD

Duration of Test

12 minutes

Number of Brokers

3

Number of Producers

3

Replication Factor

3

Active Topics

4

Inactive Topics

1

Linger.ms

0

Acks

All

keyGenerator

{"type": "null"}

manualPartitionuseConfiguredPartitioner

True

No Flushing on Throttle (skipFlush)

True

...