0z5a opened a new pull request, #3864:
URL: https://github.com/apache/dubbo-go/pull/3864
### Description
Fixes #3863
The consistent-hash load balancer rebuilds its cached ring only when a
fingerprint of the invoker list changes. The fingerprint was `crc32` over
`json.Marshal(invoker)`, and the invoker types keep their state in unexported
fields, so every invoker encoded as `{}` and the fingerprint only reflected the
number of invokers. This change takes the fingerprint from invoker identity
(`%p` of each invoker), which is what the Java implementation does with
`invokers.hashCode()`. The unused `json.Marshal` error path goes away with it.
### How I found it
Reading the load balancers next to their Java counterparts. The Java
selector is keyed on the invoker objects; the Go one encodes the invokers, and
encoding a `base.BaseInvoker` (or `DubboInvoker`, `TripleInvoker`,
`FilterInvoker`) gives `{}`.
### Where this can show up in practice
- A provider is replaced and the count stays the same, e.g. a rolling
restart where the new instance gets a different address. Keys that hashed to
the old provider keep being sent to its removed invoker. The reselect in
`doSelectInvoker` passes a list of the same length, so it hits the same stale
ring.
- A tag or condition router hands different requests different provider
subsets of the same size. The ring built for one subset is reused for the
other, so requests go to providers the router excluded.
### Validation
- New tests in `cluster/loadbalance/consistenthashing/loadbalance_test.go`:
- `TestSelectAfterProviderReplaced` and `TestSelectFromEqualSizedSubsets`
check that every pick is in the list passed to `Select`. Both fail on `develop`
(3 of 3 runs) and pass with this change.
- `TestSelectKeepsRingForSameInvokers` is the control: an unchanged list
(passed as a copy) reuses the cached ring and gives the same pick. It passes
before and after.
- The reproduction in #3863 (two providers, one replaced, 64 keys): 34 of 64
keys go to the removed invoker on `develop`, 0 of 64 with this change.
- `go test ./cluster/... ./client/... ./registry/directory/... -count=1`
passes; the consistent-hash suite also passes with `-race`.
- `BenchmarkConsistenthashingLoadbalance` on macOS: 266 → 5 allocs/op, 3393
→ about 650 B/op, about 380 → about 140 µs/op (3 runs each).
### Checklist
- [x] I confirm the target branch is `develop`
- [ ] I have run `make fmt` to format my code
- [ ] I have run `make test` to run local tests
- [x] I have added tests that prove my fix is effective or that my feature
works
--
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]