Repository navigation
reads: cut statements on narinfo and nar requests - #39
Merged
Merged
Conversation
A scoped read now admits the cache and reads the requested publication in a single statement, joining published_paths and blob_objects onto the cache row by the narinfo hash. A public narinfo hit or miss costs one database round trip. Previously every scoped read first looked up the cache, and a narinfo request then ran a second statement for the publication. Each was its own pool checkout and round trip, and narinfo requests, most of them misses, are the hottest route the service has. The cache row still decides the response on its own. An unknown cache or one without the Nix protocol is a plain miss, a private cache authorizes the caller before anything read about the path is used, and a former organization slug authenticates and then exposes nothing. The publication columns are optional on the row, so nix-cache-info and invalid hashes pass no hash and match no path.
The narinfo statement now also reports whether the publication's access stamp is missing or older than five minutes, and a hit spawns the stamp update only when it is. Previously every successful narinfo read spawned the update. Its predicate skipped the write for a fresh stamp, but the task still took a pool connection and a database round trip per hit to learn that. The update keeps its own guard, so readers that race on a due stamp still write it once, and the bounded semaphore is unchanged. Reads keep reordering LRU eviction at the same five-minute granularity.
A scoped NAR request now admits the cache and resolves the object key in one statement, the proxied body is read in 256 KiB frames, and the bandwidth upsert for a private download runs as tracked background work instead of ahead of the response headers. Previously a scoped NAR read looked up the cache and then the key in two round trips, a private download awaited the bandwidth write before sending headers, and the body was framed at the 4 KiB reader default, which costs a wakeup and a frame for every few kilobytes of a large NAR. The Bazel read path already uses 256 KiB frames. A private cache still authorizes the caller before the key is used, so a rejected read answers the same for stored and absent NARs. Metering keeps its meaning: an admitted GET counts for the full object size at its start, HEAD does not count, and graceful shutdown drains the task. The uploads test that reads the meter right after a download now waits for the row, since the write no longer precedes the response.
The statement that admits a scoped cache and resolves a NAR's key was the one read-path query still bound at runtime and decoded into a positional tuple. It now uses the query macro like the narinfo lookup beside it, so the build verifies it against the schema.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.