Expand description
Re-exports for transports + tests that need per-connection isolation, tenant / auth thread-locals, and MVCC snapshot utilities. Mirrors what PG-wire / gRPC / HTTP middleware already call, and is enough to emulate independent connections in integration tests.
Structs§
- Snapshot
Bundle - Frozen MVCC + identity context for callers that need to reinstall the same view across thread-local boundaries — long-lived cursors, background batchers, anything that detaches from the dispatch path and re-enters later.
- Snapshot
Context - Snapshot + manager pair used for read-path visibility checks.
Functions§
- capture_
current_ snapshot - Clone the current thread’s snapshot context. Parallel scan paths
(
query_all_zonedwithstd::thread::scope) call this on the main thread before spawning workers so the capturedSnapshotContextcan be moved into every worker closure. Worker threads do not inherit thread-locals, so callingentity_visible_under_current_snapshotfrom inside a spawned closure would silently skip the filter. - clear_
current_ auth_ identity - Clear the thread-local auth identity. Transports call this after the statement completes so pooled threads don’t leak identities across requests.
- clear_
current_ connection_ id - Reset the thread’s connection id back to
0(autocommit). - clear_
current_ snapshot - clear_
current_ tenant - Clear the current-thread tenant —
CURRENT_TENANT()will then return NULL and any RLS policy gated on it will hide every row. - current_
connection_ id - Read the connection id set by
set_current_connection_id. Returns0when no wrapper installed one — auto-commit path. - current_
tenant - Read the current-thread tenant id, applying overrides in priority order:
- entity_
visible_ under_ current_ snapshot - Is this entity visible under the current thread’s MVCC snapshot?
- entity_
visible_ with_ context - Apply the same visibility rules used by the thread-local helpers
against a caller-provided context. Intended for parallel workers
that captured the snapshot with
capture_current_snapshot(). - set_
current_ auth_ identity - Install the authenticated identity for the current thread (Phase 2.5.2 RLS enforcement). Transport layers call this right after resolving auth so the query dispatch can fold RLS policies into the filter.
- set_
current_ connection_ id - Install a connection id on the current thread for the duration of a
statement. Transaction state (
RuntimeInner::tx_contexts) is keyed by this id so different connections can hold independent BEGINs. - set_
current_ snapshot - Install the MVCC snapshot used by the current thread for the duration
of one statement. Paired with
clear_current_snapshot()— callers should prefer theCurrentSnapshotGuardRAII wrapper so early returns still clean up. - set_
current_ tenant - Install the session tenant id for the current thread (Phase 2.5.3
multi-tenancy). Called by
SET TENANT 'id'dispatch and by transport middleware that resolves tenant from auth claims (e.g. JWTtenantclaim, HTTP header, subdomain). - snapshot_
bundle - Capture the three read-path thread-locals into a
SnapshotBundle. Pairs withwith_snapshot_bundlefor re-entry. - with_
snapshot_ bundle - Reinstall a captured
SnapshotBundlefor the duration off. Restores the caller’s previous thread-locals on exit (panic-safe via the explicit guard struct so a panic infcannot leak the installed identity into the worker’s next request).