-
Notifications
You must be signed in to change notification settings - Fork 243
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
Conversation
LGTM |
#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]>
66f31da
to
cae12e3
Compare
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.
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 { |
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 elegant, I like it!
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
andwriteToAllStores
.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.