fix(ablegacy): #1087 cache read plans whose only unresolved refs are deterministic (malformed address / config-rejected); transient misses still uncached
This commit is contained in:
@@ -170,7 +170,7 @@ public sealed partial class AbLegacyDriver
|
||||
}
|
||||
|
||||
/// <summary>The planned, device-bucketed form of one read's reference list (#1073).</summary>
|
||||
private sealed record ReadPlan((int Index, uint Status)[] Unresolved, DevicePlan[] Devices);
|
||||
private sealed record ReadPlan((int Index, uint Status)[] Unresolved, DevicePlan[] Devices, bool HasTransient = false);
|
||||
|
||||
/// <summary>One device's units, planned with no block refusal applied (see <see cref="ApplyRefusedBlocks"/>).</summary>
|
||||
private sealed record DevicePlan(DeviceState Device, List<ReadUnit> Units);
|
||||
@@ -221,9 +221,10 @@ public sealed partial class AbLegacyDriver
|
||||
if (cache.Plans.TryGetValue(key, out var hit)) return hit;
|
||||
var plan = BuildReadPlan(devices, key);
|
||||
Interlocked.Increment(ref _readPlanBuilds);
|
||||
// Only a plan with no Unresolved entries is cached: an unresolved reference may resolve later (a transient
|
||||
// equipment-tag parse), and caching would pin the Bad answer.
|
||||
if (plan.Unresolved.Length == 0)
|
||||
// A plan is cached unless it holds a TRANSIENT unresolved reference (resolver miss / unknown device: it may
|
||||
// resolve later, and caching would pin the Bad answer). Deterministic refusals - a malformed address or a
|
||||
// config-rejected tag - are cached (#1087); both only change on re-initialise, which drops the cache.
|
||||
if (!plan.HasTransient)
|
||||
{
|
||||
if (cache.Plans.Count >= MaxCachedReadPlans) cache.Plans.Clear();
|
||||
cache.Plans[key] = plan;
|
||||
@@ -244,6 +245,7 @@ public sealed partial class AbLegacyDriver
|
||||
private ReadPlan BuildReadPlan(Dictionary<string, DeviceState> devices, string[] references)
|
||||
{
|
||||
var unresolved = new List<(int, uint)>();
|
||||
var transient = false;
|
||||
var buckets = new Dictionary<DeviceState, List<ReadItem>>(ReferenceEqualityComparer.Instance);
|
||||
for (var i = 0; i < references.Length; i++)
|
||||
{
|
||||
@@ -251,6 +253,7 @@ public sealed partial class AbLegacyDriver
|
||||
if (!_resolver.TryResolve(reference, out var def) || !devices.TryGetValue(def.DeviceHostAddress, out var device))
|
||||
{
|
||||
unresolved.Add((i, AbLegacyStatusMapper.BadNodeIdUnknown));
|
||||
transient = true;
|
||||
continue;
|
||||
}
|
||||
// A tag whose data type its device's PLC family does not ship is a per-tag configuration error: answered
|
||||
@@ -271,7 +274,8 @@ public sealed partial class AbLegacyDriver
|
||||
list.Add(new ReadItem(i, reference, def, parsed));
|
||||
}
|
||||
return new ReadPlan([.. unresolved],
|
||||
[.. buckets.Select(kv => new DevicePlan(kv.Key, PlanReadUnits(kv.Key, kv.Value, applyRefusals: false)))]);
|
||||
[.. buckets.Select(kv => new DevicePlan(kv.Key, PlanReadUnits(kv.Key, kv.Value, applyRefusals: false)))],
|
||||
transient);
|
||||
}
|
||||
|
||||
/// <summary>What a block read concluded; <see cref="Fallback"/> = read the members singly instead.</summary>
|
||||
|
||||
Reference in New Issue
Block a user