Merge branch 'main' into warnings

This commit is contained in:
Daniel J Walsh 2022-10-14 13:46:03 -04:00 committed by GitHub
commit d02a89afb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 164 deletions

View File

@ -81,18 +81,8 @@ type rwContainerStore interface {
// convenience of the caller, nothing more. // convenience of the caller, nothing more.
Create(id string, names []string, image, layer, metadata string, options *ContainerOptions) (*Container, error) Create(id string, names []string, image, layer, metadata string, options *ContainerOptions) (*Container, error)
// SetNames updates the list of names associated with the container // updateNames modifies names associated with a container based on (op, names).
// with the specified ID. updateNames(id string, names []string, op updateNameOperation) error
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`.
SetNames(id string, names []string) error
// AddNames adds the supplied values to the list of names associated with the container with
// the specified id.
AddNames(id string, names []string) error
// RemoveNames removes the supplied values from the list of names associated with the container with
// the specified id.
RemoveNames(id string, names []string) error
// Get retrieves information about a container given an ID or name. // Get retrieves information about a container given an ID or name.
Get(id string) (*Container, error) Get(id string) (*Container, error)
@ -388,19 +378,6 @@ func (r *containerStore) removeName(container *Container, name string) {
container.Names = stringSliceWithoutValue(container.Names, name) container.Names = stringSliceWithoutValue(container.Names, name)
} }
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`.
func (r *containerStore) SetNames(id string, names []string) error {
return r.updateNames(id, names, setNames)
}
func (r *containerStore) AddNames(id string, names []string) error {
return r.updateNames(id, names, addNames)
}
func (r *containerStore) RemoveNames(id string, names []string) error {
return r.updateNames(id, names, removeNames)
}
func (r *containerStore) updateNames(id string, names []string, op updateNameOperation) error { func (r *containerStore) updateNames(id string, names []string, op updateNameOperation) error {
container, ok := r.lookup(id) container, ok := r.lookup(id)
if !ok { if !ok {

View File

@ -129,21 +129,10 @@ type rwImageStore interface {
// read-only) layer. That layer can be referenced by multiple images. // read-only) layer. That layer can be referenced by multiple images.
Create(id string, names []string, layer, metadata string, created time.Time, searchableDigest digest.Digest) (*Image, error) Create(id string, names []string, layer, metadata string, created time.Time, searchableDigest digest.Digest) (*Image, error)
// SetNames replaces the list of names associated with an image with the // updateNames modifies names associated with an image based on (op, names).
// supplied values. The values are expected to be valid normalized // The values are expected to be valid normalized
// named image references. // named image references.
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`. updateNames(id string, names []string, op updateNameOperation) error
SetNames(id string, names []string) error
// AddNames adds the supplied values to the list of names associated with the image with
// the specified id. The values are expected to be valid normalized
// named image references.
AddNames(id string, names []string) error
// RemoveNames removes the supplied values from the list of names associated with the image with
// the specified id. The values are expected to be valid normalized
// named image references.
RemoveNames(id string, names []string) error
// Delete removes the record of the image. // Delete removes the record of the image.
Delete(id string) error Delete(id string) error
@ -516,19 +505,6 @@ func (i *Image) addNameToHistory(name string) {
i.NamesHistory = dedupeNames(append([]string{name}, i.NamesHistory...)) i.NamesHistory = dedupeNames(append([]string{name}, i.NamesHistory...))
} }
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`.
func (r *imageStore) SetNames(id string, names []string) error {
return r.updateNames(id, names, setNames)
}
func (r *imageStore) AddNames(id string, names []string) error {
return r.updateNames(id, names, addNames)
}
func (r *imageStore) RemoveNames(id string, names []string) error {
return r.updateNames(id, names, removeNames)
}
func (r *imageStore) updateNames(id string, names []string, op updateNameOperation) error { func (r *imageStore) updateNames(id string, names []string, op updateNameOperation) error {
if !r.IsReadWrite() { if !r.IsReadWrite() {
return fmt.Errorf("not allowed to change image name assignments at %q: %w", r.imagespath(), ErrStoreIsReadOnly) return fmt.Errorf("not allowed to change image name assignments at %q: %w", r.imagespath(), ErrStoreIsReadOnly)

View File

@ -24,7 +24,7 @@ func addTestImage(t *testing.T, store rwImageStore, id string, names []string) {
) )
require.Nil(t, err) require.Nil(t, err)
require.Nil(t, store.SetNames(id, names)) require.Nil(t, store.updateNames(id, names, setNames))
} }
func TestAddNameToHistorySuccess(t *testing.T) { func TestAddNameToHistorySuccess(t *testing.T) {
@ -72,7 +72,7 @@ func TestHistoryNames(t *testing.T) {
// And When // And When
store.Lock() store.Lock()
defer store.Unlock() defer store.Unlock()
require.Nil(t, store.SetNames(firstImageID, []string{"1", "2", "3", "4"})) require.Nil(t, store.updateNames(firstImageID, []string{"1", "2", "3", "4"}, setNames))
// Then // Then
firstImage, err = store.Get(firstImageID) firstImage, err = store.Get(firstImageID)
@ -91,13 +91,13 @@ func TestHistoryNames(t *testing.T) {
require.Equal(t, secondImage.NamesHistory[1], "2") require.Equal(t, secondImage.NamesHistory[1], "2")
// test independent add and remove operations // test independent add and remove operations
require.Nil(t, store.AddNames(firstImageID, []string{"5"})) require.Nil(t, store.updateNames(firstImageID, []string{"5"}, addNames))
firstImage, err = store.Get(firstImageID) firstImage, err = store.Get(firstImageID)
require.Nil(t, err) require.Nil(t, err)
require.Equal(t, firstImage.NamesHistory, []string{"4", "3", "2", "1", "5"}) require.Equal(t, firstImage.NamesHistory, []string{"4", "3", "2", "1", "5"})
// history should still contain old values // history should still contain old values
require.Nil(t, store.RemoveNames(firstImageID, []string{"5"})) require.Nil(t, store.updateNames(firstImageID, []string{"5"}, removeNames))
firstImage, err = store.Get(firstImageID) firstImage, err = store.Get(firstImageID)
require.Nil(t, err) require.Nil(t, err)
require.Equal(t, firstImage.NamesHistory, []string{"4", "3", "2", "1", "5"}) require.Equal(t, firstImage.NamesHistory, []string{"4", "3", "2", "1", "5"})

View File

@ -214,18 +214,8 @@ type rwLayerStore interface {
// Put combines the functions of CreateWithFlags and ApplyDiff. // Put combines the functions of CreateWithFlags and ApplyDiff.
Put(id string, parent *Layer, names []string, mountLabel string, options map[string]string, moreOptions *LayerOptions, writeable bool, flags map[string]interface{}, diff io.Reader) (*Layer, int64, error) Put(id string, parent *Layer, names []string, mountLabel string, options map[string]string, moreOptions *LayerOptions, writeable bool, flags map[string]interface{}, diff io.Reader) (*Layer, int64, error)
// SetNames replaces the list of names associated with a layer with the // updateNames modifies names associated with a layer based on (op, names).
// supplied values. updateNames(id string, names []string, op updateNameOperation) error
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`.
SetNames(id string, names []string) error
// AddNames adds the supplied values to the list of names associated with the layer with the
// specified id.
AddNames(id string, names []string) error
// RemoveNames remove the supplied values from the list of names associated with the layer with the
// specified id.
RemoveNames(id string, names []string) error
// Delete deletes a layer with the specified name or ID. // Delete deletes a layer with the specified name or ID.
Delete(id string) error Delete(id string) error
@ -1091,19 +1081,6 @@ func (r *layerStore) removeName(layer *Layer, name string) {
layer.Names = stringSliceWithoutValue(layer.Names, name) layer.Names = stringSliceWithoutValue(layer.Names, name)
} }
// Deprecated: Prone to race conditions, suggested alternatives are `AddNames` and `RemoveNames`.
func (r *layerStore) SetNames(id string, names []string) error {
return r.updateNames(id, names, setNames)
}
func (r *layerStore) AddNames(id string, names []string) error {
return r.updateNames(id, names, addNames)
}
func (r *layerStore) RemoveNames(id string, names []string) error {
return r.updateNames(id, names, removeNames)
}
func (r *layerStore) updateNames(id string, names []string, op updateNameOperation) error { func (r *layerStore) updateNames(id string, names []string, op updateNameOperation) error {
if !r.IsReadWrite() { if !r.IsReadWrite() {
return fmt.Errorf("not allowed to change layer name assignments at %q: %w", r.layerspath(), ErrStoreIsReadOnly) return fmt.Errorf("not allowed to change layer name assignments at %q: %w", r.layerspath(), ErrStoreIsReadOnly)

View File

@ -1286,22 +1286,14 @@ func (s *store) CreateLayer(id, parent string, names []string, mountLabel string
func (s *store) CreateImage(id string, names []string, layer, metadata string, options *ImageOptions) (*Image, error) { func (s *store) CreateImage(id string, names []string, layer, metadata string, options *ImageOptions) (*Image, error) {
if layer != "" { if layer != "" {
lstore, err := s.getLayerStore() layerStores, err := s.allLayerStores()
if err != nil {
return nil, err
}
lstores, err := s.getROLayerStores()
if err != nil { if err != nil {
return nil, err return nil, err
} }
var ilayer *Layer var ilayer *Layer
for _, s := range append([]roLayerStore{lstore}, lstores...) { for _, s := range layerStores {
store := s store := s
if store == lstore { store.RLock()
store.Lock()
} else {
store.RLock()
}
defer store.Unlock() defer store.Unlock()
err := store.ReloadIfChanged() err := store.ReloadIfChanged()
if err != nil { if err != nil {
@ -2137,16 +2129,7 @@ func (s *store) updateNames(id string, names []string, op updateNameOperation) e
return nil return nil
} }
layerFound = true layerFound = true
switch op { return rlstore.updateNames(id, deduped, op)
case setNames:
return rlstore.SetNames(id, deduped)
case removeNames:
return rlstore.RemoveNames(id, deduped)
case addNames:
return rlstore.AddNames(id, deduped)
default:
return errInvalidUpdateNameOperation
}
}); err != nil || layerFound { }); err != nil || layerFound {
return err return err
} }
@ -2161,16 +2144,7 @@ func (s *store) updateNames(id string, names []string, op updateNameOperation) e
return err return err
} }
if ristore.Exists(id) { if ristore.Exists(id) {
switch op { return ristore.updateNames(id, deduped, 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 // Check is id refers to a RO Store
@ -2204,16 +2178,7 @@ func (s *store) updateNames(id string, names []string, op updateNameOperation) e
return nil return nil
} }
containerFound = true containerFound = true
switch op { return rcstore.updateNames(id, deduped, 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
}
}); err != nil || containerFound { }); err != nil || containerFound {
return err return err
} }
@ -2946,40 +2911,16 @@ func (s *store) ContainerParentOwners(id string) ([]int, []int, error) {
} }
func (s *store) Layers() ([]Layer, error) { func (s *store) Layers() ([]Layer, error) {
lstore, err := s.getLayerStore() var layers []Layer
if err != nil { if done, err := s.readAllLayerStores(func(store roLayerStore) (bool, error) {
return nil, err
}
layers, err := func() ([]Layer, error) {
lstore.Lock()
defer lstore.Unlock()
if err := lstore.Load(); err != nil {
return nil, err
}
return lstore.Layers()
}()
if err != nil {
return nil, err
}
lstores, err := s.getROLayerStores()
if err != nil {
return nil, err
}
for _, s := range lstores {
store := s
store.RLock()
defer store.Unlock()
if err := store.ReloadIfChanged(); err != nil {
return nil, err
}
storeLayers, err := store.Layers() storeLayers, err := store.Layers()
if err != nil { if err != nil {
return nil, err return true, err
} }
layers = append(layers, storeLayers...) layers = append(layers, storeLayers...)
return false, nil
}); done {
return nil, err
} }
return layers, nil return layers, nil
} }
@ -3314,7 +3255,6 @@ func (s *store) FromContainerRunDirectory(id, file string) ([]byte, error) {
func (s *store) Shutdown(force bool) ([]string, error) { func (s *store) Shutdown(force bool) ([]string, error) {
mounted := []string{} mounted := []string{}
modified := false
rlstore, err := s.getLayerStore() rlstore, err := s.getLayerStore()
if err != nil { if err != nil {
@ -3348,7 +3288,6 @@ func (s *store) Shutdown(force bool) ([]string, error) {
} }
break break
} }
modified = true
} }
} }
} }
@ -3364,16 +3303,6 @@ func (s *store) Shutdown(force bool) ([]string, error) {
err = fmt.Errorf("(graphLock.Touch failed: %v) %w", err2, err) err = fmt.Errorf("(graphLock.Touch failed: %v) %w", err2, err)
} }
} }
modified = true
}
if modified {
if err2 := rlstore.Touch(); err2 != nil {
if err == nil {
err = err2
} else {
err = fmt.Errorf("rlstore.Touch failed: %v) %w", err2, err)
}
}
} }
return mounted, err return mounted, err
} }