diff --git a/docs/DriverLifecycle.md b/docs/DriverLifecycle.md index 6999d8754..c75b2d9aa 100644 --- a/docs/DriverLifecycle.md +++ b/docs/DriverLifecycle.md @@ -601,7 +601,9 @@ instead (#1113 — it used to drop it, so a respawn of an already comms-lost dri the replacement is what must re-publish those refs. Every apply's reindex trims every outstanding latch to the refs the new composition still routes for that driver (`TrimCommsLatchesToIndex`) — a ref the deploy dropped is no longer subscribed and can never be re-published, so it must not be reported — and drops a latch left empty; this runs inside the same apply -message as the respawn, so before the replacement's `Connected` can arm the audit. `StopChild` also +message as the respawn, so before the replacement's `Connected` can arm the audit. The Warning names the status the nodes +actually carry: `still BadNoCommunication`, or `still BadWaitingForInitialData` once a respawn / Restart re-stamped them +(#1113). `StopChild` also holds the id in the `ChildHealthLedger` (`Forget` then `Readmit` on the next spawn), so the stopped child's late health publish cannot resurrect its diagnostics entry. diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.cs index fa1f482ee..bdef19b95 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.cs @@ -689,6 +689,14 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn /// private readonly Dictionary> _commsLatched = new(StringComparer.Ordinal); + /// + /// Gitea #1113 item 3: drivers whose refs were re-stamped + /// by a respawn / Restart after the comms-loss stamp + /// (), so the recovery audit names the status those nodes + /// actually carry. Cleared with the latch and by a fresh comms-loss stamp. + /// + private readonly HashSet _commsLatchReplaced = new(StringComparer.Ordinal); + /// Per-driver rate limit for the supervision-reprovision hook (see /// ). private readonly TimeSpan _reprovisionBackoff; @@ -2348,6 +2356,8 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn var latched = new HashSet(entries.Count, StringComparer.Ordinal); foreach (var (rawPath, _) in entries) latched.Add(rawPath); _commsLatched[driverInstanceId] = latched; + // The nodes carry BadNoCommunication again, whatever a respawn stamped before. + _commsLatchReplaced.Remove(driverInstanceId); // A previous reconnect's audit is now meaningless — this driver is down again. Timers.Cancel(CommsAuditTimerKey(driverInstanceId)); @@ -2384,11 +2394,12 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn private static string CommsAuditTimerKey(string driverInstanceId) => $"comms-audit:{driverInstanceId}"; - /// Drops 's comms-loss latch. + /// Drops 's comms-loss latch and its replaced marker. /// The driver whose latch ends. private void ForgetCommsLatch(string driverInstanceId) { _commsLatched.Remove(driverInstanceId); + _commsLatchReplaced.Remove(driverInstanceId); } /// @@ -2444,6 +2455,12 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn return; } + // #1113 item 3: a respawn / Restart since the outage re-stamped those nodes awaiting-first-value — name the + // status they actually carry. + var latchedStatus = _commsLatchReplaced.Contains(msg.DriverInstanceId) + ? nameof(OpcUaStatus.BadWaitingForInitialData) + : nameof(OpcUaStatus.BadNoCommunication); + var driverType = _children.TryGetValue(msg.DriverInstanceId, out var child) ? child.DriverType : "unknown"; OtOpcUaTelemetry.DriverCommsLatchedRefs.Add( latched.Count, @@ -2451,11 +2468,14 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn new KeyValuePair("driver_type", driverType)); _log.Warning( - "DriverHost {Node}: driver {Driver} ({Type}) — {Count} ref(s) still BadNoCommunication {Delay} after reconnect; " + "DriverHost {Node}: driver {Driver} ({Type}) — {Count} ref(s) still {Status} {Delay} after reconnect; " + "the driver did not re-publish them (missing initial push, or a value-only dedup swallowed an unchanged value). " + "First: {First}", - _localNode, msg.DriverInstanceId, driverType, latched.Count, _commsRecoveryAuditDelay, - latched.OrderBy(r => r, StringComparer.Ordinal).First()); + new object[] + { + _localNode, msg.DriverInstanceId, driverType, latched.Count, latchedStatus, _commsRecoveryAuditDelay, + latched.OrderBy(r => r, StringComparer.Ordinal).First(), + }); ForgetCommsLatch(msg.DriverInstanceId); } @@ -5391,6 +5411,8 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn if (writes.Count == 0) return; _opcUaPublishActor.Tell(new OpcUa.OpcUaPublishActor.AttributeStatusBatchUpdate(writes)); + // #1113 item 3: an outstanding comms latch now names nodes carrying THIS status, not BadNoCommunication. + if (_commsLatched.ContainsKey(driverInstanceId)) _commsLatchReplaced.Add(driverInstanceId); _log.Info( "DriverHost {Node}: driver {Driver} object replaced — {Count} value node(s) marked BadWaitingForInitialData until its first value", _localNode, driverInstanceId, writes.Count); diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostCommsLossRecoveryTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostCommsLossRecoveryTests.cs index cf3a39c83..51202f185 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostCommsLossRecoveryTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostCommsLossRecoveryTests.cs @@ -192,12 +192,13 @@ public sealed class DriverHostCommsLossRecoveryTests : RuntimeActorTestBase driver.InitializeGate = release.Task; host.Tell(new RestartDriver("c1", "drv-restart", "test-operator", Guid.NewGuid())); - EventFilter.Warning(contains: "still BadNoCommunication") + EventFilter.Warning(contains: "ref(s) still") .Expect(0, audit + TimeSpan.FromSeconds(3), () => { }, TestContext.Current.CancellationToken); meter.SumWithTag("driver_instance", "drv-restart").ShouldBe(0); - // The new incarnation connects, re-subscribes silently, and its own audit reports the ref the restart kept. - EventFilter.Warning(contains: "still BadNoCommunication").ExpectOne(audit + ReconnectBudget, () => + // The new incarnation connects, re-subscribes silently, and its own audit reports the ref the restart kept — + // naming the status the Restart re-stamped (#1112), not BadNoCommunication (#1113 item 3). + EventFilter.Warning(contains: "1 ref(s) still BadWaitingForInitialData").ExpectOne(audit + ReconnectBudget, () => { driver.InitializeGate = null; release.SetResult(); diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostRespawnValueNodeGapTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostRespawnValueNodeGapTests.cs index e5864a500..3618f5293 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostRespawnValueNodeGapTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/DriverHostRespawnValueNodeGapTests.cs @@ -138,7 +138,7 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase // flow never re-published. Had the respawn latched it, the audit armed by the replacement's Connected would // report it after AuditDelay. - EventFilter.Warning(contains: "still BadNoCommunication") + EventFilter.Warning(contains: "ref(s) still") .Expect(0, AuditDelay + TimeSpan.FromSeconds(2), () => { }, TestContext.Current.CancellationToken); meter.SumWithTag("driver_instance", DriverId).ShouldBe(0); @@ -151,7 +151,7 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase TestContext.Current.CancellationToken); } - // ---- #1113 item 2: a config-change respawn of a driver that was ALREADY comms-lost ---- + // ---- #1113 items 2 + 3: a respawn / Restart of a driver that was ALREADY comms-lost ---- /// Long enough that a test can fire the replacement's first value before the audit runs. private static readonly TimeSpan LongAuditDelay = TimeSpan.FromSeconds(3); @@ -161,6 +161,7 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase /// replacement was never audited — unlike an operator Restart, #1053), trimmed to the refs the new composition /// still carries. The new deployment drops flow and adds temp; the silent replacement is reported /// for exactly speed — not flow (dropped: a false warning) and not temp (never latched). + /// Item 3: the warning names the status the nodes carry, BadWaitingForInitialData. /// [Fact] public void A_config_change_respawn_of_a_comms_lost_driver_audits_the_replacement_for_the_kept_refs_only() @@ -172,7 +173,7 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase using var meter = new MeterRecorder("otopcua.driver.comms_latched_refs"); GoCommsLost(oldDriver, host, publish); - EventFilter.Warning(contains: "1 ref(s) still BadNoCommunication").ExpectOne( + EventFilter.Warning(contains: "1 ref(s) still BadWaitingForInitialData").ExpectOne( LongAuditDelay + PresenceBudget, () => DispatchDroppingFlow(host, coordinator, db), TestContext.Current.CancellationToken); @@ -204,6 +205,25 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase meter.SumWithTag("driver_instance", DriverId).ShouldBe(0); } + /// + /// #1113 item 3: an operator Restart keeps the latch (#1053), but the Restart re-stamped the nodes + /// BadWaitingForInitialData (#1112) — so the audit must not claim they are "still BadNoCommunication". + /// + [Fact] + public void A_restart_of_a_comms_lost_driver_audit_names_the_awaiting_first_value_status() + { + var oldDriver = new GatedDriver(DriverId); + var newDriver = new GatedDriver(DriverId); + var (host, publish, _, _) = Arrange(oldDriver, newDriver, LongAuditDelay); + SeedGoodFromOldDriver(oldDriver, publish); + GoCommsLost(oldDriver, host, publish); + + EventFilter.Warning(contains: "2 ref(s) still BadWaitingForInitialData").ExpectOne( + LongAuditDelay + PresenceBudget, + () => host.Tell(new RestartDriver("c1", DriverId, "test-operator", Guid.NewGuid())), + TestContext.Current.CancellationToken); + } + /// Takes the old driver comms-lost (Force Reconnect with its re-initialise held forever) and waits for the /// host's latched BadNoCommunication stamp. private static void GoCommsLost(GatedDriver oldDriver, IActorRef host, TestProbe publish)