fix(grpc-data): maxAge=0 projected reads served from an awaited origin read; origin refusals are access denials; Write/CreateMonitoredItems renew lapsed leases (#938, #939, #940)
#938: OtOpcUaNodeManager implements IReadAsyncNodeManager. A projected Value read whose maxAge the cache cannot satisfy (0 always: Part 4 "read the source"; ScadaBridge's DCL and the Client CLI send 0) is served from IProjectedDataAccess.ReadNowAsync in the same request — same unary admission, authenticated freshness-checked read and cache publication as ScheduleRead, pumped through the unary budget, at most 5 s / request deadline − 250 ms, no Lock, no blocked thread. A lapsed lease is renewed first and read in the same request. Previously every maxAge=0 read answered BadWaitingForInitialData forever. #939: RemoteNamespaceResolver.RenewExactOutcomeAsync reports Renewed/Refused/Failed. Refused only for the origin's verdict (PERMISSION_DENIED call, Denied item, Metadata not granted, operation not granted / not writable) ⇒ BadUserAccessDenied, held 5 s per node+operation unsent; transport and other failures stay retryable. HistoryRead follows it. #940: RenewLapsed accepts Write (gated on the local write role) and Subscribe. WriteAsync awaits the renewal (≤ 4 s, ≤ half the timeout hint) then dispatches, BadResourceUnavailable unsent otherwise. CreateMonitoredItems awaits renewals once per request (ICreateMonitoredItemsAsyncNodeManager) and classifies each projected item PER ITEM outside Lock (lapse ⇒ BadResourceUnavailable, refusal ⇒ BadUserAccessDenied) — a refusal thrown from the item manager used to fault the whole request. Red/green: 15 wire tests in GrpcDataProjectedOriginAccessWireTests (12 red on the pre-fix source, controls green both ways); 4 existing tests updated where the first read is now Good. Evidence: docs/plans/evidence/grpc-data-ext/938-939-940-948.md.
This commit is contained in:
+27
-13
@@ -94,19 +94,29 @@ unavailable until valid authority can be established.
|
||||
`MetadataLeaseMilliseconds` keeps its retained proof; the lease is only *lapsed* when its time ran
|
||||
out or its route was replaced while the local catalog authority, mapping binding and cache
|
||||
generation are all still current and nothing revoked it. On a refused value Read / attribute Read /
|
||||
HistoryRead of such a node, the consumer first authorizes the caller against the lapsed subject
|
||||
(local grant + mapping bit, everything but the lease). A caller without the grant is still
|
||||
HistoryRead / Write / CreateMonitoredItems (the last two since #940) of such a node, the consumer first
|
||||
authorizes the caller against the lapsed subject (local grant + mapping bit, everything but the lease;
|
||||
a write also needs this node's local write role). A caller without the grant is still
|
||||
`BadUserAccessDenied` and nothing is sent to the origin. A granted caller gets the same exact
|
||||
`GetMetadata` renewal as above, for the operation it is performing (Read / HistoryRead bit, not
|
||||
Subscribe), one per node and operation at a time, with a 250 ms back-off after a failure. On-demand
|
||||
`GetMetadata` renewal as above, for the operation it is performing (its Read / HistoryRead / Write /
|
||||
Subscribe bit), one per node and operation at a time, with a 250 ms back-off after a failure. On-demand
|
||||
renewals never touch the unary budget (cold reads, writes) or the browse/subscription-renewal fetch
|
||||
slots: they queue (at most 64) for their own pool of `max(1, maxConcurrentFetches / 2)` origin calls,
|
||||
reserve 256 KiB each, and have 3 s end to end, so a batch of N lapsed nodes renews all N:
|
||||
|
||||
- **Value Read** answers `BadWaitingForInitialData` (as a cold read does) while the renewal runs off
|
||||
the request thread; once it commits, a read is scheduled so the client's retry is served from the
|
||||
fresh sample. `BadResourceUnavailable` while a renewal cannot be started (capacity, back-off).
|
||||
- **Value Read** awaits the renewal within the request (#938; the async Read, no `Lock`, at most
|
||||
5 s together with the origin read that follows) and is then served from an origin read. A renewal
|
||||
still running at the deadline answers `BadWaitingForInitialData` (as a cold read does);
|
||||
`BadResourceUnavailable` while a renewal cannot be started (capacity, back-off) or failed.
|
||||
A non-Value attribute of a lapsed node answers `BadResourceUnavailable` while it renews.
|
||||
- **Write** (#940) awaits the renewal (at most 4 s, and at most half the request's timeout hint)
|
||||
and is then dispatched. A renewal that cannot complete or start answers `BadResourceUnavailable`
|
||||
with nothing sent to the origin.
|
||||
- **CreateMonitoredItems** (#940) awaits the renewal of its lapsed Value items once per request (at
|
||||
most 4 s, async, no `Lock`) and then creates them. An item still not acquirable is answered PER
|
||||
ITEM — `BadResourceUnavailable` for a lapse the caller is granted, `BadUserAccessDenied` for a real
|
||||
refusal. (Before, a refused projected item was thrown from the item manager and faulted the whole
|
||||
CreateMonitoredItems request.)
|
||||
- **HistoryRead** renews within the request and is then served. The wait (one per batch, at most 4 s
|
||||
and never past `HistoryReadDeadline`, no node-manager `Lock` held, the request's cancellation
|
||||
honoured) takes one of the non-local history batch slots first. A batch that finds none free does
|
||||
@@ -116,13 +126,17 @@ reserve 256 KiB each, and have 3 s end to end, so a batch of N lapsed nodes rene
|
||||
- **Browse:** a cached page past half its lease is served as is *and* refreshed in the background
|
||||
(one refresh per page key), so a re-browse renews the leases of the nodes it lists.
|
||||
|
||||
An origin that stopped granting the operation fails the renewal; the consumer then keeps answering
|
||||
the retryable status (it cannot tell that from an unreachable origin).
|
||||
**An origin refusal is an access denial (#939).** The renewal reports why it did not commit. A
|
||||
definitive refusal BY THE ORIGIN — the call answered `PERMISSION_DENIED`, the item answered `Denied`,
|
||||
the principal no longer holds Metadata, or the returned metadata no longer grants the operation (for a
|
||||
write: or is no longer writable) — is answered `BadUserAccessDenied` and held for 5 s
|
||||
(`ProjectedDataAccess.LapseRefusalHold`) per node and operation, during which the node is refused
|
||||
without another origin call; after it the next request asks the origin again. Everything else (an
|
||||
unreachable, unready or non-primary origin, an `Unauthenticated` call, capacity, a timeout, a changed
|
||||
shape) stays retryable with the 250 ms back-off. HistoryRead follows the same rule.
|
||||
|
||||
Not covered yet: a **Write** or **CreateMonitoredItems** on a lapsed node is still refused
|
||||
`BadUserAccessDenied` (neither starts a renewal; a re-browse, a Read or a HistoryRead of the node
|
||||
renews it, after which they succeed). A lease that was revoked (`Invalidate`), a removed mapping and a
|
||||
retired node are refusals, not lapses, and are never renewed.
|
||||
A lease that was revoked (`Invalidate`), a removed mapping and a retired node are refusals, not
|
||||
lapses, and are never renewed.
|
||||
|
||||
An authorized logical monitored-item request can survive a physical stream expiry and seek a new
|
||||
pinned binding with bounded retries. The old binding and any queued sample evidence remain tied to
|
||||
|
||||
@@ -35,14 +35,24 @@ continuations must still match current authority, catalog and serving generation
|
||||
|
||||
A projected Value Read first acquires a current scoped demand. A cached sample can be returned
|
||||
only when its proof, serving identity, projection generation and age satisfy the request.
|
||||
`maxAge=0`, a missing sample or an unsuitable sample schedules an asynchronous bounded remote
|
||||
read and returns `BadWaitingForInitialData`; it does not block the SDK callback on the network.
|
||||
The response refreshes the local cache for a later Read. The origin's own local Read remains a
|
||||
cached read rather than a device poll.
|
||||
**Since #938** a `maxAge` the cache cannot satisfy — `maxAge=0` always (Part 4: read the source),
|
||||
a missing sample or an unsuitable one — is served from a bounded origin read **in the same
|
||||
request**: the node manager's async Read (`IReadAsyncNodeManager`, no node-manager `Lock` held, no
|
||||
request thread blocked) reads the origin, serves what it read and publishes it to the cache. The
|
||||
wait is at most 5 s per request (`OtOpcUaNodeManager.ProjectedOriginReadWait`), less the request
|
||||
deadline's margin; the reads are admitted against the same unary budget as before (the default
|
||||
1 MiB `MaxPendingBytes` admits one 1 MiB read at a time) and a batch is pumped through it as reads
|
||||
complete. A read that is not answered in time, or answers nothing servable (unreachable, not
|
||||
ready, older than the mapping's stale timeout), returns `BadWaitingForInitialData` as before; a
|
||||
read never admitted by the deadline is scheduled as before. A lapsed lease is renewed first, in the
|
||||
same request (see [Data connections](DataConnections.md#subscription-freshness-and-exact-item-renewal)).
|
||||
Before #938 `maxAge=0` was never served from the cache and never awaited, so it answered
|
||||
`BadWaitingForInitialData` on every read — which is what ScadaBridge's DCL
|
||||
(`RealOpcUaClient.ReadValuesAsync`, `session.ReadAsync(null, 0, …)`) and the Client CLI default send.
|
||||
The origin's own local Read remains a cached read rather than a device poll.
|
||||
|
||||
For explicit cached reads, the CLI accepts `read --max-age 5000` (milliseconds).
|
||||
Its default remains zero. A cold projection can still return pending; retry after
|
||||
the bounded refresh completes. This matches the [OPC UA Read age parameter](https://reference.opcfoundation.org/specs/OPC-10000-4/5.11.2);
|
||||
For explicit cached reads, the CLI accepts `read --max-age 5000` (milliseconds); its default is
|
||||
zero. This matches the [OPC UA Read age parameter](https://reference.opcfoundation.org/specs/OPC-10000-4/5.11.2);
|
||||
it does not extend a mapping's authority lease or allowed origin-sample age.
|
||||
|
||||
Projected data-change monitored items acquire live demands and share compatible upstream
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
# #938 / #939 / #940 / #948 — projected Read age, origin refusals, lapsed Write/Subscribe, consumed candidates
|
||||
|
||||
2026-12-01. Follow-ups of #920 and #922 (`920.md`, `fu922.md`). Consumer side of gRPC data connections.
|
||||
|
||||
## #938 — `maxAge = 0` never returned Good
|
||||
|
||||
**Root cause.** The projected Value Read (`OtOpcUaNodeManager.Read` pre-loop) served the cache only when `maxAge > 0`, and every
|
||||
other case scheduled a fire-and-forget origin read and answered `BadWaitingForInitialData` (the sync SDK callback could not wait).
|
||||
With `maxAge = 0` the cache is never eligible, so every read was `BadWaitingForInitialData`, forever.
|
||||
|
||||
**Who sends 0.** The Client CLI default (`read --max-age 0`) and **ScadaBridge's DCL**:
|
||||
`RealOpcUaClient.ReadValuesAsync` (`src/ZB.MOM.WW.ScadaBridge.DataConnectionLayer/Adapters/RealOpcUaClient.cs:1546`) calls
|
||||
`session.ReadAsync(null, 0, …)` for every Value read (`ReadValueAsync` delegates to it). Its other `ReadAsync` calls (lines 1687,
|
||||
1992) read DataType/ValueRank/AccessLevel, not Value.
|
||||
|
||||
**Fix.** `OtOpcUaNodeManager` implements `IReadAsyncNodeManager` (forwarded by the SDK's `AsyncNodeManagerAdapter`): before the
|
||||
unchanged sync `Read`, it serves every projected Value read the cache cannot satisfy from an awaited origin read
|
||||
(`IProjectedDataAccess.ReadNowAsync` — the same admission, authenticated/freshness-checked read and cache publication as
|
||||
`ScheduleRead`). A lapsed lease is renewed first (#922 classification) and read in the same request. Bounded by 5 s
|
||||
(`ProjectedOriginReadWait`) and the request deadline − 250 ms; reads are pumped through the unary budget (the default 1 MiB budget
|
||||
admits one read at a time). Unanswered / unservable ⇒ `BadWaitingForInitialData` as before; the caller's demand is re-checked at
|
||||
serve time. The renewal no longer schedules a separate warming read.
|
||||
|
||||
## #939 — an origin refusal read as retryable
|
||||
|
||||
**Root cause.** `RemoteNamespaceResolver.RenewExactAsync` returned `bool`, so an origin that stopped granting the operation looked
|
||||
exactly like an unreachable one (`BadResourceUnavailable`, 250 ms back-off, retried forever).
|
||||
|
||||
**Fix.** `RenewExactOutcomeAsync` → `ProjectedRenewalResult {Renewed, Refused, Failed}`. `Refused` only for the origin's own verdict:
|
||||
the call answered `PERMISSION_DENIED` (as the cause of the connection's "no ready endpoint" failure), the item answered `Denied`, the
|
||||
principal no longer holds Metadata, or the metadata no longer grants the operation (a write: or is not writable). It is answered
|
||||
`BadUserAccessDenied` (Read, HistoryRead, Write, CreateMonitoredItems) and held 5 s (`LapseRefusalHold`) per node and operation,
|
||||
unsent. `Unauthenticated`, unreachable, unready, capacity and timeouts stay `Failed` (retryable).
|
||||
|
||||
## #940 — Write / CreateMonitoredItems on a lapsed node
|
||||
|
||||
**Root cause.** Neither classified a refused acquire; both answered `BadUserAccessDenied`. CreateMonitoredItems threw it from the item
|
||||
manager, which runs under the SDK's `Lock` and faults the WHOLE request.
|
||||
|
||||
**Fix.** `RenewLapsed` accepts Write (also gated on the local write role) and Subscribe. `OtOpcUaSdkServer.WriteAsync` awaits the
|
||||
renewal (≤ 4 s, ≤ half the timeout hint) and dispatches; `BadResourceUnavailable` (unsent) when it cannot renew. CreateMonitoredItems:
|
||||
`ICreateMonitoredItemsAsyncNodeManager` awaits the renewals once per request (≤ 4 s), then the sync override classifies each projected
|
||||
Value item outside `Lock` (probe acquire; lapse ⇒ `BadResourceUnavailable`, refusal ⇒ `BadUserAccessDenied`) PER ITEM.
|
||||
|
||||
## #948 — orphan proof candidate for a consumed acquisition
|
||||
|
||||
**Decision: not intended.** A candidate exists to prove one SDK notification; a re-delivered acquisition the item already delivered
|
||||
produces none (same value/status/timestamps ⇒ the SDK filter drops it), so the candidate and its shared budget charge lingered.
|
||||
`ProjectedMonitoredItem` now remembers the last consumed acquisition (key only, no value). A complete snapshot of it, with nothing
|
||||
queued since (no candidate, no queued loss, no rebind / client mode change / unmatched notification), renews health evidence and adds
|
||||
no candidate. Any queue reset clears the memory, so a wrong skip can only cost an unproven notification + baseline request.
|
||||
|
||||
## Red / green (Runtime harness, real consumer SDK session + projection stack)
|
||||
|
||||
| Test (`Trait Issue`) | pre-fix | fix |
|
||||
|---|---|---|
|
||||
| 938 `A_max_age_zero_read_is_served_from_the_origin_in_the_same_request_every_time` | **FAIL** | pass |
|
||||
| 938 `A_max_age_zero_batch_larger_than_the_unary_budget_is_pumped_and_fully_served` | **FAIL** | pass |
|
||||
| 938 `A_max_age_zero_read_of_a_lapsed_node_renews_and_is_served_in_one_request` | **FAIL** | pass |
|
||||
| 938 `A_max_age_zero_read_without_the_read_grant_is_denied_and_never_reaches_the_origin` (control) | pass | pass |
|
||||
| 939 `An_origin_refusing_the_renewal…` × {ItemDenied, OperationNotGranted, PermissionDeniedCall} | **FAIL** ×3 | pass |
|
||||
| 939 `An_unreachable_origin_for_a_lapsed_node_stays_retryable_not_denied` | **FAIL** (final read) | pass |
|
||||
| 939 `An_origin_that_stops_granting_history_answers_a_lapsed_history_read_access_denied_unsent` | added after (pre-fix: `BadResourceUnavailable` by #922 design) | pass |
|
||||
| 940 `A_write_to_a_lapsed_node_renews_on_demand_and_is_dispatched` | **FAIL** | pass |
|
||||
| 940 `A_write_to_a_lapsed_node_whose_origin_is_unreachable_is_retryable_and_unsent` | **FAIL** | pass |
|
||||
| 940 `A_write_to_a_lapsed_node_without_the_write_grant…` (control) | pass | pass |
|
||||
| 940 `Creating_a_monitored_item_on_a_lapsed_node_renews_on_demand_instead_of_denying` | **FAIL** | pass |
|
||||
| 940 `Creating_a_monitored_item_on_a_lapsed_node_whose_origin_is_unreachable_is_retryable` | **FAIL** | pass |
|
||||
| 940 `Creating_a_monitored_item…without_the_subscribe_grant…` (control) | **FAIL** (request fault, not per item) | pass |
|
||||
| 948 `A_redelivered_already_consumed_acquisition_leaves_no_orphan_candidate` | **FAIL** (1 orphan) | pass |
|
||||
|
||||
Updated (behaviour changed by #938, first read now Good): `Sdk_mapped_read_preserves…`, `Cold_sdk_read_publishes…`,
|
||||
`New_primary_renews_same_monitored_item_after_a_prior_mapped_read(warmByRead)`, the #922 value-read test's second idle gap.
|
||||
|
||||
Not live-gated (no rig run in this change).
|
||||
Reference in New Issue
Block a user