mochengqian opened a new pull request, #928:
URL: https://github.com/apache/dubbo-go-pixiu/pull/928
## Summary
`LookUpTable.Hash` invoked `maphash.MakeSeed()` on every call, returning a
fresh random seed each time. Because `Get(key)` and `GetHash` both flow through
`Hash`, the same key produced a different slot
index on every lookup — Maglev silently degraded to pseudo-random endpoint
selection. Session affinity, cache-locality, and the consistent-hash contract
were never actually enforced.
Fix routes `Hash` through the existing package-internal `_hash1`, the same
deterministic SHA3-based hash already used by permutation/bucket generation in
this file.
## Affected versions
All Maglev users, not limited to the upcoming issue-905 (snapshot) work.
The bug has been present since the random-seed code was introduced; pre-1.1
releases are equally affected and this is a reasonable
cherry-pick candidate.
## Changes
- `pkg/cluster/loadbalancer/maglev/permutation.go`: drop `hash/maphash`
import; `Hash` now returns `_hash1(key)` (−5/+1).
- `pkg/cluster/loadbalancer/maglev/maglev_hash_test.go`: add
`TestLookUpTableHashIsStableForSameKey` — calls `Hash` on the same key 21 times
and asserts the result is stable. Self-contained, no new
dependencies.
## Test plan
- [x] `go test -v -run TestLookUpTableHashIsStableForSameKey
./pkg/cluster/loadbalancer/maglev/...`
- [x] `go test ./pkg/cluster/loadbalancer/maglev/...`
- [x] `go test -race ./pkg/cluster/loadbalancer/maglev/...`
- [x] `go test -count=20 -run TestLookUpTableHash
./pkg/cluster/loadbalancer/maglev/...` (not flaky)
- [x] Sanity: with the original buggy `permutation.go`, the new test fails
with two distinct hash values for the same key, confirming the regression
coverage is real.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]