Skip to main content

Module output

Module output 

Source
Expand description

Protected family state, spooling, and atomic publication.

Generation can produce more state than fits in memory (a family’s buffered child rows) and more than one output that must land together (rendered SQL plus an emitted model). This module supplies the security-critical primitives for both:

  • ProtectedSpool — an owner-only (0600) temporary file with a cryptographically unpredictable name, used to spill buffered rows. Its name is never printed at normal verbosity because the name alone can leak workflow details, and the file is removed when the spool is dropped (success, ordinary failure, or a handled interruption all run Drop).
  • SpoolWriter/SpoolReader/SpooledRow — a length-prefixed, typed record format with a version byte. The reader rejects a version mismatch and an oversized length prefix before allocating, so a truncated or hostile spool cannot drive a huge allocation.
  • AtomicOutput and PublicationSet — write beside the destination into a protected temp file and rename into place only after success. An existing destination is never truncated before the new content is fully written and verified; on Unix the published file follows normal output-file permissions (an existing destination’s mode is preserved; a new destination follows the umask-adjusted default) while the temp stayed owner-only throughout.
  • FamilyBuffer/FamilyState/FamilyBudget — an exact memory budget for a correlated table family. The buffer keeps rows in memory only while under budget and spills deterministically to a ProtectedSpool the moment a push would cross it, so it never retains every child row in an unbounded Vec.
  • CancellationToken and install_interrupt_handler — an atomic cancellation flag that generation/verification loops check and turn into a cancellation error, backed by a best-effort process-level Ctrl-C handler.

§Durability caveat

Cleanup is guard-based: it depends on Drop running. A normal return, a propagated Err, and a handled interruption all unwind and remove the protected files. SIGKILL, a power loss, a machine failure, or a panic = "abort" build can still leave a protected temp file behind — there is no crash-proof cleanup, only owner-only permissions limiting exposure.

Structs§

AtomicOutput
Write beside a destination and rename into place only after success.
CancellationToken
An atomic cancellation flag that generation/verification loops poll.
FamilyBudget
An exact memory budget (in bytes) for a correlated table family’s buffered rows. Once a family’s buffered rows would exceed it, the buffer spills to a protected spool rather than growing without bound.
FamilyBuffer
Buffers a family’s rows under an exact byte budget, spilling deterministically to a ProtectedSpool the moment a push would cross the budget.
PartialPublication
The outcome of publishing several destinations that are not one atomic cross-file transaction. Each destination’s own no-truncation-before-success guarantee still holds, but a failure partway through can leave earlier destinations already published; PartialPublication reports exactly which destinations landed and which one failed, so a caller never has to pretend the set was pairwise atomic across filesystems.
ProtectedSpool
An owner-only temporary file used to spill buffered rows, removed on drop.
PublicationSet
A group of AtomicOutputs published together.
SpoolReader
Reads SpooledRows written by a SpoolWriter, rejecting a version mismatch and an oversized length prefix before allocating.
SpoolWriter
Writes SpooledRows as version-tagged, length-prefixed records to any Write. ProtectedSpool has its own buffered [write_row] for hot spilling; this stand-alone writer is for one-off or caller-owned sinks.
SpooledRow
One spooled row: its owning table id, its row index, and its column values.
TempConfig
Where protected spool files are created.

Enums§

FamilyRowReplay
Incremental replay of buffered family rows.
FamilyState
Where a FamilyBuffer’s rows currently live.
SpillKind
Which kind of family rows a spool holds, for observability.

Functions§

install_interrupt_handler
Install the process-level Ctrl-C (SIGINT) handler exactly once.
publish_in_order
Publish a sequence of already-written AtomicOutputs in order, renaming each finished temp file over its destination. Returns PartialPublication if a rename fails after one or more destinations were already published — honestly reporting that the set is not atomic across files/filesystems.