-
Notifications
You must be signed in to change notification settings - Fork 4.6k
ringhash: implement gRFC A76 #8159
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5f56c4c
ringhash: implement gRFC A76
atollena db645b6
feedback from Daniel
atollena 2bfd696
Merge branch 'master' into A76
atollena 132b401
feedback from Arjan, Easwar, Daniel
atollena 8ac641b
request_hash_header -> requestHashHeader
atollena 54caf30
add testutils.SetEnvConfig
atollena 90a6ff4
add a test for random connection behaviors
atollena ee20ac2
comments from easwar
atollena c0b77ad
use balancer ExitIdle instead of relying on Pick to wake up idle chan…
atollena 3fa56e9
comments from Arjan, fix data race in test
atollena febd62a
more comments from Arjan
atollena 8816ae5
missing fixes for comments from easwar
atollena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package testutils | ||
|
|
||
| /* | ||
| * | ||
| * Copyright 2025 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| // SetEnvConfig sets the value of the given variable to the specified value, | ||
| // taking care of restoring the original value after the test completes. | ||
| func SetEnvConfig[T any](t *testing.T, variable *T, value T) { | ||
| t.Helper() | ||
| old := *variable | ||
| t.Cleanup(func() { | ||
| *variable = old | ||
| }) | ||
| *variable = value | ||
| } |
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
arjan-bal marked this conversation as resolved.
Show resolved
Hide resolved
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * | ||
| * Copyright 2025 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| // Package ringhash implements resolver related functions for the ring_hash | ||
| // load balancing policy. | ||
| package ringhash | ||
|
|
||
| import ( | ||
| "google.golang.org/grpc/resolver" | ||
| ) | ||
|
|
||
| type hashKeyType string | ||
|
|
||
| // hashKeyKey is the key to store the ring hash key attribute in | ||
| // a resolver.Endpoint attribute. | ||
| const hashKeyKey = hashKeyType("grpc.resolver.ringhash.hash_key") | ||
|
|
||
| // SetHashKey sets the hash key for this endpoint. Combined with the | ||
| // ring_hash load balancing policy, it allows placing the endpoint on the ring | ||
| // based on an arbitrary string instead of the IP address. If hashKey is empty, | ||
| // the endpoint is returned unmodified. | ||
| // | ||
| // # Experimental | ||
| // | ||
| // Notice: This API is EXPERIMENTAL and may be changed or removed in a | ||
| // later release. | ||
| func SetHashKey(ep resolver.Endpoint, hashKey string) resolver.Endpoint { | ||
| if hashKey == "" { | ||
| return ep | ||
| } | ||
| ep.Attributes = ep.Attributes.WithValue(hashKeyKey, hashKey) | ||
| return ep | ||
| } | ||
|
|
||
| // HashKey returns the hash key attribute of addr. If this attribute is not | ||
| // set, it returns the empty string. | ||
| // | ||
| // # Experimental | ||
| // | ||
| // Notice: This API is EXPERIMENTAL and may be changed or removed in a | ||
| // later release. | ||
| func HashKey(ep resolver.Endpoint) string { | ||
| hashKey, _ := ep.Attributes.Value(hashKeyKey).(string) | ||
| return hashKey | ||
| } |
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
arjan-bal marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.