fix(galaxy): clear told-active alarms absent from a complete snapshot (#944); handle provider_status/snapshot_status, withhold truncated snapshots (#945)
#944: a snapshot/QueryActiveAlarms lists active alarms only, so a Clear dropped while the host's OnAlarmEvent handler was detached (or the stream was down) was never recovered. The driver records which alarms it delivered as active; on a COMPLETE read (sentinel or re-read, new IGalaxyAlarmFeed.ActiveSetDelivered, raised under the dispatch lock) it synthesises a restatement Clear for told-active alarms of the live subscription the read does not name, before the known-state signal. A re-read counts alarms the live stream restated meanwhile as present. #945: provider_status / snapshot_status no longer fall to the decode-failure default (logged + counters). A snapshot flagged truncated (snapshot_status or per-record flag) is not complete: no sweep, no known-state signal; when the gateway clears the verdict the driver re-reads. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -173,6 +173,12 @@ public sealed class GalaxyDriver
|
||||
// _alarmHandlersLock). A subscription that becomes live after that point gets no sentinel of its own until the
|
||||
// stream reopens, so it is established by a re-read of the active-alarm set instead.
|
||||
private bool _streamSnapshotDelivered;
|
||||
// lmxopcua#944: the alarms (keyed by ConditionId = RawPath) whose last state the driver actually DELIVERED to a
|
||||
// OnAlarmEvent handler as active (Raise / Retrigger / ActiveAcknowledged), with the transition that said so (the
|
||||
// template of a synthesised Clear). A Clear delivered removes the entry; one dropped (no alarm subscription, or the
|
||||
// host actor had detached its handler) does not, so a complete snapshot that no longer lists the alarm can still
|
||||
// clear it. Guarded by _alarmHandlersLock.
|
||||
private readonly Dictionary<string, GalaxyAlarmTransition> _toldActive = new(StringComparer.Ordinal);
|
||||
// lmxopcua#925: the active-alarm re-read coalescer — 0 idle, 1 running, 2 running with another run requested.
|
||||
private int _alarmRefreshState;
|
||||
// Cancelled (and replaced) by every runtime teardown, so an in-flight re-read or its retry wait stops quietly.
|
||||
@@ -1097,6 +1103,8 @@ public sealed class GalaxyDriver
|
||||
alarmFeed.OnAlarmTransition -= OnAlarmFeedTransition;
|
||||
alarmFeed.SnapshotDelivered -= OnAlarmFeedSnapshotDelivered;
|
||||
alarmFeed.StreamOpened -= OnAlarmFeedStreamOpened;
|
||||
alarmFeed.ActiveSetDelivered -= OnAlarmFeedActiveSetDelivered;
|
||||
alarmFeed.SnapshotTruncationCleared -= OnAlarmFeedSnapshotTruncationCleared;
|
||||
_alarmFeedWired = false;
|
||||
}
|
||||
if (releaseFeed) _alarmFeed = null;
|
||||
@@ -2760,6 +2768,8 @@ public sealed class GalaxyDriver
|
||||
_alarmFeed.OnAlarmTransition += OnAlarmFeedTransition;
|
||||
_alarmFeed.SnapshotDelivered += OnAlarmFeedSnapshotDelivered;
|
||||
_alarmFeed.StreamOpened += OnAlarmFeedStreamOpened;
|
||||
_alarmFeed.ActiveSetDelivered += OnAlarmFeedActiveSetDelivered;
|
||||
_alarmFeed.SnapshotTruncationCleared += OnAlarmFeedSnapshotTruncationCleared;
|
||||
_alarmFeed.Start();
|
||||
_alarmFeedWired = true;
|
||||
}
|
||||
@@ -3046,9 +3056,26 @@ public sealed class GalaxyDriver
|
||||
},
|
||||
// A snapshot entry re-states upstream state — history-only signal for the host.
|
||||
IsRestatement: transition.IsRestatement);
|
||||
var sink = OnAlarmEvent;
|
||||
if (sink is null) return; // nobody attached (the host actor detached its handler): not told, so not recorded
|
||||
// lmxopcua#944: what the host is now told, for the clear-absent sweep.
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
switch (transition.TransitionKind)
|
||||
{
|
||||
case GalaxyAlarmTransitionKind.Raise:
|
||||
case GalaxyAlarmTransitionKind.Retrigger:
|
||||
case GalaxyAlarmTransitionKind.ActiveAcknowledged:
|
||||
_toldActive[conditionRawPath] = transition;
|
||||
break;
|
||||
case GalaxyAlarmTransitionKind.Clear:
|
||||
_toldActive.Remove(conditionRawPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
OnAlarmEvent?.Invoke(this, args);
|
||||
sink.Invoke(this, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -3058,6 +3085,59 @@ public sealed class GalaxyDriver
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#944: the feed read the gateway's COMPLETE active-alarm set (a stream sentinel or a re-read). A
|
||||
/// snapshot lists ACTIVE alarms only, so an alarm the host was last told was active that is absent from it has
|
||||
/// cleared — and its live <c>Clear</c> was dropped while no handler / no alarm subscription was attached (a
|
||||
/// stream gap or a detached <c>DriverInstanceActor</c> handler). Each such alarm of the live subscription gets a
|
||||
/// synthesised, restatement-flagged Clear through the normal bridge, before the known-state signal. Runs on the
|
||||
/// feed thread, serialised with live dispatch, so no live message can interleave. A truncated set never reaches here (#945).
|
||||
/// </summary>
|
||||
private void OnAlarmFeedActiveSetDelivered(object? sender, GalaxyAlarmSetEventArgs e)
|
||||
{
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
if (_toldActive.Count == 0 || _alarmSubscriptions.Count == 0) return;
|
||||
}
|
||||
|
||||
var present = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var alarm in e.Present)
|
||||
present.Add(ResolveAlarmRawPath(alarm.AlarmFullReference, alarm.SourceObjectReference));
|
||||
|
||||
List<GalaxyAlarmTransition> stale = [];
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
if (_alarmSubscriptions.Count == 0) return;
|
||||
var subscribed = new HashSet<string>(_alarmSubscriptionRefs, StringComparer.Ordinal);
|
||||
foreach (var (conditionId, told) in _toldActive)
|
||||
{
|
||||
if (subscribed.Contains(conditionId) && !present.Contains(conditionId)) stale.Add(told);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var told in stale)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"GalaxyDriver alarm {AlarmRef} was last reported active but is absent from the gateway's complete active-alarm set — clearing it (its Clear was missed while the alarm handler or subscription was detached).",
|
||||
told.AlarmFullReference);
|
||||
OnAlarmFeedTransition(this, told with
|
||||
{
|
||||
TransitionKind = GalaxyAlarmTransitionKind.Clear,
|
||||
TransitionTimestampUtc = DateTime.UtcNow,
|
||||
OperatorUser = string.Empty,
|
||||
OperatorComment = string.Empty,
|
||||
IsRestatement = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#945: the gateway stopped flagging its active-alarm set as truncated after a read was withheld for it —
|
||||
/// re-read the (now complete) set so the withheld sweep and known-state signal happen.
|
||||
/// </summary>
|
||||
private void OnAlarmFeedSnapshotTruncationCleared(object? sender, EventArgs e) =>
|
||||
RequestAlarmSnapshotRefresh("the gateway cleared its truncated-snapshot verdict");
|
||||
|
||||
/// <summary>A1 review round 2 F4: a feed stream (re)opened — record the subscription its snapshot is delivered under.</summary>
|
||||
private void OnAlarmFeedStreamOpened(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -63,7 +63,16 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
description: "Alarm feed messages decoded and forwarded to driver-level handlers.");
|
||||
private static readonly Counter<long> AlarmTransitionsDecodingFailures =
|
||||
Meter.CreateCounter<long>("galaxy.alarm_feed.transitions.decoding_failures", unit: "{event}",
|
||||
description: "Alarm feed messages dropped for a missing body or unspecified transition kind.");
|
||||
description: "Alarm feed messages dropped for an unrecognised payload or an unspecified transition/condition kind.");
|
||||
private static readonly Counter<long> AlarmProviderStatusFrames =
|
||||
Meter.CreateCounter<long>("galaxy.alarm_feed.provider_status", unit: "{frame}",
|
||||
description: "provider_status frames received on the alarm stream (lmxopcua#945); tagged by provider mode and degraded.");
|
||||
private static readonly Counter<long> AlarmSnapshotStatusFrames =
|
||||
Meter.CreateCounter<long>("galaxy.alarm_feed.snapshot_status", unit: "{frame}",
|
||||
description: "snapshot_status frames received on the alarm stream (lmxopcua#945); tagged by the truncated verdict.");
|
||||
private static readonly Counter<long> AlarmSnapshotsWithheld =
|
||||
Meter.CreateCounter<long>("galaxy.alarm_feed.snapshot_withheld", unit: "{snapshot}",
|
||||
description: "Active-alarm snapshots (stream sentinels or re-reads) not vouched complete because the gateway flagged the set as truncated (lmxopcua#945).");
|
||||
private static readonly Counter<long> AlarmSnapshotRefreshes =
|
||||
Meter.CreateCounter<long>("galaxy.alarm_feed.snapshot_refreshes", unit: "{refresh}",
|
||||
description: "Active-alarm set re-reads (QueryActiveAlarms) completed while the alarm stream stayed open (lmxopcua#925).");
|
||||
@@ -83,7 +92,9 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
// The alarms the live stream delivered a message for since the in-flight re-read was issued (null when none is in
|
||||
// flight), mapped to whether any of them carried the FULL state (snapshot entry, Raise, Retrigger, Clear) — true —
|
||||
// or only the ack dimension (Acknowledge) — false. Guarded by _dispatchLock.
|
||||
private Dictionary<string, bool>? _touchedDuringRefresh;
|
||||
private Dictionary<string, Touched>? _touchedDuringRefresh;
|
||||
|
||||
private readonly record struct Touched(bool FullState, string SourceObjectReference);
|
||||
// Review r1 #2: bumped (under _dispatchLock) each time a stream is (re)opened, before any of its messages. A
|
||||
// re-read replays only if no stream opened since it was issued: an alarm that cleared in a reopen gap is merely
|
||||
// ABSENT from the new snapshot, so the touched map cannot catch the re-read's stale entry for it.
|
||||
@@ -91,6 +102,18 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
// Whether the current stream has delivered its snapshot_complete sentinel. Guarded by _dispatchLock. A re-read is
|
||||
// pointless (and could signal mid-snapshot) while it has not: that stream's own sentinel covers the subscription.
|
||||
private bool _streamSnapshotComplete;
|
||||
// lmxopcua#944: the alarms the current stream's snapshot phase delivered (before its sentinel) — what the sentinel
|
||||
// vouches is standing. Cleared when a stream opens. Guarded by _dispatchLock.
|
||||
private readonly List<GalaxyAlarmIdentity> _streamSnapshotEntries = new();
|
||||
// lmxopcua#945: the gateway's latest snapshot_status verdict on the current stream (null until one arrives — an
|
||||
// older gateway sends none), and whether a snapshot entry of this stream carried the per-record truncation flag.
|
||||
// Guarded by _dispatchLock; reset when a stream opens.
|
||||
private bool? _statusTruncated;
|
||||
private bool _entryTruncated;
|
||||
// lmxopcua#945: a read (sentinel or re-read) was withheld as truncated; the next "no longer truncated" status
|
||||
// frame must tell the driver to re-read. Guarded by _dispatchLock; reset when a stream opens (its own sentinel
|
||||
// re-evaluates the verdict).
|
||||
private bool _awaitingCompleteSet;
|
||||
// One re-read at a time (a second one waits for the first).
|
||||
private readonly SemaphoreSlim _refreshGate = new(1, 1);
|
||||
private readonly ILogger _logger;
|
||||
@@ -114,6 +137,12 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? StreamOpened;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<GalaxyAlarmSetEventArgs>? ActiveSetDelivered;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? SnapshotTruncationCleared;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="GatewayGalaxyAlarmFeed"/> class.</summary>
|
||||
/// <param name="streamFactory">A factory delegate that opens the alarm stream.</param>
|
||||
/// <param name="logger">An optional logger for diagnostic output.</param>
|
||||
@@ -174,6 +203,10 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
{
|
||||
_streamEpoch++;
|
||||
_streamSnapshotComplete = false;
|
||||
_streamSnapshotEntries.Clear();
|
||||
_statusTruncated = null;
|
||||
_entryTruncated = false;
|
||||
_awaitingCompleteSet = false;
|
||||
}
|
||||
|
||||
// A1 review round 2 F4: before any message of this stream, on this (the dispatch) thread.
|
||||
@@ -225,7 +258,7 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
{
|
||||
// Track BEFORE the query is issued: any live message dispatched from here on may be newer than the
|
||||
// query's view of that alarm.
|
||||
var touched = new Dictionary<string, bool>(StringComparer.Ordinal);
|
||||
var touched = new Dictionary<string, Touched>(StringComparer.Ordinal);
|
||||
long epoch;
|
||||
lock (_dispatchLock)
|
||||
{
|
||||
@@ -248,6 +281,7 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
}
|
||||
|
||||
var superseded = 0;
|
||||
var complete = false;
|
||||
lock (_dispatchLock)
|
||||
{
|
||||
linked.Token.ThrowIfCancellationRequested();
|
||||
@@ -260,11 +294,11 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
}
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
if (!touched.TryGetValue(entry.AlarmFullReference, out var fullState))
|
||||
if (!touched.TryGetValue(entry.AlarmFullReference, out var touch))
|
||||
{
|
||||
DispatchSnapshotEntry(entry);
|
||||
}
|
||||
else if (fullState)
|
||||
else if (touch.FullState)
|
||||
{
|
||||
superseded++; // a newer full statement of this alarm already reached the host
|
||||
}
|
||||
@@ -277,6 +311,33 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
: entry);
|
||||
}
|
||||
}
|
||||
|
||||
// lmxopcua#945: a set the gateway flagged as truncated (a per-record flag, or the stream's latest
|
||||
// snapshot_status) is not vouched complete - absence from it proves nothing, so no sweep and no signal.
|
||||
var truncated = _statusTruncated == true || entries.Exists(e => e.FromTruncatedSnapshot);
|
||||
if (truncated)
|
||||
{
|
||||
// Wait for the gateway's "no longer truncated" frame. If the status already says false (the read
|
||||
// straddled the clearing frame) nothing will announce it again, and re-reading from here could
|
||||
// loop on an inconsistent gateway: stay unknown until the next stream sentinel / subscription
|
||||
// refresh instead (bounded).
|
||||
_awaitingCompleteSet = _statusTruncated != false;
|
||||
AlarmSnapshotsWithheld.Add(1, _clientTag);
|
||||
_logger.LogWarning(
|
||||
"Galaxy alarm feed re-read returned a snapshot the gateway flagged as truncated - the active-alarm set may be incomplete; not treating it as complete until the gateway clears the verdict.");
|
||||
}
|
||||
else
|
||||
{
|
||||
complete = true;
|
||||
// lmxopcua#944: every alarm this read names, plus the ones the live stream restated meanwhile
|
||||
// (the query may predate their raise). Serialised with live dispatch by the lock held here.
|
||||
var present = new List<GalaxyAlarmIdentity>(entries.Count + touched.Count);
|
||||
foreach (var entry in entries)
|
||||
present.Add(new GalaxyAlarmIdentity(entry.AlarmFullReference, entry.SourceObjectReference));
|
||||
foreach (var (reference, touch) in touched)
|
||||
present.Add(new GalaxyAlarmIdentity(reference, touch.SourceObjectReference));
|
||||
RaiseActiveSetDelivered(present);
|
||||
}
|
||||
}
|
||||
|
||||
AlarmSnapshotRefreshes.Add(1, _clientTag);
|
||||
@@ -284,7 +345,7 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
_logger.LogDebug(
|
||||
"Galaxy alarm feed re-read the active-alarm set: {Count} entr(ies) replayed, {Superseded} superseded by the live stream.",
|
||||
entries.Count - superseded, superseded);
|
||||
return true;
|
||||
return complete;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -305,10 +366,11 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
}
|
||||
|
||||
/// <summary>Under <see cref="_dispatchLock"/>: note a live message for an alarm while a re-read is in flight.</summary>
|
||||
private void NoteTouched(string reference, bool fullState)
|
||||
private void NoteTouched(string reference, string sourceObjectReference, bool fullState)
|
||||
{
|
||||
if (_touchedDuringRefresh is not { } touched) return;
|
||||
touched[reference] = fullState || (touched.TryGetValue(reference, out var prior) && prior);
|
||||
touched[reference] = new Touched(
|
||||
fullState || (touched.TryGetValue(reference, out var prior) && prior.FullState), sourceObjectReference);
|
||||
}
|
||||
|
||||
private void Dispatch(AlarmFeedMessage message)
|
||||
@@ -324,12 +386,18 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
switch (message.PayloadCase)
|
||||
{
|
||||
case AlarmFeedMessage.PayloadOneofCase.ActiveAlarm:
|
||||
NoteTouched(message.ActiveAlarm.AlarmFullReference, fullState: true);
|
||||
NoteTouched(message.ActiveAlarm.AlarmFullReference, message.ActiveAlarm.SourceObjectReference, fullState: true);
|
||||
if (!_streamSnapshotComplete)
|
||||
{
|
||||
_streamSnapshotEntries.Add(new GalaxyAlarmIdentity(
|
||||
message.ActiveAlarm.AlarmFullReference, message.ActiveAlarm.SourceObjectReference));
|
||||
if (message.ActiveAlarm.FromTruncatedSnapshot) _entryTruncated = true;
|
||||
}
|
||||
DispatchSnapshotEntry(message.ActiveAlarm);
|
||||
break;
|
||||
case AlarmFeedMessage.PayloadOneofCase.Transition:
|
||||
// An Acknowledge carries only the ack dimension; every other kind restates the active state too.
|
||||
NoteTouched(message.Transition.AlarmFullReference,
|
||||
NoteTouched(message.Transition.AlarmFullReference, message.Transition.SourceObjectReference,
|
||||
fullState: message.Transition.TransitionKind != AlarmTransitionKind.Acknowledge);
|
||||
DispatchTransition(message.Transition);
|
||||
break;
|
||||
@@ -337,10 +405,46 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
_logger.LogDebug("Galaxy alarm feed active-alarm snapshot complete.");
|
||||
_initialSnapshot.TrySetResult();
|
||||
_streamSnapshotComplete = true; // before the signal, whose handler may request a re-read
|
||||
// grpc-data A1: the ordered per-sentinel signal — on THIS thread, after the snapshot entries above
|
||||
if (_statusTruncated ?? _entryTruncated)
|
||||
{
|
||||
// lmxopcua#945: the gateway flagged this snapshot as possibly missing alarms. Its entries were raised,
|
||||
// but it does not vouch for the set: no sweep of absent alarms and no known-state signal until the
|
||||
// verdict clears (then the driver re-reads - SnapshotTruncationCleared).
|
||||
_awaitingCompleteSet = true;
|
||||
AlarmSnapshotsWithheld.Add(1, _clientTag);
|
||||
_logger.LogWarning(
|
||||
"Galaxy alarm feed snapshot ({Count} entr(ies)) was flagged truncated by the gateway - the active-alarm set may be incomplete; initial alarm state is not signalled until the gateway clears the verdict.",
|
||||
_streamSnapshotEntries.Count);
|
||||
break;
|
||||
}
|
||||
// lmxopcua#944: the complete set first, so an absent-alarm clear precedes the known-state signal.
|
||||
RaiseActiveSetDelivered(_streamSnapshotEntries.ToArray());
|
||||
// grpc-data A1: the ordered per-sentinel signal - on THIS thread, after the snapshot entries above
|
||||
// were raised; every reopened stream's sentinel raises it again.
|
||||
RaiseSnapshotDelivered();
|
||||
break;
|
||||
case AlarmFeedMessage.PayloadOneofCase.ProviderStatus:
|
||||
// lmxopcua#945: informational - the gateway's alarm provider mode (failover/failback). Not a decode failure.
|
||||
AlarmProviderStatusFrames.Add(1,
|
||||
_clientTag,
|
||||
new KeyValuePair<string, object?>("mode", message.ProviderStatus.Mode.ToString()),
|
||||
new KeyValuePair<string, object?>("degraded", message.ProviderStatus.Degraded));
|
||||
if (message.ProviderStatus.Degraded)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Galaxy alarm feed provider status: {Mode} (degraded) since {Since:o} - {Reason}",
|
||||
message.ProviderStatus.Mode, message.ProviderStatus.Since?.ToDateTime(), message.ProviderStatus.Reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Galaxy alarm feed provider status: {Mode} - {Reason}",
|
||||
message.ProviderStatus.Mode, message.ProviderStatus.Reason);
|
||||
}
|
||||
break;
|
||||
case AlarmFeedMessage.PayloadOneofCase.SnapshotStatus:
|
||||
OnSnapshotStatus(message.SnapshotStatus.Truncated);
|
||||
break;
|
||||
default:
|
||||
// Empty oneof — worker / gateway version skew. Count and drop.
|
||||
AlarmTransitionsDecodingFailures.Add(1, _clientTag);
|
||||
@@ -348,6 +452,26 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Under <see cref="_dispatchLock"/>: the gateway's snapshot-completeness verdict changed or was restated (lmxopcua#945).</summary>
|
||||
private void OnSnapshotStatus(bool truncated)
|
||||
{
|
||||
AlarmSnapshotStatusFrames.Add(1, _clientTag, new KeyValuePair<string, object?>("truncated", truncated));
|
||||
_statusTruncated = truncated;
|
||||
if (truncated)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Galaxy alarm feed snapshot status: the gateway's active-alarm set may be INCOMPLETE (truncated worker fetch) - absent alarms are not cleared and the initial alarm state is not signalled while this holds.");
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Galaxy alarm feed snapshot status: the active-alarm set is complete.");
|
||||
_entryTruncated = false; // the per-record flags described the truncated generation
|
||||
if (_awaitingCompleteSet)
|
||||
{
|
||||
_awaitingCompleteSet = false;
|
||||
RaiseTruncationCleared();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode one entry of the initial active-alarm snapshot. Each currently-active
|
||||
/// alarm is surfaced as a transition so the OPC UA Part 9 condition layer sees
|
||||
@@ -446,6 +570,30 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseActiveSetDelivered(IReadOnlyList<GalaxyAlarmIdentity> present)
|
||||
{
|
||||
try
|
||||
{
|
||||
ActiveSetDelivered?.Invoke(this, new GalaxyAlarmSetEventArgs(present));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Galaxy alarm feed ActiveSetDelivered handler threw - continuing.");
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseTruncationCleared()
|
||||
{
|
||||
try
|
||||
{
|
||||
SnapshotTruncationCleared?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Galaxy alarm feed SnapshotTruncationCleared handler threw - continuing.");
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseSnapshotDelivered()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -69,10 +69,50 @@ internal interface IGalaxyAlarmFeed : IAsyncDisposable
|
||||
/// it would be a phantom transition. An Acknowledge alone is merged instead (an Active entry replays as
|
||||
/// ActiveAcked). Completes true once every entry was raised; false — nothing replayed — when the feed has no
|
||||
/// query, is disposed, the current stream has not delivered its sentinel yet, or a stream (re)opened while the
|
||||
/// query was in flight (that stream's own sentinel then covers the subscription). Throws on an RPC failure.
|
||||
/// Raises no signal itself — the caller decides which subscription the re-read establishes.
|
||||
/// query was in flight (that stream's own sentinel then covers the subscription), or the gateway flagged the set
|
||||
/// as possibly truncated (#945 — the entries ARE still replayed, but the set is not vouched complete, so
|
||||
/// <see cref="ActiveSetDelivered"/> is not raised and the caller must not signal). Throws on an RPC failure.
|
||||
/// Raises no signal itself — the caller decides which subscription the re-read establishes. On a COMPLETE
|
||||
/// re-read it raises <see cref="ActiveSetDelivered"/> (synchronously, before returning).
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A cancellation token.</param>
|
||||
/// <returns>True when the set was re-read and its entries raised.</returns>
|
||||
Task<bool> RefreshSnapshotAsync(CancellationToken cancellationToken) => Task.FromResult(false);
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#944: raised synchronously on the feed thread, serialised with live dispatch, each time the feed has
|
||||
/// read the gateway's COMPLETE active-alarm set — a stream's <c>snapshot_complete</c> sentinel (before
|
||||
/// <see cref="SnapshotDelivered"/>) or a successful <see cref="RefreshSnapshotAsync"/> re-read — after every
|
||||
/// entry was raised on <see cref="OnAlarmTransition"/>. Carries the alarms that read vouches are standing (or
|
||||
/// were just restated by the live stream); a snapshot lists ACTIVE alarms only, so the driver clears any alarm
|
||||
/// it last told the host was active that is absent from it. Never raised for a set the gateway flagged as
|
||||
/// truncated (#945): absence from a possibly-incomplete set proves nothing. The default accessors make it a
|
||||
/// no-op for feeds with no snapshot phase.
|
||||
/// </summary>
|
||||
event EventHandler<GalaxyAlarmSetEventArgs>? ActiveSetDelivered { add { } remove { } }
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#945: raised synchronously on the feed thread when the gateway's <c>snapshot_status</c> verdict
|
||||
/// goes from truncated back to complete AFTER a read was withheld because it was truncated (<see cref="SnapshotDelivered"/>
|
||||
/// and <see cref="ActiveSetDelivered"/> were not raised for it). The cache is complete now, so the driver
|
||||
/// re-reads the active-alarm set to establish what the withheld read could not. The default accessors make it a no-op.
|
||||
/// </summary>
|
||||
event EventHandler? SnapshotTruncationCleared { add { } remove { } }
|
||||
}
|
||||
|
||||
/// <summary>One alarm named by a <see cref="GalaxyAlarmSetEventArgs"/>: the two references the driver resolves a RawPath from.</summary>
|
||||
/// <param name="AlarmFullReference">The gateway's provider-qualified alarm reference.</param>
|
||||
/// <param name="SourceObjectReference">The source reference (<c>tag.Attr</c>), possibly empty.</param>
|
||||
internal readonly record struct GalaxyAlarmIdentity(string AlarmFullReference, string SourceObjectReference);
|
||||
|
||||
/// <summary>Payload of <see cref="IGalaxyAlarmFeed.ActiveSetDelivered"/> (lmxopcua#944).</summary>
|
||||
internal sealed class GalaxyAlarmSetEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>Creates the payload.</summary>
|
||||
/// <param name="present">Every alarm the complete read named, plus any the live stream restated while a re-read was in flight.</param>
|
||||
public GalaxyAlarmSetEventArgs(IReadOnlyList<GalaxyAlarmIdentity> present) =>
|
||||
Present = present ?? throw new ArgumentNullException(nameof(present));
|
||||
|
||||
/// <summary>Every alarm the complete read vouches for.</summary>
|
||||
public IReadOnlyList<GalaxyAlarmIdentity> Present { get; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user