Skip to main content

partition_for_key

Function partition_for_key 

Source
pub fn partition_for_key(key: &[u8], num_partitions: i32) -> i32
Expand description

Pick the partition that Kafka picks for key.

Kafka computes toPositive(murmur2(key)) % num_partitions, and Utils.toPositive masks the sign bit with & 0x7fffffff. It does not take the absolute value. The two agree for a non-negative hash and disagree for every negative one, so the mask is what keeps a Krabka producer and a JVM producer on the same partition for the same key.

ยงPanics

Panics when num_partitions is not greater than zero.