Module live_projection_store
projection-store only.Expand description
Postgres-backed SendProjectionStore whose batch is a live transaction.
§Why a second projection store, and why it is an instrument
PS-2 is [FROZEN] and forbids freezing the projection port until the
conformance suite has gone green against adapters at both ends of the
batch-shape axis: one whose batch is an owned write set replayed at commit,
and one whose batch holds a live transaction. Every implementation in this
workspace — PostgresProjectionStore
included — sat at the first end, and until ADR-0062 the port’s own signatures
made the second unreachable: begin was total, synchronous and infallible,
while sqlx’s only route to a [Transaction] is pool.begin().await?; and
the probe seam was synchronous, infallible and took &Self::Batch, while a
driver borrows its connection mutably to issue a statement. ADR-0060 recorded
that finding. ADR-0062 moved the seam. This is the adapter that stands at
the end the seam now admits.
It is the same reason happenstance-postgres exists at all for the event
store: not to ship a second way of doing the same thing, but to sit at the
far end of an axis and find out whether the port is wrong about something the
near-end adapters cannot disagree with. What is different here, and stated
rather than discovered:
beginis a round trip —BEGINon a pooled connection — and can fail. A buffering store’sbeginis neither.- Every write issued into the batch has already reached the server when the batch is dropped. PS-7’s “dropping a batch rolls back and leaves the store usable” is free for a buffer and is a real obligation here: the pooled connection must go back with its transaction rolled back.
- A statement that fails mid-batch poisons the transaction — Postgres
answers every subsequent statement with “current transaction is aborted”
— so a probe write can fail, and the seam’s
Resultis where it says so. READS_THROUGH_BATCHistrue, and it is a true statement about this store: aSELECTthrough the open transaction sees the transaction’s own uncommitted writes. PS-12’s rule,batch_reads_reflect_pending_writes, runs here against a real database for the first time.
§Driving it with the typed runner, and what that costs
Since ADR-0074 the typed layer’s Projection::apply is async, so a
projection awaits LivePostgresBatch::execute inside the live transaction
and happenstance::run_projection drives it (tests/live_projection.rs).
Statements reach the server as apply runs, at a cost: a pooled connection
held for a whole chunk, and a server refusal aborts the transaction unless
apply rolls back to a SAVEPOINT it set (#103). The batch exposes no
query method; only the probe reads pending writes back (PS-12).
PostgresProjectionStore stays the default.
§The invariant
A read-model write and its checkpoint write must be one transaction. Here
that is literal: the caller’s statements and the checkpoint upsert are issued
on the same [Transaction], and commit
commits it once.
Structs§
- Live
Postgres Batch - A Postgres projection batch that is an open transaction.
- Live
Postgres Projection Store - A Postgres-backed projection store whose batches are live transactions.