feat: backfill lower cache tiers on read-through#172
Merged
Conversation
When a higher tier (e.g., S3) has data but a lower tier (e.g., disk) does not, the returned reader now transparently writes to the lowest tier as the caller reads. This ensures disk cache is populated on the first S3 hit after a pod restart, avoiding repeated slow S3 reads. On write failure or partial read, the backfill is safely abandoned via context cancellation per the Cache contract. Amp-Thread-ID: https://ampcode.com/threads/T-019cda52-ee36-738c-86cd-1fd410c47d7f Co-authored-by: Amp <amp@ampcode.com>
stuartwdouglas
approved these changes
Mar 11, 2026
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019cda52-ee36-738c-86cd-1fd410c47d7f
2e66222 to
fdb369c
Compare
alecthomas
reviewed
Mar 11, 2026
Collaborator
alecthomas
left a comment
There was a problem hiding this comment.
This is awesome, should have been this way from the start 🤦♂️
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.
Problem
After a pod restart, disk cache is empty but S3 still has snapshots.
Tiered.Openhits S3 and streams to the client, but never writes to disk. Since the cache hit path doesn't trigger mirror creation or periodic job scheduling, disk stays empty permanently — every request keeps hitting S3 (4 min for large repos vs 30s from disk).Solution
When
Tiered.Openfinds data in a higher tier (S3) but the lowest tier (disk) missed, the returned reader now transparently tees writes to disk as the caller reads. After the full stream is consumed and closed, the disk entry becomes available for future reads.On write failure or partial read, the backfill is safely abandoned via context cancellation per the Cache contract — reads are never affected.