Repository navigation
feat(qwp): add owned_by to name the owner of the tables a sender auto-creates - #82
glasstiger wants to merge 9 commits into
Conversation
…-creates QWP ingestion auto-creates the tables and columns a sender writes, and QuestDB Enterprise grants their creator the owner permissions on them. An external (OIDC) user cannot hold permissions, so it could not auto-create anything over QWP. SQL solves this with OWNED BY. The owned_by connect-string key and the ownedBy ingress option are the QWP equivalent, as in the Java client (questdb/java-questdb-client#130). - Node.js sends the owner as X-QWP-Owned-By, percent-encoded UTF-8 in the canonical form the server echoes, on every /write/v4 upgrade: reconnects, failovers and orphan drains included. Query sessions never send it, and the connect strings of the other transports reject the key. - The upgrade fails with the new QwpOwnedByMismatchError, exported from the Node.js package, unless the server echoes the owner: a server that predates the header ignores it, and the tables it creates would not get the owner. - That failure is a capability gap, handled like a durable ACK the server does not confirm: a blocking startup fails at once, background replay retries it, and an orphan drainer counts it toward the budget a missing durable ACK draws on, then quarantines the slot. - A rejected upgrade carries the text/plain body that arrived with its headers as QwpUpgradeError.reason, sanitized and capped at 256 characters, and appends it to the message, so a refused owner (403) reads "[reason=owned_by refused: ...]" instead of looking like a rejected credential. - The browser client sends the owner in the qwp_owned_by URL parameter. A browser cannot read the upgrade response, so it cannot confirm the owner, as the option's documentation says. Documents the option in QWP.md and the READMEs, and regenerates the API reference.
ownedBy combined with an X-QWP-Owned-By header in the headers escape hatch was rejected only by the first connection attempt, while a blank owner, or one with a lone surrogate, already failed when the sender or client was created. createQwpNodeSender() and the pooled client's option normalization now reject the conflict as well, against the headers ingress ends up with, so Sender.fromConfig(), new Sender(), createQwpNodeClient() and parseQwpNodeClientConfig() report it up front. The raw connector keeps its connect-time check, and both apply one rule. A Sender's invalid typed ownedBy is reported as qwp.webSocket.ownedBy, the option its caller wrote, rather than as the pooled client's ingress.ownedBy. The display-text test now covers U+2029, the one character class of the sanitizer that no test exercised.
Resolve ownedBy and raw headers at Sender construction so later overrides cannot leave a stale upgrade header. Only read a bounded prefix of complete, uncompressed text/plain upgrade rejections. Document orphan adoption, browser fallback, and reconnect event semantics. Exercise owner changes and replay on the wire, and drain notifications before asserting their absence.
Snapshot headers per parsed configuration and honor getter-backed owners on Node and browser ingress. Keep the chosen owner across lazy connects, failover, foreground replay, and orphan adoption. Report the final capability gap separately from the orphan retry budget and decode bounded upgrade refusal text using its declared charset. Cover these paths with transport and replay regressions.
|
Review of CriticalNone. ModerateNone. Minor
Tradeoffs (deliberate, not findings)
Verified at
|
…est name with the code The senders no longer call connectQwpNodeIngress(), connectQwpBrowserIngress() or createQwpBrowserConnectionFactory(): they capture ownedBy once, when they are created. Describe those functions as the test entry points they are, and put the auth-validation comment in createQwpBrowserSender() back above its call. durable-ack-unavailable events count the whole capability-gap episode, owner gaps included. Say so for that event and for QwpReconnectEvent.attempt, as the durable-ack-persistent-failure docs already did. Name the rejected-upgrade copy test after what it checks: it decodes at most 4,096 bytes and catches only a concat-based copy. Regenerates the API reference.
A Sender built from a ws/wss connect string copies qwp.webSocket.headers when its SenderOptions is created and again when the Sender is built, so edits to that object no longer reach it, reconnects included, and it reads headers and ownedBy from the qwp section it is given. The caller's object used to be read on every connection attempt. Say so in QWP.md and on QwpExtraOptions.webSocket, and pin both copies and the section read in tests. The content-coded rejection test now declares charset=iso-8859-1, which decodes any byte sequence, so it fails without the Content-Encoding check. Under UTF-8, gzip's magic number failed to decode with or without it. Regenerates the API reference.
|
Review level 3 (requested, full pass). PR #82 The title and commits follow Conventional Commits. The description explains the user impact, the retry policy, the differences from the Java client and both behavior changes. The Compatibility section leaves out two additive public type members: CriticalNone. ModerateNone. Adjacent findingsNone. Coverage mapThe test gate passes with no coverage gaps. SummaryVerdict: approve. No problems found.
What I checked at
Deliberate tradeoffs, documented in QWP.md and the PR body:
Limitations:
|
…the pooled drainer's owner No test fed the reconnect loop a sweep in which every endpoint completed the upgrade without a capability the session asked for. Disabling its handling of such a sweep left every test passing, while a blocking store-and-forward startup then retried for its whole budget and an orphan slot was never quarantined. Cover it with synthetic sweeps of owner gaps, and of an owner gap followed by a durable-ACK gap, and run the blocking startup test against two real endpoints that both ignore the owner. The pooled client's orphan drainer was untested as well: passing it no owner left every test passing, while a recovered slot then replayed without X-QWP-Owned-By. Drain a slot a pooled sender left behind and check that the recovery upgrade names the pool's owner.
createQwpNodeSender() binds ownedBy when the sender is created, so that lazy startup, foreground replay and orphan adoption all use the same owner. Only the first two were tested. The orphan-drain test adopted through connectQwpNodeIngress(), where the live and the bound owner are the same value, so a drainer that read options.ownedBy again left every test passing while it replayed adopted slots under an owner the sender was not created with. Run that test through a sender whose options change after it is created as well.
…ct error The error for an owner that an X-QWP-Owned-By header also names always called the option 'ownedBy'. A Sender or pooled client that takes its owner from the connect string now reports 'owned_by', and typed owners report 'qwp.webSocket.ownedBy' or 'ingress.ownedBy', as the other owner errors on those paths already do. createQwpNodeSender() and the raw connector keep 'ownedBy'.
|
Review level 3 (requested, full pass). PR #82 at HEAD Verdict: approve. No Critical, Moderate or Minor issues remain. The title and all nine commit subjects follow Conventional Commits. The description covers the user impact, the retry policy, how this differs from the Java client, and the two behavior changes. Since the previous passMy pass at
New cases in CriticalNone. ModerateNone. MinorNone. Adjacent findingsNone. Coverage mapThe test gate passes, with no coverage gaps. At
Summary
Deliberate tradeoffs (all documented in
What I verified at
What I verified at
Limitations: I didn't run against a server that includes #8504 or the Enterprise PR, so I checked their behavior from source only. I tested connection resets on macOS only. |
|
Review level 3 (requested, full pass). PR #82 at HEAD Verdict: approve. I found no Critical or Moderate issues and one Minor doc comment. CriticalNone. ModerateNone. Minor
Adjacent findingsNone. Coverage map
Summary
What I verified at
Limitations: I ran nothing against a QuestDB build that includes #8504 or the Enterprise PR, so their server-side behaviour is checked from source only. |
|
Verdict: approve. I found no Critical or Moderate issues and one Minor doc-comment inaccuracy. This was a level 3 review (full pass) of PR #82 at HEAD PR title and description
CriticalNone. ModerateNone. Minor
Adjacent findingsNone. Coverage mapThe test gate passes, with no coverage gaps. What I ran at
I also checked the wire format against the server source (questdb/questdb branch
Summary
|
Client side of questdb/questdb#8504 and questdb/questdb-enterprise#1572, modelled on questdb/java-questdb-client#130; the protocol and Java client are documented in questdb/documentation#652.
Problem
QWP ingestion auto-creates the tables and columns a sender writes, and QuestDB Enterprise grants their creator the owner permissions on them. An external user, one authenticated with an OIDC token, cannot hold permissions, so it could not auto-create anything over QWP. SQL solves this with
OWNED BY; this client had no QWP equivalent.Changes
Node.js
owned_by=<name>connect-string key andownedByingress option:Sender.fromConfig(),qwp.webSocket, the direct senders, and the pooled client'singress. Ingress only: query sessions never send it, and the connect strings of the ILP and UDP transports reject the key.X-QWP-Owned-Byon every/write/v4upgrade, reconnects, failovers and orphan drains included, percent-encoded UTF-8 in the canonical form the server echoes.QwpOwnedByMismatchError(exported from the Node.js package only) unless the 101 echoes the owner: a server that predates the header ignores it, and the tables it creates would not get the owner.text/plainbody that arrived with its headers asQwpUpgradeError.reason, sanitized and capped at 256 characters, and appends it to the message. A refused owner (403) reads[reason=owned_by refused: …]instead of looking like a rejected credential.ownedBycombined with a hand-writtenX-QWP-Owned-Byheader are rejected when the sender or client is created.Retry policy
An unconfirmed owner is a capability gap, handled like a durable ACK the server does not confirm; the two now share one path in the reconnect loop:
offorsync) startup fails at once, and so does a reconnect without background replay.initialConnectMode: "async", keeps retrying and keeps its rows.reconnectMaxDurationMs), then quarantines the slot behind.failedwith an error that namesowned_by. The durable-ACK events still report durable ACK only.Browser
A browser cannot set the header, so the owner travels in the
qwp_owned_byURL parameter, which the server reads when the header is absent. A browser cannot read the 101 either, so it cannot confirm the owner: a server that predates the option ignores it, and a refused owner surfaces as the opaque upgrade error. The option's TSDoc and QWP.md say so.Differences from the Java client
These follow this client's existing durable-ACK policy rather than Java's:
asyncstartup retries an unconfirmed owner; Java fails it at once.asyncstartup ends when a reconnect meets one; Java keeps retrying.QwpFailoverErrorlisting both attempts, which stays retryable; Durable-ack mismatch reported as a missing primary in mixed connect rounds java-questdb-client#131 made Java report the gap instead.owned_byas an unknown key, as they do every other QWP key, rather than with a dedicated message.Compatibility
Additive: a new option, a new error class and a new optional
QwpUpgradeError.reason. Two existing behaviors change:[reason=…]suffix when the server sends atext/plainbody; the wording of an error message is not part of the contract.Senderbuilt from a ws/wss connect string copies typedqwp.webSocket.headerswhen itsSenderOptionsis created and again when theSenderis built, so later edits to that object no longer reach reconnects; the caller's object used to be read on every connection attempt. ReplacingSenderOptions.qwpbefore building theSenderreplaces those headers and theownedByoverride. This keeps a sender from sending headers meant for another sender built from the same options; QWP.md documents it.Follow-up
questdb/documentation#652 marks
owned_byas Java-only; it can name the Node.js and browser clients once this ships.Validation
wsand raw TCP servers, the reconnect policy, orphan quarantine, config parsing, and the browser URL parameter.typecheck,typecheck:qwp-browser,typecheck:test,typecheck:bench,typecheck:dist(including TypeScript 4.9), ESLint, Prettier andcheck:packages.Most of the 614-file diff is the regenerated API reference.