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

return prune data when context canceled #33979

Merged

Conversation

allencloud
Copy link
Contributor

@allencloud allencloud commented Jul 6, 2017

Signed-off-by: allencloud [email protected]

This PR takes into user's cancel request when prune data into consideration. When context is canceled, docker daemon still returns the data which is already pruned.

Prune Object includes: container, network, image, volume, and build cache.

fixes #33957

- What I did

  1. make engine return prune data even if context is canceled.

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

/cc @mlaventure

@allencloud allencloud force-pushed the return-prune-data-when-context-canceled branch from 00888cf to 47c13aa Compare July 6, 2017 09:07
daemon/prune.go Outdated
@@ -215,7 +221,8 @@ func (daemon *Daemon) ImagesPrune(ctx context.Context, pruneFilters filters.Args
for id, img := range allImages {
select {
case <-ctx.Done():
return nil, ctx.Err()
// when the context is cancelled, only return the report struct as presently
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can stay as before as nothing was altered yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks. Updated now.

@allencloud allencloud force-pushed the return-prune-data-when-context-canceled branch 2 times, most recently from d842e14 to 5b54eb3 Compare July 6, 2017 09:53
Copy link
Contributor

@mlaventure mlaventure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

daemon/prune.go Outdated
@@ -154,6 +156,10 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg

err = daemon.traverseLocalVolumes(pruneVols)

if err == errPruneCancelled {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this new error?
Why not if err == context.Cancelled?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also check context.DeadlineExceeded

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. @cpuguy83
Currently I have updated the PR and only checked err == context.Cancelled. And if we also check context.DeadlineExceeded, what should we return, a report with nil, or a report with error?

daemon/prune.go Outdated
@@ -26,7 +26,8 @@ import (
var (
// errPruneRunning is returned when a prune request is received while
// one is in progress
errPruneRunning = fmt.Errorf("a prune operation is already running")
errPruneRunning = fmt.Errorf("a prune operation is already running")
errPruneCancelled = fmt.Errorf("a prune operation is cancelled")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think think we need to add this new error here, but in any case the wording is a bit funky.
Maybe the prune operation was cancelled

daemon/prune.go Outdated
@@ -122,7 +124,7 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg
select {
case <-ctx.Done():
logrus.Warnf("VolumesPrune operation cancelled: %#v", *rep)
return ctx.Err()
return errPruneCancelled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's right to return a cancelled error here since cancellation is just one reason why the context would be done.

daemon/prune.go Outdated
@@ -320,6 +325,7 @@ func (daemon *Daemon) localNetworksPrune(ctx context.Context, pruneFilters filte
l := func(nw libnetwork.Network) bool {
select {
case <-ctx.Done():
// when the context is cancelled, only return the report struct as presently
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't look complete.

daemon/prune.go Outdated
@@ -370,7 +376,8 @@ func (daemon *Daemon) clusterNetworksPrune(ctx context.Context, pruneFilters fil
for _, nw := range networks {
select {
case <-ctx.Done():
return rep, ctx.Err()
// when the context is cancelled, only return the report struct as presently
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't look complete.

daemon/prune.go Outdated
@@ -428,7 +435,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()
// when the context is cancelled, only return the report struct as presently
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't look complete.

@allencloud allencloud force-pushed the return-prune-data-when-context-canceled branch 4 times, most recently from c69a42b to 6f12a2b Compare July 7, 2017 02:55
s.mu.Lock()
defer s.mu.Unlock()
var size uint64

for id, snap := range s.sources {
select {
case <-ctx.Done():
logrus.Warnf("Cache prune operation cancelled, pruned size: %d", size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a debug

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see others are warnings as well...

daemon/prune.go Outdated
@@ -428,7 +432,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()
// when the context is cancelled, return current report struct and nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obvious from the return line, I don't think we need the comment explaining

daemon/prune.go Outdated
@@ -370,7 +373,8 @@ func (daemon *Daemon) clusterNetworksPrune(ctx context.Context, pruneFilters fil
for _, nw := range networks {
select {
case <-ctx.Done():
return rep, ctx.Err()
// when the context is cancelled, return current report struct and nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obvious from the return line, I don't think we need the comment explaining

@allencloud allencloud force-pushed the return-prune-data-when-context-canceled branch 2 times, most recently from 4431087 to 88a3eeb Compare July 8, 2017 01:54
@allencloud
Copy link
Contributor Author

Thanks for your review again. @cpuguy83
I have updated that, PTAL.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some questions / comments, thanks!

daemon/prune.go Outdated
err = daemon.traverseLocalVolumes(pruneVols)
if err := daemon.traverseLocalVolumes(pruneVols); err == context.Canceled {
return rep, nil
}

return rep, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now returning a different error than before, because the err = daemon.traverseLocalVolumes() is now moved inside the if ...

daemon/prune.go Outdated
@@ -152,7 +152,9 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg
return nil
}

err = daemon.traverseLocalVolumes(pruneVols)
if err := daemon.traverseLocalVolumes(pruneVols); err == context.Canceled {
return rep, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to my comment two lines below; this doesn't return if err == nil, correct?

Copy link
Contributor Author

@allencloud allencloud Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you mentioned is right, I have updated this, Thanks a lot. @thaJeztah
PTAL

daemon/prune.go Outdated
@@ -320,6 +321,7 @@ func (daemon *Daemon) localNetworksPrune(ctx context.Context, pruneFilters filte
l := func(nw libnetwork.Network) bool {
select {
case <-ctx.Done():
// when the context is cancelled, return true to stop the networks traverse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; "when" should probably be "if"

would it be enough to just mention "return true to stop network traverse"? or is "context cancelled" a special case?

@@ -427,8 +429,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see @cpuguy83 suggested "debug"; just wondering if changing from "warn" in the current code to "debug" is too big a change, and if "info" would be a better fit.

Not a show stopper, just thinking aloud

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think debug is fine. Not sure if that message being in the log by default has any benefits

@allencloud allencloud force-pushed the return-prune-data-when-context-canceled branch from 88a3eeb to 87b4dc2 Compare July 10, 2017 02:06
@thaJeztah
Copy link
Member

hm, flaky? https://jenkins.dockerproject.org/job/Docker-PRs/44175/console

03:33:45 ----------------------------------------------------------------------
03:33:45 FAIL: docker_cli_swarm_test.go:1146: DockerSwarmSuite.TestSwarmLockUnlockCluster
03:33:45 
03:33:45 [d6209096216f9] waiting for daemon to start
03:33:45 [d6209096216f9] daemon started
03:33:45 
03:33:45 [df75e109fdee3] waiting for daemon to start
03:33:45 [df75e109fdee3] daemon started
03:33:45 
03:33:45 [ded4392fb23e8] waiting for daemon to start
03:33:45 [ded4392fb23e8] daemon started
03:33:45 
03:33:45 [df75e109fdee3] exiting daemon
03:33:45 [df75e109fdee3] waiting for daemon to start
03:33:45 [df75e109fdee3] daemon started
03:33:45 
03:33:45 [df75e109fdee3] exiting daemon
03:33:45 [d6209096216f9] exiting daemon
03:33:45 [d6209096216f9] waiting for daemon to start
03:33:45 [d6209096216f9] daemon started
03:33:45 
03:33:45 [ded4392fb23e8] exiting daemon
03:33:45 [ded4392fb23e8] waiting for daemon to start
03:33:45 [ded4392fb23e8] daemon started
03:33:45 
03:33:45 [df75e109fdee3] waiting for daemon to start
03:33:45 [df75e109fdee3] daemon started
03:33:45 
03:33:45 docker_cli_swarm_test.go:1192:
03:33:45     // d2 is now set to lock
03:33:45     checkSwarmUnlockedToLocked(c, d2)
03:33:45 docker_utils_test.go:471:
03:33:45     c.Assert(v, checker, args...)
03:33:45 ... obtained bool = false
03:33:45 ... expected bool = true
03:33:45 
03:33:45 [d6209096216f9] exiting daemon
03:33:45 [df75e109fdee3] exiting daemon
03:33:45 [ded4392fb23e8] exiting daemon
03:34:06 

@allencloud
Copy link
Contributor Author

Great to see all green. ☀️ 😄

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpuguy83 PTAL

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpuguy83 cpuguy83 merged commit 73e8f56 into moby:master Jul 11, 2017
@allencloud allencloud deleted the return-prune-data-when-context-canceled branch July 11, 2017 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[question] how to deal partial success in prune API?
6 participants