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

machine: add sparse file writer #21763

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

giuseppe
Copy link
Member

Does this PR introduce a user-facing change?

None

Copy link
Contributor

openshift-ci bot commented Feb 20, 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 Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 20, 2024
@baude
Copy link
Member

baude commented Feb 20, 2024

this is great work @giuseppe I am currently testing this ... code wise, LGTM

@baude
Copy link
Member

baude commented Feb 20, 2024

circling back, seems to work nicely

Copy link
Contributor

@cfergeau cfergeau left a comment

Choose a reason for hiding this comment

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

I'll need to test this in crc as this is a more sophisticated version of what we have, code makes sense, though devil will be in the small details.

pkg/machine/compression/sparse_file_writer.go Outdated Show resolved Hide resolved
pkg/machine/compression/sparse_file_writer.go Outdated Show resolved Hide resolved
@nalind
Copy link
Member

nalind commented Feb 20, 2024

Logic looks fine. Not sure about not letting the caller control the permissions bits.

@giuseppe
Copy link
Member Author

Logic looks fine. Not sure about not letting the caller control the permissions bits.

should we export newSparseWriterToFile for maximum control?

Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe
Copy link
Member Author

Logic looks fine. Not sure about not letting the caller control the permissions bits.

should we export newSparseWriterToFile for maximum control?

I've changed the API to export only newSparseWriterToFile and not have the method to create directly a file. That can be done by the caller.

@baude does the new API work fine for you?

@baude
Copy link
Member

baude commented Feb 20, 2024

it looks fine i think ...

/hold
/lgtm

@openshift-ci openshift-ci bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Feb 20, 2024
@baude baude added the 5.0 label Feb 20, 2024
@baude
Copy link
Member

baude commented Feb 20, 2024

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 20, 2024
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.

This LGTM as for correctness of the output. As for creating the holes exactly in the desired situations, that seems that it might be possible to improve.

Also it vaguely seems to me that we shouldn’t need 3 separate state variables, but I’m not sure about that part yet.

pkg/machine/compression/sparse_file_writer.go Show resolved Hide resolved
pkg/machine/compression/sparse_file_writer.go Show resolved Hide resolved
}
}

m.buffer.Next(int(m.pos) - m.buffer.Len())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don’t understand what this is intended to do.

  • AFAICS it always calls Next(0), which does nothing
  • If it did something, moving the read offset would interfere with the bytes.Equal ensuring the expected output.

return nil
}

func testInputWithWriteLen(t *testing.T, input []byte, chunkSize int) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ensuring the implementation correctly preserves data is definitely valuable; I’d also like the test to ensure that code does create the expected holes.

// add "hello" in the middle
largeInput = make([]byte, 1024*1024)
copy(largeInput[len(largeInput)/2:], []byte("hello"))
testInput(t, largeInput)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A hole (small and large) in the middle is also a possible case to test.

sw.file.Close()
return err
}
if sw.lastIsZero {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In many (all I think?) situations this code can create a 1-byte shorter hole in the first place, instead of having to seek back.

@openshift-merge-bot openshift-merge-bot bot merged commit 1d4651b into containers:main Feb 20, 2024
91 of 92 checks passed
@mtrmac
Copy link
Collaborator

mtrmac commented Feb 20, 2024

Consider reformulating as https://github.com/mtrmac/libpod/tree/sparse ; AFAICS that’s exactly the same logic, but, I think, rather easier to prove correct.

@giuseppe
Copy link
Member Author

Consider reformulating as https://github.com/mtrmac/libpod/tree/sparse ; AFAICS that’s exactly the same logic, but, I think, rather easier to prove correct.

would you mind opening a PR with your fixes?

@mtrmac
Copy link
Collaborator

mtrmac commented Feb 23, 2024

would you mind opening a PR with your fixes?

#21797, for the record. And yes, it is exactly the same logic, apart from the handling of zeroes at the very end.

@stale-locking-app stale-locking-app bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label May 24, 2024
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
5.0 approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. machine release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants