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

blob: TryReusingBlobWithOptions consider RequiredCompression if set #2023

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

flouthoc
Copy link
Contributor

@flouthoc flouthoc commented Jul 2, 2023

TryReusingBlob now contains a new option RequiredCompression which filters the blob by checking against a compression of the blob which is considerd to be resued, in case RequiredCompression is set and info of the blob being reused does not matches, no blob is returned.

@flouthoc
Copy link
Contributor Author

flouthoc commented Jul 2, 2023

I tested the docker blob's in combination with a variant of code from #1987 and it is working as expected. I made similar changes to other transport as well where change was applicable.

@flouthoc flouthoc force-pushed the tryreusingblob-compression branch from 65b7f41 to bb04be5 Compare July 2, 2023 15:36
@flouthoc
Copy link
Contributor Author

flouthoc commented Jul 2, 2023

@mtrmac PTAL

directory/directory_dest.go Outdated Show resolved Hide resolved
docker/docker_image_dest.go Outdated Show resolved Hide resolved
docker/docker_image_dest.go Outdated Show resolved Hide resolved
internal/private/private.go Show resolved Hide resolved
storage/storage_dest.go Outdated Show resolved Hide resolved
internal/private/private.go Outdated Show resolved Hide resolved
@mtrmac
Copy link
Collaborator

mtrmac commented Jul 7, 2023

I think it would be easier if the new option only applied in the CanSubstitute case; then these simple implementations that never substitute blobs wouldn’t need to add extra conditions.

On second thought, I’m afraid that doesn’t work well. For converting from gzip to zstd, we ideally want an operation to express “I have a gzip blob, but I want zstd; so check if there is a zstd variant, but don’t use a gzip one even if it is an exact match”. In that case CanSubstitute will be set, but even an exact match needs to consider the RequiredCompression condition.

So every single transport needs to deal with this, sadly, and your original approach was correct.


The options.RequiredCompression == nil || (options.RequiredCompression.Name() == info.CompressionAlgorithm.Name()) condition will, then, be copy&pasted so many times that it seems useful to share it as a helper function in the internal/imagedestination/impl package.


Note that the info.CompressionAlgorithm field is not, in general, expected to be provided to TryReusingBlob (really adding that field has been a mistake.) We do set it in the copy pipeline, but really it is only documented as an input to .UpdateLayerInfos. A minimal fix would be to document that if RequiredCompression is set, info.CompressionAlgorithm must be set as well; I think it would be cleaner instead, to provide the algorithm specifically as an input for TryReusingBlobWithOptions, as a new field TryReusingBlobOptions.OriginalCompression or something like that. And then document that it must be set along with RequiredCompression.

@flouthoc flouthoc force-pushed the tryreusingblob-compression branch from 1bf8943 to d3d5df7 Compare July 7, 2023 05:33
@flouthoc
Copy link
Contributor Author

flouthoc commented Jul 8, 2023

@mtrmac PTAL

Copy link
Collaborator

@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.

I’m sorry, for some reason 3 comments were left pending.

docker/docker_image_dest.go Outdated Show resolved Hide resolved
docker/docker_image_dest.go Outdated Show resolved Hide resolved
internal/private/private.go Outdated Show resolved Hide resolved
internal/imagedestination/impl/compat.go Outdated Show resolved Hide resolved
internal/imagedestination/impl/compat.go Outdated Show resolved Hide resolved
@flouthoc flouthoc force-pushed the tryreusingblob-compression branch from d3d5df7 to 7304098 Compare July 8, 2023 01:56
@flouthoc flouthoc requested a review from mtrmac July 8, 2023 02:01
@flouthoc flouthoc force-pushed the tryreusingblob-compression branch 2 times, most recently from 1779182 to 77b9752 Compare July 10, 2023 15:33
Copy link
Collaborator

@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.

