Skip to content

Commit

Permalink
storage destination: commit layer in PutBlob()
Browse files Browse the repository at this point in the history
Commit a layer directly in PutBlob() to the storage. This will allow
future commits to implement blob locking without leaking and deferring
parts of the logic to callers.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Apr 4, 2019
1 parent 1edfec7 commit 15e1750
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 131 deletions.
11 changes: 8 additions & 3 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (ic *imageCopier) copyLayers(ctx context.Context) error {
}

data := make([]copyLayerData, numLayers)
copyLayerHelper := func(index int, srcLayer types.BlobInfo, pool *mpb.Progress) {
copyLayerHelper := func(index int, srcLayer types.BlobInfo, previousLayer string, pool *mpb.Progress) {
defer copySemaphore.Release(1)
defer copyGroup.Done()
cld := copyLayerData{}
Expand All @@ -483,7 +483,8 @@ func (ic *imageCopier) copyLayers(ctx context.Context) error {
logrus.Debugf("Skipping foreign layer %q copy to %s", cld.destInfo.Digest, ic.c.dest.Reference().Transport().Name())
}
} else {
cld.destInfo, cld.diffID, cld.err = ic.copyLayer(ctx, srcLayer, pool)
c := context.WithValue(ctx, "previousLayer", previousLayer)
cld.destInfo, cld.diffID, cld.err = ic.copyLayer(c, srcLayer, pool)
}
data[index] = cld
}
Expand All @@ -493,8 +494,12 @@ func (ic *imageCopier) copyLayers(ctx context.Context) error {
defer progressCleanup()

for i, srcLayer := range srcInfos {
previousLayer := ""
if i >= 1 {
previousLayer = srcInfos[i-1].Digest.String()
}
copySemaphore.Acquire(ctx, 1)
go copyLayerHelper(i, srcLayer, progressPool)
go copyLayerHelper(i, srcLayer, previousLayer, progressPool)
}

// Wait for all layers to be copied
Expand Down
Loading

0 comments on commit 15e1750

Please sign in to comment.