Repository navigation
Description
Context
selectConsistentHash in internal/distributed/coordinator.go:923 has a comment "in practice you'd use a proper consistent hash ring" and its body is return nodes[:count], nil — a simple slice prefix. This defeats cache key affinity: the same key maps to different nodes depending on Go map iteration order, breaking the fundamental property that consistent hashing is supposed to provide.
What to implement
Create internal/distributed/hashring/hashring.go:
type HashRing interface {
Add(nodeID string)
Remove(nodeID string)
Lookup(key string) string // primary owner
LookupN(key string, n int) []string // n replicas, ordered by score
}Implement RendezvousRing using Highest Random Weight (HRW) hashing:
- For each node, compute
score = xxhash.Sum64String(nodeID + "#" + key) - Return the N nodes with the highest scores
- Use
github.com/cespare/xxhash/v2— already a transitive dependency via prometheus, so no newgo.modentry needed
Results must be deterministic regardless of Go map iteration order (sort candidates by nodeID before scoring, or collect scores into a slice and sort).
Update selectConsistentHash in coordinator.go to construct a RendezvousRing from availableNodes and call LookupN(op.Key, count).
Acceptance criteria
HashRinginterface andRendezvousRingininternal/distributed/hashring/- Unit tests verify:
- Same key + same node set → same result (determinism)
- Removing a non-owning node doesn't remap keys that node didn't own
LookupNreturns exactly n distinct node IDs- Empty node set returns empty slice (no panic)
- No new dependency in
go.mod - Benchmark:
BenchmarkLookup100Nodesto confirm O(n) is acceptable
Sequencing
Independent — can land any time in v0.11.0.
Activity
fix: make the consistent-hash strategy actually consistent (#131) (#271)