Skip to main content

Module atomic

Module atomic 

Source
Expand description

Atomic file write pipeline: tempfile, fsync, rename, fsync directory.

Workload: I/O-bound (single-file durable write + optional backup/journal). Parallelism: none inside one write (ordered rename/fsync contract). Multi-file callers (backup, batch, delete) fan out with rayon around this module.

Three write strategies are available, selected automatically:

  • WriteStrategy::Rename — classic tempfile + rename(2) (atomic, but destroys hardlinks and inode identity).
  • WriteStrategy::InPlaceftruncate(0) + pwrite + fsync_data on the existing file descriptor (preserves inode and hardlinks, but NOT atomic against a crash between truncate and write).
  • WriteStrategy::CopyBack — like InPlace but with a journal sidecar for crash recovery; slowest but most durable. (Reserved for v0.1.13.)

The default policy is auto-detect: hardlinks and symlinks trigger InPlace automatically, regular files use Rename. Pass WriteStrategy::Rename explicitly via the strategy field of AtomicWriteOptions to force the legacy behavior.

Structs§

AtomicWriteOptions
Configuration for an atomic write operation.
WriteResult
Result metadata returned after a successful atomic write.

Enums§

WriteStrategy
Write strategy selected by the atomic pipeline.

Functions§

atomic_write
Write content atomically via tempfile, fsync, and rename.
rfc3339_now
Return the current UTC time as an RFC 3339 string (e.g. 2024-01-15T14:30:22Z).