Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
ktock committed Jan 26, 2022
1 parent b8bdfaf commit 840667e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions fs/layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (r *Resolver) Resolve(ctx context.Context, hosts source.RegistryHosts, refs
log.G(ctx).Debugf("resolving")

// Resolve the blob.
blobR, err := r.resolveBlob(ctx, hosts, refspec, desc)
blobR, err := r.resolveBlob(ctx, hosts, refspec, desc, name)
if err != nil {
return nil, errors.Wrapf(err, "failed to resolve the blob")
}
Expand Down Expand Up @@ -315,6 +315,11 @@ func (r *Resolver) Resolve(ctx context.Context, hosts source.RegistryHosts, refs
}), 0, blobR.Size())
vr, err := r.newReader(sr, desc, fsCache, esgzOpts...)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
r.blobCacheMu.Lock()
r.blobCache.Remove(name)
r.blobCacheMu.Unlock()
}
return nil, errors.Wrap(err, "failed to read layer")
}
// do not propagate context after resolve is done
Expand Down Expand Up @@ -361,12 +366,10 @@ func (r *Resolver) newReader(sr *io.SectionReader, desc ocispec.Descriptor, fsCa
}

// resolveBlob resolves a blob based on the passed layer blob information.
func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts, refspec reference.Spec, desc ocispec.Descriptor) (_ *blobRef, retErr error) {
name := refspec.String() + "/" + desc.Digest.String()

func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts, refspec reference.Spec, desc ocispec.Descriptor, cacheKey string) (_ *blobRef, retErr error) {
// Try to retrieve the blob from the underlying cache.
r.blobCacheMu.Lock()
c, done, ok := r.blobCache.Get(name)
c, done, ok := r.blobCache.Get(cacheKey)
r.blobCacheMu.Unlock()
if ok {
blob := c.(remote.Blob)
Expand All @@ -376,7 +379,7 @@ func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts,
// invalid blob. discard this.
done()
r.blobCacheMu.Lock()
r.blobCache.Remove(name)
r.blobCache.Remove(cacheKey)
r.blobCacheMu.Unlock()
}

Expand All @@ -396,7 +399,7 @@ func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts,
return nil, errors.Wrap(err, "failed to resolve the source")
}
r.blobCacheMu.Lock()
cachedB, done, added := r.blobCache.Add(name, b)
cachedB, done, added := r.blobCache.Add(cacheKey, b)
r.blobCacheMu.Unlock()
if !added {
b.Close() // blob already exists in the cache. discard this.
Expand Down

0 comments on commit 840667e

Please sign in to comment.