-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
return prune data when context canceled #33979
Conversation
00888cf
to
47c13aa
Compare
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks. Updated now.
d842e14
to
5b54eb3
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
c69a42b
to
6f12a2b
Compare
builder/fscache/fscache.go
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be a debug
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
4431087
to
88a3eeb
Compare
Thanks for your review again. @cpuguy83 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Signed-off-by: allencloud <[email protected]>
88a3eeb
to
87b4dc2
Compare
|
Great to see all green. ☀️ 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@cpuguy83 PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
/cc @mlaventure