Skip to content

Commit

Permalink
storage, dest: clarify when TOCDigest is used
Browse files Browse the repository at this point in the history
This update introduces an enhancement in the blob handling mechanism,
specifically by separating the TOC digest from the
uncompressed/compressed digest.

Follow-up for: #1080.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Feb 6, 2024
1 parent 40a9359 commit 56e3443
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 93 deletions.
14 changes: 12 additions & 2 deletions copy/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,16 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo, to
requiredCompression = ic.compressionFormat
}

var tocDigest digest.Digest

// Check if we have a chunked layer in storage that's based on that blob. These layers are stored by their TOC digest.
tocDigest, err := chunkedToc.GetTOCDigest(srcInfo.Annotations)
d, err := chunkedToc.GetTOCDigest(srcInfo.Annotations)
if err != nil {
return types.BlobInfo{}, "", err
}
if d != nil {
tocDigest = *d
}

reused, reusedBlob, err := ic.c.dest.TryReusingBlobWithOptions(ctx, srcInfo, private.TryReusingBlobOptions{
Cache: ic.c.blobInfoCache,
Expand All @@ -713,7 +718,12 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo, to
if reused {
logrus.Debugf("Skipping blob %s (already present):", srcInfo.Digest)
func() { // A scope for defer
bar := ic.c.createProgressBar(pool, false, types.BlobInfo{Digest: reusedBlob.Digest, Size: 0}, "blob", "skipped: already exists")
d := reusedBlob.Digest
label := "skipped: already exists"
if reusedBlob.TOCDigest != "" {
label = "skipped: already exists (found by TOC)"
}
bar := ic.c.createProgressBar(pool, false, types.BlobInfo{Digest: d, Size: 0}, "blob", label)
defer bar.Abort(false)
bar.mark100PercentComplete()
}()
Expand Down
12 changes: 7 additions & 5 deletions internal/private/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ type ImageDestination interface {
// UploadedBlob is information about a blob written to a destination.
// It is the subset of types.BlobInfo fields the transport is responsible for setting; all fields must be provided.
type UploadedBlob struct {
Digest digest.Digest
Size int64
Digest digest.Digest
Size int64
TOCDigest digest.Digest
}

// PutBlobOptions are used in PutBlobWithOptions.
Expand Down Expand Up @@ -118,14 +119,15 @@ type TryReusingBlobOptions struct {
PossibleManifestFormats []string // A set of possible manifest formats; at least one should support the reused layer blob.
RequiredCompression *compression.Algorithm // If set, reuse blobs with a matching algorithm as per implementations in internal/imagedestination/impl.helpers.go
OriginalCompression *compression.Algorithm // May be nil to indicate “uncompressed” or “unknown”.
TOCDigest *digest.Digest // If specified, the blob can be looked up in the destination also by its TOC digest.
TOCDigest digest.Digest // If specified, the blob can be looked up in the destination also by its TOC digest.
}

// ReusedBlob is information about a blob reused in a destination.
// It is the subset of types.BlobInfo fields the transport is responsible for setting.
type ReusedBlob struct {
Digest digest.Digest // Must be provided
Size int64 // Must be provided
Digest digest.Digest // Must be provided, can be empty if TOCDigest is present
TOCDigest digest.Digest // Must be provided, can be empty if Digest is present
Size int64 // Must be provided
// The following compression fields should be set when the reuse substitutes
// a differently-compressed blob.
CompressionOperation types.LayerCompression // Compress/Decompress, matching the reused blob; PreserveOriginal if N/A
Expand Down
Loading

0 comments on commit 56e3443

Please sign in to comment.