BobSong-dev opened a new pull request, #7358:
URL: https://github.com/apache/shenyu/pull/7358

   Fixes #7356
   
   ## Background
   
   `DataChangedEvent` is a local Spring event and the `WebsocketCollector` 
session
   collections are local JVM state. When several standalone admin nodes
   (`shenyu.cluster.enabled=false`) share one database, a change written through
   admin 1 reaches only the gateways connected to admin 1; gateways connected to
   admin 2 stay stale until an operator clicks synchronize or the gateway
   reconnects, because no local event is generated on admin 2.
   
   ## Changes
   
   - New admin-side `WebsocketDataReconciler`, registered by
     `WebSocketSyncConfiguration` (so it exists only when websocket sync is
     enabled). It runs with `scheduleWithFixedDelay` (no overlapping runs) and 
an
     initial jitter, so several admin nodes do not query the shared database
     simultaneously.
   - Only namespaces with live websocket sessions on this node are reconciled;
     namespaces without sessions are not polled at all.
   - Per namespace and config group it compares an md5 digest of the freshly
     loaded data with an in-memory cursor and pushes a full `REFRESH` only for
     changed groups through the normal `WebsocketCollector` path. Unchanged
     cycles push nothing.
   - The cursor advances only after a successful load and push, so a failed 
group
     is retried in the next cycle without failing the whole cycle.
   - Empty groups are pushed with `REFRESH` so gateway caches can be cleared 
once
     the gateway applies empty snapshots (#7094); with the current gateway code
     empty pushes no-op, so this is forward-compatible either way.
   - In cluster mode, non-master nodes skip every cycle; the master reconciles.
     Reconciliation only reads the database and pushes events, so a pushed cycle
     can never retrigger itself.
   - Namespace-scoped loaders added where missing:
     `AppAuthService`, `MetaDataService`, `AiProxyApiKeyService` and
     `DiscoveryUpstreamService` gained `listAllByNamespaceId` (discovery 
upstreams
     resolve the namespace through the linked selector / proxy selector; rows
     that cannot be resolved are skipped, and no discovery processor is 
invoked).
   - `application.yml` documents the new 
`shenyu.sync.websocket.reconciliation.*`
     properties and the consistency-delay / database-load trade-off.
   
   ## Verification
   
   - New `WebsocketDataReconcilerTest` (8 tests): unchanged digest pushes 
nothing;
     a changed group pushes exactly once per namespace; an emptied group is 
pushed
     as `REFRESH` with `[]`; a failed load is retried in the next cycle; only 
the
     changed namespace is re-pushed; cluster non-master skips while master
     reconciles; lifecycle start/stop; no sessions means no loads.
   - Targeted regression (all pass): `WebsocketCollectorTest` (29),
     `WebsocketDataChangedListenerTest` (17), `WebsocketListenerTest` (7),
     `WebsocketConfiguratorTest` (14), `WebSocketSyncConfigurationTest` (3),
     `AiProxyApiKeyServiceImplTest` (12), `AbstractDataChangedListenerTest` (8),
     `DataChangedEventDispatcherTest` (13).
   - Full `shenyu-admin` module: `Tests run: 1518, Failures: 0, Errors: 0,
     Skipped: 1`, BUILD SUCCESS. Checkstyle: 0 violations.


-- 
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]

Reply via email to