MCPcopy
hub / github.com/containerd/containerd / open

Method open

core/remotes/docker/fetcher.go:442–617  ·  view source on GitHub ↗
(ctx context.Context, req *request, mediatype string, offset int64, lastHost bool)

Source from the content-addressed store, hash-verified

440}
441
442func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string, offset int64, lastHost bool) (_ io.ReadCloser, _ int64, retErr error) {
443 const minChunkSize = 512
444
445 chunkSize := int64(r.performances.ConcurrentLayerFetchBuffer)
446 parallelism := int64(r.performances.MaxConcurrentDownloads)
447 if chunkSize < minChunkSize || req.body != nil {
448 parallelism = 1
449 }
450 log.G(ctx).WithField("initial_parallelism", r.performances.MaxConcurrentDownloads).
451 WithField("parallelism", parallelism).
452 WithField("chunk_size", chunkSize).
453 WithField("offset", offset).
454 Debug("fetching layer")
455 req.setMediaType(mediatype)
456 req.header.Set("Accept-Encoding", "zstd;q=1.0, gzip;q=0.8, deflate;q=0.5")
457 if parallelism > 1 || offset > 0 {
458 req.setOffset(offset)
459 }
460
461 if err := r.Acquire(ctx, 1); err != nil {
462 return nil, 0, err
463 }
464 var remaining int64
465 resp, err := req.doWithRetries(ctx, lastHost, withErrorCheck, withOffsetCheck(offset, parallelism))
466 switch err {
467 case nil:
468 // all good
469 remaining = resp.ContentLength
470 case errContentRangeIgnored:
471 if parallelism != 1 {
472 log.G(ctx).WithError(err).Info("remote host ignored content range, forcing parallelism to 1")
473 parallelism = 1
474 }
475 remaining = resp.ContentLength - offset
476 default:
477 log.G(ctx).WithError(err).Debug("fetch failed")
478 r.Release(1)
479 return nil, 0, err
480 }
481
482 body := &fnOnClose{
483 BeforeClose: func() {
484 r.Release(1)
485 },
486 ReadCloser: resp.Body,
487 }
488 defer func() {
489 if retErr != nil {
490 body.Close()
491 }
492 }()
493
494 encoding := strings.FieldsFunc(resp.Header.Get("Content-Encoding"), func(r rune) bool {
495 return r == ' ' || r == '\t' || r == ','
496 })
497
498 if remaining <= chunkSize {
499 parallelism = 1

Callers 11

openReferrersMethod · 0.95
FetchMethod · 0.95
FetchByDigestMethod · 0.95
FuzzFetcherFunction · 0.95
TestFetcherOpenFunction · 0.95
TestFetcherOpenParallelFunction · 0.95
TestContentEncodingFunction · 0.95
TestDockerFetcherOpenFunction · 0.95
readerMethod · 0.80

Calls 15

withOffsetCheckFunction · 0.85
newbufferPoolFunction · 0.85
newPipeWriterFunction · 0.85
setMediaTypeMethod · 0.80
setOffsetMethod · 0.80
doWithRetriesMethod · 0.80
cloneMethod · 0.80
CopyMethod · 0.80
SetMethod · 0.65
AcquireMethod · 0.65
InfoMethod · 0.65
ReleaseMethod · 0.65

Tested by 7

FuzzFetcherFunction · 0.76
TestFetcherOpenFunction · 0.76
TestFetcherOpenParallelFunction · 0.76
TestContentEncodingFunction · 0.76
TestDockerFetcherOpenFunction · 0.76