Skip to content

Commit

Permalink
cache: add global prune lock
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
tonistiigi committed Jan 5, 2018
1 parent b88a98b commit 1c9b9c9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cache/manager.go
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@ type cacheManager struct {
mu sync.Mutex
ManagerOpt
md *metadata.Store

muPrune sync.Mutex // make sure parallel prune is not allowed so there will not be inconsistent results
}

func NewManager(opt ManagerOpt) (Manager, error) {
@@ -283,8 +285,12 @@ func (cm *cacheManager) GetMutable(ctx context.Context, id string) (MutableRef,
}

func (cm *cacheManager) Prune(ctx context.Context, ch chan client.UsageInfo) error {
// TODO: global prune lock
cm.muPrune.Lock()
defer cm.muPrune.Unlock()
return cm.prune(ctx, ch)
}

func (cm *cacheManager) prune(ctx context.Context, ch chan client.UsageInfo) error {
var toDelete []*cacheRecord
cm.mu.Lock()

@@ -375,7 +381,7 @@ func (cm *cacheManager) Prune(ctx context.Context, ch chan client.UsageInfo) err
case <-ctx.Done():
return ctx.Err()
default:
return cm.Prune(ctx, ch)
return cm.prune(ctx, ch)
}
}

0 comments on commit 1c9b9c9

Please sign in to comment.