-
Notifications
You must be signed in to change notification settings - Fork 251
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
race, storage: add independent AddNames
and RemoveNames
for images,layers and containers
#1153
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,14 @@ import ( | |
"github.com/pkg/errors" | ||
) | ||
|
||
type updateNameOperation int | ||
|
||
const ( | ||
setNames updateNameOperation = iota | ||
addNames | ||
removeNames | ||
) | ||
|
||
var ( | ||
stores []*store | ||
storesLock sync.Mutex | ||
|
@@ -368,8 +376,17 @@ type Store interface { | |
|
||
// SetNames changes the list of names for a layer, image, or container. | ||
// Duplicate names are removed from the list automatically. | ||
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`. | ||
SetNames(id string, names []string) error | ||
|
||
// AddNames adds the list of names for a layer, image, or container. | ||
// Duplicate names are removed from the list automatically. | ||
AddNames(id string, names []string) error | ||
|
||
// RemoveNames removes the list of names for a layer, image, or container. | ||
// Duplicate names are removed from the list automatically. | ||
RemoveNames(id string, names []string) error | ||
|
||
// ListImageBigData retrieves a list of the (possibly large) chunks of | ||
// named data associated with an image. | ||
ListImageBigData(id string) ([]string, error) | ||
|
@@ -2050,7 +2067,20 @@ func dedupeNames(names []string) []string { | |
return deduped | ||
} | ||
|
||
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`. | ||
func (s *store) SetNames(id string, names []string) error { | ||
flouthoc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return s.updateNames(id, names, setNames) | ||
} | ||
|
||
func (s *store) AddNames(id string, names []string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m not sure whether to go there — others, feel free to say this is not the time. If we are adding a new top-level API, do we have to follow the generic |
||
return s.updateNames(id, names, addNames) | ||
} | ||
|
||
func (s *store) RemoveNames(id string, names []string) error { | ||
return s.updateNames(id, names, removeNames) | ||
} | ||
|
||
func (s *store) updateNames(id string, names []string, op updateNameOperation) error { | ||
deduped := dedupeNames(names) | ||
|
||
rlstore, err := s.LayerStore() | ||
|
@@ -2063,7 +2093,16 @@ func (s *store) SetNames(id string, names []string) error { | |
return err | ||
} | ||
if rlstore.Exists(id) { | ||
return rlstore.SetNames(id, deduped) | ||
switch op { | ||
flouthoc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case setNames: | ||
return rlstore.SetNames(id, deduped) | ||
case removeNames: | ||
return rlstore.RemoveNames(id, deduped) | ||
case addNames: | ||
return rlstore.AddNames(id, deduped) | ||
default: | ||
return errInvalidUpdateNameOperation | ||
} | ||
} | ||
|
||
ristore, err := s.ImageStore() | ||
|
@@ -2076,7 +2115,16 @@ func (s *store) SetNames(id string, names []string) error { | |
return err | ||
} | ||
if ristore.Exists(id) { | ||
return ristore.SetNames(id, deduped) | ||
switch op { | ||
case setNames: | ||
return ristore.SetNames(id, deduped) | ||
case removeNames: | ||
return ristore.RemoveNames(id, deduped) | ||
case addNames: | ||
return ristore.AddNames(id, deduped) | ||
default: | ||
return errInvalidUpdateNameOperation | ||
} | ||
} | ||
|
||
// Check is id refers to a RO Store | ||
|
@@ -2114,7 +2162,16 @@ func (s *store) SetNames(id string, names []string) error { | |
return err | ||
} | ||
if rcstore.Exists(id) { | ||
return rcstore.SetNames(id, deduped) | ||
switch op { | ||
case setNames: | ||
return rcstore.SetNames(id, deduped) | ||
case removeNames: | ||
return rcstore.RemoveNames(id, deduped) | ||
case addNames: | ||
return rcstore.AddNames(id, deduped) | ||
default: | ||
return errInvalidUpdateNameOperation | ||
} | ||
} | ||
return ErrLayerUnknown | ||
} | ||
|
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.
@nalind do we even need to make these methods public? I can’t see any external users of the
ContainerStore
interface.So maybe we just need a single
updateNames
here, withSetNames
a compatibility forwarder. Having each of the three stores provide anupdateNames
would allowstore.UpdateNames
to avoid the switch statements.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.
I'm not attached to the new methods being public. The early guess was that we'd find ourselves needing to call into LayerStore/ImageStore/ContainerStore methods directly far more often than we do now, but I don't think that's turned out to be the case in practice.