Browse code

Try to cross-repo mount until success

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ář <miminar@redhat.com>

Michal Minář authored on 2016/09/16 21:05:51
Showing 1 changed files
... ...
@@ -29,7 +29,7 @@ import (
29 29
 	"github.com/docker/docker/registry"
30 30
 )
31 31
 
32
-const maxRepositoryMountAttempts = 3
32
+const maxRepositoryMountAttempts = 4
33 33
 
34 34
 // PushResult contains the tag, manifest digest, and manifest size from the
35 35
 // 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.
379 379
 			pd.v2MetadataService.Remove(mountCandidate)
380 380
 		}
381 381
 
382
-		layerUpload = lu
383
-		if layerUpload != nil {
384
-			break
382
+		if lu != nil {
383
+			// cancel previous upload
384
+			cancelLayerUpload(ctx, mountCandidate.Digest, layerUpload)
385
+			layerUpload = lu
385 386
 		}
386 387
 	}
387 388
 
... ...
@@ -583,3 +584,13 @@ func getPathComponents(path string) []string {
583 583
 	}
584 584
 	return strings.Split(path, "/")
585 585
 }
586
+
587
+func cancelLayerUpload(ctx context.Context, dgst digest.Digest, layerUpload distribution.BlobWriter) {
588
+	if layerUpload != nil {
589
+		logrus.Debugf("cancelling upload of blob %s", dgst)
590
+		err := layerUpload.Cancel(ctx)
591
+		if err != nil {
592
+			logrus.Warnf("failed to cancel upload: %v", err)
593
+		}
594
+	}
595
+}