From 74d442a058a9c83cc01a74565e50b5c79b23815a Mon Sep 17 00:00:00 2001 From: Grant Watters Date: Mon, 10 Feb 2020 10:57:52 -0800 Subject: [PATCH] Consider redis.ErrNil as distribution.ErrBlobUnknown for Stat HGET * Update redis.go If the dgst key does not exist in the cache when calling HGET, `redis.String` will return an `ErrNil` which we need to translate into `distribution.ErrBlobUnknown` so that the error being returned can be properly handled. This will ensure that `SetDescriptor` is properly called from `cachedBlobStatter::Stat` for `repositoryScopedRedisBlobDescriptorService` which will update the redis cache and be considered as a Miss rather than an Error. cc @manishtomar * Update suite.go Add unit test to ensure missing blobs for scoped repo properly return ErrBlobUnknown when HGET returns redis.ErrNil. (cherry picked from commit dca6b9526a1d30dd218a9f321c4f84ecc4b5e62e) Signed-off-by: Derek McGowan --- registry/storage/cache/cachecheck/suite.go | 4 ++++ registry/storage/cache/redis/redis.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/registry/storage/cache/cachecheck/suite.go b/registry/storage/cache/cachecheck/suite.go index d241bd04c..12d6e45de 100644 --- a/registry/storage/cache/cachecheck/suite.go +++ b/registry/storage/cache/cachecheck/suite.go @@ -54,6 +54,10 @@ func checkBlobDescriptorCacheEmptyRepository(ctx context.Context, t *testing.T, t.Fatalf("expected error checking for cache item with empty digest: %v", err) } + if _, err := cache.Stat(ctx, "sha384:cba111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); err != distribution.ErrBlobUnknown { + t.Fatalf("expected unknown blob error with uncached repo: %v", err) + } + if _, err := cache.Stat(ctx, "sha384:abc111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); err != distribution.ErrBlobUnknown { t.Fatalf("expected unknown blob error with empty repo: %v", err) } diff --git a/registry/storage/cache/redis/redis.go b/registry/storage/cache/redis/redis.go index 531fae2f4..8d32aa486 100644 --- a/registry/storage/cache/redis/redis.go +++ b/registry/storage/cache/redis/redis.go @@ -186,6 +186,10 @@ func (rsrbds *repositoryScopedRedisBlobDescriptorService) Stat(ctx context.Conte // We allow a per repository mediatype, let's look it up here. mediatype, err := redis.String(conn.Do("HGET", rsrbds.blobDescriptorHashKey(dgst), "mediatype")) if err != nil { + if err == redis.ErrNil { + return distribution.Descriptor{}, distribution.ErrBlobUnknown + } + return distribution.Descriptor{}, err }