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

feat: internal manifest package #144

Merged
merged 20 commits into from
Sep 14, 2024

Conversation

letFunny
Copy link
Collaborator

@letFunny letFunny commented Jul 2, 2024

  • Have you signed the CLA?

@letFunny letFunny added the Priority Look at me first label Jul 2, 2024
@letFunny letFunny mentioned this pull request Jul 2, 2024
1 task
Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

This is looking very good, Alberto.

Many comments, but nothing fundamental.

internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest_test.go Outdated Show resolved Hide resolved
@letFunny letFunny requested a review from niemeyer July 10, 2024 08:04
Copy link
Member

@rebornplusplus rebornplusplus left a comment

Choose a reason for hiding this comment

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

Looks good to me overall, only a few questions and suggestions.

internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Show resolved Hide resolved
@letFunny
Copy link
Collaborator Author

letFunny commented Aug 6, 2024

Discussed offline with @niemeyer some parts of the PR. We agreed to:

  • Keep duplicated lines in manifest.wall as "undefined behavior" because it means the file is malformed. We should not support it but for now we won't report an error.
  • Change manifest.go to use pointers if it makes sense.

EDIT: I have done the tests for the second point and using pointers and a closure means that Go is allocating memory because of the escape analysis, i.e. it cannot figure out if the pointer will escape from the closure. To be discussed further, but keeping the structs for now.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Thanks for the tuning, Alberto. Final review, I believe.

internal/manifest/manifest.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Show resolved Hide resolved
return iteratePrefix(manifest, Path{Kind: "path", Path: pathPrefix}, onMatch)
}

func (manifest *Manifest) IteratePackages(onMatch func(Package) error) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We talked about using pointers for these but it's still using values. Is there a reason to keep these, or maybe I just misunderstood the plan?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed on the meeting last week, I did the full escape analysis on the real code and not synthetically with some closures. If I am interpreting it correctly, it turns out that passing by value or by pointer in this case does not matter because inside iteratePrefix we are passing it to functions that expect any, which means the value is moved to the heap and it does not matter whether it is a pointer or a struct. I have written a somewhat more lengthy discussion with the commands I have used and the output of the compiler here if you want to double check.

I have changed the code to use pointers because we are moving the values to the heap anyway and we avoid one of the copies.

internal/manifest/manifest.go Outdated Show resolved Hide resolved

// Read loads a Manifest from a file without performing any validation. The file
// is assumed to be both valid jsonwall and a valid Manifest (see [Validate]).
func Read(absPath string) (manifest *Manifest, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've missed this on the first review: why is this not an io.Reader? It seems curious that it's not only a filename, but a filename to a zstd compressed file. Doesn't feel like this package should care about the compression format of the manifest, or how the manifest is being read from disk. Note how the jsonwall.ReadDB function blended nicely below. We won't be able to do this with this function.

Copy link
Collaborator Author

@letFunny letFunny Aug 19, 2024

Choose a reason for hiding this comment

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

Agree I was thinking that zstd was part of the "format" but there is nothing dictating that, we could be storing it in a completely different way and this package should continue working correctly. The initial idea was to get the filename to be able to do some more things in the validation but I think that is better suited for slicer not for the general manifest.

I have made the changes in https://github.com/canonical/chisel/pull/144/files/56dd49ca33944ab4e09cc7778cdaec7245732924..4e0e33b13cd8319e31fb0a0c36587cfa479dfd7c.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Thanks for the tuning, Alberto. This looks great.

@niemeyer niemeyer merged commit 2cea830 into canonical:main Sep 14, 2024
14 checks passed
@letFunny letFunny deleted the chisel-db-manifest-package branch October 17, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority Look at me first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants