Skip to main content

Module mvcc

Module mvcc 

Source
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§

SnapshotBundle
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.
SnapshotContext
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_zoned with std::thread::scope) call this on the main thread before spawning workers so the captured SnapshotContext can be moved into every worker closure. Worker threads do not inherit thread-locals, so calling entity_visible_under_current_snapshot from 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. Returns 0 when 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 the CurrentSnapshotGuard RAII 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. JWT tenant claim, HTTP header, subdomain).
snapshot_bundle
Capture the three read-path thread-locals into a SnapshotBundle. Pairs with with_snapshot_bundle for re-entry.
with_snapshot_bundle
Reinstall a captured SnapshotBundle for the duration of f. Restores the caller’s previous thread-locals on exit (panic-safe via the explicit guard struct so a panic in f cannot leak the installed identity into the worker’s next request).