Class BuiltInPartitioner
java.lang.Object
org.apache.kafka.clients.producer.internals.BuiltInPartitioner
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInfo for the current sticky partition. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBuiltInPartitioner(org.apache.kafka.common.utils.LogContext logContext, String topic, int stickyBatchSize) BuiltInPartitioner constructor. -
Method Summary
Modifier and TypeMethodDescriptionintTest-only function.static intpartitionForKey(byte[] serializedKey, int numPartitions) voidupdatePartitionLoadStats(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
-
Field Details
-
mockRandom
-
-
Constructor Details
-
BuiltInPartitioner
public BuiltInPartitioner(org.apache.kafka.common.utils.LogContext logContext, String topic, int stickyBatchSize) BuiltInPartitioner constructor.- Parameters:
topic- The topicstickyBatchSize- 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 excludedpartitionIds- The partition ids for the queues, partitions without leaders are excludedlength- 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)
-