-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: fix normalizeWeights #7156
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing because some subConn
are instantiated with a default weight of 0 at
grpc-go/xds/internal/balancer/ringhash/ring_test.go
Lines 41 to 43 in 1949035
testSubConnMap.Set(testAddrs[0], &subConn{addr: "a"}) | |
testSubConnMap.Set(testAddrs[1], &subConn{addr: "b"}) | |
testSubConnMap.Set(testAddrs[2], &subConn{addr: "c"}) |
Thanks for the review @atollena and @aranjans. I still think this diff is not ready to be merged yet. There is still the open question why getWeightAttribute(a) doesnt work in this case, even though (*subConn).weight is set using getWeightAttribute(a). I wanted to check with @zasweq if he knows what's going on. |
There's two other maintainers actively looking at this so I'll remove myself. |
Ha. I thought that you had that figured out. I took a look at the code and, with my limited understanding, it looks like the "bug" is in At L86, when we found that we already had the address in the map, the code only updates the value, not the addr. So if the BalancerAttribute changed, the addr isn't updated. As a result, if the weight changes, which is a From the documentation of I see two options to fix this:
I'd sollicit Doug and Zach's input on this because I don't have the context of when address map is useful (looks like it's mostly to find existing subconn associated with an address in O(1)?), but option 1 seems more realistic. |
If we are open to making a breaking change, another option to consider, in addition to those listed in #7156 (comment) :
We could also achieve the same by first deprecating the existing |
what the docstring on resolver.AddressMap really talks about is that we should not be relying on the balancerAttributes in the key, but use value instead. And in ringHash, the value is of type The actual bug is with using the rignhash.getWeightAttribute helper. This is helpful when getting the balancerattribute weight when updating addresses. But is incorrect when used to get weights from the AddressMap. Instead, we should type assert to ringhash.subConn and read weights from that instead. cc'ing: @easwars; since he has most context on ringhash. |
min := 1.0 | ||
for _, a := range scVals { | ||
scInfo := a.(*subConn) | ||
// (*subConn).weight returns 1 if the weight attribute is not found on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it doesn't "return"
// (*subConn).weight returns 1 if the weight attribute is not found on | |
// (*subConn).weight is set to 1 if the weight attribute is not found on the address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Done.
min := 1.0 | ||
for _, a := range scVals { | ||
scInfo := a.(*subConn) | ||
// (*subConn).weight returns 1 if the weight attribute is not found on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated per comments. PTAL
min := 1.0 | ||
for _, a := range scVals { | ||
scInfo := a.(*subConn) | ||
// (*subConn).weight returns 1 if the weight attribute is not found on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Done.
// each struct contains a subConn and its corresponding weight. The function | ||
// also returns the minimum weight among all subConns. | ||
// | ||
// The weight of each subConn is calculated by dividing its weight attribute by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/The weight of each subConn/The normalized weight of each subConn/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Done.
Something is wrong with this presubmit check. Will need to investigate. Merging since this change is not expected to break 386 variant of go1.22 test |
RELEASE NOTES: