Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prevent unnecessary conversions #517

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/converter/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
LayerAnnotationNydusBootstrap = "containerd.io/snapshot/nydus-bootstrap"
LayerAnnotationNydusSourceChainID = "containerd.io/snapshot/nydus-source-chainid"
LayerAnnotationNydusEncryptedBlob = "containerd.io/snapshot/nydus-encrypted-blob"
LayerAnnotationNydusSourceDigest = "containerd.io/snapshot/nydus-source-digest"
LayerAnnotationNydusTargetDigest = "containerd.io/snapshot/nydus-target-digest"

LayerAnnotationNydusReferenceBlobIDs = "containerd.io/snapshot/nydus-reference-blob-ids"

Expand Down
24 changes: 23 additions & 1 deletion pkg/converter/convert_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,28 @@ func LayerConvertFunc(opt PackOption) converter.ConvertFunc {
return nil, nil
}

// Use remote cache to avoid unnecessary conversion
info, err := cs.Info(ctx, desc.Digest)
if err != nil {
return nil, errors.Wrapf(err, "get blob info %s", desc.Digest)
}
if info.Labels[LayerAnnotationNydusTargetDigest] != "" {
targetInfo, err := cs.Info(ctx, digest.Digest(info.Labels[LayerAnnotationNydusTargetDigest]))
if err != nil {
return nil, errors.Wrapf(err, "get blob info %s", desc.Digest)
}
targetDesc := ocispec.Descriptor{
Digest: targetInfo.Digest,
Size: targetInfo.Size,
MediaType: MediaTypeNydusBlob,
Annotations: map[string]string{
LayerAnnotationUncompressed: targetInfo.Digest.String(),
LayerAnnotationNydusBlob: "true",
},
}
return &targetDesc, nil
}

ra, err := cs.ReaderAt(ctx, desc)
if err != nil {
return nil, errors.Wrap(err, "get source blob reader")
Expand Down Expand Up @@ -825,7 +847,7 @@ func LayerConvertFunc(opt PackOption) converter.ConvertFunc {
}

blobDigest := digester.Digest()
info, err := cs.Info(ctx, blobDigest)
info, err = cs.Info(ctx, blobDigest)
if err != nil {
return nil, errors.Wrapf(err, "get blob info %s", blobDigest)
}
Expand Down
Loading