Skip to content

Commit

Permalink
Merge pull request #3540 from tonistiigi/v0.11.2-picks2
Browse files Browse the repository at this point in the history
[v0.11] cherry-pick: Make local cache importer non-lazy
  • Loading branch information
tonistiigi committed Jan 26, 2023
2 parents 2e5781e + b71812b commit 9449399
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,14 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispecs.Descriptor,

cm.records[id] = rec

return rec.ref(true, descHandlers, nil), nil
ref := rec.ref(true, descHandlers, nil)
if s := unlazySessionOf(opts...); s != nil {
if err := ref.unlazy(ctx, ref.descHandlers, ref.progress, s, true); err != nil {
return nil, err
}
}

return ref, nil
}

// init loads all snapshots from metadata state and tries to load the records
Expand Down
11 changes: 11 additions & 0 deletions cache/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ type NeedsRemoteProviderError []digest.Digest //nolint:errname
func (m NeedsRemoteProviderError) Error() string {
return fmt.Sprintf("missing descriptor handlers for lazy blobs %+v", []digest.Digest(m))
}

type Unlazy session.Group

func unlazySessionOf(opts ...RefOption) session.Group {
for _, opt := range opts {
if opt, ok := opt.(session.Group); ok {
return opt
}
}
return nil
}
11 changes: 10 additions & 1 deletion cache/remotecache/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ func getContentStore(ctx context.Context, sm *session.Manager, g session.Group,
if err != nil {
return nil, err
}
return sessioncontent.NewCallerStore(caller, storeID), nil
return &unlazyProvider{sessioncontent.NewCallerStore(caller, storeID), g}, nil
}

type unlazyProvider struct {
content.Store
s session.Group
}

func (p *unlazyProvider) UnlazySession(desc ocispecs.Descriptor) session.Group {
return p.s
}

func attrsToCompression(attrs map[string]string) (*compression.Config, error) {
Expand Down
21 changes: 21 additions & 0 deletions util/contentutil/multiprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/moby/buildkit/session"
digest "github.com/opencontainers/go-digest"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -90,3 +91,23 @@ func (mp *MultiProvider) Add(dgst digest.Digest, p content.Provider) {
defer mp.mu.Unlock()
mp.sub[dgst] = p
}

func (mp *MultiProvider) UnlazySession(desc ocispecs.Descriptor) session.Group {
type unlazySession interface {
UnlazySession(ocispecs.Descriptor) session.Group
}

mp.mu.RLock()
if p, ok := mp.sub[desc.Digest]; ok {
mp.mu.RUnlock()
if cd, ok := p.(unlazySession); ok {
return cd.UnlazySession(desc)
}
} else {
mp.mu.RUnlock()
}
if cd, ok := mp.base.(unlazySession); ok {
return cd.UnlazySession(desc)
}
return nil
}
8 changes: 8 additions & 0 deletions worker/base/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ func (w *Worker) FromRemote(ctx context.Context, remote *solver.Remote) (ref cac
cache.WithCreationTime(tm),
descHandlers,
}
if ul, ok := remote.Provider.(interface {
UnlazySession(ocispecs.Descriptor) session.Group
}); ok {
s := ul.UnlazySession(desc)
if s != nil {
opts = append(opts, cache.Unlazy(s))
}
}
if dh, ok := descHandlers[desc.Digest]; ok {
if ref, ok := dh.Annotations["containerd.io/distribution.source.ref"]; ok {
opts = append(opts, cache.WithImageRef(ref)) // can set by registry cache importer
Expand Down

0 comments on commit 9449399

Please sign in to comment.