feat(central): one central cache-invalidation topic; role-mapping and external-definition caches follow peer edits (ScadaBridge#100 item 3, ScadaBridge#83)
The #96 site-psk-invalidation topic was the first cross-node invalidation broadcast. It is generalised into ONE central DistributedPubSub topic, central-cache-invalidation, carrying typed messages (Commons ICentralCacheInvalidation: SitePskInvalidated, RoleMappingsInvalidated, ExternalDefinitionsInvalidated, InboundApiMethodInvalidated) in an envelope stamped with the publisher's process-unique origin id. - Host: CentralCacheInvalidationBus (ICentralCacheInvalidationPublisher, no-op until the mediator is set, never throws) and CentralCacheInvalidationSubscriber, which skips its own node's envelopes and hands the peer's to every registered ICentralCacheInvalidationHandler (a failing handler does not stop the rest). Replaces SitePskInvalidationSubscriber. - Migration of #96: SitePskRotationInvalidator publishes through the bus and is the PSK handler; SitePskInvalidated keeps its type name and is also published bare on site-psk-invalidation, which the subscriber still listens to, so a mixed-version central pair keeps exchanging PSK invalidations. Remove after one release. - Audit D1: RoleMappingCache is a handler; ManagementActor's post-commit role-mapping invalidation also publishes RoleMappingsInvalidated, so a revocation is immediate on the peer instead of after RoleMappingCacheSeconds. - Audit D3 / #83 (peer half): ExternalDefinitionLookupCache is a handler; the 9 ManagementActor handlers and the Transport bundle importer publish ExternalDefinitionsInvalidated after commit. (#83's local import half was already in.) TTLs remain the fallback for a lost broadcast or a direct SQL edit. Tests: bus and subscriber unit tests (origin filter, legacy topic), peer-node tests through the real caches in ManagementService.Tests, importer publish, composition root, and a real two-node cluster from the production HOCON (CentralCacheInvalidationTwoNodeTests) proving every message type crosses with the production serializer. Docs: Host, Communication, Security, ManagementService, ESG, and the #85 cache audit. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Communication;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Tells the peer central node to drop a cache entry this node has just invalidated
|
||||
/// (ScadaBridge#100 item 3). Central only; resolved optionally, so a host without it (a site
|
||||
/// node, a plain test host) simply keeps invalidations local.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Callers invalidate their own node's cache first and then publish: the publishing node does
|
||||
/// not apply its own broadcast. Publishing never throws; before the actor system is up it is a
|
||||
/// no-op, and the peer's cache TTL bounds the staleness exactly as it did before.
|
||||
/// </remarks>
|
||||
public interface ICentralCacheInvalidationPublisher
|
||||
{
|
||||
/// <summary>Broadcasts <paramref name="invalidation"/> to the other central node.</summary>
|
||||
/// <param name="invalidation">The typed invalidation.</param>
|
||||
void Publish(ICentralCacheInvalidation invalidation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a peer's <see cref="ICentralCacheInvalidation"/> to one of this node's caches. Each
|
||||
/// cache-owning component registers one (as an enumerable service) and ignores the message types
|
||||
/// it does not own; the central invalidation subscriber hands every received message to all of
|
||||
/// them.
|
||||
/// </summary>
|
||||
public interface ICentralCacheInvalidationHandler
|
||||
{
|
||||
/// <summary>Applies <paramref name="invalidation"/> if this handler owns its type.</summary>
|
||||
/// <param name="invalidation">The received invalidation.</param>
|
||||
void Apply(ICentralCacheInvalidation invalidation);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Communication;
|
||||
|
||||
/// <summary>
|
||||
/// Marker for a typed cache-invalidation message exchanged between the two central nodes over
|
||||
/// the single central <c>DistributedPubSub</c> topic <c>central-cache-invalidation</c>
|
||||
/// (ScadaBridge#100 item 3, #83, #103). Each central node caches configuration-database state
|
||||
/// in-process; a change made through one node drops that node's cache directly and publishes
|
||||
/// one of these so the peer drops its copy too, instead of waiting out the cache TTL.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Delivery is best-effort and at-most-once: every cache that takes part still has a TTL or a
|
||||
/// per-request revision check as its correctness fallback. Message contracts follow the
|
||||
/// additive-only evolution rule — a node that does not know a message type ignores it.
|
||||
/// </remarks>
|
||||
public interface ICentralCacheInvalidation;
|
||||
|
||||
/// <summary>
|
||||
/// The LDAP group → role mapping table or a Deployer site-scope rule changed: drop the
|
||||
/// <c>RoleMappingCache</c> snapshot (audit D1).
|
||||
/// </summary>
|
||||
public sealed record RoleMappingsInvalidated : ICentralCacheInvalidation;
|
||||
|
||||
/// <summary>
|
||||
/// An external system, external-system method or database connection definition changed
|
||||
/// (management edit or Transport bundle import): drop every <c>ExternalDefinitionLookupCache</c>
|
||||
/// entry (audit D3, #83).
|
||||
/// </summary>
|
||||
public sealed record ExternalDefinitionsInvalidated : ICentralCacheInvalidation;
|
||||
|
||||
/// <summary>
|
||||
/// An inbound API method was created, updated, deleted or recompiled: drop the method's
|
||||
/// compiled handler, its known-bad compile record and its cached row (#103).
|
||||
/// </summary>
|
||||
/// <param name="MethodName">The API method's name.</param>
|
||||
public sealed record InboundApiMethodInvalidated(string MethodName) : ICentralCacheInvalidation;
|
||||
|
||||
/// <summary>
|
||||
/// What travels on the <c>central-cache-invalidation</c> topic: the invalidation plus the
|
||||
/// publishing node's process-unique origin id, so a node can skip its own broadcast (it already
|
||||
/// invalidated locally before publishing).
|
||||
/// </summary>
|
||||
/// <param name="OriginId">Process-unique id of the publishing node's invalidation bus.</param>
|
||||
/// <param name="Invalidation">The typed invalidation.</param>
|
||||
public sealed record CentralCacheInvalidationEnvelope(string OriginId, ICentralCacheInvalidation Invalidation);
|
||||
Reference in New Issue
Block a user