Repository navigation
Conversation
|
Sign your DCO |
4babee7 to
a241145
Compare
done, thanks! |
The in-memory blob descriptor cache can hold stale entries after garbage collection removes blobs from disk. Since GC runs as a separate process, it cannot clear the in-process cache. This causes docker push to skip uploading layers (reporting "Layer already exists") and docker pull to fail with "short read: unexpected EOF". After a cache hit, verify the blob still exists on the backend storage. If the backend reports ErrBlobUnknown, clear the stale cache entry and return the error so the client re-uploads the layer. Fixes distribution#1803 Signed-off-by: Chinzzii <[email protected]>
a241145 to
df7deaa
Compare
milosgajdos
left a comment
There was a problem hiding this comment.
Nice Claud-ing, but we need to direct Claude better going forward. I've left some comments in.
Furthermore I wonder if this is the "right" fix 🤔
I wonder if could do invalidation on read failure i.e. clear cache when Get/Open/ServeBlob hits PathNotFoundError. It would fix the pull case cheaply but not the push-corruption case, so that's kinda annoying.
Another option could be some sort of TTL-based validation i.e. only validate entries older than some interval - not sure what that'd be, maybe configuratble (a few minutes could do). That would bound the stale cache window while preserving most cache benefit.
| cacheRequestCount = prometheus.StorageNamespace.NewCounter("cache_requests", "The number of cache request received") | ||
| // cacheRequestCount is the number of total cache requests received. | ||
| // cacheHitCount is the number of total cache requests that were a hit. | ||
| cacheHitCount = prometheus.StorageNamespace.NewCounter("cache_hits", "The number of cache request received") |
There was a problem hiding this comment.
prometheus description wasn't updated, only the Go comment. NewCounter("cache_hits", "The number of cache request received")
| // may have deleted the blob from storage without being able to clear | ||
| // the in-process cache. Without this check, clients are told the | ||
| // layer already exists and skip uploading, leading to pull failures. | ||
| if _, err := cbds.backend.Stat(ctx, dgst); err != nil { |
There was a problem hiding this comment.
I get the PR highights the fact that this means remote storage hit, which ironically is the exact I/O the cache was designed to eliminate...I feel like this PR changes defaults to protect operators who don't follow that guidance but taxes everyone else 🤔
| @@ -40,6 +42,22 @@ func (cbds *cachedBlobStatter) Stat(ctx context.Context, dgst digest.Digest) (v1 | |||
| desc, cacheErr := cbds.cache.Stat(ctx, dgst) | |||
| if cacheErr == nil { | |||
| cacheHitCount.Inc(1) | |||
There was a problem hiding this comment.
Would this increment a stale hit? Should this be moved after successful validation>
| // the in-process cache. Without this check, clients are told the | ||
| // layer already exists and skip uploading, leading to pull failures. | ||
| if _, err := cbds.backend.Stat(ctx, dgst); err != nil { | ||
| if err == distribution.ErrBlobUnknown { |
There was a problem hiding this comment.
I reckon we should use errors.Is() here 🤔
Summary
The in-memory blob descriptor cache can hold stale entries after garbage collection removes blobs from disk. Since GC runs as a separate CLI process (
registry garbage-collect), it cannot clear the in-process cache of a running registry. This causes:docker pushto skip uploading layers (reporting "Layer already exists")docker pullto fail withshort read: unexpected EOFAfter a cache hit, this PR adds a backend
Stat()call to verify the blob still exists on storage. If the backend reportsErrBlobUnknown, the stale cache entry is cleared and the error is returned so the client re-uploads the layer.Changes
registry/storage/cache/cachedblobdescriptorstore.go: After a cache hit inStat(), validate against the backend. If the blob is missing, clear the stale cache entry and returnErrBlobUnknown. Addedcache_stale_clearsprometheus counter for observability. Fixed a copy-paste typo in thecacheHitCountcomment.registry/storage/cache/cache_test.go: AddedTestCacheStaleClearAfterGCthat simulates GC removing a blob from the backend while the cache retains a stale entry, and verifies the stale entry is detected and cleared. FixedtestStatter.Clear()to actually delete entries from its map.Design considerations
Stat(). This is a metadata-only check (no data read) and is the same call that already happens on a cache miss. For registries where GC is infrequent, the extra call is negligible. For high-throughput registries concerned about the overhead, disabling the blob descriptor cache (blobdescriptor: none) is already the recommended approach.ErrBlobUnknown(e.g., a transient storage issue), the cached descriptor is still returned. Only confirmed-missing blobs trigger cache invalidation.Fixes #1803