Actually starting to use the deallocator to clean up services#2778
Actually starting to use the deallocator to clean up services#2778anshulpundir merged 1 commit intomoby:masterfrom
Conversation
|
Please sign your commits following these rules: $ git clone -b "wk8/network_rm_follow_up" git@github.com:wk8/swarmkit.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354378880
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -fAmending updates the existing PR. You DO NOT need to open a new one. |
f511af4 to
4d41f49
Compare
a3d477b to
8ee61c6
Compare
Codecov Report
@@ Coverage Diff @@
## master #2778 +/- ##
=========================================
Coverage ? 61.97%
=========================================
Files ? 137
Lines ? 22094
Branches ? 0
=========================================
Hits ? 13692
Misses ? 6929
Partials ? 1473 |
|
LGTM, especially with the tests. |
anshulpundir
left a comment
There was a problem hiding this comment.
looks good overall, minor comments/questions
| return status.Errorf(codes.NotFound, "service %s not found", request.ServiceID) | ||
| } | ||
|
|
||
| if service.PendingDelete { |
There was a problem hiding this comment.
should this be moved up higher in the function?
There was a problem hiding this comment.
I don't think it can. Sure, we could check whether it's pending deletion as soon as we retrieve the service object above, but we would still also need to re-check here, once we hold the write lock; otherwise it could have been marked for deletion in the meantime. Maybe it's worth adding a comment to that effect?
There was a problem hiding this comment.
(added a comment to this effect)
| fmt.Fprintln(w, "Template\t") | ||
| fmt.Fprintln(w, " Container\t") | ||
| ctr := service.Spec.Task.GetContainer() | ||
| task := spec.Task |
There was a problem hiding this comment.
What is the motivation for this change?
There was a problem hiding this comment.
It seemed a bit silly to define spec := service.Spec above without consistently using it in the rest of the function?
| func (deallocator *Deallocator) handleEvent(ctx context.Context, event events.Event) (bool, error) { | ||
| switch typedEvent := event.(type) { | ||
| case api.EventUpdateTask: | ||
| return deallocator.processTaskEvent(ctx, typedEvent.Task, typedEvent.OldTask) |
There was a problem hiding this comment.
Maybe a comment on how each of these invocations of the same functions are different and the different value passed for different arguments.
There was a problem hiding this comment.
Updated the function's comment itself, should hopefully be clearer?
|
|
||
| if present && isTaskStillAlive(oldTask) && (newTask == nil || !isTaskStillAlive(newTask)) { | ||
| // this task belongs to a service that's shutting down, and was amongst | ||
| // the ones that we counted as alive when adding this service to our |
There was a problem hiding this comment.
adding this service to our internal state
What does this mean? Please clarify the comment.
| serviceWithCount, present := deallocator.services[serviceID] | ||
|
|
||
| if present && isTaskStillAlive(oldTask) && (newTask == nil || !isTaskStillAlive(newTask)) { | ||
| // this task belongs to a service that's shutting down, and was amongst |
There was a problem hiding this comment.
The if condition has two tasks: oldTask and newTask. Which one is the comment for? What about the other task?
There was a problem hiding this comment.
They both belong to the same service, since a task can never be re-allocated :)
| serviceID := oldTask.ServiceID | ||
| serviceWithCount, present := deallocator.services[serviceID] | ||
|
|
||
| if present && isTaskStillAlive(oldTask) && (newTask == nil || !isTaskStillAlive(newTask)) { |
There was a problem hiding this comment.
I think we need a clearer comment on what this if statement achieves
There was a problem hiding this comment.
Tried to make the existing comment clearer
| } | ||
| } | ||
|
|
||
| // Common logic for handling task update/delete events |
There was a problem hiding this comment.
Please enhance the comment to include a description of the function params.
| if orchestrator.IsGlobalService(s) { | ||
| g.updateService(s) | ||
| reconcileServiceIDs = append(reconcileServiceIDs, s.ID) | ||
| if s.PendingDelete { |
| // ask the tasks to shut down | ||
| orchestrator.SetServiceTasksRemove(ctx, g.store, v.Service) | ||
| // delete the service from service map | ||
| delete(g.globalServices, v.Service.ID) |
There was a problem hiding this comment.
Once removed from here, is the service still accessible from UI/CLI using list commands etc? Is that the behavior we're going for?
There was a problem hiding this comment.
Yes it is. There will be a CLI change to explicitly mark it as pending for deletion in the CLI's output.
**- What I did** This patch actually stars to use the deallocator to clean up services, as well as service-level resources (as of now, only networks). **- How I did it** A previous patch (moby#2759) introduced a new component, the deallocator, responsible for cleaning up services and service-level resources. This patch is actually starting to make use of that component. Since the deallocator used to rely on the reaper deleting the tasks belonging to services that had been marked for removal, a previous version of this patch was modifying the task reaper quite heavily to also keep track of such services (needed since otherwise the reaper would fail to clean up all of them, instead keeping some for history tracking purposes). However, it soon appeared that this was not the best approach: * this creates a hidden coupling between the reaper and the deallocator * it's also not the best user experience to suddenly remove all of a service's task history while shutting down, for not apparent reason to the user For these reasons, this patch instead amends the deallocator to also look at tasks status when keeping track of how many alive tasks remain to a service. **- How to test it** Updated tests. **- Description for the changelog** Services & networks are no longer deleted immediately when a user requests their deletion; instead, they are deleted when all their tasks are actually shut down. Signed-off-by: Jean Rouge <jer329@cornell.edu>
decedca to
2ba1cd9
Compare
Mainly for the sake of testing the new "soft delete" capabilities of Swarmkit, see more at moby/swarmkit#2778 Signed-off-by: Jean Rouge <jer329@cornell.edu>
|
This is a breaking change. Before delete was synchronous and now it is async. I agree with and like the change, but ultimately seems problematic. For docker to not break we will need to poll the service to check for deletion before the API returns. |
**- What I did** This patch allows users to choose to make removals of services and networks asynchronous, which means that they only get deleted once all the containers belonging to them or using them are safely shut down. **- How I did it** A previous patch (moby#2759) introduced a new component, the deallocator, responsible for cleaning up services and service-level resources. This patch is actually starting to make use of that component. Since the deallocator used to rely on the reaper deleting the tasks belonging to services that had been marked for removal, a previous version of this patch was modifying the task reaper quite heavily to also keep track of such services (needed since otherwise the reaper would fail to clean up all of them, instead keeping some for history tracking purposes). However, it soon appeared that this was not the best approach: * this creates a hidden coupling between the reaper and the deallocator * it's also not the best user experience to suddenly remove all of a service's task history while shutting down, for not apparent reason to the user For these reasons, this patch instead amends the deallocator to also look at tasks status when keeping track of how many alive tasks remain to a service. Part of this test was already reviewed in moby#2778, which subsequently got reverted following the discussion in moby/moby#38525. The main difference between this PR and moby#2778 is that asynchronous removal is an opt-in behaviour here instead of changing the existing behaviour. **- How to test it** Updated tests. **- Description for the changelog** Services & networks can be deleted asynchronously, in which case the request for their removal simply marks them for removal, and they are then actually deleted only when all their tasks are actually shut down. Signed-off-by: Jean Rouge <rougej+github@gmail.com>
**- What I did** This patch allows users to choose to make removals of services and networks asynchronous, which means that they only get deleted once all the containers belonging to them or using them are safely shut down. **- How I did it** A previous patch (moby#2759) introduced a new component, the deallocator, responsible for cleaning up services and service-level resources. This patch is actually starting to make use of that component. Since the deallocator used to rely on the reaper deleting the tasks belonging to services that had been marked for removal, a previous version of this patch was modifying the task reaper quite heavily to also keep track of such services (needed since otherwise the reaper would fail to clean up all of them, instead keeping some for history tracking purposes). However, it soon appeared that this was not the best approach: * this creates a hidden coupling between the reaper and the deallocator * it's also not the best user experience to suddenly remove all of a service's task history while shutting down, for not apparent reason to the user For these reasons, this patch instead amends the deallocator to also look at tasks status when keeping track of how many alive tasks remain to a service. Part of this test was already reviewed in moby#2778, which subsequently got reverted following the discussion in moby/moby#38525. The main difference between this PR and moby#2778 is that asynchronous removal is an opt-in behaviour here instead of changing the existing behaviour. **- How to test it** Updated tests. **- Description for the changelog** Services & networks can be deleted asynchronously, in which case the request for their removal simply marks them for removal, and they are then actually deleted only when all their tasks are actually shut down. Signed-off-by: Jean Rouge <rougej+github@gmail.com>
**- What I did** This patch allows users to choose to make removals of services and networks asynchronous, which means that they only get deleted once all the containers belonging to them or using them are safely shut down. **- How I did it** A previous patch (moby#2759) introduced a new component, the deallocator, responsible for cleaning up services and service-level resources. This patch is actually starting to make use of that component. Since the deallocator used to rely on the reaper deleting the tasks belonging to services that had been marked for removal, a previous version of this patch was modifying the task reaper quite heavily to also keep track of such services (needed since otherwise the reaper would fail to clean up all of them, instead keeping some for history tracking purposes). However, it soon appeared that this was not the best approach: * this creates a hidden coupling between the reaper and the deallocator * it's also not the best user experience to suddenly remove all of a service's task history while shutting down, for not apparent reason to the user For these reasons, this patch instead amends the deallocator to also look at tasks status when keeping track of how many alive tasks remain to a service. Part of this test was already reviewed in moby#2778, which subsequently got reverted following the discussion in moby/moby#38525. The main difference between this PR and moby#2778 is that asynchronous removal is an opt-in behaviour here instead of changing the existing behaviour. **- How to test it** Updated tests. **- Description for the changelog** Services & networks can be deleted asynchronously, in which case the request for their removal simply marks them for removal, and they are then actually deleted only when all their tasks are actually shut down. Signed-off-by: Jean Rouge <rougej+github@gmail.com>
**- What I did** This patch allows users to choose to make removals of services and networks asynchronous, which means that they only get deleted once all the containers belonging to them or using them are safely shut down. **- How I did it** A previous patch (moby#2759) introduced a new component, the deallocator, responsible for cleaning up services and service-level resources. This patch is actually starting to make use of that component. Since the deallocator used to rely on the reaper deleting the tasks belonging to services that had been marked for removal, a previous version of this patch was modifying the task reaper quite heavily to also keep track of such services (needed since otherwise the reaper would fail to clean up all of them, instead keeping some for history tracking purposes). However, it soon appeared that this was not the best approach: * this creates a hidden coupling between the reaper and the deallocator * it's also not the best user experience to suddenly remove all of a service's task history while shutting down, for not apparent reason to the user For these reasons, this patch instead amends the deallocator to also look at tasks status when keeping track of how many alive tasks remain to a service. Part of this test was already reviewed in moby#2778, which subsequently got reverted following the discussion in moby/moby#38525. The main difference between this PR and moby#2778 is that asynchronous removal is an opt-in behaviour here instead of changing the existing behaviour. **- How to test it** Updated tests. **- Description for the changelog** Services & networks can be deleted asynchronously, in which case the request for their removal simply marks them for removal, and they are then actually deleted only when all their tasks are actually shut down. Signed-off-by: Jean Rouge <rougej+github@gmail.com>
- What I did
This patch actually stars to use the deallocator to clean up services, as
well as service-level resources (as of now, only networks).
List of changes:
now the deallocator's job
by swarmctl
deletion
- How I did it
A previous patch (#2759) introduced a
new component, the deallocator, responsible for cleaning up services and
service-level resources. This patch is actually starting to make use of that
component.
Since the deallocator used to rely on the reaper deleting the tasks belonging
to services that had been marked for removal, a previous version of this patch
was modifying the task reaper quite heavily to also keep track of such services
(needed since otherwise the reaper would fail to clean up all of them, instead
keeping some for history tracking purposes). However, it soon appeared that
this was not the best approach:
task history while shutting down, for not apparent reason to the user
For these reasons, this patch instead amends the deallocator to also look at tasks status when keeping track of how many alive tasks remain to a service.
- How to test it
Updated tests.
- Description for the changelog
Services & networks are no longer deleted immediately when a user requests their
deletion; instead, they are deleted when all their tasks are actually shut down.