fix(grpc-data): removal admission keyed on the credential, lazy + bounded, no stale verdict write-back (#936 review r1)

S3: the SDK installs a new identity object on every ActivateSession (decompiled
Opc.Ua.Server 2.0.1: Session.UpdateUserIdentity assigns EffectiveIdentity;
MonitoredItem/Subscription.EffectiveIdentity read the current session's), so an
object-keyed admission forgot a re-activated or transferred session. Admission
is now keyed on RoleCarryingUserIdentity.AdmissionKey (principal + api key id),
and a removal also tells an item that passes the current gate (uncached).
S4: the per-condition record is a lazily allocated locked HashSet<string> (no
ConditionalWeakTable per condition), one entry per credential, capped at 1024,
dropped after the removal's RefreshRequired is decided.
N4: Verdict writes back only while that instance is still live.
Tests: OI re-activation (red on revert), unit S3/S4 + N4 (red on revert); docs.
Also DataConnections.md for #933 r1 S1/S2.
This commit is contained in:
Joseph Doherty
2026-11-25 12:06:02 -05:00
parent 9d969c4724
commit e61db01686
6 changed files with 159 additions and 13 deletions
+4 -1
View File
@@ -867,7 +867,10 @@ This section is what an OPC UA client of the **consumer** sees. Code: `OpcUaServ
`MaxUnknownHold`). Removal emits **no** `NodeDeleted` model change. For a removal, "may see" means "its identity was
admitted by the gate to that condition instance" (a delivery, a refresh replay or a Read/Browse of it), recorded per
instance — not the current mapping set, which no longer admits anybody once the removal was caused by the mapping
leaving it (#936). The event carries no condition field (`SourceNode = Server`, `Message = "RefreshRequired"`), and a
leaving it (#936) — or "passes the current gate". The record is keyed on the credential (principal + API key id), not
the SDK identity object, because the SDK installs a new identity object on every ActivateSession: a session re-activated
on a new channel, or a transferred subscription, is still told. It is allocated on first admission, holds one entry per
credential (capped at 1024 per condition), and is dropped with the condition. The event carries no condition field (`SourceNode = Server`, `Message = "RefreshRequired"`), and a
session never admitted to the condition is not sent one;
- a resync leaves retained EventIds un-re-bindable (see EventIds below).
- **Before the first barrier, a refresh returns nothing imported**, because nothing is materialised yet. Conditions appear
+10 -1
View File
@@ -461,6 +461,15 @@ refresh, EventIds) is documented in [Alarm tracking § Imported conditions](Alar
(new EventIds). The hold cannot be narrowed to "mappings whose scope could list the key": an origin deploy can move a
condition's placements into the unknown mapping's root, so the consumer cannot prove it. 20 min outlasts the transient
retry cycle (snapshot timeout × 8) and the first two re-checks of a definitive refusal (`LongRetryDelay` 5 min, then 10).
- **A mapping's own keys are not bounded while it is only transiently unknown** (review r1 S1). A key the unknown mapping
itself listed when it was last known (its previous stream, or before a capacity reset) is held with no bound while that
mapping is `Pending` / `Unavailable` / retrying — its origin may well still list it, exactly as when the connection's
stream never opens at all (held stale indefinitely). Its clock starts only when that mapping's refusal is
**definitive** (`Denied` / `NotFound` / `Unsupported` / `ConditionCapacity`); that verdict is remembered across its
retries and stream ends until it completes a snapshot, so a durably denied mapping's retries do not restart the bound.
- **The clock runs only while a stream is past its barrier** (review r1 S2): it pauses when that stream ends and resumes
at the next barrier, so a connection outage never counts and a merely slow snapshot after one removes nothing.
- `MaxUnknownHold` must be positive (the access refuses zero or negative at construction).
7. **Known state (T2 invariant).** *The consumer never retires or clears an alarm that is active at the origin.*
- A record with `state_known = false` never changes the consumer's last state.
- A condition first seen unknown is materialised with `Quality = UncertainInitialValue` until a known record arrives.
@@ -639,7 +648,7 @@ status and diagnostic), and each snapshot barrier (per-mapping status, record co
| `ConditionCapacity` | The listing's `total` against the mapping's or export's `MaxConditions`, and the host caps. Narrow the remote root or raise the limits. |
| Conditions `Uncertain` | The origin has not established their state: a scripted alarm has not completed an evaluation; a native driver has not signalled (see `…conditions.unsignalled`). |
| Conditions `BadNoCommunication` | Stream down longer than `ConditionStaleTimeoutMilliseconds`, or the mapping was incomplete at the last barrier. |
| A retired condition stays `BadNoCommunication` while another mapping of the connection is `Unavailable` / `Denied` | Expected for up to `MaxUnknownHold` (20 min, #933): the unknown mapping might still list it, so it is held (T2). After that it is removed with `RefreshRequired` (logged Warning "held past MaxUnknownHold", naming the unknown mappings). Fix the unknown mapping (its refusal is on the AdminUI mappings line) to settle it sooner. |
| A retired condition stays `BadNoCommunication` while another mapping of the connection is `Unavailable` / `Denied` | Expected for up to `MaxUnknownHold` (20 min, #933) of live-stream time (an outage does not count): the unknown mapping might still list it, so it is held (T2). A key the unknown mapping listed itself is held with no bound until that mapping is refused definitively (Denied / NotFound / Unsupported / capacity). After that it is removed with `RefreshRequired` (logged Warning "held past MaxUnknownHold", naming the unknown mappings). Fix the unknown mapping (its refusal is on the AdminUI mappings line) to settle it sooner. |
| Ack answers `BadEventIdUnknown` | The client holds an old EventId (superseded occurrence, or an origin restart that re-announced a different time). ConditionRefresh and ack with the new EventId. |
| Ack answers "OutcomeUnknown" | Check the origin's audit log (`ZB.MOM.WW.OtOpcUa.DataConnections.Audit`) for the operation and watch the condition's events. Never replay blindly. |
| All `ConditionId`s changed | `ConditionKeySecret` was rotated or differs between the origin pair members, or the connection was re-created under a new id. |