ZB.MOM.WW.Auth.ApiKeys: debounce MarkUsedAsync (last_used_utc) and take it off the verification path #61
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Cross-repo follow-up from historiangw#169 (HOST-01, 2026-12-02 performance & bug review of HistorianGateway; decision D3, 2026-12-03).
Problem
ApiKeyVerifier.VerifyAsyncruns on every authenticated RPC in consuming gateways, and each successful verification callsIApiKeyStore.MarkUsedAsync(src/ZB.MOM.WW.Auth.ApiKeys/ApiKeyVerifier.cs:98) synchronously on the request path.SqliteApiKeyStore.MarkUsedAsyncopens a fresh connection, re-runs thejournal_mode=WAL/busy_timeout=5000PRAGMAs and commits anUPDATE api_keys SET last_used_utc = ...(Sqlite/SqliteApiKeyStore.cs:27-40).*Asyncis synchronous, so this blocks a thread-pool thread per call.UPDATEserializes every RPC of every key through the database write lock. Throughput is bounded by the key-store volume's commit rate, not by the gateway or historian.Affects HistorianGateway (OtOpcUa sends one
SendEventper alarm) and any other consumer of the verifier (mxaccessgw).Requested change (decided)
Debounce the last-used stamp and take it off the request path:
last_used_utcat most about once per minute per key (configurable interval;0= current per-call behaviour if a consumer needs it).VerifyAsyncdoes only the read + HMAC compare.last_used_utcbecomes accurate to the debounce interval; document that.Gateway side (not in this issue)
historiangw#169 step 2 adds a gateway-owned success cache (
ApiKeys:VerificationCacheSeconds, default 0 = off) on top. The gateway picks up this change by bumping itsZB.MOM.WW.Auth.*package pins once published.Tests
MarkUsedAsync/ oneUPDATE.MarkUsedAsync).