fix(historian): read-only historian bindings + ProvisionTags policy; provision OPC UA type names (#899, #898)
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
#899 — EnsureTags is an upsert, so binding a node to an existing AVEVA tag via historianTagname re-typed/re-described it on every add and host start. - TagConfig `historianReadOnly: true` (TagConfigIntent -> RawTagPlan.HistorianReadOnly): HistoryRead from an existing historian tag that OtOpcUa never provisions and never records into (AddressSpaceApplier.IsOwnedHistorizedValue gates both the EnsureTags hook and the recorder feed). Node-inert: surgical, not mirrored on UNS refs, in the RawTagPlan equality/hash. A non-bool value is the deploy error HistorianReadOnlyInvalid. AdminUI: CSV column HistorianReadOnly (strict), TagHistorizeConfig reads via the runtime parse. - ServerHistorian:ProvisionTags = CreateOrUpdate (default, unchanged) | CreateOnly (Gateway only: TagExistsAsync first, existing tags left alone, failed lookup not sent) | Off. Unknown value / CreateOnly on a SQL backend fail host start. - Default for an explicit historianTagname stays OWNED: overrides pin owned history across renames, a read-only default would silently stop provisioning + recording. #898 — the hook parsed Tag.DataType (an OPC UA name) as DriverDataType, so historized Float/Double/Byte/SByte tags were never provisioned. New shared HistorianDataTypeNames.TryResolve: Float->Float32, Double->Float64, Byte/SByte->Int16 (lossless, provisioned as Int2); unmapped names logged at Information. Gateway now skips Int64/UInt64 (HistorianGateway cannot create Int8/UInt8: lossless-cast-or-reject). UPGRADE: the first host start after this provisions (upserts) every existing historized Float/Double/Byte/SByte tag. Mark foreign-tag bindings historianReadOnly, or set ServerHistorian:ProvisionTags=CreateOnly/Off, before upgrading (docs/Historian.md). Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -199,7 +199,13 @@ public sealed class AddressSpaceApplier
|
||||
// notifier wiring, and an alarm-bearing delta never reaches here — the classifier routes it
|
||||
// to Rebuild). So a delta whose ONLY difference is the referencing set needs NOTHING said to
|
||||
// the sink: compare the two sides with the referencing set copied across, and skip on equal.
|
||||
if ((d.Previous with { ReferencingEquipmentPaths = d.Current.ReferencingEquipmentPaths }).Equals(d.Current))
|
||||
// HistorianReadOnly (lmxopcua#899) is node-inert the same way: it only steers the provisioning
|
||||
// hook and the recorder feed below, never the node's attributes.
|
||||
if ((d.Previous with
|
||||
{
|
||||
ReferencingEquipmentPaths = d.Current.ReferencingEquipmentPaths,
|
||||
HistorianReadOnly = d.Current.HistorianReadOnly,
|
||||
}).Equals(d.Current))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -621,6 +627,15 @@ public sealed class AddressSpaceApplier
|
||||
private static string ResolveHistorianName(RawTagPlan tag) =>
|
||||
string.IsNullOrWhiteSpace(tag.HistorianTagname) ? tag.NodeId : tag.HistorianTagname;
|
||||
|
||||
/// <summary>
|
||||
/// A historized value tag (not a native-alarm condition) whose historian tag OtOpcUa OWNS — i.e. not a
|
||||
/// read-only binding (<see cref="RawTagPlan.HistorianReadOnly"/>, lmxopcua#899). Only these are provisioned
|
||||
/// (<c>EnsureTags</c>) and fed to the continuous-historization recorder; a read-only binding still serves
|
||||
/// HistoryRead from the existing historian tag, which OtOpcUa never creates, modifies or writes.
|
||||
/// </summary>
|
||||
private static bool IsOwnedHistorizedValue(RawTagPlan tag) =>
|
||||
tag.IsHistorized && tag.Alarm is null && !tag.HistorianReadOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Auto-provision the historian for the added (and newly-historized / renamed-historian) raw tags. Runs on the OPC UA
|
||||
/// publish actor's pinned thread, so the synchronous portion is kept to building the request
|
||||
@@ -639,7 +654,7 @@ public sealed class AddressSpaceApplier
|
||||
// and skip them.
|
||||
foreach (var tag in plan.AddedRawTags)
|
||||
{
|
||||
if (!tag.IsHistorized || tag.Alarm is not null) continue;
|
||||
if (!IsOwnedHistorizedValue(tag)) continue;
|
||||
AddRequest(tag);
|
||||
}
|
||||
|
||||
@@ -647,12 +662,14 @@ public sealed class AddressSpaceApplier
|
||||
// EXISTING raw tag never appears in AddedRawTags, so EnsureTags never fired for it. EnsureTags is
|
||||
// an upsert, so re-ensuring is safe; an unchanged pair is a no-op. Only raw deltas are used - a
|
||||
// UNS mirror delta must not double-provision the same historian tag.
|
||||
// A read-only binding (lmxopcua#899) is never provisioned; flipping read-only OFF counts as becoming
|
||||
// owned, so it provisions like a historization flip.
|
||||
foreach (var d in plan.ChangedRawTags)
|
||||
{
|
||||
var cur = d.Current;
|
||||
if (!cur.IsHistorized || cur.Alarm is not null) continue;
|
||||
if (!IsOwnedHistorizedValue(cur)) continue;
|
||||
var prev = d.Previous;
|
||||
var wasProvisioned = prev.IsHistorized && prev.Alarm is null;
|
||||
var wasProvisioned = IsOwnedHistorizedValue(prev);
|
||||
if (wasProvisioned
|
||||
&& ResolveHistorianName(prev) == ResolveHistorianName(cur)
|
||||
&& string.Equals(prev.DataType, cur.DataType, StringComparison.OrdinalIgnoreCase))
|
||||
@@ -662,12 +679,15 @@ public sealed class AddressSpaceApplier
|
||||
|
||||
void AddRequest(RawTagPlan tag)
|
||||
{
|
||||
// An unparseable data type is skipped (logged at Debug) rather than faulting the hook.
|
||||
if (!Enum.TryParse<DriverDataType>(tag.DataType, ignoreCase: true, out var dataType))
|
||||
// Tag.DataType is an OPC UA built-in name (Float, Double, Byte, …); resolve it with the shared
|
||||
// map (lmxopcua#898 — a bare Enum.TryParse<DriverDataType> silently skipped Float/Double/Byte/SByte).
|
||||
// A type with no historian mapping (Guid, ByteString, …) is skipped rather than faulting the hook,
|
||||
// at Information so a historized tag that never provisions is visible without Debug logging.
|
||||
if (!HistorianDataTypeNames.TryResolve(tag.DataType, out var dataType))
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"AddressSpaceApplier: skipping historian provisioning for a historized tag whose data type '{DataType}' is not a DriverDataType",
|
||||
tag.DataType);
|
||||
_logger.LogInformation(
|
||||
"AddressSpaceApplier: not provisioning historized tag {Node}: data type '{DataType}' has no historian mapping",
|
||||
tag.NodeId, tag.DataType);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -786,12 +806,15 @@ public sealed class AddressSpaceApplier
|
||||
/// <c>HistorianName</c> = the value the EnsureTags hook / materialiser write under (a non-alarm
|
||||
/// historized value variable's <c>HistorianTagname</c> override, else its <c>FullName</c>). The
|
||||
/// two diverge ONLY when an override is set. Returns <c>null</c> when the tag is not a historized
|
||||
/// value variable (not historized, or a native-alarm condition node).
|
||||
/// value variable OtOpcUa records (not historized, a native-alarm condition node, or a read-only binding,
|
||||
/// lmxopcua#899).
|
||||
/// </summary>
|
||||
/// <param name="tag">The raw tag to resolve a historized ref for.</param>
|
||||
/// <returns>The resolved historized ref pair, or <c>null</c> when the tag is not a historized value variable.</returns>
|
||||
private static HistorizedTagRef? HistorizedRef(RawTagPlan tag) =>
|
||||
tag.IsHistorized && tag.Alarm is null
|
||||
// lmxopcua#899: a read-only binding is never recorded into — the recorder's WriteLiveValues would write
|
||||
// into a historian tag OtOpcUa does not own. A flip of the flag is a ref appearing/disappearing below.
|
||||
IsOwnedHistorizedValue(tag)
|
||||
// v3: the RawPath (== NodeId) is BOTH the mux ref (the driver fans values by RawPath) and the
|
||||
// default historian tagname; an override diverges only the historian name.
|
||||
? new HistorizedTagRef(
|
||||
|
||||
@@ -143,7 +143,7 @@ public static class AddressSpaceChangeClassifier
|
||||
}).Equals(d.Current);
|
||||
|
||||
// v3 surgical raw-tag eligibility: a NON-alarm raw tag whose only differences are the in-place-updatable
|
||||
// attributes (Writable / IsHistorized / HistorianTagname / DataType / IsArray / ArrayLength / ArrayWritable)
|
||||
// attributes (Writable / IsHistorized / HistorianTagname / HistorianReadOnly / DataType / IsArray / ArrayLength / ArrayWritable)
|
||||
// and/or its ReferencingEquipmentPaths. ArrayWritable only feeds the node's writability — the
|
||||
// same AccessLevel + OnWriteValue swap Writable already drives in place — so it must be listed here or
|
||||
// every array-tag edit that flips it would fall through to a full rebuild. The referencing set is node-inert for a VALUE tag — it only drives native-alarm
|
||||
@@ -160,6 +160,9 @@ public static class AddressSpaceChangeClassifier
|
||||
Writable = d.Current.Writable,
|
||||
IsHistorized = d.Current.IsHistorized,
|
||||
HistorianTagname = d.Current.HistorianTagname,
|
||||
// lmxopcua#899: node-inert — the node serves HistoryRead the same either way; only the
|
||||
// provisioning hook and the recorder feed read it.
|
||||
HistorianReadOnly = d.Current.HistorianReadOnly,
|
||||
DataType = d.Current.DataType,
|
||||
IsArray = d.Current.IsArray,
|
||||
ArrayLength = d.Current.ArrayLength,
|
||||
|
||||
@@ -155,6 +155,11 @@ public sealed record RawContainerNode(
|
||||
/// every other tag. AVEVA stores the alarm's history under that reference's object, so the node manager adds the
|
||||
/// object to the event-history sources of every folder the condition fires on (Gitea #886). It is not in the
|
||||
/// surgical whitelist either: an alarm-bearing tag's delta rebuilds anyway.
|
||||
/// <see cref="HistorianReadOnly"/> (lmxopcua#899, <c>TagConfig.historianReadOnly</c>) marks a historized tag whose
|
||||
/// history is read from an existing historian tag OtOpcUa does not own: the node still serves HistoryRead, but the
|
||||
/// applier neither provisions the historian tag (<c>EnsureTags</c>) nor feeds it to the continuous-historization
|
||||
/// recorder. It is node-inert, so it is in the surgical whitelist, and a UNS reference node does not mirror it
|
||||
/// (UNS nodes neither provision nor record).
|
||||
/// <para><b>ADDING A FIELD IS A FOUR-PLACE CONTRACT — the hand-written equality below does NOT close
|
||||
/// over new members.</b> Because <see cref="ReferencingEquipmentPaths"/> forces a custom
|
||||
/// <c>Equals</c>/<c>GetHashCode</c>, the compiler's positional equality is suppressed, so a field added
|
||||
@@ -184,7 +189,8 @@ public sealed record RawTagPlan(
|
||||
AddressSpaceRealm Realm = AddressSpaceRealm.Raw,
|
||||
bool ArrayWritable = false,
|
||||
bool ScalarRefusesArrayValue = false,
|
||||
string? NativeAlarmReference = null)
|
||||
string? NativeAlarmReference = null,
|
||||
bool HistorianReadOnly = false)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
// Structural equality: the auto-generated record equality compares ReferencingEquipmentPaths (an
|
||||
@@ -209,6 +215,7 @@ public sealed record RawTagPlan(
|
||||
ArrayWritable == other.ArrayWritable &&
|
||||
ScalarRefusesArrayValue == other.ScalarRefusesArrayValue &&
|
||||
NativeAlarmReference == other.NativeAlarmReference &&
|
||||
HistorianReadOnly == other.HistorianReadOnly &&
|
||||
ReferencingEquipmentPaths.SequenceEqual(other.ReferencingEquipmentPaths, StringComparer.Ordinal);
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -219,6 +226,7 @@ public sealed record RawTagPlan(
|
||||
hash.Add(Name); hash.Add(DataType); hash.Add(Writable); hash.Add(Alarm);
|
||||
hash.Add(IsHistorized); hash.Add(HistorianTagname); hash.Add(IsArray); hash.Add(ArrayLength);
|
||||
hash.Add(Realm); hash.Add(ArrayWritable); hash.Add(ScalarRefusesArrayValue); hash.Add(NativeAlarmReference);
|
||||
hash.Add(HistorianReadOnly);
|
||||
foreach (var p in ReferencingEquipmentPaths) hash.Add(p, StringComparer.Ordinal);
|
||||
return hash.ToHashCode();
|
||||
}
|
||||
@@ -847,7 +855,8 @@ public static class AddressSpaceComposer
|
||||
ArrayLength: intent.ArrayLength,
|
||||
ArrayWritable: arrayWritable,
|
||||
ScalarRefusesArrayValue: scalarRefusesArray,
|
||||
NativeAlarmReference: nativeAlarmReference));
|
||||
NativeAlarmReference: nativeAlarmReference,
|
||||
HistorianReadOnly: intent.HistorianReadOnly));
|
||||
}
|
||||
|
||||
containers.Sort((x, y) => string.CompareOrdinal(x.NodeId, y.NodeId));
|
||||
|
||||
Reference in New Issue
Block a user