Skip to content

Commit

Permalink
Merge pull request twmb#747 from rrreeezzz/fix/sarama-compat-hasher-doc
Browse files Browse the repository at this point in the history
docs: update SaramaCompatHasher documentation
  • Loading branch information
twmb authored May 28, 2024
2 parents 1c152ac + ac2b9ce commit 7641d9e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/kgo/partitioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,16 @@ func SaramaHasher(hashFn func([]byte) uint32) PartitionerHasher {
//
// In short, to *exactly* match the Sarama defaults, use the following:
//
// kgo.StickyKeyPartitioner(kgo.SaramaCompatHasher(fnv.New32a()))
// kgo.StickyKeyPartitioner(kgo.SaramaCompatHasher(fnv32a))
//
// Where fnv32a is a function returning a new 32 bit fnv-1a hasher.
//
// func fnv32a(b []byte) uint32 {
// h := fnv.New32a()
// h.Reset()
// h.Write(b)
// return h.Sum32()
// }
func SaramaCompatHasher(hashFn func([]byte) uint32) PartitionerHasher {
return func(key []byte, n int) int {
p := int32(hashFn(key)) % int32(n)
Expand Down

0 comments on commit 7641d9e

Please sign in to comment.