Skip to content

Commit c68af33

Browse files
committed
Make local cache non-lazy
Signed-off-by: Kohei Tokunaga <[email protected]>
1 parent 5ab03b4 commit c68af33

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

cache/manager.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,14 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispecs.Descriptor,
301301

302302
cm.records[id] = rec
303303

304-
return rec.ref(true, descHandlers, nil), nil
304+
ref := rec.ref(true, descHandlers, nil)
305+
if s := unlazySessionOf(opts...); s != nil {
306+
if err := ref.unlazy(ctx, ref.descHandlers, ref.progress, s, true); err != nil {
307+
return nil, err
308+
}
309+
}
310+
311+
return ref, nil
305312
}
306313

307314
// init loads all snapshots from metadata state and tries to load the records

cache/opts.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ type NeedsRemoteProviderError []digest.Digest //nolint:errname
3535
func (m NeedsRemoteProviderError) Error() string {
3636
return fmt.Sprintf("missing descriptor handlers for lazy blobs %+v", []digest.Digest(m))
3737
}
38+
39+
type Unlazy session.Group
40+
41+
func unlazySessionOf(opts ...RefOption) session.Group {
42+
for _, opt := range opts {
43+
if opt, ok := opt.(session.Group); ok {
44+
return opt
45+
}
46+
}
47+
return nil
48+
}

cache/remotecache/local/local.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,16 @@ func getContentStore(ctx context.Context, sm *session.Manager, g session.Group,
9898
if err != nil {
9999
return nil, err
100100
}
101-
return sessioncontent.NewCallerStore(caller, storeID), nil
101+
return &unlazyProvider{sessioncontent.NewCallerStore(caller, storeID), g}, nil
102+
}
103+
104+
type unlazyProvider struct {
105+
content.Store
106+
s session.Group
107+
}
108+
109+
func (p *unlazyProvider) UnlazySession(desc ocispecs.Descriptor) session.Group {
110+
return p.s
102111
}
103112

104113
func attrsToCompression(attrs map[string]string) (*compression.Config, error) {

util/contentutil/multiprovider.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/containerd/containerd/content"
88
"github.com/containerd/containerd/errdefs"
9+
"github.com/moby/buildkit/session"
910
digest "github.com/opencontainers/go-digest"
1011
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1112
"github.com/pkg/errors"
@@ -90,3 +91,23 @@ func (mp *MultiProvider) Add(dgst digest.Digest, p content.Provider) {
9091
defer mp.mu.Unlock()
9192
mp.sub[dgst] = p
9293
}
94+
95+
func (mp *MultiProvider) UnlazySession(desc ocispecs.Descriptor) session.Group {
96+
type unlazySession interface {
97+
UnlazySession(ocispecs.Descriptor) session.Group
98+
}
99+
100+
mp.mu.RLock()
101+
if p, ok := mp.sub[desc.Digest]; ok {
102+
mp.mu.RUnlock()
103+
if cd, ok := p.(unlazySession); ok {
104+
return cd.UnlazySession(desc)
105+
}
106+
} else {
107+
mp.mu.RUnlock()
108+
}
109+
if cd, ok := mp.base.(unlazySession); ok {
110+
return cd.UnlazySession(desc)
111+
}
112+
return nil
113+
}

worker/base/worker.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ func (w *Worker) FromRemote(ctx context.Context, remote *solver.Remote) (ref cac
477477
cache.WithCreationTime(tm),
478478
descHandlers,
479479
}
480+
if ul, ok := remote.Provider.(interface {
481+
UnlazySession(ocispecs.Descriptor) session.Group
482+
}); ok {
483+
s := ul.UnlazySession(desc)
484+
if s != nil {
485+
opts = append(opts, cache.Unlazy(s))
486+
}
487+
}
480488
if dh, ok := descHandlers[desc.Digest]; ok {
481489
if ref, ok := dh.Annotations["containerd.io/distribution.source.ref"]; ok {
482490
opts = append(opts, cache.WithImageRef(ref)) // can set by registry cache importer

0 commit comments

Comments
 (0)