Versions Compared

Key

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

...

The sticky partitioner will be part of the default partitioner, so there will not be a public interface directly.

There is a are two new method methods exposed on the partitioner interface.


Code Block
languagejava
default public Integer    /**
     * Runs before the new batch is created if willCallOnNewBatch returns true.
     * 
     * @param topic The topic name
     * @param keyBytes The serialized key of the record ( or null if no key)
     * @param valueBytes The serialized value of the record or null
     * @param cluster The current cluster metadata
     */
    default void onNewBatch(String topic, byte[] keyBytes, byte[] valueBytes, Cluster cluster) {
        return;
    }
    
    /**
     * Determines whether to call onNewBatch based on the key, value, and whether there is an explicit partition
     *

  return null;

}     * @param keyBytes The serialized key of the record ( or null if no key)
     * @param valueBytes The serialized value of the record or null
     * @param explicitPartition A boolean to represent whether an explicit partition id has been provided
     */
    default boolean willCallOnNewBatch(byte[] keyBytes, byte[] valueBytes, boolean explicitPartition) {
        return false;
    }


When adding a record and a new record batch is created, the result of willCallOnNewBatch will determine whether onNewBatch is called. onNewBatch is called before the new batch is created, so the partition can be changed before the batch is made.

The sticky partitioner will use these methods to call onNewBatch for records with no keys and no explicit partitions, and switch the sticky partition on the new batch.

The default will result in no change to the current behavior for other user-defined partitioners. If a user wants to implement a sticky partitioner in their own partitioner class, this these method can be overridden.

...

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.

...