Skip to content
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

Lock layers only for reading #1386

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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