Skip to content

fix(storage): cache blob descriptors only after linking - #5105

Merged
milosgajdos merged 1 commit into
distribution:mainfrom
perfloop-oss:perfloop-pr-open-bbz5hwfnvs
Nov 27, 2026
Merged

milosgajdos merged 1 commit into
distribution:mainfrom
perfloop-oss:perfloop-pr-open-bbz5hwfnvs

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

With a descriptor cache enabled, a failed repository-link write can make a newly uploaded manifest look present even though storage has no repository link. Cache eviction can then make it disappear. Put now writes the link before caching its descriptor, preventing failed link creation from advertising an unlinked digest.

cc @milosgajdos

linkedBlobStore.Put keeps the global data write first, then creates the repository link and updates the descriptor cache, matching blobWriter.Commit. A link error returns a zero blob descriptor and the original error.

When custom SetDescriptor middleware rejects a small-blob put and the client retries, each retry now writes the link first, taking about 4.09 ms instead of 35.2 µs and allocating 15.4 KB in 99 allocations instead of 3.13 KB in 39. Shipped cache setters do not reject puts.

This is not transactional rollback: pre-existing links and writes completed by storage before reporting an error remain intact.

Go tests for the scoped blob/manifest storage paths and descriptor caches, including Redis, passed.

AI assisted with this change.

Regression coverage

The regression test in registry/storage/linkedblobstore_test.go covers data-write and link-write failures with caching enabled and disabled for small blobs, Docker schema2 manifests, OCI manifests, manifest lists and OCI indexes. Successful retries on the same store populate the cache and return the original bytes.

Paired filesystem comparison of small-blob retries with rejecting custom descriptor middleware:

Metric Base median Patched median Matched-run change
Time (ns/op) 35,177 4,086,122 +4,050,003.5 ns/op (+3,616,518 to +4,423,149); +11,513.2% (+10,280.9% to +12,574.0%, n=12)
Allocated bytes (B/op) 3,128 15,360 +12,231 B/op (+11,992 to +12,234); +391.0% (+383.4% to +391.1%, n=12)
Allocations (allocs/op) 39 99 +60 allocs/op (+60 to +60); +153.8% (+153.8% to +153.8%, n=12)

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

@milosgajdos

Copy link
Copy Markdown
Member

@perfloop-agent please squash your commits

@tsenart
tsenart force-pushed the perfloop-pr-open-bbz5hwfnvs branch from 987c145 to 8663c79 Compare November 26, 2026 20:52
@tsenart

tsenart commented Nov 26, 2026

Copy link
Copy Markdown

@milosgajdos squashed into one commit, with the same code as before. The CI runs are now waiting for a maintainer to approve them, because I pushed the squash from my account. Could you approve them?

Publishing the repository descriptor before its link is written lets cached
lookups find an unlinked blob after a storage error. Write the link before
populating the descriptor cache, matching blobWriter.Commit, and return an
empty descriptor if linking fails.

This does not roll back preexisting links or writes completed by the driver
before an error is reported.

Exercise data and repository link write failures with and without a descriptor
cache. Verify failed puts remain unavailable, return no blob descriptor, and can
be retried successfully.

Signed-off-by: Perfloop Agent <[email protected]>
@perfloop-agent
perfloop-agent force-pushed the perfloop-pr-open-bbz5hwfnvs branch from 8663c79 to 7ee51e3 Compare November 26, 2026 22:13
@milosgajdos
milosgajdos merged commit bd4edd8 into distribution:main Nov 27, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants