Skip to content

sow gc

Reclaim local package files nothing needs any more, and delete superseded target files once client caches have expired.

SOW never deletes a file the moment it stops being current. Old packages stay in the local pool while a build, a retained Generation, a publication, or a recovery record still needs them, and superseded files stay on a target until client caches have expired. sow gc removes what nothing needs any more: without arguments it collects the local package pool; with TARGET it cleans up that publication target.

Synopsis

sow gc          [-C|--workdir DIR] [-r|--repo NAME] [-T|--timeout DUR | -N|--no-wait] [--json] [--passfile PATH]
sow gc TARGET [--delete] [-C|--workdir DIR]         [-T|--timeout DUR | -N|--no-wait] [--json] [--passfile PATH]

sow help gc prints both forms as one line, sow gc [TARGET [--delete]] ....

Flag Meaning Default
-C, --workdir DIR Workspace discovery start directory current directory
-r, --repo NAME Repository for local GC; a target already names its repository selection rules
--delete Delete eligible objects on an R2 target, or resume an interrupted R2 deletion false
-T, --timeout DUR Maximum lock wait; 0 waits indefinitely 0
-N, --no-wait Fail immediately when the lock is held false
--passfile PATH Signing password file, needed only if SOW must first recover an interrupted local operation (Password files) —
--json Output JSON false

gc TARGET -r NAME and --delete without TARGET are usage errors (exit 2). Neither form accepts --dist.

Local GC

Local GC deletes pool files that no record refers to. A package is kept while any of these needs it:

  • current desired or built membership, or the previous built membership kept for clients that still hold the old indexes;
  • an explicit retain record;
  • recovery records and unfinished operations;
  • publication records: attempts in progress and publications that target GC has not finished with;
  • active maintenance work.

Run it on a clean repository whose last build completed. A dirty repository, packages waiting in the pending area, or an unfinished operation make it exit 5; run sow build first.

sow gc
local gc demo: generation=00000000000000000006 objects=1 bytes=19776
sow gc
local gc demo: no unreachable payloads (noop)

objects and bytes count the package files removed. pool/ is part of the served tree, so removing files from it advances the repository to a new Generation. When nothing is eligible, the command changes nothing.

Target GC

Cache grace

Clients and CDNs may still hold an old repomd.xml or InRelease and request the files it lists. When sow publish records a new checkpoint, it sets a grace deadline from the time the publication was verified plus the target’s max_cache_ttl. A later deadline already recorded for the target is carried forward.

Target GC checks the recorded deadline, the current TTL, and live references. Rebinding a target with a longer TTL can extend protection for an earlier publication. With max_cache_ttl: 0s, a superseded object can become a candidate at the next target GC if earlier grace has elapsed and neither the current publication nor any protected publication references it. Filesystem targets delete eligible files. R2 reports candidates by default.

Note

Upgrading a target configured with max_cache_ttl: 0s? Read the upgrade guide first: grace periods recorded from 0.9.0 on follow max_cache_ttl directly, while deadlines recorded earlier stay in force.

What each provider does

Provider Behavior
filesystem After grace, conditionally deletes eligible files, confirms that their public URLs no longer serve them, and records the result
r2 Saves a candidate report by default and deletes nothing. With --delete, deletes the objects that are eligible after grace

R2 deletion can follow a report you reviewed, or run directly. Before each DeleteObject, SOW rechecks the protected publications and the object’s size, SHA-256 metadata, and ETag. It then confirms that the object is gone from storage and that the public URL returns HTTP 404 or 410, and records a deletion receipt tied to the publication that superseded the object. Use a target prefix that only this workspace writes.

sow gc local
target gc demo/local (filesystem): phase=done candidates=3 deleted=3 retained=0 pending=0
sow gc local
target gc demo/local: no due maintenance (noop)
Field Meaning
candidates Objects found eligible in this run
deleted Objects deleted and confirmed absent
retained R2 candidates recorded in a report without --delete
pending Publications whose grace deadline has not passed yet

When every recorded publication is still in grace, the text output also reads no due maintenance (noop); --json shows "phase": "pending_grace" and the pending_grace count.

Details

Interrupted GC

  • Local GC first replays any interrupted retain-remove-* tombstones, then journals the operation and saves its plan to .sow/<repo>/recovery/<operation-id>/plan.json before deleting pool files. A large backlog runs in batches that keep each plan under 64 MiB. If the run stops after deleting some files, the next run replays the saved plan and completes the new Generation.
  • R2 deletion: rerun sow gc TARGET --delete. Without --delete, target GC refuses to touch an unfinished deletion report and exits 5.
  • The R2 identity check and the delete are separate storage requests, not one atomic operation.

Other preconditions

  • Target GC refuses (exit 5) while a publication attempt on that target is in progress; finish it with sow publish TARGET or abandon it with --abort.
  • Filesystem target paths are checked as for publish: sibling targets that share a parent directory, such as /srv/www/pgsql and /srv/www/pigsty, do not block each other.
  • Both forms first finish any interrupted local operation in the repository; pass --passfile if that recovery must re-sign metadata. Collection itself signs nothing.

Exit behavior

Code Trigger
0 GC completed, or nothing was eligible
1 Filesystem, provider, network, or runtime failure
2 Usage error, workspace discovery error, invalid sow.yml, or implicit repository ambiguity
4 Repository write lock unavailable
5 Local GC preconditions not met, a publication or deletion must be finished first, or recovery, state, receipt, or manifest evidence is inconsistent
6 Explicit repository or target is not configured or not safe, or a safety precondition rejects the deletion

See also

Table reader