ringhash: ensure addresses are consistenly hashed across updates#6066
Merged
Conversation
dfawley
reviewed
Mar 2, 2023
| // per-address, these entries hash to the same value across address | ||
| // updates. | ||
| idx := 0 | ||
| for currentHashes < targetHashes { |
Member
There was a problem hiding this comment.
Why are we accumulating targetHashes and currentHashes instead of resetting them? e.g.
for _, scw := range normalizedWeights {
targetHashes := scale * scw.weight
for idx := 0; idx < targetHashes; idx++ {
h := xxhash.Sum...
items = append...
}
}
Contributor
Author
There was a problem hiding this comment.
Since scw.weight is not a whole number, targetHashes is not a whole number either. In order to ensure that we end up with the correct number of items in the ring, we need to keep a running sum.
I based this change on C-core and Java's implementation. Looks like envoy also does the same: https://github.com/envoyproxy/envoy/blob/main/source/common/upstream/ring_hash_lb.cc#L159.
dfawley
approved these changes
Mar 3, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR ensures that for every address
$addr, the string used to compute the hash is$addr_1,$addr_2..$addr_n. This aligns with implementations in the other languages.RELEASE NOTES: