Merge fix/258-worker-followup
This commit is contained in:
@@ -909,10 +909,11 @@ Galaxy's last deploy time (`GetLastDeployTimeAsync`), so an undeployed galaxy
|
||||
costs one deploy-time query per refresh rather than the alarm-attribute query
|
||||
and a rebuilt list; a failed discovery or an unknown deploy time is not cached.
|
||||
The gateway compares a SHA-256 of a canonical fingerprint of all six target
|
||||
fields and sends `UpdateAlarmWatchListCommand` only for a material change. The worker constructs,
|
||||
subscribes, and attaches the replacement standby on its STA before swapping it
|
||||
in; a setup failure leaves the previous standby and the current primary/subtag
|
||||
mode unchanged. The gateway advances its acknowledged fingerprint only after an
|
||||
fields and sends `UpdateAlarmWatchListCommand` only for a material change. The worker applies
|
||||
the new list to its existing subtag standby as a diff on its STA — advising only
|
||||
added alarms' subtags, unadvising only removed ones, and keeping the state of
|
||||
unchanged alarms; a failure leaves the previous list in force and the current
|
||||
primary/subtag mode unchanged. The gateway advances its acknowledged fingerprint only after an
|
||||
OK reply, so a rejected update remains degraded and is retried.
|
||||
|
||||
`SubscribeAlarmsCommand.fallback_enabled` distinguishes an initially empty but
|
||||
|
||||
+5
-3
@@ -45,9 +45,11 @@ The shared alarm command model includes `SubscribeAlarms` and
|
||||
initial watch list explicitly fallback-capable, allowing discovery recovery to
|
||||
populate a standby without restarting the primary alarm-manager subscription.
|
||||
`UpdateAlarmWatchListCommand.watch_list` is the complete replacement list. The
|
||||
worker prepares the replacement on its STA before swapping it into the existing
|
||||
failover consumer and returns a normal `MxCommandReply`; callers must treat only
|
||||
`protocol_status = OK` as acknowledgement of the new list.
|
||||
worker applies it to the existing failover consumer's standby as a diff on its
|
||||
STA (advising added alarms, unadvising removed ones, keeping unchanged alarms'
|
||||
state) and returns a normal `MxCommandReply`; a failed update leaves the previous
|
||||
list in force. Callers must treat only `protocol_status = OK` as acknowledgement
|
||||
of the new list.
|
||||
|
||||
`AcknowledgeAlarmRequest` carries the operator's identity: `operator_user`
|
||||
(required), `operator_password` (field 6) and `operator_domain` (field 7). The
|
||||
|
||||
@@ -534,7 +534,7 @@ behavior.
|
||||
| `MxGateway:Alarms:SubscriptionExpression` | _(empty)_ | AVEVA alarm-subscription expression the monitor subscribes on startup, in canonical `\\<machine>\Galaxy!<area>` form. The literal `Galaxy` provider is correct regardless of the Galaxy database name. When empty and `Enabled` is `true`, the gateway falls back to `\\<MachineName>\Galaxy!<DefaultArea>` if `DefaultArea` is set. |
|
||||
| `MxGateway:Alarms:DefaultArea` | _(empty)_ | Area name used to compose a default subscription when `SubscriptionExpression` is empty. If both are empty while `Enabled` is `true`, the monitor faults with a configuration diagnostic. |
|
||||
| `MxGateway:Alarms:ReconcileIntervalSeconds` | `30` | How often the monitor reconciles its in-process alarm cache against the worker's authoritative active-alarm snapshot, and, on a separate loop at the same cadence, re-resolves and on material change hot-swaps the subtag fallback watch-list (the resolution is cached per Galaxy deploy time, so an undeployed galaxy costs one deploy-time query per tick). The acknowledged watch-list fingerprint advances only after an OK worker reply. Must be between 1 and 86,400 when `Enabled` is true; the monitor floors it at 5 seconds. |
|
||||
| `MxGateway:Alarms:PollIntervalMilliseconds` | `500` | Cadence at which the worker's STA polls the AVEVA alarm consumer (`GetXmlCurrentAlarms2`) for the active-alarm snapshot the live feed diffs. Must be between `100` and `3600000` (one hour): every poll is a COM call plus an XML parse on the same STA that serves reads and writes, so a tighter cadence starves the command path, while a value above an hour stops being a cadence and silently disables alarm polling. The gateway conveys the value to the worker via the `MXGATEWAY_ALARM_POLL_INTERVAL_MS` environment variable; a missing or out-of-range value leaves the worker on the 500 ms default rather than failing the session. |
|
||||
| `MxGateway:Alarms:PollIntervalMilliseconds` | `500` | Cadence at which the worker's STA polls the AVEVA alarm consumer (`GetXmlCurrentAlarms2`) for the active-alarm snapshot the live feed diffs. The worker polls only while the session has an alarm subscription; an unsubscribed session's poll loop is parked and costs nothing at this cadence. Must be between `100` and `3600000` (one hour): every poll is a COM call plus an XML parse on the same STA that serves reads and writes, so a tighter cadence starves the command path, while a value above an hour stops being a cadence and silently disables alarm polling. The gateway conveys the value to the worker via the `MXGATEWAY_ALARM_POLL_INTERVAL_MS` environment variable; a missing or out-of-range value leaves the worker on the 500 ms default rather than failing the session. |
|
||||
| `MxGateway:Alarms:MaxAlarmsPerFetch` | `1024` | Cap the worker passes to `GetXmlCurrentAlarms2`'s `maxAlmCnt`. Must be between `64` and `65536` — the worker is a 32-bit process that materializes each reply as one BSTR (streamed into one record per alarm, not a DOM), so an unbounded cap faults the STA with an out-of-memory rather than merely slowing it. It doubles as the **truncation threshold**: a fetch returning exactly this many records is treated as truncated, because the COM API caps its reply with no "more available" flag. On a truncated poll the worker retains the alarms the capped reply could not mention instead of letting their absence read as a clear, and logs a rate-limited `AlarmSnapshotTruncated` warning to its stderr (identifiers and counts only). **Remediation when you see that warning: raise this value** so the steady-state active-alarm count fits inside one fetch. A galaxy permanently above the cap holds stale entries in the snapshot until a sub-cap poll, and loses clear→re-raise cycles that happen entirely out of window (see `docs/DesignDecisions.md`). Conveyed to the worker via the `MXGATEWAY_ALARM_MAX_ALARMS_PER_FETCH` environment variable; a missing or out-of-range value leaves the worker on the 1024 default. |
|
||||
| `MxGateway:Alarms:AckClientName` | `MxGateway` | MXAccess client name the alarm worker's ack writer registers with; the Historian records it as each acknowledgement's OperatorNode. 1-64 printable characters. Conveyed via `MXGATEWAY_ALARM_ACK_CLIENT_NAME`. |
|
||||
|
||||
|
||||
@@ -459,14 +459,30 @@ its entry.
|
||||
## Live alarm watch-list replacement
|
||||
|
||||
An auto-mode `SubscribeAlarms` with `fallback_enabled = true` always builds a
|
||||
`FailoverAlarmConsumer`, even when initial discovery supplied no targets. The
|
||||
handler retains the subscription expression so `UpdateAlarmWatchList` can build
|
||||
and subscribe a new subtag consumer entirely on the session STA. The failover
|
||||
consumer attaches the replacement's transition callback before swapping the
|
||||
standby reference, then detaches and disposes the old standby. If construction,
|
||||
subscription, or attachment fails, it disposes the replacement and preserves
|
||||
the old standby. The active-provider selector is never reset, so primary mode
|
||||
stays primary and subtag mode immediately delegates to the new standby.
|
||||
`FailoverAlarmConsumer`, even when initial discovery supplied no targets.
|
||||
`UpdateAlarmWatchList` runs entirely on the session STA and applies the new list
|
||||
to the existing `SubtagAlarmConsumer` as a diff (MXA-010): the subtags of added
|
||||
alarms are advised on the standby's existing `LmxSubtagAlarmSource`, the subtags
|
||||
of removed alarms are unadvised (`UnAdvise` + `RemoveItem`), and an alarm whose
|
||||
target is unchanged in every field keeps its advice and its tracked state, so no
|
||||
transition is re-emitted for it. Rebuilding the standby instead cost a second
|
||||
MXAccess registration and an `AddItem`/`Advise` for every watched subtag on each
|
||||
change, however small. An alarm whose target changed is treated as removed and
|
||||
re-added and starts from fresh state; when its subtags are already advised, the
|
||||
consumer initialises it from the last value delivered for each subtag (acked and
|
||||
priority before active, so an already-acknowledged alarm syncs as `ACK_ALM`)
|
||||
rather than re-advising.
|
||||
|
||||
The update is all-or-nothing. The new list is validated and the added subtags
|
||||
are advised before anything is swapped; if advising fails, the subtags the call
|
||||
added are unadvised again, the standby keeps serving the previous list, and the
|
||||
command fails. Unadvising removed subtags happens after the swap and is best
|
||||
effort, because an unbound subtag's callbacks are already ignored. A standby that
|
||||
is not a `SubtagAlarmConsumer` (a test seam) is still rebuilt: the handler
|
||||
retains the subscription expression, builds and subscribes a replacement, and the
|
||||
failover consumer attaches its transition callback before swapping it in and
|
||||
disposing the old one. Either way the active-provider selector is never reset, so
|
||||
primary mode stays primary and subtag mode keeps delegating to the standby.
|
||||
|
||||
## COM Creation
|
||||
|
||||
@@ -1067,6 +1083,19 @@ the STA more than 75 s without pumping *should* fault — that is the ceiling's
|
||||
contract). The flag is named generically so any future non-dispatcher STA work
|
||||
reuses it.
|
||||
|
||||
The poll loop runs only while the handler has an alarm subscription (MXA-011).
|
||||
It starts with the session but parks on a semaphore while
|
||||
`IAlarmCommandHandler.IsSubscribed` is false, so a session that never subscribes
|
||||
to alarms — or has unsubscribed — takes no timer, thread-pool or STA wake-ups at
|
||||
the poll rate. A successful `Subscribe` raises `SubscriptionActivated`, which
|
||||
releases the semaphore; the loop then resumes ticking at `AlarmPollInterval`.
|
||||
While subscribed it never parks, so the failover consumer still sees every
|
||||
`PollOnce` it counts primary failures and failback probes on (MXA-001). Shutdown
|
||||
cancels a parked loop the same way as a sleeping one, so the graceful-shutdown
|
||||
join and its grace bound (MXA-003) are unchanged. The consecutive-failure count
|
||||
below resets when the loop parks, so a new subscription does not inherit an
|
||||
earlier one's failure run.
|
||||
|
||||
A `PollOnce` that throws does not fault the session on the first failure. The
|
||||
poll loop counts consecutive failures and records the alarm-poll fault
|
||||
(`MxaccessEventConversionFailed`) only when the count reaches
|
||||
|
||||
Reference in New Issue
Block a user