internal/imagedestination/impl/helpers.go Outdated Show resolved Hide resolved
docker/docker_image_dest.go Show resolved Hide resolved
docker/docker_image_dest.go Outdated Show resolved Hide resolved
docker/docker_image_dest.go Outdated Show resolved Hide resolved
continue
}
if !impl.BlobMatchesRequiredCompression(options, compressionAlgorithm) {
logrus.Debugf("Ignoring candidate blob %s as reuse candidate since compression %s was requested and blob has compression %s", candidate.Digest.String(), options.RequiredCompression.Name(), compressionAlgorithm.Name())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also needs to not crash on compressionAlgorithm == nil.

(Also compare the “Trying to reuse” code; including candidateRepo.Name() seems useful — especially if the code is moved so that the “trying” logs aren’t emitted at all.)

(Absolutely non-blocking: making this a bit shorter would help on narrow terminals / log viewers: “Not using …, compression mismatch (%s vs. %s)”. The text should make sense but it can probably be assumed the reader can refer to the related source code, so it doesn’t need to be quite self-documenting.)

docker/docker_image_dest.go Outdated Show resolved Hide resolved
@flouthoc flouthoc force-pushed the tryreusingblob-compression branch from 77b9752 to cdd22f1 Compare July 11, 2023 06:14
@flouthoc
Copy link
Contributor Author

@mtrmac Could you PTAL again.

@flouthoc flouthoc requested a review from mtrmac July 11, 2023 14:42
Copy link
Collaborator

@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, one last cleanup round please.

docker/docker_image_dest.go Outdated Show resolved Hide resolved
internal/imagedestination/impl/helpers.go Outdated Show resolved Hide resolved
internal/private/private.go Outdated Show resolved Hide resolved
internal/private/private.go Outdated Show resolved Hide resolved
@flouthoc flouthoc force-pushed the tryreusingblob-compression branch 4 times, most recently from 3938c90 to c637ac7 Compare July 12, 2023 08:14
@flouthoc flouthoc requested a review from mtrmac July 12, 2023 16:32
Copy link
Collaborator

@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.

Also one outstanding item from #2023 (review):

blobCacheDestination.TryReusingBlobWithOptions also needs to implement this

ostree/ostree_dest.go Outdated Show resolved Hide resolved
internal/imagedestination/impl/helpers.go Outdated Show resolved Hide resolved
@flouthoc flouthoc force-pushed the tryreusingblob-compression branch from 3d230ea to 4f8c039 Compare July 12, 2023 18:28
Copy link
Collaborator

@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 fa37116 into containers:main Jul 12, 2023
flouthoc added a commit to flouthoc/image that referenced this pull request Jul 13, 2023
Fixes: containers#2023 (comment).

`assert.Equal` expects `assert.Equal(t, expected, actual)` instead of `assert.Equal(t, actual, expected)`.

Ref:https://pkg.go.dev/github.com/stretchr/testify/assert#Assertions.Equal

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Jul 18, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Jul 19, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Jul 20, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Jul 20, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Jul 20, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Jul 21, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 2, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 2, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 2, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 2, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 2, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 2, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 3, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
mtrmac pushed a commit to flouthoc/image that referenced this pull request Aug 3, 2023
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 4, 2023
Fixes: containers#2023 (comment).

`assert.Equal` expects `assert.Equal(t, expected, actual)` instead of `assert.Equal(t, actual, expected)`.

Ref:https://pkg.go.dev/github.com/stretchr/testify/assert#Assertions.Equal

Signed-off-by: Aditya R <[email protected]>
flouthoc added a commit to flouthoc/image that referenced this pull request Aug 4, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
mtrmac pushed a commit to mtrmac/image that referenced this pull request Aug 4, 2023
Fixes: containers#2023 (comment).

`assert.Equal` expects `assert.Equal(t, expected, actual)` instead of `assert.Equal(t, actual, expected)`.

Ref:https://pkg.go.dev/github.com/stretchr/testify/assert#Assertions.Equal

Signed-off-by: Aditya R <[email protected]>
mtrmac pushed a commit to mtrmac/image that referenced this pull request Aug 4, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
mtrmac pushed a commit to mtrmac/image that referenced this pull request Aug 5, 2023
Fixes: containers#2023 (comment).

`assert.Equal` expects `assert.Equal(t, expected, actual)` instead of `assert.Equal(t, actual, expected)`.

Ref:https://pkg.go.dev/github.com/stretchr/testify/assert#Assertions.Equal

Signed-off-by: Aditya R <[email protected]>
mtrmac pushed a commit to mtrmac/image that referenced this pull request Aug 5, 2023
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants