MCPcopy
hub / github.com/segmentio/kafka-go / ReferenceHash

Struct ReferenceHash

balancer.go:194–202  ·  view source on GitHub ↗

ReferenceHash is a Balancer that uses the provided hash function to determine which partition to route messages to. This ensures that messages with the same key are routed to the same partition. The logic to calculate the partition is: (int32(hasher.Sum32()) & 0x7fffffff) % len(partitions) => pa

Source from the content-addressed store, hash-verified

192// the Sarama NewReferenceHashPartitioner and ensures that messages produced by kafka-go will
193// be delivered to the same topics that the Sarama producer would be delivered to.
194type ReferenceHash struct {
195 rr randomBalancer
196 Hasher hash.Hash32
197
198 // lock protects Hasher while calculating the hash code. It is assumed that
199 // the Hasher field is read-only once the Balancer is created, so as a
200 // performance optimization, reads of the field are not protected.
201 lock sync.Mutex
202}
203
204func (h *ReferenceHash) Balance(msg Message, partitions ...int) int {
205 if msg.Key == nil {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected