Class BuiltInPartitioner

java.lang.Object
org.apache.kafka.clients.producer.internals.BuiltInPartitioner

public class BuiltInPartitioner extends Object
Built-in default partitioner. Note, that this is just a utility class that is used directly from RecordAccumulator, it does not implement the Partitioner interface. The class keeps track of various bookkeeping information required for adaptive sticky partitioning (described in detail in KIP-794). There is one partitioner object per topic.
  • Field Details

  • Constructor Details

    • BuiltInPartitioner

      public BuiltInPartitioner(org.apache.kafka.common.utils.LogContext logContext, String topic, int stickyBatchSize)
      BuiltInPartitioner constructor.
      Parameters:
      topic - The topic
      stickyBatchSize - How much to produce to partition before switch
  • Method Details

    • loadStatsRangeEnd

      public int loadStatsRangeEnd()
      Test-only function. When partition load stats are defined, return the end of range for the random number.
    • updatePartitionLoadStats

      public void updatePartitionLoadStats(int[] queueSizes, int[] partitionIds, int length)
      Update partition load stats from the queue sizes of each partition NOTE: queueSizes are modified in place to avoid allocations
      Parameters:
      queueSizes - The queue sizes, partitions without leaders are excluded
      partitionIds - The partition ids for the queues, partitions without leaders are excluded
      length - The logical length of the arrays (could be less): we may eliminate some partitions based on latency, but to avoid reallocation of the arrays, we just decrement logical length Visible for testing
    • partitionForKey

      public static int partitionForKey(byte[] serializedKey, int numPartitions)