Skip to content

Commit

Permalink
Merge pull request #1386 from mtrmac/read-layer-lock
Browse files Browse the repository at this point in the history
Lock layers only for reading
  • Loading branch information
rhatdan authored Oct 14, 2022
2 parents 8d8d6be + d498257 commit 9a72db8
Showing 1 changed file with 9 additions and 41 deletions.
50 changes: 9 additions & 41 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if layer != "" {
lstore, err := s.getLayerStore()
if err != nil {
return nil, err
}
lstores, err := s.getROLayerStores()
layerStores, err := s.allLayerStores()
if err != nil {
return nil, err
}
var ilayer *Layer
for _, s := range append([]roLayerStore{lstore}, lstores...) {
for _, s := range layerStores {
store := s
if store == lstore {
store.Lock()
} else {
store.RLock()
}
store.RLock()
defer store.Unlock()
err := store.ReloadIfChanged()
if err != nil {
Expand Down Expand Up @@ -2946,40 +2938,16 @@ func (s *store) ContainerParentOwners(id string) ([]int, []int, error) {
}

func (s *store) Layers() ([]Layer, error) {
lstore, err := s.getLayerStore()
if err != nil {
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
}
var layers []Layer
if done, err := s.readAllLayerStores(func(store roLayerStore) (bool, error) {
storeLayers, err := store.Layers()
if err != nil {
return nil, err
return true, err
}
layers = append(layers, storeLayers...)
return false, nil
}); done {
return nil, err
}
return layers, nil
}
Expand Down

0 comments on commit 9a72db8

Please sign in to comment.