docs(grpc-data): X0 evidence (rev-4 investigations + scratch harness) and mixed-version rollout note

This commit is contained in:
Joseph Doherty
2026-11-23 17:52:54 -05:00
parent f441549a9e
commit d89bc86194
4 changed files with 178 additions and 0 deletions
+16
View File
@@ -123,6 +123,22 @@ retained bytes, metadata and call lifetimes. Tune them together for measured wor
defaults are admission bounds, not a throughput or capacity guarantee. Overload can reject work or
reset a stream, requiring a fresh snapshot. Do not interpret that recovery as lossless replay.
### Mixed versions (X0 rollout)
The remote history and alarm work (`docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`)
adds new operation bits (`HistoryRead` 32, `AlarmSubscribe` 64, `AlarmAcknowledge` 128,
`AlarmConfirm` 256, `AlarmShelve` 512). A node older than X0 rejects the whole data-connection
snapshot when a row carries a bit it does not know, taking down every connection on that node.
- **Run X0 on every node of both clusters before any of these bits is authored.** Nothing checks
this: ConfigDb records no node build, so it is a deploy-checklist step.
- An X0 node drops an unknown bit from that row only, fail closed (an unknown grant is no grant),
and logs a warning naming the connection. It also counts it:
`otopcua.dataconnection.unknown_operations_dropped`. Exports and mappings are read the same way.
Authoring still rejects the bits until the release that implements them.
- The optional per-call header `x-otopcua-data-features` is reserved. X0 parses it but supports no
feature, and an X0 consumer never sends it, so the wire behaviour is unchanged v1.
## Feature boundary
Remote history, alarm/event forwarding and relay operations are future work. Authorized imported
+118
View File
@@ -0,0 +1,118 @@
# X0 evidence: tolerant readers and contract reservation
Phase X0 of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`. It has two parts:
1. the provenance of revision 4's settled offline investigations (plan §5.1, §5.5, §5.6, §9.3);
2. what X0 changed, and the gate runs.
## 1. Revision 4 investigations (provenance)
All three investigations were offline, against the pinned `OPCFoundation.NetStandard.Opc.Ua.Server` 2.0.1
(`Directory.Packages.props`). The second Fable pass reviewed them in
`docs/plans/2026-11-23-grpc-data-connections-history-alarms-relay-plan-review.md` (§"B5 — `ICallAsyncNodeManager.CallAsync`:
confirmed", N5, m-T7). That pass could not re-run the harness, because the harness was not yet in the repo. It is committed
here.
### (a) SDK Call dispatch trace (B5, plan §5.6 step 1)
The trace was decompiled with `ilspycmd` from
`~/.nuget/packages/opcfoundation.netstandard.opc.ua.server/2.0.1/lib/net10.0/Opc.Ua.Server.dll`. The excerpts were kept in
the session scratchpad and are not committed (SDK source). Files and members used:
| Step | Decompiled file | Member |
|---|---|---|
| Service entry, async end to end | `StandardServer.cs` | `StandardServer.CallAsync` awaits `ServerInternal.NodeManager.CallAsync` |
| Master hand-off | `Opc.Ua.Server.MasterNodeManager.cs` | `MasterNodeManager.CallAsync` → `NodeManagerServiceDispatcher.CallAsync`; managers wrapped by `ToAsyncNodeManager()` |
| Validation, then per-manager await | `Opc.Ua.Server.NodeManagerServiceDispatcher.cs` | `CallAsync` runs `ValidateCallRequestItemAsync` (`GetManagerHandleAsync`, `FindMethodStateAsync`, `ValidatePermissionsAsync`). It marks bad items `Processed`, then awaits `IAsyncNodeManager.CallAsync` on each registered manager **sequentially**, with `ConfigureAwait(false)` |
| Adapter decision | `Opc.Ua.Server.AsyncNodeManagerAdapter.cs` | `CallAsync`: `if (SyncNodeManager is ICallAsyncNodeManager m) return m.CallAsync(...)`, else the synchronous `Call` (checked at call time, ≈ line 269) |
| Lock scope during validation | `Opc.Ua.Server.CustomNodeManager2.cs` | `FindMethodState` holds `lock (Lock)` only around `ValidateNode` + `FindMethod` |
| Where the lock is taken today | `Opc.Ua.Server.CustomNodeManager2.cs` | `Call` → `CallSynchronousBatch` → `GetMethodCalls`, which skips `Processed` items and locks per owned item. NM adds its own `lock (Lock)` in `ReportAfterMethod` |
| Interface | `Opc.Ua.Server.ICallAsyncNodeManager.cs` | `ValueTask CallAsync(OperationContext, ArrayOf<CallMethodRequest>, IList<CallMethodResult>, IList<ServiceResult>, CancellationToken)` |
Conclusion: `OtOpcUaNodeManager` can implement `ICallAsyncNodeManager`. It claims imported-condition calls (sets `Processed`),
runs `base.Call` for the rest, and then awaits the claimed calls with no NM `Lock` held. Lock-freedom stays a hard A3 gate (L3).
The review added two non-blocking notes, both now in §5.6:
- `base.Call` runs under `BeginNodeManagerOperation()`. Finish it before awaiting.
- Managers are awaited sequentially. A mixed batch delays later-registered managers.
### (b) Condition node and byte count (N5, plan §5.5)
The harness is `harness/Program.cs` and `harness/count.csproj`, copied verbatim. It builds each condition type with the
optional children NM adds before `Create()`: `ConfirmedState`, `Confirm`, `ShelvingState` and `MaxTimeShelved`
(`NM:2461-2475`). It then counts the tree through `GetChildren`.
| Type | Nodes | Objects / variables / methods |
|---|---|---|
| `AlarmConditionType` | 48 | 2 / 38 / 8 |
| `OffNormalAlarmType` | 49 | 2 / 39 / 8 |
| `DiscreteAlarmType` | 48 | 2 / 38 / 8 |
`Quality`, `BranchId` and `Comment` are present.
Retained size is ≈ 157 KiB per condition (160,997 B). It was measured on 2,000 `OffNormal` instances as a
`GC.GetTotalMemory(true)` delta.
- It excludes NM's indexes, the `c1.` identifier strings, the EventId registry and placement sets (m-T7).
- L2 (A3 exit) is the authority for `MaxImportedConditionBytes`.
### (c) Snapshot-copy timing (plan §5.1)
The same harness copies the snapshot fields of each of the 2,000 `OffNormalAlarmState` instances into a record. It takes
3.3–5.8 ms per 2,000 over three warm runs, which is ≈ 1.7–2.9 µs per condition.
- At `MaxConditions` 1,000, one `Lock` hold is ≈ 2–3 ms.
- This was measured outside the server. L1 (A1) measures the real hold under load.
To re-run: `dotnet run -c Release --project docs/plans/evidence/grpc-data-ext/harness/count.csproj`. It is not part of the
solution.
## 2. What X0 changed
- **Operation bits.** `DataOperations` reserves `HistoryRead`, `AlarmSubscribe`, `AlarmAcknowledge`, `AlarmConfirm` and
`AlarmShelve` (32 to 512). `DataOperationSets` is the one authority: `V1`, `Understood` (= `V1` in X0) and `Reserved`.
- **Tolerant readers.** Each drops unknown bits, fail closed:
- `DataConnectionDeploymentRuntime.Apply` drops them per row and counts them (diagnostics property, Warning log, counter
`otopcua.dataconnection.unknown_operations_dropped`);
- `DataCapabilities.Operations` masks in its accessor, both at construction and on `with`;
- `DataProtoMapper` masks metadata and capabilities on decode;
- `LocalExportCatalog` masks export rules.
- **Two node-side sites the plan missed.**
- `DeploymentArtifact` data-row parsing and `LocalExportCatalog.Compile` re-ran the authoring validator, which rejects
unknown bits.
- Either would still have rejected a whole snapshot (consumer side) or the whole origin catalog (origin side) when a newer
central authored a reserved bit.
- Both now call `DataConnectionValidator.ValidateDeployed`. This is the same validator, but the reserved bits (32 to 512)
are ignored rather than rejected. Any other unknown bit is still a malformed row. Nothing can author it, and
`GrpcDataArtifactReadTests` (P02) pins `1 << 30` failing closed.
- The runtime, decoders and catalog rules still drop any unknown bit.
- **Grow sites unchanged.** Authoring `Validate`, `ProjectedDataAccess` and `LocalDataServices.Implemented` are unchanged, and
authoring still rejects bit 32.
- **Feature header.** `x-otopcua-data-features` is parsed on every RPC after authentication.
- The server records requested and effective features. Effective = requested ∩ `SupportedFeatures` = none in X0.
- A binary value, or a value longer than 256 characters in total, gets `InvalidArgument`.
- The consumer derives the header per selected endpoint. It is always empty in X0, so it is never sent.
- **Proto reservations.** These are comments plus `DataConnectionProtoContract` constants and descriptor golden tests:
- Capabilities 16 (`history`) and 17 (`conditions`);
- Metadata 14 (`history`);
- SubscriptionItem 4 (`condition_scope`);
- SubscriptionFrame arm 9 (`condition_states`).
No field was added, so the server advertises nothing new.
- **Recorded-v1-client gate.** `GrpcDataV1CompatibilityTests` (Host.Tests) replays recorded v1 requests for all six RPCs
against the real `DataConnectionGrpcService` and a deterministic origin. It compares `ToByteArray()` hex with goldens
captured on pre-X0 master `2e4e4063` (commit `3279a7f9d`, before any X0 change).
- No field is time-varying, so nothing is normalised.
- It runs with no header and with `history,conditions`.
- H2, A2 and A3 rerun it unchanged.
## 3. Gate runs
See the X0 report for the run results. Commands:
```bash
dotnet build ZB.MOM.WW.OtOpcUa.slnx
python3 scripts/validation/grpc-data/run-unit-phase.py X0 # and P01 … P09
python3 -m pytest scripts/validation/grpc-data/test_unit_phase_runner.py
```
@@ -0,0 +1,40 @@
using Opc.Ua;
sealed class Ids : INodeIdFactory { int n; public NodeId New(ISystemContext c, NodeState node) => new NodeId("n" + (++n), 2); }
static class P {
static int Count(ISystemContext ctx, NodeState n, Dictionary<string,int> kinds) {
kinds[n.NodeClass.ToString()] = kinds.GetValueOrDefault(n.NodeClass.ToString()) + 1;
var children = new List<BaseInstanceState>(); n.GetChildren(ctx, children);
int c = 1; foreach (var ch in children) c += Count(ctx, ch, kinds); return c;
}
static void Run(string name, Func<NodeState, AlarmConditionState> make, ISystemContext ctx) {
var parent = new FolderState(null);
var alarm = make(parent);
alarm.ConfirmedState = new TwoStateVariableState(alarm);
alarm.Confirm = new AddCommentMethodState(alarm);
alarm.ShelvingState = new ShelvedStateMachineState(alarm);
alarm.MaxTimeShelved = new PropertyState<double>.Implementation<VariantBuilder>(alarm);
alarm.Create(ctx, new NodeId("cond", 2), new QualifiedName("cond", 2), new LocalizedText("cond"), true);
var kinds = new Dictionary<string,int>();
int total = Count(ctx, alarm, kinds);
Console.WriteLine($"{name}: total={total} ({string.Join(", ", kinds.Select(k => k.Key + "=" + k.Value))}); Quality={(alarm.Quality!=null)} BranchId={(alarm.BranchId!=null)} Comment={(alarm.Comment!=null)}");
}
static void Main() {
var ctx = new SystemContext((ITelemetryContext)null) { NodeIdFactory = new Ids(), NamespaceUris = new NamespaceTable() };
ctx.NamespaceUris.Append("urn:a"); ctx.NamespaceUris.Append("urn:b");
Run("AlarmConditionState", p => new AlarmConditionState(p), ctx);
Run("OffNormalAlarmState", p => new OffNormalAlarmState(p), ctx);
Run("DiscreteAlarmState", p => new DiscreteAlarmState(p), ctx);
var keep = new List<object>(); long before = GC.GetTotalMemory(true);
for (int i = 0; i < 2000; i++) { var parent = new FolderState(null); var a = new OffNormalAlarmState(parent);
a.ConfirmedState = new TwoStateVariableState(a); a.Confirm = new AddCommentMethodState(a); a.ShelvingState = new ShelvedStateMachineState(a);
a.MaxTimeShelved = new PropertyState<double>.Implementation<VariantBuilder>(a);
a.Create(ctx, new NodeId("c"+i, 2), new QualifiedName("c"+i, 2), new LocalizedText("c"+i), true); keep.Add(a); }
long after = GC.GetTotalMemory(true); Console.WriteLine($"retained bytes/condition (2000, OffNormal, no address-space indexes): {(after-before)/2000}"); GC.KeepAlive(keep);
var conds = keep.Cast<OffNormalAlarmState>().ToArray(); var recs = new object[conds.Length];
for (int w = 0; w < 3; w++) { var sw = System.Diagnostics.Stopwatch.StartNew();
for (int i = 0; i < conds.Length; i++) { var c = conds[i]; recs[i] = (c.NodeId, c.ActiveState?.Id?.Value, c.AckedState?.Id?.Value, c.ConfirmedState?.Id?.Value,
c.EnabledState?.Id?.Value, c.ShelvingState?.CurrentState?.Value, c.Severity?.Value, c.Message?.Value, c.Quality?.Value, c.Retain?.Value,
c.Time?.Value, c.Comment?.Value, c.ClientUserId?.Value, c.ConditionClassId?.Value, c.ActiveState?.TransitionTime?.Value); }
sw.Stop(); Console.WriteLine($"snapshot copy of {conds.Length} conditions: {sw.Elapsed.TotalMilliseconds:F2} ms"); }
}
}
@@ -0,0 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net10.0</TargetFramework><Nullable>disable</Nullable><ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<ItemGroup><PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Server" Version="2.0.1" /></ItemGroup>
</Project>