Skip to content

Commit

Permalink
Merge pull request moby#18202 from aidanhs/aphs-content-addressabilit…
Browse files Browse the repository at this point in the history
…y-layerstore

Rearrange layerstore locking
  • Loading branch information
LK4D4 committed Nov 24, 2015
2 parents 87e7ee9 + cbf55b9 commit 900c8f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
34 changes: 12 additions & 22 deletions layer/layer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (ls *layerStore) Register(ts io.Reader, parent ChainID) (Layer, error) {
ls.layerL.Lock()
defer ls.layerL.Unlock()

if existingLayer := ls.getAndRetainLayer(layer.chainID); existingLayer != nil {
if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil {
// Set error for cleanup, but do not return the error
err = errors.New("layer already exists")
return existingLayer.getReference(), nil
Expand All @@ -284,18 +284,21 @@ func (ls *layerStore) Register(ts io.Reader, parent ChainID) (Layer, error) {
return layer.getReference(), nil
}

func (ls *layerStore) get(l ChainID) *roLayer {
ls.layerL.Lock()
defer ls.layerL.Unlock()

layer, ok := ls.layerMap[l]
func (ls *layerStore) getWithoutLock(layer ChainID) *roLayer {
l, ok := ls.layerMap[layer]
if !ok {
return nil
}

layer.referenceCount++
l.referenceCount++

return l
}

return layer
func (ls *layerStore) get(l ChainID) *roLayer {
ls.layerL.Lock()
defer ls.layerL.Unlock()
return ls.getWithoutLock(l)
}

func (ls *layerStore) Get(l ChainID) (Layer, error) {
Expand Down Expand Up @@ -412,17 +415,6 @@ func (ls *layerStore) saveMount(mount *mountedLayer) error {
return nil
}

func (ls *layerStore) getAndRetainLayer(layer ChainID) *roLayer {
l, ok := ls.layerMap[layer]
if !ok {
return nil
}

l.referenceCount++

return l
}

func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit) (string, error) {
// Use "<graph-id>-init" to maintain compatibility with graph drivers
// which are expecting this layer with this special name. If all
Expand Down Expand Up @@ -465,9 +457,7 @@ func (ls *layerStore) Mount(name string, parent ChainID, mountLabel string, init
var pid string
var p *roLayer
if string(parent) != "" {
ls.layerL.Lock()
p = ls.getAndRetainLayer(parent)
ls.layerL.Unlock()
p = ls.get(parent)
if p == nil {
return nil, ErrLayerDoesNotExist
}
Expand Down
2 changes: 1 addition & 1 deletion layer/layer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (ls *layerStore) RegisterDiffID(graphID string, size int64) (Layer, error)
ls.layerL.Lock()
defer ls.layerL.Unlock()

if existingLayer := ls.getAndRetainLayer(layer.chainID); existingLayer != nil {
if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil {
// Set error for cleanup, but do not return
err = errors.New("layer already exists")
return existingLayer.getReference(), nil
Expand Down
6 changes: 2 additions & 4 deletions layer/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func (ls *layerStore) MountByGraphID(name string, graphID string, parent ChainID

var p *roLayer
if string(parent) != "" {
ls.layerL.Lock()
p = ls.getAndRetainLayer(parent)
ls.layerL.Unlock()
p = ls.get(parent)
if p == nil {
return nil, ErrLayerDoesNotExist
}
Expand Down Expand Up @@ -209,7 +207,7 @@ func (ls *layerStore) RegisterByGraphID(graphID string, parent ChainID, tarDataF
ls.layerL.Lock()
defer ls.layerL.Unlock()

if existingLayer := ls.getAndRetainLayer(layer.chainID); existingLayer != nil {
if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil {
// Set error for cleanup, but do not return
err = errors.New("layer already exists")
return existingLayer.getReference(), nil
Expand Down

0 comments on commit 900c8f5

Please sign in to comment.