From 4faddb1cb350f159c51931074c844d48ce72e217 Mon Sep 17 00:00:00 2001 From: Archipelago Date: Mon, 16 Nov 2026 23:06:33 +0300 Subject: [PATCH] Expire our own keep refs so retired deployments release objects --- SERVICE.md | 8 +++++--- src/gc.rs | 16 +++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/SERVICE.md b/SERVICE.md index e3137e2..0c67f53 100644 --- a/SERVICE.md +++ b/SERVICE.md @@ -28,9 +28,11 @@ and, paradoxically, could keep old objects pinned forever. them **retained** until a history/readiness policy exists. - `archipelago cleanup apply` takes the shared host mutation lock, refuses live/no-booted/ pending states, establishes keep refs for the complete protected commit graph and - invokes only `ostree prune --refs-only`. It does **not** run `admin cleanup`, delete - deployments or remove any old keep/service/history refs. The record stores protected - commit identities and the before/after repo size in `/var/lib/archipelago/cleanup/`. + invokes only `ostree prune --refs-only`. It does **not** run `admin cleanup` or delete + deployments; it removes only its own `archipelago/keep/*` refs for commits no longer + named by a deployment, active plan or retained intent (those deployments were already + retired by OSTree finalize-staged retention). Service/history refs stay untouched. + The record stores protected commit identities and the before/after repo size. This safely removes objects already unreachable from every ref; it cannot yet reclaim commits kept alive by obsolete deployment/history refs. - The `archipelago-ostree-gc.timer` unit (30 minutes after boot, then weekly) runs the diff --git a/src/gc.rs b/src/gc.rs index 2903aee..c8721c1 100644 --- a/src/gc.rs +++ b/src/gc.rs @@ -335,9 +335,13 @@ pub fn apply() -> Result<(), String> { for (name, commit) in keep_ref_sync(&ref_names(&refs), &protected) { repository(&["refs", "--force", &format!("--create={name}"), &commit])?; } - // Never expire old keep/service/history refs here. An extra ref is a leak; - // removing a recovery root is destructive. D-047 readiness-bound retention - // must own that step. + // Remove only our own keep refs for commits that are no longer a deployment or + // a plan/intent input. Those deployments were already retired by OSTree's own + // finalize-staged retention; keeping the artificial ref would pin their objects + // forever and defeat the collection. Service/history refs remain untouched. + for (name, _) in stale_keep_refs(&refs, &protected) { + repository(&["refs", "--delete", &name])?; + } for commit in &protected { repository(&["ls", commit, "/"])?; } @@ -473,7 +477,7 @@ mod tests { } #[test] - fn keep_refs_add_protected_roots_but_do_not_retire_old_roots() { + fn keep_refs_add_protected_roots_and_expire_only_their_own_stale_refs() { let deployments = parse_deployments(&status()).unwrap(); let protected: BTreeSet = deployments.iter().map(|deployment| deployment.checksum.clone()).collect(); let existing = vec![ @@ -488,7 +492,9 @@ mod tests { let all_refs = ["a".repeat(64), "b".repeat(64), "c".repeat(64)].into_iter() .map(|sum| format!("{KEEP}/{sum}")).collect::>(); assert!(keep_ref_sync(&all_refs, &with_old_root).is_empty()); - assert_eq!(stale_keep_refs(&[(format!("{KEEP}/{}", "c".repeat(64)), "c".repeat(64))], &protected).len(), 1); + let stale = stale_keep_refs(&[(format!("{KEEP}/{}", "c".repeat(64)), "c".repeat(64)), + ("service/bases/old".to_owned(), "d".repeat(64))], &protected); + assert_eq!(stale, vec![(format!("{KEEP}/{}", "c".repeat(64)), "c".repeat(64))]); } #[test]