Transactions & Recovery
A repository update rewrites many files: package files, per-architecture indexes, signatures,
and the pointer files (repomd.xml, InRelease) that clients read first. If an update stops
halfway, through Ctrl-C, a crash, or a full disk, or if two writers run at once, a copy-and-index
script can leave indexes that name packages that are not there, and nobody knows what state the
repository is in. In a standard repository, SOW
journals a change before applying it and allows one writer at a time per repository. A build stages the package files and switches each complete Dist directory atomically. After an
interruption, recovery is usually a single command.
Recover an interrupted operation
Start with the recorded state:
status |
Meaning | Next step |
|---|---|---|
clean |
The built state matches the desired state; nothing is pending | Run sow check before delivery |
dirty |
Committed membership or configuration changes wait for a build | Run sow build |
recovering |
An operation stopped before it finished | Run the recovery command for that operation, listed below |
error |
Recorded state or files need attention | Read the diagnostic, then inspect sow check and sow log |
| Interrupted operation | Recovery command |
|---|---|
add, rm, dist new, dist rm, or build |
sow build -r demo |
init, repo new, or repo rm |
Rerun the same lifecycle command |
| Publication | sow publish TARGET |
| Local or target garbage collection | sow gc -r demo or sow gc TARGET; an interrupted R2 conditional delete resumes with sow gc TARGET --delete |
| Retained Generation removal | sow retain rm GENERATION -r demo |
sow create or sow prune on a simple repository |
Rerun it with the original options |
Repository writers such as add, rm, build, and gc first settle whatever the journal
left pending, so the recovery command is usually what you would run next anyway. An operation
stopped while it was only planned is rolled back; once its inputs are staged, recovery
completes it. Local or target gc and retain rm keep their frozen plan, so rerunning them
finishes the cleanup. Afterwards sow log shows which way it went. Here an add was killed
right after it was planned:
A rolled_back or failed operation committed nothing, so run it again. done or
done_dirty means it took effect; for done_dirty, run sow build.
First correct whatever stopped the command, such as a bad input, a configuration error, or a
full disk, and keep the workspace configuration, database, and .sow/ state together. If
recovery has to sign metadata, it needs the key’s password again, because SOW never stores
passwords in its journals: pass --passfile PATH, rely on the key’s configured passfile, or
set SOW_GPG_PASSFILE (see Password files). For a pending
init, repo new, or repo rm, supply the password through the command line or the
environment and leave sow.yml as it is, because recovery compares it with the journal.
After a local recovery, run sow check -r demo. See Troubleshooting
for common causes and publish for publication recovery.
How a local build switches Dists
Clients read an entry point first, then fetch the metadata and packages it names. A local build makes each new file available before clients can discover it through a new entry point.
- Prepare each affected Dist on the same filesystem. The staged tree includes all architecture views, indexes, client entry points, and configured signatures. It also carries the preceding build’s checksum-named RPM metadata and APT by-hash indexes.
- Install new package files in the public
pool/. The old Dist directories are still available. - Atomically exchange each staged tree with its live
dists/<dist>/directory. All views, indexes, entry points, and signatures for that Dist switch together. - After every affected Dist has switched and the public tree has been checked, record the repository Generation.
A reader can see Dists from different builds while a multi-Dist build is switching them. Clients that just read the old entry point can still fetch the preceding metadata by digest. To keep older builds, see sow retain.
sow build updates the local tree. To deliver a checked build to a live target, use sow publish. It transfers objects in phases, sending packages and metadata before updating client entry points.
What SOW records
| Record | Location | Purpose |
|---|---|---|
| Workspace lifecycle journal | .sow/workspace-ops/active.json |
Coordinates configuration with repository creation or removal |
| Repository operation journal | .sow/<repo>.db |
Records local membership changes, builds, and maintenance |
| Publication state | .sow/<repo>.db |
Records target bindings, frozen publication plans, and progress |
Each repository operation writes its intended scope to the journal before touching anything,
then records its progress as it moves through planned → staged → applied → built → done.
That record is what lets recovery decide between rolling back and finishing, and it is what
sow log shows. Read one operation’s transitions and timestamps with
sow log OPERATION -r demo.
Locks and waiting
Two writers on one repository would interleave their files, so SOW lets only one writer at a time change a repository; a second writer waits for the lock. The wait is unbounded by default, which scripts usually want to limit:
| Option | Behavior |
|---|---|
-T 30s |
Wait up to 30 seconds for a write lock |
-T 0 |
Wait until the lock is available; default |
-N |
Try once; exit immediately if another writer holds the lock |
A failed lock attempt exits 4. Combining -N with a nonzero -T exits 2. Only write
commands accept these options. Read commands that need a consistent snapshot take a shared lock
and wait for the writer; status instead reports locked=true without waiting. See
Exit codes for scripted responses to interruption, lock
contention, and integrity errors.
Details
Operation states
| State | Meaning |
|---|---|
planned |
SOW recorded the operation and its intended scope |
staged |
SOW prepared the inputs for the next stage |
applied |
SOW committed the desired state; the previous Generation can still be the public one |
built |
SOW installed the generated public tree |
done |
The operation is complete |
done_dirty |
SOW committed the desired state and left a build pending |
Other outcomes are rolled_back and failed, and an operation that recovery is finishing shows
recovering; Operation lifecycle defines each one.
--skip normally ends at done_dirty. A recognized signing-policy change, a configuration
change before a build plan freezes, or a supported contract upgrade can also leave a committed
operation dirty; the log records the reason. Correct the configuration if needed, then run
build again. SOW finds the active operation by its pending state, not its timestamp, so a
clock adjustment cannot hide an unfinished operation behind an older completed one.
Errors after a committed change
Database commit and later maintenance are separate steps, so a checkpoint or cleanup error can
occur after package membership or a build has committed. SOW keeps the committed result in the
command output and does not report those items as rolled back. Read the result and
sow status, inspect the operation with sow log, and resume the command named in the
diagnostic. Keep the original input files until you have confirmed the result.
Workspace lifecycle recovery
Recovery of init, repo new, or repo rm compares the current sow.yml digest with the old
and new configurations recorded in the journal. Which one matches decides whether SOW rolls the
change back or finishes it. A digest that matches neither is an integrity error.
Lock files
Workspace lifecycle commands use .sow/workspace.lock, and repository writes use
.sow/repo-locks/<repo>.lock. A command that needs both acquires the workspace lock first.
sow create and sow prune lock the simple repository’s directory and release the parent
directory’s lock as soon as that lock is held, so simple repositories in sibling directories
do not block each other.
Filesystem requirements
The ordering above relies on advisory locks, fsync, and atomic rename, so use a local POSIX
filesystem that provides them; on macOS, use APFS. Do not place a workspace on a network
filesystem. Keep public files and private staging on the same filesystem. SOW rejects
symlinked control paths, unexpected file types, and path escapes, and checks file identity
before it replaces or removes a controlled object.