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

o/registrystate: manage accesses to registries #14544

Merged
merged 7 commits into from
Oct 15, 2024

Conversation

MiguelPires
Copy link
Contributor

This change changes the registries accesses to use GetTransaction that determines which kind of access it's dealing with (e.g,. snap set, snapctl set, in or out of a hook, registry hook or non-registry, etc). This omits the concurrency checks and I've also opted to removed the bits allowing reading concurrently if the registry being read is different than the one with a transaction ongoing (this will require changes anyway since we'll add a load-registry change in the future). At the moment, the user API endpoint isn't connected to this yet since that will require more changes to it and this is already large enough.

@MiguelPires MiguelPires added the confdb confdb work (previously called registries and before aspects) label Sep 27, 2024
@github-actions github-actions bot added the Needs Documentation -auto- Label automatically added which indicates the change needs documentation label Sep 27, 2024
Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 79.28994% with 35 lines in your changes missing coverage. Please review.

Project coverage is 78.91%. Comparing base (03772c2) to head (b250f2b).
Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
overlord/registrystate/registrystate.go 80.17% 17 Missing and 6 partials ⚠️
overlord/hookstate/ctlcmd/get.go 76.31% 6 Missing and 3 partials ⚠️
overlord/hookstate/ctlcmd/set.go 72.72% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14544      +/-   ##
==========================================
+ Coverage   78.87%   78.91%   +0.03%     
==========================================
  Files        1083     1083              
  Lines      146109   146480     +371     
==========================================
+ Hits       115244   115590     +346     
- Misses      23668    23686      +18     
- Partials     7197     7204       +7     
Flag Coverage Δ
unittests 78.91% <79.28%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This change changes the registries accesses to use GetTransaction which
determines which kind of access it's dealing with (e.g,. snap set,
snapctl set, in or out of a hook, registry hook or non-registry, etc)
and takes the appropriate action.
This omits the concurrency checks and I've also opted to removed the
bits allowing reading concurrently if the registry being read is
different than the one with a transaction ongoing (this will require
changes anyway since we'll add a load-registry change in the future).
At the moment, the user API endpoint isn't connected to this yet since
that will require more changes to it.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
Copy link
Member

@andrewphelpsj andrewphelpsj left a comment

Choose a reason for hiding this comment

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

Changes look good, thanks! Just some minor comments.

overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
overlord/registrystate/registrystate.go Show resolved Hide resolved
overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
overlord/registrystate/registrystate.go Show resolved Hide resolved
overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

did a pass, maybe it's because it's an intermediate step but some things are a bit unclear, bunch of questions

overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
overlord/registrystate/registrystate.go Show resolved Hide resolved
return fmt.Errorf("cannot modify registry in %q hook", ctx.HookName())
}

regCtx := registrystate.NewContext(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we cannot use onDone on regCtx here, so not sure why we don't pass ctx and GetTransaction makes then its Context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The registrystate.Context is a way to defer the creation of the change or updating of state until the right time. For a registry hook, that might be when it ends. The API will not block but it will trigger it and then get the change (it'll need minor changes for that) and include it in the http response

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
Make reads through snapctl go through a different flow than the writes.
This will change in the future as the reads will also trigger a change
to load data but for now this makes access logic easier to reason about
and it's also slightly more correct.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
@MiguelPires
Copy link
Contributor Author

@andrewphelpsj can you have a look at the last commit c268103 please? It makes reads go through a simpler flow which is more correct than having it just reuse the write side access function and is also easier to reason about. I was going to do this separately but, for expediency reasons, I'm including it here. thanks

Copy link
Member

@andrewphelpsj andrewphelpsj left a comment

Choose a reason for hiding this comment

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

Thanks!

overlord/hookstate/ctlcmd/get.go Outdated Show resolved Hide resolved
overlord/hookstate/ctlcmd/get.go Outdated Show resolved Hide resolved
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

couple more clarification comments

overlord/registrystate/registrystate.go Show resolved Hide resolved
overlord/registrystate/registrystate.go Outdated Show resolved Hide resolved
overlord/registrystate/registrystate.go Show resolved Hide resolved
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thank you

@MiguelPires
Copy link
Contributor Author

The failure is an unrelated timeout in the document-interfaces-url test on 24.04

@pedronis pedronis merged commit 4a721a2 into canonical:master Oct 15, 2024
56 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confdb confdb work (previously called registries and before aspects) Needs Documentation -auto- Label automatically added which indicates the change needs documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants