From b08e1573b5c9eb1b33062ac842a58fc5a3402812 Mon Sep 17 00:00:00 2001 From: James Harris Date: Wed, 20 Mar 2024 07:15:38 +1000 Subject: [PATCH] Reset rendezvous hash before use (not after). --- internal/cluster/partition.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/internal/cluster/partition.go b/internal/cluster/partition.go index d75c0b2f..b8b6851b 100644 --- a/internal/cluster/partition.go +++ b/internal/cluster/partition.go @@ -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 }