Files
Martin DisibioandGitHub 2c6fa98cd9 Fix distributor rebatch bug (#5186)
* Fix distributor rebatch bug, by not using a 32-bit hash for deduping, only for ring sharding (as required)

* lint

* changelog
2025-05-29 18:59:32 -04:00

31 lines
816 B
Go

package util
import (
"hash/fnv"
)
// TokenFor generates a token used for finding ingesters from ring.
// Not suitable for in-memory hashing or deduping because it is only 32-bit.
// The collision rate is about 1 in 8000.
func TokenFor(userID string, b []byte) uint32 {
h := fnv.New32()
_, _ = h.Write([]byte(userID))
_, _ = h.Write(b)
return h.Sum32()
}
// TokenForTraceID generates a hashed value for a trace id. Used for bloom lookups.
// Do not change because it will break lookups on existing bloom filters.
func TokenForTraceID(b []byte) uint32 {
h := fnv.New32()
_, _ = h.Write(b)
return h.Sum32()
}
// HashForTraceID generates a generic hash for the trace ID, suitable for mapping and deduping.
func HashForTraceID(tid []byte) uint64 {
h := fnv.New64()
_, _ = h.Write(tid)
return h.Sum64()
}