Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ringhash: ensure addresses are consistenly hashed across updates #6066

Merged
merged 1 commit into from Mar 3, 2023

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Feb 28, 2023

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:

  • ringhash: ensure addresses are consistenly hashed across updates

@easwars easwars requested a review from dfawley February 28, 2023 21:05
@easwars easwars added this to the 1.54 Release milestone Feb 28, 2023
// per-address, these entries hash to the same value across address
// updates.
idx := 0
for currentHashes < targetHashes {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 dfawley assigned easwars and unassigned dfawley Mar 2, 2023
@easwars easwars assigned dfawley and unassigned easwars Mar 2, 2023
@dfawley dfawley assigned easwars and unassigned dfawley Mar 3, 2023
@easwars easwars merged commit ae4a231 into grpc:master Mar 3, 2023
1 check passed
@easwars easwars deleted the ringhash_index branch March 23, 2023 18:41
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants