Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedupe layer uploads where possible #396

Merged
merged 4 commits into from
Mar 6, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/v1/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,21 @@ func Write(ref name.Reference, img v1.Image, auth authn.Authenticator, t http.Ro
}

// Upload individual layers in goroutines and collect any errors.
// If we can dedupe by the layer digest, try to do so. If the layer is
// a stream.Layer, we can't dedupe and might re-upload.
var g errgroup.Group
seen := map[v1.Hash]struct{}{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you call this uploaded - it'll probably be a little clearer.

Also if you use map[v1.Hash]bool, then you can do

if uploaded[h]

for _, l := range ls {
l := l
if h, err := l.Digest(); err == nil {
// If we can determine the layer's digest ahead of
// time, use it to dedupe uploads.
if _, found := seen[h]; found {
continue // Already uploading.
}
seen[h] = struct{}{}
}

g.Go(func() error {
return w.uploadOne(l)
})
Expand Down