Module oneshot
Expand description
The shared one-shot coordinator (303-PUBLIC-SQL-COORDINATOR-EXTRACTION-PLAN.md, PRs
1–4): the public-SQL batch, DDL, script, and migration orchestrations — validation,
replay decisions, the statement loops with their byte accounting, the lost-race
re-reads, and the migration replay/adopt matrix inside the host-owned barrier — written
once over the OneShotBackend trait so a second write host implements the trait
instead of re-deriving the control flow.
The trait is required, not defaulted (decision C1): a host implements it or the
one-shot routes don’t exist, so one-shot support is a compile-time property. It is disjoint
from the interactive SessionBackend — nothing in this flow calls the interactive
begin/exec/commit, and session.rs imports nothing from this module.
No function here reads a clock (decision C2): entry points take now_ms and the backend’s
floor method injects the host’s own clock.
Structs§
- Public
Migrate Ack - The typed outcome of one public migration:
appliedisfalseon an exact replay. The cursor is required — a fresh apply always commits one, and a replay either resolves the exact stored cursor or refusesMIGRATION_OUTCOME_UNAVAILABLE(extraction plan C6). - Public
Operation Commit - The typed outcome of one committed — or exactly replayed — public one-shot operation.
resultsare wire-encoded statement results (the dedicated tagged SQL codec), so a stored replay is byte-equivalent to the fresh commit; the hosts wrap this in their own success envelope (decision C7 — routing metadata and the HTTP layer stay per-host). - Script
Outcome - The typed outcome of one public script (execute-multiple). A script never fails at the
top level — failure is data: the completed prefix’s wire-encoded
results, the last committed statement’scursor, and the failing statement’s index with its pre-classified error. The hosts renderfailurethroughrender_public_script_errorand wrap success per-host (decision C7).
Traits§
- Migration
Section - The migration-store view
OneShotBackend::with_migration_barrierpasses to its closure. Reads carry NO decisions — the replay/adopt matrix over them isexecute_public_migration’s, the same compiled code on every host; every op executes under the barrier’s exclusion span. - OneShot
Backend - The backend contract of the one-shot public SQL surface. The master implements it over its
session-transaction primitives; a standalone daemon implements it over its own store (303
S5). Every method returns pre-classified
WritePlaneError— classification happens once, host-side, and there is no conversion back out (decision C3). - Public
Replay Reads - The three reads behind the shared replay spine, generic over the host’s error currency.
The coordinator instantiates it over
OneShotBackend(withWritePlaneError); the replicator’s transaction-outcome cursor path instantiates it over a raw connection withMasterError— ONE decision matrix and ONE resolver, no twin, which is what decision C4 means by “generic by construction”.
Functions§
- execute_
public_ batch - Execute one public SQL batch: validate the idempotency key against the caller’s
now_ms(future skew bounded — the coordinator reads no clock), check for an exact replay, then run every statement inside one backend transaction while bounding the encoded result array — the JSON array delimiters (2 bytes) and inter-result separators count towardaggregate_result_byte_limit— and commit with the outcome row. Any statement or accounting error rolls the unit back. A commit error is re-read: a concurrent request carrying the same identity may have won while this attempt was open, and its co-transactional outcome is authoritative — the exact stored bytes are returned instead of a duplicate-key/conflict error. - execute_
public_ ddl - Execute one public DDL operation: validate the idempotency key against the caller’s
now_ms, refuse non-DDL statements before any backend call, check for an exact replay, then hand the fresh apply to the backend’s critical section as one atomic unit (OneShotBackend::apply_public_ddl). - execute_
public_ migration - Execute one public migration (extraction plan C6): apply a permanent, checksum-guarded migration identity, where reusing an id with identical bytes is an exact replay and reusing it for different DDL is refused instead of silently accepting schema drift.
- execute_
public_ script - Execute one public script (execute-multiple): an ORDERED sequence of autocommit units,
each dispatched by statement class into
execute_public_batch(reads/writes) orexecute_public_ddl(DDL) under a per-index derived idempotency key —sql-script:<key>:<index>. Replay identity across retries depends on that exact format: every completed statement’s outcome is stored under its derived key, so a retry of the whole script replays the durable prefix instead of re-applying it, then resumes at the statement that failed. Transaction-control statements and classes outside the v1 surface are refused without reaching the backend. - resolve_
public_ outcome_ cursor - Resolve the exact cursor carried by one retained outcome row —
resolve_replay_cursorwired to the outcome surface: the run_id scan, and the durable outcome row as the GC-race re-read. - resolve_
replay_ cursor - The ONE exact-cursor resolution algorithm (decision C4), generic over the durable row it
resolves: the stored
cursorshort-circuits, then the legacyrun_idscan, then the GC-race re-read of the durable row filtered on the same run_id — journal GC may have backfilled the row and removed the run frame between the first read and the scan, so the re-read is what carries correctness. The outcome surface wires it to the outcome row (resolve_public_outcome_cursor); the migration surface wires it to the section’s scan withrecord()as the re-read leg, inside the barrier. - stored_
public_ operation - The replay spine at the coordinator surface:
stored_public_operation_overdriven through the backend trait. Used by both the batch and DDL flows. - stored_
public_ operation_ over - The shared replay decision matrix (decision C4), generic over the host error: a miss whose
key minted at or below the retention floor fails closed (
OPERATION_OUTCOME_EXPIRED); a stored request identity that differs from the retry refuses (OPERATION_ID_MISMATCH); a run_id-bearing outcome whose exact cursor cannot be resolved refuses (OPERATION_OUTCOME_EXPIRED) rather than answer with a fabricated cursor.