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

chunked: rework GetBlobAt usage #2162

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

giuseppe
Copy link
Member

@giuseppe giuseppe commented Nov 6, 2024

rewrite how the result from GetBlobAt is used, to make sure 1) that the streams are always closed, and 2) that any error is processed.

Closes: https://issues.redhat.com/browse/OCPBUGS-43968

Copy link
Contributor

openshift-ci bot commented Nov 6, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Nov 6, 2024
giuseppe added a commit to giuseppe/libpod that referenced this pull request Nov 6, 2024
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/libpod that referenced this pull request Nov 6, 2024
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/libpod that referenced this pull request Nov 6, 2024
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe marked this pull request as draft November 6, 2024 11:36
giuseppe added a commit to giuseppe/libpod that referenced this pull request Nov 6, 2024
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe marked this pull request as ready for review November 6, 2024 12:16
@giuseppe
Copy link
Member Author

giuseppe commented Nov 6, 2024

testing in containers/podman#24478

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! Just a quick look for now — this looks like the right approach in general.

@@ -48,21 +48,21 @@ func readEstargzChunkedManifest(blobStream ImageSourceSeekable, blobSize int64,
Offset: uint64(blobSize - footerSize),
Length: uint64(footerSize),
}
parts, errs, err := blobStream.GetBlobAt([]ImageSourceChunk{chunk})

footer := make([]byte, footerSize)
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIRC, a lot of the code could benefit from a single “ask for one chunk, read it into memory, validate against a digest” utility.

Arguably that’s a cleanup that should not block this PR…

pkg/chunked/compression_linux.go Show resolved Hide resolved
if err != nil {
return nil, nil, nil, 0, err
}

defer func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works.

Maybe another way to structure the consumers would be to:

defer consumeRemainingStreamsOrErrors(streamsOrErrors) // this loop, ignoring all errors. Also see elsewhere — maybe this should be a context cancellation instead.
// consume data: if there is only one chunk:
reader, err := getNextStream(streamsOrErrors) // if this contains an error, or is closed, returns an error
// Optionally, after all data is consumed: Alternatively, this can be enforced in `getBlobAt` — if we are fine with ignoring errors after all expected data is consumed, like excess chunks.
err := ensureAllDone(streamsOrErrors) // Ensure straemsOrErrors is at EOF, there are no unexpected items, there are no errors reported .

Copy link
Member Author

@giuseppe giuseppe Nov 7, 2024

Choose a reason for hiding this comment

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

looking more into this, I don't think we should ignore errors. I'll move the code to a new function

pkg/chunked/compression_linux.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux.go Outdated Show resolved Hide resolved
if err != nil {
return nil, nil, nil, 0, err
}

defer func() {
Copy link
Collaborator

@mtrmac mtrmac Nov 6, 2024

Choose a reason for hiding this comment

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

Having to consume everything is, generally, an undesired cost.

The typical handling for that is to use a cancellable context, and to have the consumer here defer cancelTheContext; and for the goroutine to observe that context and terminate on cancellation.

Sadly that is not possible in ImageSourceSeekable (no Context parameter), but maybe we could build the streamsOrErrors the idiomatic way, and have getBlobAt deal with draining the produced output, instead of doing that in every consumer.

(I didn’t try, this might be too hard to do. Notably channel sends in getBlobAt would also have to select vs. the context terminating.)

pkg/chunked/compression_linux.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux.go Show resolved Hide resolved
@giuseppe
Copy link
Member Author

giuseppe commented Nov 7, 2024

@cgwalters thanks for the review. Addressed the comments and pushed a new version

giuseppe added a commit to giuseppe/libpod that referenced this pull request Nov 8, 2024
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/libpod that referenced this pull request Nov 8, 2024
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
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.

ACK overall, and the tests are great.

pkg/chunked/storage_linux.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux_test.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux_test.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux_test.go Outdated Show resolved Hide resolved
@giuseppe
Copy link
Member Author

@mtrmac addressed your comments, pushed a new version

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.

Code LGTM. Can I ask for one last test change?

pkg/chunked/storage_linux_test.go Outdated Show resolved Hide resolved
pkg/chunked/storage_linux_test.go Outdated Show resolved Hide resolved
@giuseppe
Copy link
Member Author

Code LGTM. Can I ask for one last test change?

what do you think of the last version?

@mtrmac
Copy link
Collaborator

mtrmac commented Nov 14, 2024

Sure, that works.


The lint CI step is failing, and the error message is not very helpful.

rewrite how the result from GetBlobAt is used, to make sure 1) that
the streams are always closed, and 2) that any error is processed.

Closes: https://issues.redhat.com/browse/OCPBUGS-43968

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@mtrmac
Copy link
Collaborator

mtrmac commented Nov 14, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Nov 14, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit d075620 into containers:main Nov 14, 2024
20 checks passed
@mtrmac
Copy link
Collaborator

mtrmac commented Nov 14, 2024

@giuseppe Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants