Skip to content

Commit

Permalink
Reset rendezvous hash before use (not after).
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Mar 30, 2024
1 parent 43d4d86 commit b08e157
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions internal/cluster/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ func (p *Partitioner) Route(workload *uuidpb.UUID) *uuidpb.UUID {
}

var (
hash xxhash.Digest
winningNode *uuidpb.UUID
winningScore uint64
hash xxhash.Digest
winner *uuidpb.UUID
score uint64
)

for _, node := range nodes {
hash.Reset()
hash.Write(node.AsBytes())
hash.Write(workload.AsBytes())

score := hash.Sum64()
hash.Reset()

if score > winningScore {
winningNode = node
winningScore = score
if s := hash.Sum64(); s > score {
winner = node
score = s
}
}

return winningNode
return winner
}

0 comments on commit b08e157

Please sign in to comment.