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

Consolidate the common parts of simple writers #1383

Merged
merged 4 commits into from
Oct 14, 2022

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Oct 13, 2022

Factor out the repetitive “find and lock C/I/L store” parts out of the top-level storage.Store API into helpers: writeTo{Container,Image,Layer}Store and writeToAllStores.

Overall, this is just a refactoring that should not change behavior. The goal is to decrease the number of individual call sites to the locking code — so that the code refactored here does not need to be touched again for locking changes.

The more complex writers that don’t fit the simple locking schemes of these helpers remain unchanged; the locking in them will be updated individually.

See individual commit messages for (a bit) more detail. It might be more convenient to review this in a view that ignores whitespace changes.

@rhatdan
Copy link
Member

rhatdan commented Oct 13, 2022

@mtrmac
Copy link
Collaborator Author

mtrmac commented Oct 13, 2022

#1384 is a counterpart for the more complex read paths.

... to avoid the repetition of getting, locking,
and reloading, the store.

Use it at least for the simplest writers.

This could be more elegant with Go generics, returning
(T, error), with T possibly being void = struct{}.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... to avoid the repetition of getting, locking,
and reloading, the store.

Use it at least for the simplest writers.

This could be more elegant with Go generic returning
(T, error), with T possibly being void = struct{}.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... to avoid the repetition of getting, locking,
and reloading, the store.

Use it at least for the simplest writers.

This could be more elegant with Go generics, returning
(T, error), with T possibly being void = struct{}.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... to avoid the repetition of getting, locking,
and reloading, the stores.

This also makes it less error-prone to use a consistent
locking order (but note that other instances of manual
locking still exist).

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

// writeToLayerStore is a helper for working with store.getLayerStore():
// It locks the store for writing, checks for updates, and calls fn()
// It returns the return value of fn, or its own error initializing the store.
func (s *store) writeToLayerStore(fn func(store rwLayerStore) error) error {
Copy link
Member

Choose a reason for hiding this comment

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

Very elegant, I like it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants