Skip to content

Server: removal runs inside the server, ordered against uploads - #107

Merged
aoinoikaz merged 1 commit into
mainfrom
server-removal
Nov 16, 2026
Merged

aoinoikaz merged 1 commit into
mainfrom
server-removal

Conversation

@aoinoikaz

Copy link
Copy Markdown
Contributor

Nothing in the server removed anything. The one removal path, reclaim-nars --delete, ran on the host against the store directory with no lock shared with the server, so a narinfo stored after its listing could lose its NAR, and a NAR uploaded after the listing was removed; the README asked that no push run during a reclaim.

Removal now runs inside the server, ordered against uploads by a reader-writer gate on the store: a narinfo upload holds it shared from the check of its NAR through its write, every rename into nar/ holds it shared for the rename, and a reclaim or a narinfo removal holds it exclusive. Request bodies are never read under the gate, and a waiting removal lets nothing new in. All three requests take the write key:

Request Does
DELETE /<hash>.narinfo removes an entry; its NAR stays until a reclaim
GET /reclaim lists what a reclaim would remove
POST /reclaim removes NARs no narinfo names and abandoned uploads older than ?min-age-hours=N (default 336)

nova-cache-server reclaim-nars now exits 1 naming these requests, and the README drops its no-push-in-progress rule. The shape follows attic's split between removing an entry and reaping orphan archives; attic orders reaping against uploads with a per-NAR hold in its database, and the gate is the in-process equivalent for a store with none. A removed archive needs no grace period: upstream's substituter treats a 404 for a NAR as a garbage-collected path and tries the next substituter (SubstituteGone). Deterministic tests stop a reclaim between its listing and its removals and an upload between its check and its write, and each fails with its part of the gate removed.

FileStore becomes abstract and fileStoreAt goes, so the next release is 0.13.0.0, as the walk-error change already requires.

Closes #96.

No request removed anything. The one removal path, reclaim-nars
--delete, ran on the host against the store directory and shared no
lock with the server, so a narinfo that arrived after its listing lost
an old NAR, and a NAR uploaded again after its listing was removed
anyway. The README asked for no push in progress during a run.

DELETE /<hash>.narinfo removes an entry, POST /reclaim removes the
NARs no narinfo names and the abandoned uploads, and GET /reclaim lists
what it would remove; all three need the write key. Each FileStore
carries a gate, a reader-writer lock over STM. A narinfo upload holds
it shared from the check of its NAR through its write (storeNarInfo),
each rename into nar/ holds it shared for the rename, and a reclaim or
a narinfo removal holds it alone. A waiting removal lets nothing new
take the gate, an interrupted one withdraws, and no request body is
read under it. DELETE leaves the NAR to the reclaim, which removes it
once nothing names it, as attic's garbage collection reaps orphan NARs.
A narinfo uploaded over an entry replaces it, so a push can store a
smaller encoding of the same NAR; the NAR it displaces is reclaimed the
same way, and a client still holding the old narinfo gets upstream's
SubstituteGone, a miss rather than a failure.

reclaim-nars now exits nonzero and names the requests, since the
server ignores arguments it does not know and would start a second
server over the store. FileStore becomes abstract, fileStoreAt goes,
scanStore takes a clock and lists the staged uploads, and stm joins
the dependencies.

The tests stop a reclaim between its listing and its removals through
its clock and send a narinfo, a NAR or a multipart completion
meanwhile, and stop a narinfo upload between its check and its write
through its signer and start a reclaim meanwhile; each must wait at the
gate and leave the store consistent. Removing the gate from any of
those paths, narrowing the upload's hold to its check, or dropping the
gate's writer preference or its withdrawal on interrupt fails the
suite.
@aoinoikaz
aoinoikaz merged commit 9842982 into main Nov 16, 2026
12 checks passed
@aoinoikaz
aoinoikaz deleted the server-removal branch November 16, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server: a cached path is never removed or replaced, and NAR removal runs outside the server

1 participant