Skip to content

Commit

Permalink
kgo: un-deprecate SaramaHasher and add docs explaining why
Browse files Browse the repository at this point in the history
Closes #669.
  • Loading branch information
twmb committed Feb 7, 2024
1 parent a2d69ce commit d40ac19
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/kgo/partitioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,16 @@ func KafkaHasher(hashFn func([]byte) uint32) PartitionerHasher {
}
}

// Deprecated: SaramaHasher is not compatible with Sarama's default partitioner
// and only remains to avoid re-keying records for existing users of this API. See
// [SaramaCompatHasher] for a correct partitioner.
// SaramaHasher is a historical misnamed partitioner. This library's original
// implementation of the SaramaHasher was incorrect, if you want an exact
// match for the Sarama partitioner, use the [SaramaCompatHasher].
//
// This partitioner remains because as it turns out, other ecosystems provide
// a similar partitioner and this partitioner is useful for compatibility.
//
// In particular, using this function with a crc32.ChecksumIEEE hasher makes
// this partitioner match librdkafka's consistent partitioner, or the
// zendesk/ruby-kafka partitioner.
func SaramaHasher(hashFn func([]byte) uint32) PartitionerHasher {
return func(key []byte, n int) int {
p := int(hashFn(key)) % n
Expand Down

0 comments on commit d40ac19

Please sign in to comment.