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 Jan 31, 2024
1 parent ef4bd23 commit 8d50e4d
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 @@ -696,11 +696,16 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo, to
originalCompression = srcInfo.CompressionAlgorithm
}

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 @@ -718,7 +723,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 @@ -117,14 +118,15 @@ type TryReusingBlobOptions struct {
EmptyLayer bool // True if the blob is an "empty"/"throwaway" layer, and may not necessarily be physically represented.
LayerIndex *int // If the blob is a layer, a zero-based index of the layer within the image; nil otherwise.
SrcRef reference.Named // A reference to the source image that contains the input blob.
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 8d50e4d

Please sign in to comment.