-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
HashPartitioner cast uint32 to int32 #1090
Comments
It's not clear to me how this is a problem? The partition chosen is still valid, consistent, and well-distributed. |
The problem is the result is different when integrating with software written in other languages. We have a program that is written in Rust and using Rust Kafka Crate. They are using By casting to signed |
Ah, this is true... hmm. The main problem with fixing it is that it's basically a breaking change; we need to maintain the consistency of the hash function between versions for existing users. I think the best we can do is implement a If we ever do a sarama 2.0 with breaking changes we could fix it for the default at that point. Added to https://github.com/Shopify/sarama/wiki/Ideas-that-will-break-backwards-compatibility |
Just to follow up: we've already had to adjust this once for different implementations of the absolute-value function (6967cdb). I would also note that the HashPartitioner code is fairly simple and the interface is public, so you're free to implement the entirely new partitioner behaviour yourself. |
Thanks for the feedback. We are now using the entirely new custom hash partitioner in our project. |
Versions
Sarama Version: e8552c0 (latest master)
Kafka Version: 1.0.0
Go Version: 1.10
Configuration
Standard Configuration.
Logs
No specific logs.
Problem Description
https://github.com/Shopify/sarama/blob/e8552c0dbf502cd7ec9186b57897e6cf9f15fb34/partitioner.go#L126
The
p.hasher.Sum32()
is being cast to int32. The default hasher sarama uses is FNV-1. In golang,Sum32()
for FNV-1 returnsuint32
, and it can overflow if cast toint32
.In my case, I'm using custom hash (xxHash32) and with the key="123", the hash value="3062191159" which overflows int32. It would be nice to not have the
p.hasher.Sum32()
cast toint32
.The text was updated successfully, but these errors were encountered: