MCPcopy Index your code
hub / github.com/containerd/containerd / Commit

Method Commit

core/metadata/content.go:582–641  ·  view source on GitHub ↗
(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt)

Source from the content-addressed store, hash-verified

580}
581
582func (nw *namespacedWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {
583 ctx = namespaces.WithNamespace(ctx, nw.namespace)
584
585 nw.l.RLock()
586 defer nw.l.RUnlock()
587
588 var innerErr error
589 var actualDgst digest.Digest
590 var actualSize int64
591
592 // We pre-sync the in-flight writes to the disk. This avoids the
593 // subsequent fp.Sync() call[1] from taking too long (10s+) while
594 // holding the metadata database lock as in the following `update`
595 // transaction.
596 //
597 // REF:
598 // [1]: https://github.com/containerd/containerd/blob/c4c3c6ea568ce0cfbcf754863abadeea37d77c8f/plugins/content/local/writer.go#L95
599 if err := nw.Sync(); err != nil {
600 nw.Close()
601 return fmt.Errorf("failed to perform sync: %w", err)
602 }
603
604 if err := update(ctx, nw.db, func(tx *bolt.Tx) error {
605 dgst, size, err := nw.commit(ctx, tx, size, expected, opts...)
606 if err != nil {
607 if !errdefs.IsAlreadyExists(err) {
608 return err
609 }
610 innerErr = err
611 }
612 actualDgst = dgst
613 actualSize = size
614 bkt := getIngestsBucket(tx, nw.namespace)
615 if bkt != nil {
616 if err := bkt.DeleteBucket([]byte(nw.ref)); err != nil && err != errbolt.ErrBucketNotFound {
617 return err
618 }
619 }
620 if err := removeIngestLease(ctx, tx, nw.ref); err != nil {
621 return err
622 }
623 return addContentLease(ctx, tx, dgst)
624 }); err != nil {
625 return err
626 }
627 if innerErr != nil {
628 return innerErr
629 }
630
631 if publisher := nw.db.Publisher(ctx); publisher != nil {
632 if err := publisher.Publish(ctx, "/content/create", &eventstypes.ContentCreate{
633 Digest: actualDgst.String(),
634 Size: actualSize,
635 }); err != nil {
636 return err
637 }
638 }
639

Callers

nothing calls this directly

Calls 11

SyncMethod · 0.95
CloseMethod · 0.95
commitMethod · 0.95
WithNamespaceFunction · 0.92
updateFunction · 0.85
getIngestsBucketFunction · 0.85
removeIngestLeaseFunction · 0.85
addContentLeaseFunction · 0.85
PublisherMethod · 0.80
PublishMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected