fix(redundancy): a failed OPC UA endpoint drops ServiceLevel to 0 and steps the Primary down (lmxopcua#762)
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
IOpcUaEndpointState (review-remediation lane C3) recorded whether the SDK started, but only the health check read it: a fused node whose endpoint failed (port 4840 taken, ...) still advertised 250/240 and stayed driver Primary, so the Primary-gated data plane ran on a node no client could reach while the reachable peer refused writes as Secondary. - Move IOpcUaEndpointState/OpcUaEndpointState/OpcUaEndpointStatus from Host to Commons.OpcUa so the Runtime can consume it. - ServiceLevelCalculator: new NodeHealthInputs.EndpointListening (default true). false -> 0, ahead of every other input including the +10 Primary bonus. - OpcUaPublishActor: takes the endpoint state, feeds EndpointListening (Failed only; NotStarted / Stopped are boot/shutdown windows) on the DB-backed and DB-less paths, and the legacy role-only seam returns 0 for a failed endpoint too. - New OpcUaEndpointStepDownActor (one per driver node): a Primary (ClusterActiveNode.SelfIsActive, the election's own primitive) with a Failed endpoint gracefully Leaves its mesh - the manual failover mechanism - so the peer becomes the oldest Up driver member, hosts the singletons and is Primary. The election itself is not bent. Guarded on a peer having recently reported its own endpoint listening (EndpointReport on the new opcua-endpoint-state DPS topic), so a pair with both endpoints failed does not bounce the role and restart nodes forever, and a lone node never shuts itself down. - Runtime now references ZB.MOM.WW.Health.Akka (ClusterActiveNode). - Docs: Redundancy.md tier table + new "Endpoint start failure: Primary step-down" section; cluster-topology rule; HealthEndpoints / OpcUaEndpointHealthCheck comments (F-C1 landed). Tests: ServiceLevelCalculatorTests (+5), OpcUaPublishActorEndpointStateTests (7: DB-less, DB-backed, legacy seam, NotStarted/Stopped do not demote, a later failure demotes on the next tick), OpcUaEndpointStepDownActorTests (3, real two-node mesh: holds while the peer is not listening then leaves and the peer becomes Primary; failed Secondary and healthy Primary never leave). Each was mutation-checked: removing the calculator/legacy guard, the Leave, the peer-listening guard or the Primary guard fails the corresponding tests.
This commit is contained in:
@@ -2,12 +2,24 @@ using Akka.Cluster;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Cluster.Redundancy;
|
||||
|
||||
/// <summary>The health facts <see cref="ServiceLevelCalculator.Compute"/> tiers a node on.</summary>
|
||||
/// <param name="MemberState">This node's Akka cluster member status.</param>
|
||||
/// <param name="DbReachable">Whether the config DB answered (constant <c>true</c> on a DB-less driver node).</param>
|
||||
/// <param name="OpcUaProbeOk">A peer's recent TCP probe verdict about this node's OPC UA port (benefit of the
|
||||
/// doubt when there is none). Observes the PORT only: when another process holds it, the probe succeeds against
|
||||
/// that process — which is why <paramref name="EndpointListening"/> exists.</param>
|
||||
/// <param name="Stale">Whether this node is running behind on config.</param>
|
||||
/// <param name="IsDriverPrimary">Whether this node is the driver Primary (oldest Up driver member).</param>
|
||||
/// <param name="EndpointListening">This node's OWN view of its OPC UA endpoint: <c>false</c> when the SDK failed
|
||||
/// to start (<c>IOpcUaEndpointState</c> reports <c>Failed</c>). Defaults to <c>true</c> so a caller with no
|
||||
/// endpoint fact (a harness, an admin-only node) keeps the previous tiering. lmxopcua#762.</param>
|
||||
public readonly record struct NodeHealthInputs(
|
||||
MemberStatus MemberState,
|
||||
bool DbReachable,
|
||||
bool OpcUaProbeOk,
|
||||
bool Stale,
|
||||
bool IsDriverPrimary);
|
||||
bool IsDriverPrimary,
|
||||
bool EndpointListening = true);
|
||||
|
||||
/// <summary>
|
||||
/// Pure ServiceLevel computation per design §6. Output range 0–255, where higher = "more
|
||||
@@ -16,6 +28,8 @@ public readonly record struct NodeHealthInputs(
|
||||
///
|
||||
/// Tiering:
|
||||
/// - Member not Up/Joining: 0 (cluster cannot trust this node).
|
||||
/// - OPC UA endpoint not listening (the SDK failed to start on this node): 0, with no Primary bonus — the node
|
||||
/// cannot serve a single client, so it must never out-rank a peer that can (lmxopcua#762).
|
||||
/// - DB reachable + OPC UA probe ok + not stale: 240 (full service).
|
||||
/// - Stale config (DB reachable or not, OPC UA probe state ignored): 100 or 200 depending on DB.
|
||||
/// - +10 bonus when this node is the driver Primary (the oldest Up member with the "driver" role —
|
||||
@@ -32,6 +46,12 @@ public static class ServiceLevelCalculator
|
||||
if (h.MemberState is not (MemberStatus.Up or MemberStatus.Joining))
|
||||
return 0;
|
||||
|
||||
// lmxopcua#762: a node whose own SDK failed to start serves nothing, whatever its DB, probe, staleness or
|
||||
// Primary status say. Checked before the tiering so no input can lift it — in particular not the +10
|
||||
// Primary bonus, which is exactly what used to keep a dead endpoint advertising 250.
|
||||
if (!h.EndpointListening)
|
||||
return 0;
|
||||
|
||||
var basis = (h.DbReachable, h.OpcUaProbeOk, h.Stale) switch
|
||||
{
|
||||
(true, true, false) => 240,
|
||||
|
||||
Reference in New Issue
Block a user