Merge ConfigDb follow-ups: script FKs + ZTag/SAPID filtered unique indexes, ExternalIdReservation retired (#1040/#1049, migration ScriptForeignKeysAndExternalIdUniqueness with pre-check), SqlNamedQueryInvalid deploy rule (#1058), read-only otopcua-preflight upgrade tool (#1013/#1015/#1021)
# Conflicts: # docs/VirtualTags.md
This commit is contained in:
@@ -550,83 +550,23 @@ public sealed class AdminOperationsActor : ReceiveActor
|
||||
// derivation, cross-cluster/namespace binding, driver-namespace compat, signal collisions,
|
||||
// …) gates the deploy. A green build in this repo does not prove the config is valid; this
|
||||
// is the last guard before a bad address space (or a non-derived EquipmentId) ships.
|
||||
// NOTE: a BadDuplicateExternalIdentifier rejection from the reservation pre-flight can
|
||||
// (rarely) be a false positive if an external-id reservation release has not yet been
|
||||
// committed/visible when the snapshot is read — operators seeing a spurious one should
|
||||
// check ExternalIdReservation state before re-submitting.
|
||||
var draft = await DraftSnapshotFactory.FromConfigDbAsync(db);
|
||||
phases.Mark("snapshot-read");
|
||||
var errors = DraftValidator.Validate(draft).ToList();
|
||||
|
||||
// Cluster-topology guard. The SQL
|
||||
// CK_ServerCluster_RedundancyMode_NodeCount CHECK enforces the (NodeCount, RedundancyMode)
|
||||
// pair on the row itself, but it cannot see the per-node ClusterNode.Enabled flag — an
|
||||
// operator can disable a node (effective enabled-count = 1) while leaving RedundancyMode at
|
||||
// Hot/Warm and the constraint stays green, which would boot the runtime into an
|
||||
// InvalidTopology band. ValidateClusterTopology catches that drift; it is not part of
|
||||
// DraftValidator.Validate, so it runs separately here over the snapshot's cluster/node rows.
|
||||
// Errors fold into the same reject summary alongside the snapshot rules so a deploy failing
|
||||
// either check is rejected with both sets of messages. ClusterId-ordered for a deterministic summary.
|
||||
// R03:3.2 — both come off the SAME snapshot read as every other table (one SNAPSHOT
|
||||
// transaction), not a second query that could observe a later edit.
|
||||
var clusters = draft.ServerClusters.OrderBy(c => c.ClusterId, StringComparer.Ordinal).ToList();
|
||||
var nodesByCluster = draft.ClusterNodes
|
||||
.GroupBy(n => n.ClusterId, StringComparer.Ordinal)
|
||||
.ToDictionary(g => g.Key, g => g.ToList(), StringComparer.Ordinal);
|
||||
foreach (var cluster in clusters)
|
||||
{
|
||||
var nodes = nodesByCluster.TryGetValue(cluster.ClusterId, out var ns)
|
||||
? (IReadOnlyList<ClusterNode>)ns
|
||||
: [];
|
||||
errors.AddRange(DraftValidator.ValidateClusterTopology(cluster, nodes));
|
||||
}
|
||||
|
||||
// Deploy-time TagConfig strictness inspection over equipment tags. The
|
||||
// driver-typed EquipmentTagConfigInspector surfaces every blob the driver's own reader would
|
||||
// REJECT — a present-but-invalid enum value, an absent or malformed address field, a
|
||||
// structurally-unparseable TagConfig — each of which makes the driver skip the tag so it reads
|
||||
// BadNodeIdUnknown forever. (The runtime used to silently default a typo'd enum;
|
||||
// it now rejects the tag, so these warnings describe rejections.) In Warn mode
|
||||
// (default) these are non-blocking (logged + appended to the accepted result Message); in Error
|
||||
// mode they fold into the reject list so a typo'd config cannot be re-deployed until fixed.
|
||||
// Running servers are untouched either way — the gate only sees re-deploys.
|
||||
// v3: a raw Tag's driver is resolved via its Device (Tag no longer carries EquipmentId /
|
||||
// DriverInstanceId). Inspect EVERY raw tag's TagConfig against its device's driver type.
|
||||
var driverTypeById = draft.DriverInstances
|
||||
.GroupBy(d => d.DriverInstanceId, StringComparer.Ordinal)
|
||||
.ToDictionary(g => g.Key, g => g.First().DriverType, StringComparer.Ordinal);
|
||||
var driverByDevice = draft.Devices
|
||||
.GroupBy(d => d.DeviceId, StringComparer.Ordinal)
|
||||
.ToDictionary(g => g.Key, g => g.First().DriverInstanceId, StringComparer.Ordinal);
|
||||
var deviceConfigById = draft.Devices
|
||||
.GroupBy(d => d.DeviceId, StringComparer.Ordinal)
|
||||
.ToDictionary(g => g.Key, g => g.First().DeviceConfig, StringComparer.Ordinal);
|
||||
var tagConfigWarnings = new List<(string TagId, string Text)>();
|
||||
foreach (var t in draft.Tags)
|
||||
{
|
||||
if (!driverByDevice.TryGetValue(t.DeviceId, out var driverInstanceId)) continue;
|
||||
if (!driverTypeById.TryGetValue(driverInstanceId, out var driverType)) continue;
|
||||
foreach (var w in EquipmentTagConfigInspector.Inspect(
|
||||
driverType, t.TagConfig, deviceConfigById.GetValueOrDefault(t.DeviceId)))
|
||||
tagConfigWarnings.Add((t.TagId, $"tag '{t.TagId}': {w}"));
|
||||
}
|
||||
if (tagConfigWarnings.Count > 0)
|
||||
{
|
||||
if (_tagConfigValidationMode == TagConfigValidationMode.Error)
|
||||
errors.AddRange(tagConfigWarnings.Select(x => new ValidationError("TagConfigInvalid", x.Text, x.TagId)));
|
||||
else
|
||||
foreach (var x in tagConfigWarnings)
|
||||
_log.Warning("StartDeployment: TagConfig warning (Warn mode, non-blocking): {Warning}", x.Text);
|
||||
}
|
||||
// The rule pass — DraftValidator, per-cluster topology, TagConfig inspection, the non-blocking Sql / data-
|
||||
// connection warnings — is DeployGateRules (shared with the upgrade preflight, lmxopcua#1013/#1015/#1058).
|
||||
// R03:3.2: every check runs off this ONE snapshot read.
|
||||
var gate = DeployGateRules.Evaluate(draft, _tagConfigValidationMode);
|
||||
var errors = gate.Errors.ToList();
|
||||
foreach (var w in gate.TagConfigWarnings)
|
||||
_log.Warning("StartDeployment: TagConfig warning (Warn mode, non-blocking): {Warning}", w.Message);
|
||||
|
||||
// lmxopcua#781 item 3: always non-blocking (independent of TagConfigValidationMode) — the Tag
|
||||
// entity's Writable flag and the Sql blob's "writable" disagree.
|
||||
var writableWarnings = SqlTagDeployChecks.WritableMismatchWarnings(draft);
|
||||
foreach (var w in writableWarnings)
|
||||
foreach (var w in gate.SqlWritableWarnings)
|
||||
_log.Warning("StartDeployment: Sql writable mismatch (non-blocking): {Warning}", w);
|
||||
|
||||
// A2b (plan §6): Σ MaxConditions × 49 of a consumer node's alarm mappings over the host cap — non-blocking.
|
||||
foreach (var w in DataConnectionValidator.DeployWarnings(draft))
|
||||
foreach (var w in gate.DataConnectionWarnings)
|
||||
_log.Warning("StartDeployment: data-connection warning (non-blocking): {Warning}", w);
|
||||
|
||||
phases.Mark("validate");
|
||||
@@ -749,8 +689,8 @@ public sealed class AdminOperationsActor : ReceiveActor
|
||||
// the operator sees the non-blocking strictness findings on a successful deploy.
|
||||
var messageParts = new List<string>();
|
||||
if (advisory is not null) messageParts.Add(advisory);
|
||||
messageParts.AddRange(tagConfigWarnings.Select(x => x.Text));
|
||||
messageParts.AddRange(writableWarnings);
|
||||
messageParts.AddRange(gate.TagConfigWarnings.Select(x => x.Message));
|
||||
messageParts.AddRange(gate.SqlWritableWarnings);
|
||||
messageParts.AddRange(scriptWarnings);
|
||||
var acceptedMessage = messageParts.Count > 0 ? string.Join("; ", messageParts) : null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user