Skip to content

feat: internal manifest package - #144

Merged
niemeyer merged 20 commits into
canonical:mainfrom
letFunny:chisel-db-manifest-package
Sep 14, 2024
Merged

niemeyer merged 20 commits into
canonical:mainfrom
letFunny:chisel-db-manifest-package

Conversation

@letFunny

@letFunny letFunny commented Jul 2, 2024

Copy link
Copy Markdown
Collaborator
  • Have you signed the CLA?

@letFunny letFunny added the Priority Look at me first label Jul 2, 2024
Comment thread internal/manifest/manifest.go Resolved
@letFunny letFunny mentioned this pull request Jul 2, 2024
1 task done

@niemeyer niemeyer left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest_test.go Resolved
@letFunny
letFunny requested a review from niemeyer July 10, 2024 08:04

@rebornplusplus rebornplusplus left a comment

Copy link
Copy Markdown

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.

Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
@letFunny

letFunny commented Aug 6, 2024 •

Copy link
Copy Markdown
Collaborator Author

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.

@niemeyer niemeyer left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Outdated
return iteratePrefix(manifest, Path{Kind: "path", Path: pathPrefix}, onMatch)
}

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

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread internal/manifest/manifest.go Resolved
Comment thread internal/manifest/manifest.go Outdated

// 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
Copy Markdown
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.

@letFunny letFunny Aug 19, 2024 •

Copy link
Copy Markdown
Collaborator Author

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.

@niemeyer niemeyer left a comment

Copy link
Copy Markdown
Contributor

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
@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