Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default partitioner does not match Java client #398

Closed
mjparrott opened this issue Mar 4, 2020 · 3 comments
Closed

Default partitioner does not match Java client #398

mjparrott opened this issue Mar 4, 2020 · 3 comments

Comments

@mjparrott
Copy link
Contributor

When using KafkaEx to produce to a topic that is also produced to by an application that is using the default Java client, I noticed that the partitions that were being produced to weren't the same in KafkaEx and the Java client.

The reason appears to be how umurmur2 compares to the Java client.

In KafkaEx, the hash is calculated like so:

key |> murmur2() |> band(0xFFFFFFFF)

In the default Java client, it is calculated here: https://github.com/apache/kafka/blob/717c55be971df862c55f55d245b9997f1d6f998c/clients/src/main/java/org/apache/kafka/clients/producer/internals/DefaultPartitioner.java#L59

The difference here is in the value we use to bitwise AND the key hash and the number of partitions. In KafkaEx, it is 0xFFFFFFFF. In the Java client, it is 0x7fffffff.

Changing the 0xFFFFFFFF to 0x7FFFFFFF seems to make things match. I'm wondering if just changing the umurmur2 method is the correct approach here? And if so, how would versioning work? Since this would affect anyone using KafkaEx's default partitioner. Happy to make a PR if we have an approach.

@mjparrott
Copy link
Contributor Author

mjparrott commented Mar 4, 2020

I've made a PR that could possibly fix this issue, see the linked #399 .

@jbruggem
Copy link
Collaborator

jbruggem commented Mar 9, 2020

Good catch @mjparrott 👍

@dantswain
Copy link
Collaborator

Closed by #399 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants