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

Simplify the tarball: transport #1923

Merged
merged 16 commits into from
Apr 18, 2023
Merged

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Apr 14, 2023

Track layer data in a single map[digest]struct instead of 6 separate arrays, some completely unused, and other fields.

Also simplify how that data is created, and fix pedantically-invalid uses of bytes.NewBuffer.

See individual commit messages for details.

(Motivated by containers/podman#18193 but this doesn’t do anything to actually fix it.)

@@ -57,7 +55,7 @@ func (r *tarballReference) NewImageSource(ctx context.Context, sys *types.System
blobTime = time.Now()
reader = bytes.NewReader(r.stdin)
} else {
file, err = os.Open(filename)
file, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("error opening %q for reading: %w", filename, err)
Copy link
Member

Choose a reason for hiding this comment

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

This is a stutter, can you just return err.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Dropped the wrapping from the two os.Open errors.

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
We only want a Reader, so be more precise.

More importantly, we want to remove all instances of the habit to use
bytes.NewBuffer instead of bytes.NewReader (which can actually be unsafe),
although that concern does not directly apply to these calls

Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
NewBuffer documentation says
> The new Buffer takes ownership of buf, and the
> caller should not use buf after this call.

which is not really what we want, and a potential risk.

So, use the more directly applicable and safer bytes.Reader.

Hopefully doesn't change behavior, except that reading
the same laeyr from a tarball or sif transport is now well-defined.

Signed-off-by: Miloslav Trmač <[email protected]>
The slice already contains that value.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Should not change behavior

Signed-off-by: Miloslav Trmač <[email protected]>
Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
This allows removing the blobTimes array.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
This allows us to remove the blobTypes array.

Also fix a comment implying that only one layer can be present.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Currently it only replaces blobIDs, replacing an O(N) scan with a
hash lookup (although that's quite likely to be worse for the typical
single-layer source); the use of fileIndex is a bit awkward.  It will
get better soon.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Keep the data together and avoid extra indexing.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Remove that separate array/indexing.

This allows us to remove the short-lived fileIndex again.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... in more cases, not just stdin.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Use the same []byte storage for stdin layers and for configs; that allows
us to drop the config-specific fields from tarballImageSource and simplify.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
The standard library's
> open /this/does/not/exist: no such file or directory
might be sufficient.

Signed-off-by: Miloslav Trmač <[email protected]>
@vrothberg vrothberg merged commit 9270e46 into containers:main Apr 18, 2023
@mtrmac mtrmac deleted the tarball-simplify branch April 18, 2023 13:47
@mtrmac mtrmac restored the tarball-simplify branch April 18, 2023 13:47
@mtrmac mtrmac deleted the tarball-simplify branch April 18, 2023 13:47
@mtrmac mtrmac restored the tarball-simplify branch April 18, 2023 13:47
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.

3 participants