saveAll

open suspend override fun saveAll(snapshots: List<SnapshotRecord>): List<SnapshotSaveOutcome>

Saves snapshots: in the rounds SnapshotSaveOutcome.rounds gives, each round's snapshots of one aggregate type with one statement (PostgresSnapshotTables.saveRows, at most PostgresSnapshotTables.MAX_ROWS a statement), then, only when some were refused, one statement marking those of a higher state revision stale. So a batch of one aggregate type that all lands is one round trip, as one save is.

All of it is one transaction and one commit, the aggregate types in name order and each statement's rows in key order, so concurrent batches lock their common rows in the same order.

When the store is covered, the commit does not wait for its WAL flush (synchronous_commit = off). Covered means the node found the context's log, the checkpoints its snapshot subscription saves and every store its snapshots go to all on this one store (me.ahoo.wow.spi.store.CoveredSnapshots). Then the snapshots are its log folded, and the subscription saves the checkpoint covering them, which waits for its own flush, only after they are written. The WAL being written in order, that flush carries them, as any append's does, or the WAL writer's after wal_writer_delay. A crash of PostgreSQL loses at most the snapshots after the last durable checkpoint, which the subscription then takes again and writes again; meanwhile a load replays more of the log. Waiting for the flush there too doubled a command's WAL flushes, its append's and its snapshot's. PostgreSQL flushes one at a time, so on a disk whose flushes take half a millisecond a node at a thousand commands a second spent more than a second of flushing a second, and its commits queued.

A store not covered commits as any write, waiting for its flush. A checkpoint durable elsewhere, in another database or backend, would otherwise cover snapshots this one could lose with nothing to write them again, and an idle aggregate's snapshot would stay at the state before until its next command.

A statement PostgreSQL refuses for a value (PostgresFailures.isRefused) aborts the transaction, which then wrote nothing: the rounds run again statement by statement in autocommit, where such a statement's snapshots are saved one by one, so the one refused is SnapshotSaveOutcome.Failed alone. Any other failure is thrown, and nothing of the batch was written.