fix(grpc-data): A1 review S2 + F5 re-arm + nits — native known is withdrawn on comms loss
- The Bad connectivity edge (and a Good edge with no Bad edge since the last Good one, or from a new child incarnation) sends MarkConditionsKnown(Known: false) for the driver's condition nodes, ahead of the quality annotation, so an alarm raised during an outage never reads known-inactive, Good after the reconnect. Stopping a child (a respawn) withdraws too. - DriverInstanceActor stamps a connection epoch (bumped on every Connected entry) on the initial-state signal and on ConnectivityChanged(Connected); a signal raised under an earlier connection is dropped by the child and the host. - G3 never discards a deferred withdrawal. - F5 'still unknown' follows the node manager: a native transition takes its ref out of Pending. - Re-arm F5 at the alarm-ref reindex for refs a deploy adds while connected (defensive: today such a deploy respawns the driver because its RawTags are folded into its config). - Nits: signals/edges from a retired or non-current child never (re)create a tracker; the injected clock replaces DateTime.UtcNow. - Primary demote/re-promote: checked, not a stale-known window — drivers and their condition writes run ungated on both pair members.
This commit is contained in:
@@ -20,12 +20,16 @@ public sealed partial class DriverHostActor
|
||||
private sealed record ConditionSignalTimedOut(string DriverInstanceId, long Epoch);
|
||||
private sealed record ConditionBackstopElapsed(string DriverInstanceId, long Epoch);
|
||||
|
||||
/// <summary>Per driver instance: the current connectivity epoch, when its quality went Good, the conditions not
|
||||
/// yet signalled since then, and the conditions the driver reported unsignalable.</summary>
|
||||
/// <summary>Per driver instance: the current connectivity epoch, the child that sent the last edge, its connection
|
||||
/// epoch at the last Good edge, when its quality went Good, when the current F5 window started, the conditions not
|
||||
/// yet established since then, and the conditions the driver reported unsignalable.</summary>
|
||||
private sealed class ConditionSignalTracker
|
||||
{
|
||||
public long Epoch;
|
||||
public IActorRef? Owner;
|
||||
public long? ConnectionEpoch;
|
||||
public DateTime? GoodSinceUtc;
|
||||
public DateTime? PendingSinceUtc;
|
||||
public readonly HashSet<string> Pending = new(StringComparer.Ordinal);
|
||||
public readonly HashSet<string> Unsignalable = new(StringComparer.Ordinal);
|
||||
public bool DiagnosticRaised;
|
||||
@@ -37,6 +41,9 @@ public sealed partial class DriverHostActor
|
||||
private static string SignalTimeoutKey(string driverInstanceId) => "cond-signal-timeout:" + driverInstanceId;
|
||||
private static string BackstopKey(string driverInstanceId) => "cond-backstop:" + driverInstanceId;
|
||||
|
||||
/// <summary>The injected clock (review nit: never <see cref="DateTime.UtcNow"/> here).</summary>
|
||||
private DateTime ConditionClockUtc => _writeClock.GetUtcNow().UtcDateTime;
|
||||
|
||||
private void ReceiveConditionSignals()
|
||||
{
|
||||
Receive<DriverInstanceActor.AlarmInitialStatePublished>(OnAlarmInitialState);
|
||||
@@ -62,35 +69,117 @@ public sealed partial class DriverHostActor
|
||||
private string? DriverTypeOf(string driverInstanceId) =>
|
||||
_children.TryGetValue(driverInstanceId, out var child) ? child.DriverType : null;
|
||||
|
||||
/// <summary>A connectivity edge restarts the F5 window (from quality Good) and the backstop; a Bad edge cancels both.</summary>
|
||||
private void OnConditionSignalConnectivity(string driverInstanceId, bool connected)
|
||||
/// <summary>Whether <paramref name="sender"/> is the CURRENT child for <paramref name="driverInstanceId"/> — not a
|
||||
/// stopped (retired) incarnation whose late message must not recreate a tracker after
|
||||
/// <see cref="ForgetConditionSignals"/>, nor anything else.</summary>
|
||||
private bool IsCurrentChild(string driverInstanceId, IActorRef sender) =>
|
||||
!_retiredChildren.Contains(sender)
|
||||
&& _children.TryGetValue(driverInstanceId, out var child) && Equals(child.Actor, sender);
|
||||
|
||||
/// <summary>
|
||||
/// A connectivity edge restarts the F5 window (from quality Good) and the backstop; a Bad edge cancels both.
|
||||
/// Review S2: the Bad edge withdraws "known" from the driver's conditions — the source can no longer vouch for
|
||||
/// their state, and an alarm raised during the outage would otherwise read known-inactive, Good after the
|
||||
/// reconnect until the replay. A Good edge withdraws too (ahead of the Good quality annotation) when no Bad edge
|
||||
/// was seen since the previous Good one, or it comes from a new child incarnation. They become known again only
|
||||
/// on the reconnected source's next signal (or transition).
|
||||
/// </summary>
|
||||
private void OnConditionSignalConnectivity(string driverInstanceId, bool connected, IActorRef sender, long? connectionEpoch)
|
||||
{
|
||||
if (!IsCurrentChild(driverInstanceId, sender))
|
||||
{
|
||||
// A stopped incarnation (or a stray sender): never recreate or reset the tracker. Its Bad edge still
|
||||
// withdraws known unless the CURRENT child of the same id is connected (its state is the live one).
|
||||
var currentConnected = _conditionSignalTrackers.TryGetValue(driverInstanceId, out var live) && live.GoodSinceUtc is not null
|
||||
&& _children.TryGetValue(driverInstanceId, out var current) && Equals(live.Owner, current.Actor);
|
||||
if (!connected && !currentConnected) WithdrawDriverConditionsKnown(driverInstanceId);
|
||||
return;
|
||||
}
|
||||
|
||||
var t = Tracker(driverInstanceId);
|
||||
// A Good edge with no Bad edge since the previous Good one (or from a new incarnation) — withdraw here instead.
|
||||
var missedBadEdge = connected && (t.GoodSinceUtc is not null || (t.Owner is not null && !Equals(t.Owner, sender)));
|
||||
t.Owner = sender;
|
||||
t.Epoch++;
|
||||
Timers.Cancel(SignalTimeoutKey(driverInstanceId));
|
||||
Timers.Cancel(BackstopKey(driverInstanceId));
|
||||
t.Pending.Clear();
|
||||
t.PendingSinceUtc = null;
|
||||
if (!connected || missedBadEdge) WithdrawDriverConditionsKnown(driverInstanceId);
|
||||
if (!connected)
|
||||
{
|
||||
t.GoodSinceUtc = null;
|
||||
t.ConnectionEpoch = null;
|
||||
return;
|
||||
}
|
||||
|
||||
t.GoodSinceUtc = DateTime.UtcNow;
|
||||
t.GoodSinceUtc = ConditionClockUtc;
|
||||
t.ConnectionEpoch = connectionEpoch;
|
||||
if (_alarmRefsByDriver.TryGetValue(driverInstanceId, out var refs))
|
||||
foreach (var (rawPath, _) in refs) t.Pending.Add(rawPath);
|
||||
if (t.Pending.Count > 0 && DriverTypeOf(driverInstanceId) is { } type)
|
||||
{
|
||||
Timers.StartSingleTimer(SignalTimeoutKey(driverInstanceId), new ConditionSignalTimedOut(driverInstanceId, t.Epoch),
|
||||
_conditionSignals.SignalTimeoutFor(type));
|
||||
}
|
||||
|
||||
ArmSignalTimeout(driverInstanceId, t);
|
||||
if (t.Unsignalable.Count > 0) ScheduleBackstop(driverInstanceId, t);
|
||||
}
|
||||
|
||||
/// <summary>(Re)start the F5 window for the tracker's pending conditions, from now.</summary>
|
||||
private void ArmSignalTimeout(string driverInstanceId, ConditionSignalTracker t)
|
||||
{
|
||||
if (t.Pending.Count == 0 || DriverTypeOf(driverInstanceId) is not { } type) return;
|
||||
t.PendingSinceUtc = ConditionClockUtc;
|
||||
Timers.StartSingleTimer(SignalTimeoutKey(driverInstanceId), new ConditionSignalTimedOut(driverInstanceId, t.Epoch),
|
||||
_conditionSignals.SignalTimeoutFor(type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open-question answer (re-arm F5): after a deploy re-indexed the alarm refs, a CONNECTED driver's newly added
|
||||
/// refs join <c>Pending</c> and the F5 window restarts now; refs the deploy removed leave it. (Today a deploy that
|
||||
/// adds alarm refs also changes the driver's config — its RawTags are folded in — so the driver is respawned and
|
||||
/// the new incarnation's Good edge re-arms F5 anyway; this covers an in-place deploy.)
|
||||
/// </summary>
|
||||
/// <param name="previousRefs">Each driver's alarm RawPaths before the reindex.</param>
|
||||
private void RearmConditionSignalsAfterReindex(IReadOnlyDictionary<string, HashSet<string>> previousRefs)
|
||||
{
|
||||
foreach (var (driverInstanceId, t) in _conditionSignalTrackers)
|
||||
{
|
||||
if (t.GoodSinceUtc is null) continue; // armed on the next Good edge
|
||||
var current = _alarmRefsByDriver.TryGetValue(driverInstanceId, out var refs)
|
||||
? refs.Select(r => r.RawPath).ToHashSet(StringComparer.Ordinal)
|
||||
: new HashSet<string>(StringComparer.Ordinal);
|
||||
previousRefs.TryGetValue(driverInstanceId, out var before);
|
||||
var added = current.Where(r => before is null || !before.Contains(r)).ToList();
|
||||
t.Pending.IntersectWith(current);
|
||||
t.Unsignalable.IntersectWith(current);
|
||||
if (added.Count > 0)
|
||||
{
|
||||
t.Pending.UnionWith(added);
|
||||
ArmSignalTimeout(driverInstanceId, t);
|
||||
}
|
||||
else if (t.Pending.Count == 0)
|
||||
{
|
||||
ClearPendingWindow(driverInstanceId, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAlarmInitialState(DriverInstanceActor.AlarmInitialStatePublished msg)
|
||||
{
|
||||
if (!IsCurrentChild(msg.DriverInstanceId, Sender))
|
||||
{
|
||||
_log.Debug("DriverHost {Node}: dropping an initial alarm-state signal for {Id} from a sender that is not its current child",
|
||||
_localNode, msg.DriverInstanceId);
|
||||
return;
|
||||
}
|
||||
|
||||
var t = Tracker(msg.DriverInstanceId);
|
||||
// Review S2: a signal from an earlier connection (queued across a Connected→Reconnecting→Connected bounce)
|
||||
// covers state the reconnect withdrew; it must not mark anything known.
|
||||
if (msg.ConnectionEpoch is { } epoch && t.ConnectionEpoch != epoch)
|
||||
{
|
||||
_log.Debug("DriverHost {Node}: dropping a stale initial alarm-state signal from {Id} (connection {Epoch}, current {Current})",
|
||||
_localNode, msg.DriverInstanceId, epoch, t.ConnectionEpoch);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Args.Unsignalable)
|
||||
{
|
||||
// InitialStateUnsignalable: no real signal will come. Only a driver type with a backstop (OpcUaClient) marks
|
||||
@@ -101,23 +190,61 @@ public sealed partial class DriverHostActor
|
||||
}
|
||||
|
||||
var marked = MarkDriverConditionsKnown(msg.DriverInstanceId, msg.Args.ConditionIds);
|
||||
t.Pending.ExceptWith(msg.Args.ConditionIds);
|
||||
t.Unsignalable.ExceptWith(msg.Args.ConditionIds);
|
||||
if (t.Pending.Count == 0)
|
||||
NoteConditionsEstablished(msg.DriverInstanceId, t, msg.Args.ConditionIds);
|
||||
_log.Debug("DriverHost {Node}: driver {Driver} established {Count} condition(s) ({Marked} routed)",
|
||||
_localNode, msg.DriverInstanceId, msg.Args.ConditionIds.Count, marked);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Keep F5's "still unknown" set consistent with the node manager: a condition leaves <c>Pending</c> when the
|
||||
/// node manager marks it known — on its driver's signal, and on a native transition (a native projection is an
|
||||
/// established state there). An emptied set ends the F5 window and clears the diagnostic.
|
||||
/// </summary>
|
||||
private void NoteConditionsEstablished(string driverInstanceId, ConditionSignalTracker t, IEnumerable<string> rawPaths)
|
||||
{
|
||||
if (t.Pending.Count == 0) return;
|
||||
t.Pending.ExceptWith(rawPaths);
|
||||
if (t.Pending.Count == 0) ClearPendingWindow(driverInstanceId, t);
|
||||
}
|
||||
|
||||
/// <summary>A forwarded native transition established <paramref name="rawPath"/> (see <see cref="NoteConditionsEstablished"/>).</summary>
|
||||
private void NoteNativeTransitionEstablished(string driverInstanceId, string rawPath)
|
||||
{
|
||||
if (_conditionSignalTrackers.TryGetValue(driverInstanceId, out var t) && t.GoodSinceUtc is not null)
|
||||
NoteConditionsEstablished(driverInstanceId, t, [rawPath]);
|
||||
}
|
||||
|
||||
private void ClearPendingWindow(string driverInstanceId, ConditionSignalTracker t)
|
||||
{
|
||||
Timers.Cancel(SignalTimeoutKey(driverInstanceId));
|
||||
t.PendingSinceUtc = null;
|
||||
// F5: a late signal clears the "not signalled" diagnostic.
|
||||
if (!t.DiagnosticRaised) return;
|
||||
t.DiagnosticRaised = false;
|
||||
_conditionSignals.Hub?.ClearUnsignalled(driverInstanceId);
|
||||
_log.Info("DriverHost {Node}: driver {Driver} signalled its initial alarm state late — diagnostic cleared",
|
||||
_localNode, driverInstanceId);
|
||||
}
|
||||
|
||||
/// <summary>Review S2: withdraw "known" from every condition node of <paramref name="driverInstanceId"/> (one
|
||||
/// <see cref="PublishActor.MarkConditionsKnown"/> with <c>Known: false</c> per realm), on the same chain as its
|
||||
/// alarm projections and quality annotations.</summary>
|
||||
private void WithdrawDriverConditionsKnown(string driverInstanceId)
|
||||
{
|
||||
if (_opcUaPublishActor is null || !_alarmRefsByDriver.TryGetValue(driverInstanceId, out var refs)) return;
|
||||
var byRealm = new Dictionary<AddressSpaceRealm, List<string>>();
|
||||
foreach (var (_, nodes) in refs)
|
||||
{
|
||||
Timers.Cancel(SignalTimeoutKey(msg.DriverInstanceId));
|
||||
// F5: a late signal clears the "not signalled" diagnostic.
|
||||
if (t.DiagnosticRaised)
|
||||
foreach (var n in nodes)
|
||||
{
|
||||
t.DiagnosticRaised = false;
|
||||
_conditionSignals.Hub?.ClearUnsignalled(msg.DriverInstanceId);
|
||||
_log.Info("DriverHost {Node}: driver {Driver} signalled its initial alarm state late — diagnostic cleared",
|
||||
_localNode, msg.DriverInstanceId);
|
||||
if (!byRealm.TryGetValue(n.Realm, out var list)) byRealm[n.Realm] = list = new List<string>();
|
||||
list.Add(n.NodeId);
|
||||
}
|
||||
}
|
||||
|
||||
_log.Debug("DriverHost {Node}: driver {Driver} established {Count} condition(s) ({Marked} routed)",
|
||||
_localNode, msg.DriverInstanceId, msg.Args.ConditionIds.Count, marked);
|
||||
foreach (var (realm, ids) in byRealm)
|
||||
_opcUaPublishActor.Tell(new PublishActor.MarkConditionsKnown(driverInstanceId, ids, realm, Known: false));
|
||||
}
|
||||
|
||||
private void ScheduleBackstop(string driverInstanceId, ConditionSignalTracker t)
|
||||
@@ -130,7 +257,7 @@ public sealed partial class DriverHostActor
|
||||
return;
|
||||
}
|
||||
|
||||
var remaining = goodSince + settle - DateTime.UtcNow;
|
||||
var remaining = goodSince + settle - ConditionClockUtc;
|
||||
Timers.StartSingleTimer(BackstopKey(driverInstanceId), new ConditionBackstopElapsed(driverInstanceId, t.Epoch),
|
||||
remaining > TimeSpan.Zero ? remaining : TimeSpan.Zero);
|
||||
}
|
||||
@@ -141,9 +268,8 @@ public sealed partial class DriverHostActor
|
||||
return;
|
||||
var ids = t.Unsignalable.ToList();
|
||||
t.Unsignalable.Clear();
|
||||
t.Pending.ExceptWith(ids);
|
||||
if (t.Pending.Count == 0) Timers.Cancel(SignalTimeoutKey(msg.DriverInstanceId));
|
||||
var marked = MarkDriverConditionsKnown(msg.DriverInstanceId, ids);
|
||||
NoteConditionsEstablished(msg.DriverInstanceId, t, ids);
|
||||
_log.Info("DriverHost {Node}: backstop settled — {Count} unsignalable condition(s) of {Driver} marked known (residual: an upstream alarm active and never re-transitioned reads inactive)",
|
||||
_localNode, marked, msg.DriverInstanceId);
|
||||
}
|
||||
@@ -153,7 +279,7 @@ public sealed partial class DriverHostActor
|
||||
if (!_conditionSignalTrackers.TryGetValue(msg.DriverInstanceId, out var t) || t.Epoch != msg.Epoch || t.Pending.Count == 0)
|
||||
return;
|
||||
// F5: the conditions STAY unknown (Uncertain on a consumer) — never known-inactive.
|
||||
var elapsed = t.GoodSinceUtc is { } since ? DateTime.UtcNow - since : TimeSpan.Zero;
|
||||
var elapsed = (t.PendingSinceUtc ?? t.GoodSinceUtc) is { } since ? ConditionClockUtc - since : TimeSpan.Zero;
|
||||
t.DiagnosticRaised = true;
|
||||
if (_conditionSignals.Hub is { } hub) hub.ReportUnsignalled(msg.DriverInstanceId, elapsed, t.Pending.Count);
|
||||
else OtOpcUaTelemetry.DataConnConditionsUnsignalled.Add(t.Pending.Count,
|
||||
|
||||
@@ -2016,7 +2016,7 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
// The mux fan-out is independent of the OPC UA sink — a node with scripted alarms but no
|
||||
// publish actor (the mux-only test/dev path) must still see comms loss. Done before the early
|
||||
// return for exactly that reason.
|
||||
OnConditionSignalConnectivity(msg.DriverInstanceId, msg.Connected);
|
||||
OnConditionSignalConnectivity(msg.DriverInstanceId, msg.Connected, Sender, msg.ConnectionEpoch);
|
||||
if (!msg.Connected)
|
||||
{
|
||||
if (!_retiredChildren.Contains(Sender) &&
|
||||
@@ -2340,6 +2340,8 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
_localNode, msg.DriverInstanceId, msg.Args.ConditionId);
|
||||
}
|
||||
|
||||
// A1 review S2: the node manager marks a native condition known on this projection, so F5 stops counting it.
|
||||
NoteNativeTransitionEstablished(msg.DriverInstanceId, msg.Args.ConditionId);
|
||||
foreach (var n in nodeIds)
|
||||
{
|
||||
var nodeId = n.NodeId;
|
||||
@@ -4058,6 +4060,9 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
// The per-driver secondary indexes are rebuilt WHOLE alongside their primaries below — same pass,
|
||||
// same clear — so no incremental maintenance exists to get out of step with them.
|
||||
_valueRefsByDriver.Clear();
|
||||
// A1 review (re-arm F5): each driver's alarm refs before this reindex, so a deploy's added refs can be found.
|
||||
var previousAlarmRefs = _alarmRefsByDriver.ToDictionary(
|
||||
kv => kv.Key, kv => kv.Value.Select(e => e.RawPath).ToHashSet(StringComparer.Ordinal), StringComparer.Ordinal);
|
||||
_alarmRefsByDriver.Clear();
|
||||
foreach (var t in composition.RawTags)
|
||||
{
|
||||
@@ -4139,6 +4144,7 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
// so the two stay in step. Keyed by the bare condition NodeId, exactly as ForwardNativeAlarm projects.
|
||||
_nativeAlarmProjector.RetainOnly(_driverRefByAlarmNodeId.Keys.ToHashSet(StringComparer.Ordinal));
|
||||
PublishAckPreflight();
|
||||
RearmConditionSignalsAfterReindex(previousAlarmRefs);
|
||||
|
||||
// Cache the per-driver payload as THE authority, in the same clear-and-repopulate pass as the routing
|
||||
// maps above so a rename/removal can never leave a stale entry behind. Keyed over the UNION of the two
|
||||
@@ -4680,6 +4686,9 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
_dataWriteRuntime?.BeforeDriverStopForTests?.Invoke(driverInstanceId);
|
||||
Context.Stop(entry.Actor);
|
||||
_children.Remove(driverInstanceId);
|
||||
// A1 review S2: the stopped incarnation can no longer vouch for its conditions (a respawn's carried-over
|
||||
// known state would otherwise stand until the new incarnation signals). No-op when the deploy removed them.
|
||||
WithdrawDriverConditionsKnown(driverInstanceId);
|
||||
ForgetConditionSignals(driverInstanceId);
|
||||
PublishAckPreflight();
|
||||
EvictRetainedValues(driverInstanceId);
|
||||
|
||||
@@ -108,7 +108,8 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
/// annotates this driver's native alarm conditions' source-data Quality from it (comms lost → Bad,
|
||||
/// restored → Good) — independently of alarm transitions, since a comms-lost driver emits no alarm
|
||||
/// events. Fire-and-forget.</summary>
|
||||
public sealed record ConnectivityChanged(string DriverInstanceId, bool Connected, long? ProducerIncarnation = null);
|
||||
public sealed record ConnectivityChanged(string DriverInstanceId, bool Connected, long? ProducerIncarnation = null,
|
||||
long? ConnectionEpoch = null);
|
||||
|
||||
/// <summary>
|
||||
/// Sent to the parent from <see cref="PostRestart"/> so the host re-provisions THIS incarnation.
|
||||
@@ -236,8 +237,11 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
/// <see cref="IAlarmInitialStateSignal.InitialAlarmStateDelivered"/>. It travels the SAME self-Tell → parent path as
|
||||
/// <see cref="AttributeAlarmPublished"/>, so it reaches <see cref="DriverHostActor"/> after every alarm event the
|
||||
/// driver raised before it.</summary>
|
||||
public sealed record AlarmInitialStatePublished(string DriverInstanceId, AlarmInitialStateEventArgs Args);
|
||||
private sealed record NativeAlarmInitialState(AlarmInitialStateEventArgs Args);
|
||||
/// <remarks>A1 review S2: <paramref name="ConnectionEpoch"/> is the connection (Connected entry) the driver raised
|
||||
/// it under, matching <see cref="ConnectivityChanged.ConnectionEpoch"/> of that Good edge.</remarks>
|
||||
public sealed record AlarmInitialStatePublished(string DriverInstanceId, AlarmInitialStateEventArgs Args,
|
||||
long? ConnectionEpoch = null);
|
||||
private sealed record NativeAlarmInitialState(AlarmInitialStateEventArgs Args, long Epoch);
|
||||
/// <summary>Self-sent on Connected entry / when alarm refs are (re)pushed, to establish the native-alarm
|
||||
/// subscription that un-gates an <see cref="IAlarmSource"/> driver's feed. Handled async so the
|
||||
/// <see cref="IAlarmSource.SubscribeAlarmsAsync"/> call is bounded + off the synchronous handlers.</summary>
|
||||
@@ -505,6 +509,8 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
// A1 (plan §5.1 G5): attached and detached WITH the alarm handler, so the signal obeys exactly the gate
|
||||
// OnAlarmEvent obeys.
|
||||
private EventHandler<AlarmInitialStateEventArgs>? _alarmInitialStateHandler;
|
||||
// A1 review S2: bumped on every Connected entry; read on the driver's thread when it raises its signal.
|
||||
private long _connectionEpoch;
|
||||
private EventHandler<RediscoveryEventArgs>? _rediscoveryHandler;
|
||||
private EventHandler<HostStatusChangedEventArgs>? _hostStatusHandler;
|
||||
private EventHandler<DriverConnectionLossEventArgs>? _connectionLossHandler;
|
||||
@@ -898,7 +904,10 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
// Announce connectivity to the host so it can clear any comms-lost Quality annotation on this
|
||||
// driver's native alarm conditions (Bad → Good). Fire-and-forget; the host defaults conditions to a
|
||||
// non-Good "waiting for initial data" quality at materialise, and this is what confirms them Good.
|
||||
Context.Parent.Tell(new ConnectivityChanged(_driverInstanceId, Connected: true, ProducerIncarnation: _sourceIncarnation));
|
||||
// A1 review S2: a new connection epoch — a signal the driver raised under an earlier one is dropped below.
|
||||
var epoch = Interlocked.Increment(ref _connectionEpoch);
|
||||
Context.Parent.Tell(new ConnectivityChanged(_driverInstanceId, Connected: true, ProducerIncarnation: _sourceIncarnation,
|
||||
ConnectionEpoch: epoch));
|
||||
|
||||
// Baseline for the comms-loss watchdog. Re-stamped on every Connected entry so a driver that
|
||||
// reconnects but never manages a read is measured from THIS connect, not from a stale earlier one.
|
||||
@@ -1000,7 +1009,18 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
// project it to the parent the same way DataChangeForward projects AttributeValueBatchPublished.
|
||||
Receive<NativeAlarmRaised>(m => Context.Parent.Tell(new AttributeAlarmPublished(_driverInstanceId, m.Args)));
|
||||
// A1 F2: the same mailbox and the same forward, so the signal follows every alarm event raised before it.
|
||||
Receive<NativeAlarmInitialState>(m => Context.Parent.Tell(new AlarmInitialStatePublished(_driverInstanceId, m.Args)));
|
||||
// Review S2: a signal raised under an earlier connection (queued across a Connected→Reconnecting→Connected
|
||||
// bounce, e.g. while an async reconnect held the mailbox) covers events of a feed that no longer exists — drop it.
|
||||
Receive<NativeAlarmInitialState>(m =>
|
||||
{
|
||||
if (m.Epoch != Interlocked.Read(ref _connectionEpoch))
|
||||
{
|
||||
_log.Debug("DriverInstance {Id}: initial alarm-state signal from an earlier connection — dropped", _driverInstanceId);
|
||||
return;
|
||||
}
|
||||
|
||||
Context.Parent.Tell(new AlarmInitialStatePublished(_driverInstanceId, m.Args, m.Epoch));
|
||||
});
|
||||
// ResubscribeDesired self-Tells Subscribe; HandleSubscribeAsync replies SubscriptionEstablished to the
|
||||
// sender, which on the self-resubscribe path is Self. Swallow it (trace only) so it doesn't dead-letter.
|
||||
Receive<SubscriptionEstablished>(msg =>
|
||||
@@ -2557,7 +2577,7 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
src.OnAlarmEvent += _alarmEventHandler;
|
||||
if (_driver is IAlarmInitialStateSignal signal)
|
||||
{
|
||||
_alarmInitialStateHandler = (_, e) => self.Tell(new NativeAlarmInitialState(e));
|
||||
_alarmInitialStateHandler = (_, e) => self.Tell(new NativeAlarmInitialState(e, Interlocked.Read(ref _connectionEpoch)));
|
||||
signal.InitialAlarmStateDelivered += _alarmInitialStateHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1176,7 +1176,8 @@ public sealed class OpcUaPublishActor : ReceiveActor, IWithTimers
|
||||
var discarded = 0;
|
||||
foreach (var mark in _deferred.Marks)
|
||||
{
|
||||
if (_deferred.SourceLost(mark.Source))
|
||||
// A withdrawal (Known: false) is never discarded: it only makes conditions unknown, which is always safe.
|
||||
if (mark.Known && _deferred.SourceLost(mark.Source))
|
||||
{
|
||||
discarded++;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user