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 runDrop).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.AtomicOutputandPublicationSet— write beside the destination into a protected temp file andrenameinto 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 aProtectedSpoolthe moment a push would cross it, so it never retains every child row in an unboundedVec.CancellationTokenandinstall_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§
- Atomic
Output - Write beside a destination and
renameinto place only after success. - Cancellation
Token - An atomic cancellation flag that generation/verification loops poll.
- Family
Budget - 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.
- Family
Buffer - Buffers a family’s rows under an exact byte budget, spilling deterministically
to a
ProtectedSpoolthe moment a push would cross the budget. - Partial
Publication - 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;
PartialPublicationreports exactly which destinations landed and which one failed, so a caller never has to pretend the set was pairwise atomic across filesystems. - Protected
Spool - An owner-only temporary file used to spill buffered rows, removed on drop.
- Publication
Set - A group of
AtomicOutputs published together. - Spool
Reader - Reads
SpooledRows written by aSpoolWriter, rejecting a version mismatch and an oversized length prefix before allocating. - Spool
Writer - Writes
SpooledRows as version-tagged, length-prefixed records to anyWrite.ProtectedSpoolhas its own buffered [write_row] for hot spilling; this stand-alone writer is for one-off or caller-owned sinks. - Spooled
Row - One spooled row: its owning table id, its row index, and its column values.
- Temp
Config - Where protected spool files are created.
Enums§
- Family
RowReplay - Incremental replay of buffered family rows.
- Family
State - Where a
FamilyBuffer’s rows currently live. - Spill
Kind - 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. ReturnsPartialPublicationif a rename fails after one or more destinations were already published — honestly reporting that the set is not atomic across files/filesystems.