-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat: create manifest.wall #142
Conversation
This commit adds support for the creation of the manifest.wall file. The manifest file(s) are generated at the specified paths, marked with the "generate: manifest" keyword. The files are ZSTD compressed and have the basename "chisel.db". The format of the Chisel DB follows the RK009 spec. Co-authored-by: Rafid Bin Mostofa <rafid.mostofa@canonical.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks quite nice to me! Thank you.
Co-authored-by: Rafid Bin Mostofa <rafid.mostofa@canonical.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Alberto. Final details below.
internal/slicer/slicer.go
Outdated
targetDir string | ||
} | ||
|
||
func generateManifests(options *generateManifestsOptions) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The earlier comment was about generateManifest itself, not just LocateManifestSlices. Per earlier thread, that's also why I was mentioning that the testing of what is in here can be done in the manifest, so we don't need to involve the slicer on everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better, but still one pass to go I think. Details below:
internal/manifest/manifest.go
Outdated
@@ -158,6 +164,65 @@ func Validate(manifest *Manifest) (err error) { | |||
return nil | |||
} | |||
|
|||
// LocateManifestSlices finds the paths marked with "generate:manifest" and | |||
// returns a map from the manifest path to all the slices that declare it. | |||
func LocateManifestSlices(slices []*setup.Slice, manifestFileName string) map[string][]*setup.Slice { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please rename this function to manifest.FindPaths
(per docs), and have it taking the slices as its single argument. The manifest filename should be in this package since the slicer has no use for it given this function is the one pointing to the targets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 087d09d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The remaining part about the manifestFileName
I wonder whether you should be able to customize it. If I want to write it to somewhere that is not manifest.wall
then I should still be able to use this function. Maybe instead of taking manifestFileName we could return the directory and the caller is the one expected to concatenate the filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is pointing out what is the standard path given the following slices. We can write manifests anywhere using manifest.Write.
Do I misunderstand the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just that I thought the helper should be more generic and that in our previous conversations we said to move the manifest filename to slicer and keep manifest generic. I will move it back here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 8445042.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the conversation was about moving the function itself to slicer, for reasons related to what we've been discussing in this iteration. The comment now was about the fact we chose not to move the function out of manifest, and yet the filename is still there.
internal/manifest/manifest.go
Outdated
err := dbw.Add(&Path{ | ||
Kind: "path", | ||
Path: path, | ||
Mode: fmt.Sprintf("0%o", unixPerm(manifestMode)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know this mode? The answer is we don't, not here. That's a relatively small issue, but it's also a hint of a larger issue that is quite clear: there's an unfortunate cross-dependency and disconnect right now between the manifest package and the slicer package about how to write stuff to disk.
Let's please try to fix this by:
-
Introduce fsutil.CreateWriter, which returns (io.WriterCloser, *Entry, error). Let's please do it right, in the sense that we'll have a writerProxy, similar to the readerProxy that we have today, to fill up the hash and size as we go, as that's trivial to do. We won't depend on it, though. See below.
-
Add the *Entry to the actual Report as soon as we create the *Entry. At this point the entry will still be empty as far as the hash goes, and that's the way it should be as otherwise we'd need to add it at the end, which doesn't work since entries are sorted.
-
Remove manifestAddManifestPaths and the respective field from the options type.
With these steps, there's nothing special anymore about manifest files here: the slicer cuts it, the report holds it, the manifest writes it down, just like everything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One extra detail here: CreateWriter can take the same Options parameter we have in the Create function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in dad0ed7. Hopefully now everything should be unified and there is nothing special about manifest files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thank you!
Just one detail missing from the prior review.
internal/manifest/manifest.go
Outdated
Selection []*setup.Slice | ||
// Map manifest path to all the slices that declare it. See | ||
// manifest.FindPaths. | ||
ManifestSlices map[string][]*setup.Slice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per earlier comments, it doesn't make sense to have this here anymore. See how it's being used below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a9ee6ac, my bad for missing it earlier.
internal/manifest/manifest.go
Outdated
@@ -270,6 +263,9 @@ func manifestAddSlices(dbw *jsonwall.DBWriter, slices []*setup.Slice) error { | |||
} | |||
|
|||
func manifestAddReport(dbw *jsonwall.DBWriter, report *Report) error { | |||
if report == nil { | |||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a manifest without a report looks like a bug. What code elsewhere is doing this and why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That Write function is beautiful now. Thank you!
This commit adds support for the creation of the manifest.wall file. The manifest file(s) are generated at the specified paths, marked with the "generate: manifest" keyword. The files are ZSTD compressed and have the basename "manifest.wall". The format of the Chisel DB follows the RK009 spec.