Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
118 changes: 108 additions & 10 deletions QWP.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ keys they correspond to, so a typed `reconnect: { onEvent }` keeps the
`reconnect_*` or `failover_*` budgets the string sets, while `reconnect: false`
still disables reconnecting.

A `Sender` built from a connect string copies `qwp.webSocket.headers` when the
`SenderOptions` is created and again when the `Sender` is built, and sends that
copy on every connection, reconnects included. Edits to the object you passed
in are not seen after the `SenderOptions` is created, and no edit reaches a
`Sender` that already exists: build a new `Sender` to send different headers.
The copies keep a sender from sending headers meant for another sender built
from the same options object. The `Sender` reads `headers` and `ownedBy` from
the `SenderOptions.qwp` it is given, so replacing that section before building
the `Sender` replaces both: typed headers the new section leaves out are
dropped, and an `ownedBy` it leaves out falls back to the connect string's
`owned_by`. Every other typed value keeps the value it had when the
`SenderOptions` was created.

Typed `ExtraOptions.qwp` sections are transport-specific, and a mismatched or
unknown section is rejected rather than ignored: `webSocket` applies only to
`ws::`/`wss::` and `udp` only to `udp::`, and each takes that sender's complete
Expand Down Expand Up @@ -121,6 +134,7 @@ empty `qwp: {}` remains valid for callers that build the object conditionally.
| `transaction` | `on`, `off` | off | Group each flush into a per-table transaction. |
| `request_durable_ack` | `on`, `off` | off | Require durable ACKs; fails if the server cannot confirm them. |
| `durable_ack_keepalive_interval_millis` | integer ms | `200` | Durable-ACK poll interval; ignored unless `request_durable_ack=on`. |
| `owned_by` | string | — | Owner of the tables and columns the sender auto-creates (Enterprise). |
| `max_name_len` | integer | `127` | Maximum table and column name length, in UTF-8 bytes. |
| `sender_id` | string | `default` | Names this producer's journal slot on disk. Not sent to the server. |
| `max_frame_rejections` | integer | `4` | Consecutive suspect outcomes for one frame before terminal escalation. |
Expand Down Expand Up @@ -626,16 +640,24 @@ reports a typed `data-loss` sender error. Callback exceptions cannot interrupt
recovery.

Blocking (`off` or `sync`) foreground startup fails immediately if every usable
endpoint lacks durable-ACK support. Asynchronous foreground startup and steady-state
store-and-forward reconnects retain their records and retry through rolling upgrades.
An orphan slot retries a consecutive durable-ACK capability-gap episode until it has
endpoint lacks durable-ACK support, or leaves the `ownedBy` owner unconfirmed (see
[Owner of auto-created tables](#owner-of-auto-created-tables)). Asynchronous
foreground startup and steady-state store-and-forward reconnects retain their records
and retry through rolling upgrades. An orphan slot retries a consecutive
capability-gap episode, sweeps in which every endpoint lacked a durable ACK or left
the owner unconfirmed, the two counted together, until it has
lasted both 16 connection sweeps and the configured `reconnectMaxDurationMs`, then it
is quarantined behind `.failed` (with `reconnectMaxDurationMs: 0` the time half is
spent at once, so the 16 sweeps decide). A transport outage or an all-replica window resets both halves of this
orphan budget; neither transient condition can itself quarantine persisted data. The
`durable-ack-unavailable`,
`durable-ack-persistent-failure`, and `primary-unavailable` orphan events expose the
distinction to operators.
distinction to operators. A `durable-ack-unavailable` or
`durable-ack-persistent-failure` event means its sweep reported a missing durable
ACK, the latter on the sweep that exhausts the budget. The `attempt` and `episodeMs`
of both cover the whole capability-gap episode, including owner gaps, so the first
such event after owner gaps reports an attempt above 1. When an unconfirmed owner
exhausts the budget, the drainer reports quarantine through `failed` instead.

A foreground sender retries a symbol-dictionary catch-up entry that is too large for
the current target forever because a larger-cap node may return. An orphan drainer
Expand Down Expand Up @@ -1152,6 +1174,73 @@ ignore the query parameter; after a bounded 250 ms negotiation window the client
continues in unknown-cap mode. Set `ingressNegotiationTimeoutMs` to tune that window,
or keep using `maxBatchSizeBytes` as a local compatibility limit.

### Owner of auto-created tables

QuestDB creates the tables and columns a batch names that do not exist yet, and
QuestDB Enterprise grants their creator every permission on them. Set `ownedBy`
on the ingress options (`owned_by=<name>` in a connect string) to have them
granted to another user, group, or service account instead, the way `OWNED BY`
does in SQL:

```typescript
const sender = await Sender.fromConfig(
"wss::addr=questdb.example:9000;token=OIDC_ACCESS_TOKEN;owned_by=fx_ingest",
);
```

A principal may name itself or one of its groups. An external user, one that
authenticates with an OpenID Connect token, cannot hold permissions itself, so it
must name one of its groups for the server to auto-create anything for it at all.
Writing to existing tables and columns needs no owner. The option is ingress-only:
a query session creates nothing and never sends it, and the connect strings of the
ILP and UDP transports reject the key. It needs QuestDB Enterprise with access
control.

Node.js sends the owner in the `X-QWP-Owned-By` upgrade header, as percent-encoded
UTF-8, on every `/write/v4` upgrade -- reconnects, failovers and orphan drains
included -- and checks it there:

- A server that accepts the owner echoes it in the `101` response. A server that
predates the option ignores the header, and the tables it auto-created would not
get the owner, so a missing or different echo fails the connection with
`QwpOwnedByMismatchError`.
- An owner the principal may not name is refused with `403`, and so is any owner
when the server cannot set one: QuestDB open source, or Enterprise with access
control disabled. The refusal holds on every node, so it is handled as a rejected
credential is (see [Reconnect, failover, and roles](#reconnect-failover-and-roles)):
it ends the endpoint sweep, and only a sender that retries a rejected credential
retries it. When the client can read QuestDB's explanation, it reports it as
`QwpUpgradeError.reason` and appends it to the message, as in
`[reason=owned_by refused: fx_ingest does not exist]`.

A sender captures `ownedBy` when it is created and uses that owner on every
reconnect. Changing the options for another sender does not change the first
sender's owner. The journaled frames themselves carry no owner: when one
sender adopts another's orphan slot, it replays with its **own** `ownedBy`, or
without an owner if it has none configured. Use separate `storeAndForward.directory`
roots for senders that require different owners. Likewise, drain pending frames
before changing a slot's owner on restart.

An endpoint that does not confirm the owner lacks the feature, as one that does not
confirm a requested durable ACK lacks that, and a rolling upgrade clears both, so
`QwpOwnedByMismatchError` is handled as that durable-ACK gap is. The sweep goes on
to the next endpoint. When every endpoint it reaches leaves the owner unconfirmed, a
blocking (`off` or `sync`) startup fails at once rather than retry, and so does a
reconnect of a sender with neither a journal nor an `"async"` startup, while a
store-and-forward sender that has connected, or one started with `"async"`, keeps its
rows and retries until an endpoint confirms the owner. An orphan drainer counts such
sweeps toward the same capability-gap budget as a missing durable ACK, and
quarantines the slot once that runs out. A sweep that also met an endpoint that was
offline or not the primary stays an ordinary retryable failure.

A browser can neither set the header nor read the upgrade response. The browser
client sends the owner in the `qwp_owned_by` URL parameter instead, which QuestDB
reads when the header is absent. An older server ignores the parameter and applies
its existing ownership rules: a successful upgrade does not mean that an external
user can auto-create a table or that its group will own new columns. A server that
refuses the owner fails the upgrade with the same opaque `QwpUpgradeError` as any
rejected browser upgrade.

### Reconnect, failover, and roles

The preferred URL and `failoverUrls` form one endpoint set. Endpoints are ranked by
Expand Down Expand Up @@ -1239,9 +1328,16 @@ endpoints ranked after it are never tried, and unless one of the exemptions belo
applies, the reconnect loop rethrows it without retrying, so no reconnect setting
extends it. A credential is cluster-wide, so a node rejecting it reports a
configuration error that walking on to a peer would only mask; the Java client applies
the same rule. Every other rejected status keeps the sweep walking, including `404`,
which one node can return mid-deploy while its peers are healthy, and a sweep mixing
such attempts stays retryable if any one of them was.
the same rule. QuestDB also answers `403` to an `ownedBy` owner it refuses, which holds
on every node as well; the error's `reason` can distinguish an owner refusal from
a rejected credential. Every other rejected status keeps the sweep walking,
including `404`, which one node can return mid-deploy while its peers are healthy.
A sweep mixing such attempts stays retryable if any one of them was. Node.js reports
`QwpUpgradeError.reason` only for an uncompressed `text/plain` body that arrives
in full with the response headers. It decodes at most the first 4,096 bytes using
the declared charset (UTF-8 if absent), removes control and other invisible
characters, and caps the displayed reason at 256 characters. An unsupported
charset or invalid text leaves the HTTP status intact without a reason.

Note how this composes with health ranking. A non-orderly close demotes the endpoint
it happened on, so a peer that answers `401` can rank ahead of the endpoint that just
Expand Down Expand Up @@ -1298,9 +1394,10 @@ Python clients deliver to their connection listeners, named by
once per outage, `reconnected` or `failed-over` when a reconnect reaches the same
or a different endpoint, `endpoint-attempt-failed` as each endpoint in a sweep
fails, `all-endpoints-unreachable` once for a sweep that no endpoint accepted, and
`auth-failed` when the server rejects the credentials, which ends the sweep. Unlike
those clients, this one fires the success events only after the unacknowledged
frames are replayed, so an endpoint that fails the replay is reported as
`auth-failed` for a server `401` or `403`, including a Node ingress `403` refusing
the requested `ownedBy` owner. This ends the sweep. Unlike those clients, this
one fires the success events only after the unacknowledged frames are replayed,
so an endpoint that fails the replay is reported as
`endpoint-attempt-failed`. `durable-ack-unavailable`,
`durable-ack-persistent-failure` and `primary-unavailable` report store-and-forward
conditions on the same stream. Egress sessions report the same connection events,
Expand Down Expand Up @@ -2058,6 +2155,7 @@ The public error classes preserve enough context for policy decisions:
| `QwpPoolResourceError` | Creating a new pooled sender or query connection failed |
| `QwpClientClosedError` | The pooled client or an individual returned lease is already closed |
| `QwpDurableAckUnavailableError` | Durable acknowledgement was required but not negotiated |
| `QwpOwnedByMismatchError` | Node.js only: the server completed the upgrade without confirming the `ownedBy` owner |
| `QwpProtocolError` | A QWP payload is malformed, truncated, or unsupported |
| `QwpSendError` | Base class for a frame that could not be handed to the transport |
| `QwpSendClosedError` | The WebSocket was closed, or not open, when a frame was sent |
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ the pooled Node client. Use comma-separated or repeated `addr` values for
failover; standalone ingress validates but otherwise ignores egress- and
pool-only keys.

With QuestDB Enterprise, `owned_by=<name>` (the `ownedBy` ingress option) names
the user, group, or service account that owns the tables and columns a sender
auto-creates, as `OWNED BY` does in SQL. An external user, such as one that
authenticates with an OpenID Connect token, must name one of its groups to have
anything auto-created. Node.js fails the connection with `QwpOwnedByMismatchError`
when the server does not confirm the owner; a browser sends the owner too but
cannot confirm it. See [QWP.md](QWP.md#owner-of-auto-created-tables).

Node.js also supports fire-and-forget QWP-over-UDP through the same API:

```typescript
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/hierarchy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading