balancer/ringhash: fix uint32 weight sum overflow in normalizeWeights - #9357
balancer/ringhash: fix uint32 weight sum overflow in normalizeWeights#9357nvxbug wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9357 +/- ##
==========================================
+ Coverage 87.42% 87.55% +0.12%
==========================================
Files 424 429 +5
Lines 30283 30622 +339
==========================================
+ Hits 26476 26812 +336
- Misses 3806 3809 +3
Partials 1 1
🚀 New features to boost your workflow:
|
Check exact 0.5 distribution in overflow test, add a test for a sum that wraps to a non-zero value, and expand the accumulator comment to cover both wrap outcomes.
eshitachandwani
left a comment
There was a problem hiding this comment.
LGTM with 2 small comments about test comments. Adding @easwars as a second reviewer.
| } | ||
| } | ||
|
|
||
| // TestRingNewWeightSumOverflow checks that endpoint weights whose sum exceeds |
There was a problem hiding this comment.
Nit : can we reword this a little to make it more readable , something along the lines of ... Tests the scenario where the sum of endpoint weights exceed math.MaxUint32 and would have been wrapped to zero using a unit32. Verifies that ring-build loop does not go on forever and produces a correct ring.
Or something more clear.
|
|
||
| // TestRingNewWeightSumOverflowToNonZero checks that endpoint weights whose sum | ||
| // exceeds math.MaxUint32 and wraps to a non-zero value still produce a ring | ||
| // within the configured size bounds. A wrapped non-zero sum used to make |
There was a problem hiding this comment.
We need not write what the code used to do , rather we can write something like using uint32 can wrap it to a smaller value....
newRingwith two endpoints whose uint32 weights sum to 2^32 (e.g. an EDS locality weight of 2 times an endpoint weight of 2^30, which pass the per-locality and per-priority weight-sum checks):normalizeWeightssums endpoint weights into auint32, so a total abovemath.MaxUint32wraps and can land on zero. Theweight / weightSumdivide then yields+Inf,newRingsetstargetHashesto+Inf, and itsfor currentHashes < targetHashesloop never ends, growing the ring until the process is out of memory. Summing inuint64cannot wrap and stays non-zero, since every endpoint weight is at least 1.RELEASE NOTES:
math.MaxUint32will get wrapped by storing the weight ituint64