refactor(host): remove legacy site-psk-invalidation topic (#105)

Removes the #96 compatibility path that the unified central-cache-invalidation
topic (#100 item 3, 153609ef; compat 3a31dd2d) carried for one release:
- CentralCacheInvalidationBus no longer publishes a bare SitePskInvalidated
  on site-psk-invalidation; LegacySitePskTopic constant deleted.
- CentralCacheInvalidationSubscriber no longer subscribes to that topic or
  handles a bare SitePskInvalidated; it applies envelopes only.
central-cache-invalidation behaviour is unchanged (one envelope per
invalidation, origin filtering, per-handler fault isolation).

Gate met: 8e32f353 (carries 153609ef and 3a31dd2d) runs on every central
node - DEV vd03 (record 581e25ca) and QA vq03/vq04 (record 8ba5d5d7).

Mixed-version / rolling-upgrade constraint: a central node built before
153609ef listens only on site-psk-invalidation and no longer receives PSK
invalidations from a newer peer (only its TTL and the site-rejection refresh
bound the staleness). Mixed pairs across that boundary are no longer
supported; central pairs are stopped and started together anyway.
Documented in Component-Host.md and Component-Communication.md.

Tests: the legacy publish/subscribe tests are replaced by
PskRotation_OnOneNode_ReachesThePeersCaches_ThroughTheUnifiedTopic (node A
publishes, node B's PSK cache and secret-resolver cache are invalidated, and
nothing else is published) and a bare-message-ignored test with an envelope
positive control. The two-node cluster test now asserts the PSK invalidation
arrives exactly once and the publisher applies nothing.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-13 08:43:55 -05:00
parent 8ba5d5d7fd
commit 89d2becba9
7 changed files with 69 additions and 39 deletions
@@ -26,11 +26,13 @@ namespace ZB.MOM.WW.ScadaBridge.Host;
/// the subscriber skips its own.
/// </para>
/// <para>
/// <b>Migration from <c>site-psk-invalidation</c>.</b> A <see cref="SitePskInvalidated"/> is also
/// published, bare, on <see cref="LegacySitePskTopic"/>, and the subscriber still listens there,
/// so a central pair that is briefly mixed-version during an upgrade keeps exchanging PSK
/// invalidations. Applying a PSK invalidation twice is harmless. Remove both once every central
/// node runs this build.
/// <b>No legacy topic.</b> The #96 per-cache topic <c>site-psk-invalidation</c> was published to
/// and subscribed for one release as a mixed-version bridge; it was removed in ScadaBridge#105
/// once every central node ran a build with this topic. A central node built before
/// ScadaBridge#100 item 3 listens only on the old topic and so no longer receives PSK
/// invalidations from a newer peer (its TTL still bounds the staleness): the two central nodes
/// of a pair must run builds that both carry this topic, which the stop-both/start-both
/// upgrade of a central pair already guarantees.
/// </para>
/// </remarks>
public sealed class CentralCacheInvalidationBus : ICentralCacheInvalidationPublisher
@@ -38,9 +40,6 @@ public sealed class CentralCacheInvalidationBus : ICentralCacheInvalidationPubli
/// <summary>The single central cache-invalidation topic.</summary>
public const string Topic = "central-cache-invalidation";
/// <summary>The #96 per-cache topic, kept for mixed-version central pairs (see remarks).</summary>
public const string LegacySitePskTopic = "site-psk-invalidation";
private readonly ILogger<CentralCacheInvalidationBus> _logger;
private volatile IActorRef? _mediator;
@@ -77,10 +76,6 @@ public sealed class CentralCacheInvalidationBus : ICentralCacheInvalidationPubli
try
{
mediator.Tell(new Publish(Topic, new CentralCacheInvalidationEnvelope(OriginId, invalidation)));
if (invalidation is SitePskInvalidated psk)
{
mediator.Tell(new Publish(LegacySitePskTopic, psk));
}
}
catch (Exception ex)
{
@@ -101,8 +96,7 @@ public sealed class CentralCacheInvalidationBus : ICentralCacheInvalidationPubli
}
/// <summary>
/// Central actor that subscribes to <see cref="CentralCacheInvalidationBus.Topic"/> (and the
/// legacy <see cref="CentralCacheInvalidationBus.LegacySitePskTopic"/>) and hands every
/// Central actor that subscribes to <see cref="CentralCacheInvalidationBus.Topic"/> and hands every
/// invalidation published by the peer central node to this node's
/// <see cref="ICentralCacheInvalidationHandler"/>s.
/// </summary>
@@ -127,8 +121,6 @@ public sealed class CentralCacheInvalidationSubscriber : ReceiveActor
Apply(envelope.Invalidation);
}
});
// Bare message on the #96 topic, from a peer that predates the shared topic.
Receive<SitePskInvalidated>(Apply);
Receive<SubscribeAck>(_ => { });
}
@@ -156,7 +148,6 @@ public sealed class CentralCacheInvalidationSubscriber : ReceiveActor
{
var mediator = DistributedPubSub.Get(Context.System).Mediator;
mediator.Tell(new Subscribe(CentralCacheInvalidationBus.Topic, Self));
mediator.Tell(new Subscribe(CentralCacheInvalidationBus.LegacySitePskTopic, Self));
}
catch (Exception ex)
{
@@ -108,9 +108,9 @@ public sealed class SitePskRotationInvalidator : ISecretCacheInvalidator, ICentr
/// <summary>
/// Peer message: the gRPC preshared key of <paramref name="SiteId"/> was rotated on a central node.
/// Rides the central cache-invalidation topic; kept in this namespace because the #96
/// <c>site-psk-invalidation</c> topic carries it bare by this type name (see
/// <see cref="CentralCacheInvalidationBus"/>).
/// Rides the central cache-invalidation topic inside a <see cref="CentralCacheInvalidationEnvelope"/>
/// (see <see cref="CentralCacheInvalidationBus"/>); the #96 bare <c>site-psk-invalidation</c>
/// topic was removed in ScadaBridge#105.
/// </summary>
/// <param name="SiteId">The site whose key changed.</param>
public sealed record SitePskInvalidated(string SiteId) : ICentralCacheInvalidation;