Skip to content

Commit

Permalink
feat: prevent unnecessary conversions
Browse files Browse the repository at this point in the history
If content store provides remote cache,  we can use remote cache to avoid unnecessary conversions.
The layer converted using cache is the same as the layer converted normally, both containing two annotations: LayerAnnotationUncompressed, LayerAnnotationNydusBlob.
Also add two constant LayerAnnotations labels.

Signed-off-by: breezeTuT <[email protected]>
  • Loading branch information
PerseidMeteor committed Aug 15, 2023
1 parent a6f4457 commit a138538
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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[LayerAnnotationTargetDigest] != "" {

Check failure on line 779 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Build and Lint

undefined: LayerAnnotationTargetDigest

Check failure on line 779 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (linux, amd64)

undefined: LayerAnnotationTargetDigest

Check failure on line 779 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (linux, arm64)

undefined: LayerAnnotationTargetDigest

Check failure on line 779 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (darwin, amd64)

undefined: LayerAnnotationTargetDigest

Check failure on line 779 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (darwin, arm64)

undefined: LayerAnnotationTargetDigest

Check failure on line 779 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Smoke

undefined: LayerAnnotationTargetDigest
targetInfo, err := cs.Info(ctx, digest.Digest(info.Labels[LayerAnnotationTargetDigest]))

Check failure on line 780 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Build and Lint

undefined: LayerAnnotationTargetDigest

Check failure on line 780 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (linux, amd64)

undefined: LayerAnnotationTargetDigest

Check failure on line 780 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (linux, arm64)

undefined: LayerAnnotationTargetDigest

Check failure on line 780 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (darwin, amd64)

undefined: LayerAnnotationTargetDigest

Check failure on line 780 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Cross Build Test (darwin, arm64)

undefined: LayerAnnotationTargetDigest

Check failure on line 780 in pkg/converter/convert_unix.go

View workflow job for this annotation

GitHub Actions / Smoke

undefined: LayerAnnotationTargetDigest
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

0 comments on commit a138538

Please sign in to comment.