Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 3958980

Browse files
committed
Avoid a HEAD request for each layer in a v2 pull
We were calling Stat for each layer to get the size so we could indicate progress, but distribution/distribution#1226 made it possible to get the length from the GET request that Open initiates. Saving one round-trip per layer should make pull operations slightly faster and more robust. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
1 parent c80d03d commit 3958980

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

distribution/pull_v2.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ func (p *v2Puller) download(di *downloadInfo) {
130130

131131
blobs := p.repo.Blobs(context.Background())
132132

133-
desc, err := blobs.Stat(context.Background(), di.digest)
134-
if err != nil {
135-
logrus.Debugf("Error statting layer: %v", err)
136-
di.err <- err
137-
return
138-
}
139-
di.size = desc.Size
140-
141133
layerDownload, err := blobs.Open(context.Background(), di.digest)
142134
if err != nil {
143135
logrus.Debugf("Error fetching layer: %v", err)
@@ -146,6 +138,21 @@ func (p *v2Puller) download(di *downloadInfo) {
146138
}
147139
defer layerDownload.Close()
148140

141+
di.size, err = layerDownload.Seek(0, os.SEEK_END)
142+
if err != nil {
143+
// Seek failed, perhaps because there was no Content-Length
144+
// header. This shouldn't fail the download, because we can
145+
// still continue without a progress bar.
146+
di.size = 0
147+
} else {
148+
// Restore the seek offset at the beginning of the stream.
149+
_, err = layerDownload.Seek(0, os.SEEK_SET)
150+
if err != nil {
151+
di.err <- err
152+
return
153+
}
154+
}
155+
149156
verifier, err := digest.NewDigestVerifier(di.digest)
150157
if err != nil {
151158
di.err <- err

0 commit comments

Comments
 (0)