Merge pull request #33979 from allencloud/return-prune-data-when-context-canceled

return prune data when context canceled
This commit is contained in:
Brian Goff 2017-07-10 21:17:18 -04:00 committed by GitHub
commit 73e8f56d6a
4 changed files with 23 additions and 13 deletions

View File

@ -70,7 +70,7 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
// PruneCache removes all cached build sources
func (b *Backend) PruneCache(ctx context.Context) (*types.BuildCachePruneReport, error) {
size, err := b.fsCache.Prune()
size, err := b.fsCache.Prune(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to prune build cache")
}

View File

@ -154,8 +154,8 @@ func (fsc *FSCache) DiskUsage() (int64, error) {
}
// Prune allows manually cleaning up the cache
func (fsc *FSCache) Prune() (uint64, error) {
return fsc.store.Prune()
func (fsc *FSCache) Prune(ctx context.Context) (uint64, error) {
return fsc.store.Prune(ctx)
}
// Close stops the gc and closes the persistent db
@ -396,12 +396,19 @@ func (s *fsCacheStore) DiskUsage() (int64, error) {
}
// Prune allows manually cleaning up the cache
func (s *fsCacheStore) Prune() (uint64, error) {
func (s *fsCacheStore) Prune(ctx context.Context) (uint64, error) {
s.mu.Lock()
defer s.mu.Unlock()
var size uint64
for id, snap := range s.sources {
select {
case <-ctx.Done():
logrus.Debugf("Cache prune operation cancelled, pruned size: %d", size)
// when the context is cancelled, only return current size and nil
return size, nil
default:
}
if len(snap.refs) == 0 {
ss, err := snap.getSize()
if err != nil {

View File

@ -97,7 +97,7 @@ func TestFSCache(t *testing.T) {
assert.Equal(t, s, int64(8))
// prune deletes everything
released, err := fscache.Prune()
released, err := fscache.Prune(context.TODO())
assert.Nil(t, err)
assert.Equal(t, released, uint64(8))

View File

@ -74,8 +74,8 @@ func (daemon *Daemon) ContainersPrune(ctx context.Context, pruneFilters filters.
for _, c := range allContainers {
select {
case <-ctx.Done():
logrus.Warnf("ContainersPrune operation cancelled: %#v", *rep)
return rep, ctx.Err()
logrus.Debugf("ContainersPrune operation cancelled: %#v", *rep)
return rep, nil
default:
}
@ -121,7 +121,7 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg
pruneVols := func(v volume.Volume) error {
select {
case <-ctx.Done():
logrus.Warnf("VolumesPrune operation cancelled: %#v", *rep)
logrus.Debugf("VolumesPrune operation cancelled: %#v", *rep)
return ctx.Err()
default:
}
@ -153,6 +153,9 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg
}
err = daemon.traverseLocalVolumes(pruneVols)
if err == context.Canceled {
return rep, nil
}
return rep, err
}
@ -303,8 +306,7 @@ deleteImagesLoop:
}
if canceled {
logrus.Warnf("ImagesPrune operation cancelled: %#v", *rep)
return nil, ctx.Err()
logrus.Debugf("ImagesPrune operation cancelled: %#v", *rep)
}
return rep, nil
@ -320,6 +322,7 @@ func (daemon *Daemon) localNetworksPrune(ctx context.Context, pruneFilters filte
l := func(nw libnetwork.Network) bool {
select {
case <-ctx.Done():
// context cancelled
return true
default:
}
@ -370,7 +373,7 @@ func (daemon *Daemon) clusterNetworksPrune(ctx context.Context, pruneFilters fil
for _, nw := range networks {
select {
case <-ctx.Done():
return rep, ctx.Err()
return rep, nil
default:
if nw.Ingress {
// Routing-mesh network removal has to be explicitly invoked by user
@ -427,8 +430,8 @@ func (daemon *Daemon) NetworksPrune(ctx context.Context, pruneFilters filters.Ar
select {
case <-ctx.Done():
logrus.Warnf("NetworksPrune operation cancelled: %#v", *rep)
return nil, ctx.Err()
logrus.Debugf("NetworksPrune operation cancelled: %#v", *rep)
return rep, nil
default:
}