This repository was archived by the owner on Nov 15, 2026. It is now read-only.
Repository navigation
feat: a daily mark-and-scan sweep removes orphaned blobs after a grace period - #12
Merged
Merged
Conversation
…s after a grace period ADR-0007 (Proposed). readd marks the hashes the database names, scans blobs/, records in blob_orphans when it first finds an unnamed file, and removes a file once that record and its modification time are both past blob_grace_days (7). Put touches a blob that exists, and a removal checks the file's time and the database again under the blob store's lock, so a save beside a sweep keeps its blob. The sweep runs 10 minutes after start, then every 24 hours (blob_sweep: on, dry-run or off), and readctl sweep [-dry-run] runs it now through blobs.sweep, caller local only. A dry run removes and writes nothing.
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Today readd never removes a blob: the originals and images of items whose source is removed stay on disk. This adds a sweep, as ADR-0007 (Proposed) decides.
The decision
blobsrow; a count would need triggers and could drift. The sweep derives what is in use fromitems.original_hashanditem_blobs.hasheach time, and also finds files no row ever named.blob_orphans (hash, since)(migration 2) records when the sweep first found a file unnamed. A file goes only whensinceand its modification time are both older thanblob_grace_days(default 7, 1 to 365).Putof an existing blob touches its modification time.blobs.Storehas a read-write lock:Putholds it shared, a removal alone, and the removal re-checks the file time and the database under it. Theblobsrow is deleted only when noitem_blobsrow names the hash again.readd, 10 minutes after start, then every 24 hours.blob_sweep:on(default),dry-run(the schedule only logs),off.readctl sweep [-dry-run]runs it now throughblobs.sweep, callerlocalonly (a session getsmethodNotFound).since.Tests
internal/engine/sweep_test.go: blobs in use stay (image, original, saved note, pending item, starred, archived, shared); orphans past the grace go with their rows; orphans inside the grace stay (new, recent mtime, recentsince); a removed source's blobs wait, then go, and a shared one stays; the dry run removes and writes nothing; a save during the sweep (Putthen reference,Putalone, reference alone) keeps its blob; and a sweep running beside 60 saves under the race detector.internal/blobs,internal/store,internal/config,internal/readapi,cmd/readd,cmd/readctl:List,RemoveIf, the touch, the queries, the settings, local-only, the CLI.Checks
make check,make raceandmake crosspass locally.make contract-updatechanges no golden; the web bundle does not change.Notes for review
sinceand the cutoff use the engine clock; the modification time is the file system's. In production they are the same clock.blob_grace_days: 0reads as the default, 7.Humans merge.