Atomic download writes: durability, orphan reaping, and untested failure paths #22
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
#20 introduced
writeAtomicinsrc/download/index.ts: downloads are staged in a temporarysibling of the destination and renamed into place only after the whole stream has decrypted and
verified. That is exactly what #1 specified, and it closed the silent-corruption hole.
Three reviewers deferred a set of adjacent items rather than expand that PR's scope. Collecting
them here so they are tracked rather than lost.
No
fsync, so the guarantee does not survive power loss.writeFilethenrenameisatomic with respect to a crashing process, but not with respect to a crashing machine: the
rename can reach disk before the data does, leaving a destination file that is correctly named
and silently short. For a backup tool this is the same class of failure #1 existed to close,
just with a smaller window. Fixing it means syncing the temp file before the rename, and
syncing the containing directory after it.
Orphaned temp files are never reaped. Cleanup runs on the error path, but a process killed
between the write and the rename leaves a
.quak-*.tmpsibling behind forever. Over manyinterrupted backup runs these accumulate silently inside the backup tree.
Rename-over-existing changes semantics that nothing documents or tests.
renamereplacesthe destination inode rather than writing through it, so an existing destination that is a
symlink is replaced rather than followed, and the resulting file carries the temp file's mode
rather than the previous file's. Neither behaviour is wrong, but neither is stated anywhere,
and the backup-layout section of the README describes a tree built out of symlinks.
Failure paths involving the destination directory are untested. An unwritable destination
directory, and a destination directory that does not exist, are both plausible in real use and
neither has coverage.
The
.quak-*.tmpnaming is undocumented. The README's backup layout section enumerateswhat appears in a backup tree; transient temp files should be mentioned so a user who
interrupts a run and finds one knows what it is.
Definition of done
before the rename, and the containing directory is synced after it. If the cost of syncing is
judged unacceptable for the common case, make it an option and document the default and the
trade-off — but make the choice explicitly rather than by omission.
a temp file belonging to a concurrently running download.
renameare documented in a codecomment and, where user-visible, in the README backup layout section.
both
downloadFileanddownloadThumbnail..quak-*.tmpname is documented in the README backup layout section.make checkgreen.Not a 1.0.0 blocker
Deliberately outside the
1.0.0milestone. The main correctness hole is closed; these harden theedges. Promote it if the durability item turns out to matter more than it currently appears to.
Context
Deferred by review during #20. See the three review comments on that PR for the original wording.