Skip to content

The blobcache improvments#757

Merged
mtrmac merged 3 commits intocontainers:mainfrom
Honny1:blobcache-improvments
Apr 14, 2026
Merged

The blobcache improvments#757
mtrmac merged 3 commits intocontainers:mainfrom
Honny1:blobcache-improvments

Conversation

@Honny1
Copy link
Copy Markdown
Member

@Honny1 Honny1 commented Apr 10, 2026

I made some improvements based on the review by @mtrmac.

@github-actions github-actions bot added the image Related to "image" package label Apr 10, 2026
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 10, 2026

PTAL @mtrmac @nalind

@Honny1 Honny1 marked this pull request as ready for review April 10, 2026 12:27
Copy link
Copy Markdown
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Honny1 added a commit to Honny1/buildah that referenced this pull request Apr 10, 2026
TODO: Revendor with containers/container-libs#757

- go.podman.io/storage@main
- go.podman.io/image/v5@main
- go.podman.io/common@main

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Copy link
Copy Markdown
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up!

I’m not sure about the wantFirstAvailableAlgo code. Will it be used?

  • It is non-deterministic (iterating over the noted algorithms in a Go-determined order)
  • What will Buildah use? Due to containers/buildah#6660 , I think Buildah would not want to randomly use Zstd.
  • If we ever build the complex “any pre-existing layer” (with dependence on the destination manifest and users’ copy.Options) discussed in #731 (review) , I think a natural way to obtain that would be to call NewBlobCache without WithCompressAlgorithm. If we now define that call to be “first available without more conditions”, we would later need to add a WithSmartCompressSelection() to opt into the better behavior. That would not be much of a problem, but if we can’t see any current user of wantFirstAvailableAlgo, maybe it would be better to drop that (and continue conservatively using Gzip as in the previous version).

(Non-blocking: The commit split is not correct; the branch does not compile at one of the commits.)

Comment on lines 242 to 243
logrus.Debugf("suggesting cached blob with digest %q, type %q (decompress) in place of blob with digest %q", replaceDigest.String(), info.MediaType, info.Digest.String())
info.CompressionOperation = s.reference.compress
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In #731 (comment) I meant primarily

Suggested change
logrus.Debugf("suggesting cached blob with digest %q, type %q (decompress) in place of blob with digest %q", replaceDigest.String(), info.MediaType, info.Digest.String())
info.CompressionOperation = s.reference.compress
logrus.Debugf("suggesting cached blob with digest %q, type %q (decompress) in place of blob with digest %q", replaceDigest.String(), info.MediaType, info.Digest.String())
info.CompressionOperation = types.Decompress

but you’re right that the debug log does not need to include the %q either.)

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 10, 2026

Thanks for the follow-up!

I’m not sure about the wantFirstAvailableAlgo code. Will it be used?

  • It is non-deterministic (iterating over the noted algorithms in a Go-determined order)
  • What will Buildah use? Due to containers/buildah#6660 , I think Buildah would not want to randomly use Zstd.
  • If we ever build the complex “any pre-existing layer” (with dependence on the destination manifest and users’ copy.Options) discussed in #731 (review) , I think a natural way to obtain that would be to call NewBlobCache without WithCompressAlgorithm. If we now define that call to be “first available without more conditions”, we would later need to add a WithSmartCompressSelection() to opt into the better behavior. That would not be much of a problem, but if we can’t see any current user of wantFirstAvailableAlgo, maybe it would be better to drop that (and continue conservatively using Gzip as in the previous version).

You're right, I have an idea for a simple solution: let's change the requested algorithm parameter to an array. This would allow callers to specify multiple acceptable compressions, and we would return the first match. Since they already know the destination, they can make the choice from there. They can use manifest.CandidateCompressionMatchesReuseConditions along with dest.SupportedManifestMIMETypes() to filter the candidate algorithms. WDYT?

@mtrmac
Copy link
Copy Markdown
Contributor

mtrmac commented Apr 13, 2026

Structurally, the BlobCache use is:

srcRef := NewBlobCache(srcref)
copy.Image(…, srcRef, copy.Options{
  ForceManifestMIMEType: …,
  EnsureCompressionVariantsExist: …,
  ForceCompressionFormat: …,
  DestinationCtx: &types.SystemContext{CompressionFormat: …},
})
// hypothetically repeated copies from the same srcRef

i.e. the options governing the copy are not yet available in NewBlobCache, and some of them are not constant (EnsureCompressionVariantsExist might cause one gzip and one zstd variant to be created during a single copy.Image).

I.e. the caller would need to duplicate a bunch of that logic (now that isn’t exposed, CandidateCompressionMatchesReuseConditions is internal; suppose we expose that, the caller would still need to be dealing with that when it’s not something the caller distinctly cares about), and the non-constant cases couldn’t be accommodated at all.

If you want all of this resolved now and perfectly, passing the relevant data to a new LayerInfosForCopyWithOptions should not be too difficult, it’s just some mechanical work. (It would be nice to have, it would simplify the Buildah caller, and perhaps be a better semantic fit than the strict WithCompressAlgorithm matching. We might even get to drop that option before making a release with that API.)

I think I’d prefer dropping that part from this PR and fixing primarily the DetectCompressionFormat call (and whatever else is already done) now, so that that part isn’t lost. The LayerInfosForCopyWithOptions part would be large enough that having that in a separate PR (even if it were to follow immediately) would probably simplify the discussion.

@Honny1 Honny1 force-pushed the blobcache-improvments branch from 7dec204 to 8a56004 Compare April 13, 2026 19:43
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 13, 2026

Thanks for the explanation. I've addressed all the nits, and I think it's ready to merge.

@Honny1 Honny1 force-pushed the blobcache-improvments branch 2 times, most recently from 8ac3fdc to d422c55 Compare April 14, 2026 08:35
@packit-as-a-service
Copy link
Copy Markdown

Packit jobs failed. @containers/packit-build please check.

Honny1 added 3 commits April 14, 2026 10:41
… check

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Use types.Compress and types.Decompress literals instead of s.reference.compress. Fix panic format in test helper.

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
@Honny1 Honny1 force-pushed the blobcache-improvments branch from d422c55 to c4f0f43 Compare April 14, 2026 08:45
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 14, 2026

PTAL @mtrmac @nalind @containers/podman-maintainers

Copy link
Copy Markdown
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mtrmac mtrmac merged commit 129af75 into containers:main Apr 14, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

image Related to "image" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants