Merge driver follow-ups A: Modbus RTU response correlation + cancel redial + rebuild e2e (#1029/#1055), MTConnect malformed-item BadDecodingError + cross-chunk condition severity (#1055/#1037), TwinCAT write fail-fast + retired-client reads (#1035), OpcUaClient skipped-tag ledger append + zone-qualified IPv6 probe (#1039)
This commit is contained in:
@@ -124,6 +124,16 @@ public sealed class SkippedTagLedger
|
||||
private int _stagedAuthored;
|
||||
private int _stagedSkipped;
|
||||
private List<SkippedTag>? _stagedSample;
|
||||
private HashSet<string>? _stagedPaths;
|
||||
|
||||
// What the VISIBLE report was built from, kept so a late Append / Withdraw can recompute it (#1039).
|
||||
private int _builtAuthored;
|
||||
private int _builtSkipped;
|
||||
private List<SkippedTag> _builtSample = [];
|
||||
private HashSet<string> _builtPaths = [];
|
||||
|
||||
/// <summary>Skips noticed AFTER the build (a subscribe-time refusal), in encounter order. Reset by every rebuild.</summary>
|
||||
private readonly List<SkippedTag> _appended = [];
|
||||
|
||||
/// <summary>
|
||||
/// Starts staging a new tag-table build. The visible snapshot is left alone until
|
||||
@@ -137,6 +147,7 @@ public sealed class SkippedTagLedger
|
||||
_stagedAuthored = authoredCount;
|
||||
_stagedSkipped = 0;
|
||||
_stagedSample = new List<SkippedTag>(Math.Min(authoredCount, MaxSample));
|
||||
_stagedPaths = new HashSet<string>(StringComparer.Ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,11 +165,75 @@ public sealed class SkippedTagLedger
|
||||
{
|
||||
if (_stagedSample is null) return;
|
||||
_stagedSkipped++;
|
||||
_stagedPaths?.Add(rawPath ?? "");
|
||||
if (_stagedSample.Count < MaxSample)
|
||||
_stagedSample.Add(new SkippedTag(rawPath ?? "", reason ?? ""));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records a skip that was only discovered AFTER the build, against the already-visible report (#1039) — e.g. the
|
||||
/// upstream server refusing a monitored item at subscribe time. The build-time skips are authored-config
|
||||
/// problems; this is the same operator signal for a tag that only fails once the driver dials the device. Idempotent
|
||||
/// per raw path (a subscribe retried every health tick must not inflate the count); a path the build already
|
||||
/// skipped is not counted twice. A no-op before the first <see cref="Commit"/> ("no answer yet" is never turned
|
||||
/// into a report), and cleared by the next <see cref="BeginRebuild"/>/<see cref="Commit"/> — a re-initialise
|
||||
/// re-subscribes and re-appends what is still refused.
|
||||
/// </summary>
|
||||
/// <param name="rawPath">The authored raw path that was refused.</param>
|
||||
/// <param name="reason">Operator-facing reason; should name the offending status.</param>
|
||||
/// <returns><see langword="true"/> when the report changed.</returns>
|
||||
public bool Append(string rawPath, string reason)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_visible is null) return false;
|
||||
rawPath ??= "";
|
||||
if (_builtPaths.Contains(rawPath)) return false;
|
||||
var existing = _appended.FindIndex(s => string.Equals(s.RawPath, rawPath, StringComparison.Ordinal));
|
||||
if (existing >= 0)
|
||||
{
|
||||
if (_appended[existing].Reason == (reason ?? "")) return false;
|
||||
_appended[existing] = new SkippedTag(rawPath, reason ?? "");
|
||||
}
|
||||
else
|
||||
{
|
||||
_appended.Add(new SkippedTag(rawPath, reason ?? ""));
|
||||
}
|
||||
Republish();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Withdraws a skip recorded by <see cref="Append"/> — the ref now has its upstream item (a later subscribe
|
||||
/// succeeded), so it must stop being reported. Build-time skips are never withdrawn.
|
||||
/// </summary>
|
||||
/// <param name="rawPath">The raw path that is no longer refused.</param>
|
||||
/// <returns><see langword="true"/> when the report changed.</returns>
|
||||
public bool Withdraw(string rawPath)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_appended.Count == 0) return false;
|
||||
var removed = _appended.RemoveAll(s => string.Equals(s.RawPath, rawPath ?? "", StringComparison.Ordinal)) > 0;
|
||||
if (removed) Republish();
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Rebuilds the visible report from the committed build + the appended skips. Caller holds the gate.</summary>
|
||||
private void Republish()
|
||||
{
|
||||
var sample = new List<SkippedTag>(_builtSample);
|
||||
foreach (var a in _appended)
|
||||
{
|
||||
if (sample.Count >= MaxSample) break;
|
||||
sample.Add(a);
|
||||
}
|
||||
_visible = new SkippedTagReport(_builtAuthored, _builtSkipped + _appended.Count, sample);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes the staged build as the visible snapshot, atomically. A call with no staged build
|
||||
/// is a no-op.
|
||||
@@ -168,8 +243,14 @@ public sealed class SkippedTagLedger
|
||||
lock (_gate)
|
||||
{
|
||||
if (_stagedSample is null) return;
|
||||
_visible = new SkippedTagReport(_stagedAuthored, _stagedSkipped, _stagedSample);
|
||||
_builtAuthored = _stagedAuthored;
|
||||
_builtSkipped = _stagedSkipped;
|
||||
_builtSample = _stagedSample;
|
||||
_builtPaths = _stagedPaths ?? [];
|
||||
_appended.Clear();
|
||||
_visible = new SkippedTagReport(_stagedAuthored, _stagedSkipped, _builtSample);
|
||||
_stagedSample = null;
|
||||
_stagedPaths = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user