From c6dd51c32cfccc06e77b4f7cb2358f788753df72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Min=C3=A1=C5=99?= Date: Fri, 16 Sep 2016 14:05:51 +0200 Subject: [PATCH] Try to cross-repo mount until success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't fallback back immediately to blob upload if the cross-repo mount fails and layer upload is initiated by registry. Instead cancel the upload and re-try cross-repo mount from different source repository before doing full re-upload. Signed-off-by: Michal Minář --- distribution/push_v2.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/distribution/push_v2.go b/distribution/push_v2.go index d2012704db..41d4e69e91 100644 --- a/distribution/push_v2.go +++ b/distribution/push_v2.go @@ -29,7 +29,7 @@ import ( "github.com/docker/docker/registry" ) -const maxRepositoryMountAttempts = 3 +const maxRepositoryMountAttempts = 4 // PushResult contains the tag, manifest digest, and manifest size from the // push. It's used to signal this information to the trust code in the client @@ -379,9 +379,10 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress. pd.v2MetadataService.Remove(mountCandidate) } - layerUpload = lu - if layerUpload != nil { - break + if lu != nil { + // cancel previous upload + cancelLayerUpload(ctx, mountCandidate.Digest, layerUpload) + layerUpload = lu } } @@ -583,3 +584,13 @@ func getPathComponents(path string) []string { } return strings.Split(path, "/") } + +func cancelLayerUpload(ctx context.Context, dgst digest.Digest, layerUpload distribution.BlobWriter) { + if layerUpload != nil { + logrus.Debugf("cancelling upload of blob %s", dgst) + err := layerUpload.Cancel(ctx) + if err != nil { + logrus.Warnf("failed to cancel upload: %v", err) + } + } +}