From de64be38a5d94fece6e2b2b590b9c6d396adfbb5 Mon Sep 17 00:00:00 2001 From: Yan Song Date: Wed, 26 Oct 2022 03:30:52 +0000 Subject: [PATCH] cache: try to fix content not found Prioritize checking that the layer content does not exist to make sure the cache is lazy. Signed-off-by: Yan Song --- cache/refs.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cache/refs.go b/cache/refs.go index dc2cd561b01d..772fa87390ca 100644 --- a/cache/refs.go +++ b/cache/refs.go @@ -277,14 +277,12 @@ func (cr *cacheRecord) walkUniqueAncestors(f func(*cacheRecord) error) error { } func (cr *cacheRecord) isLazy(ctx context.Context) (bool, error) { - if !cr.getBlobOnly() { - return false, nil - } dgst := cr.getBlob() // special case for moby where there is no compressed blob (empty digest) if dgst == "" { return false, nil } + _, err := cr.cm.ContentStore.Info(ctx, dgst) if errors.Is(err, errdefs.ErrNotFound) { return true, nil @@ -292,6 +290,10 @@ func (cr *cacheRecord) isLazy(ctx context.Context) (bool, error) { return false, err } + if !cr.getBlobOnly() { + return false, nil + } + // If the snapshot is a remote snapshot, this layer is lazy. if info, err := cr.cm.Snapshotter.Stat(ctx, cr.getSnapshotID()); err == nil { if _, ok := info.Labels["containerd.io/snapshot/remote"]; ok {