Skip to content

Commit

Permalink
Only lock the primary layer store for reading in Layers
Browse files Browse the repository at this point in the history
... and use readAllLayerStores.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Oct 14, 2022
1 parent 8d8d6be commit 61c00d1
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2946,40 +2946,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 61c00d1

Please sign in to comment.