dmsolr opened a new pull request, #7880:
URL: https://github.com/apache/shenyu/pull/7880
## What this PR does
Moves the defensive-copy cost off the request path in
`UpstreamCacheManager.findUpstreamListBySelectorId`. Previously every routing
lookup allocated `new ArrayList<>(healthyCowList)`. Now `UpstreamCheckTask`
re-publishes an immutable `List.copyOf` snapshot of the healthy list inside its
existing `synchronized (lock)` block whenever the set structurally changes
(config submit, health transition, removal), and readers take the snapshot
reference directly — zero allocation per request, with writers owning the
bounded, low-frequency copy.
## Related Issue
Fixes #7825
Refs #7650
Related: #6857
## Type of change
- [ ] Bug fix
- [ ] New feature / enhancement
- [x] Refactor (no functional change)
- [ ] Documentation
- [ ] Chore / build
## How was this tested
- [x] Unit tests added / updated — new `UpstreamSnapshotPublishTest` (5
cases):
- returned list is a read-only snapshot (`UnsupportedOperationException`
on mutation)
- removed targets are no longer routing candidates in the newly published
snapshot; already handed-out snapshots stay coherent; `removeByKey` clears the
snapshot
- healthy↔unhealthy transitions republish the snapshot
- concurrent readers/writers regression (4 readers + health churn + config
churn, no torn state, removed targets never remain candidates)
- `ThreadMXBean` allocation comparison: snapshot lookup allocates >10x
less than the legacy per-request copy (100 upstreams × 50k lookups)
- [x] `./mvnw -pl shenyu-loadbalancer -am test` passed (57 tests, BUILD
SUCCESS, checkstyle clean)
- [x] Audited all consumers of `findUpstreamListBySelectorId` (DividePlugin,
DefaultRetryStrategy, WebSocketPlugin, ApacheDubboGrayLoadBalance, k8s
ShenyuCacheRepository) and the LB SPI implementations — all read-only, safe
with an immutable list
- Semantics preserved: `null` when the selector has no entry; element
shared-instance semantics unchanged (the old copy also only copied references)
## Checklist
- [x] Apache 2.0 license header added to new source files
- [x] No CHANGELOG entry needed (apache/shenyu tracks releases via
RELEASE-NOTES)
- [x] No breaking changes to public API / config / DB schema
--
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]