-
Notifications
You must be signed in to change notification settings - Fork 656
Don't delete tasks until they're actually removed by the agent #2446
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ func (r *Orchestrator) handleServiceEvent(ctx context.Context, event events.Even | |
| if !orchestrator.IsReplicatedService(v.Service) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated by not totally: Please add a comment for this case. |
||
| return | ||
| } | ||
| orchestrator.DeleteServiceTasks(ctx, r.store, v.Service) | ||
| orchestrator.SetServiceTasksRemove(ctx, r.store, v.Service) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to make the same change in Then, you can remove the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| r.restarts.ClearServiceHistory(v.Service.ID) | ||
| delete(r.reconcileServices, v.Service.ID) | ||
| case api.EventCreateService: | ||
|
|
@@ -86,6 +86,12 @@ func (r *Orchestrator) resolveService(ctx context.Context, task *api.Task) *api. | |
| return service | ||
| } | ||
|
|
||
| // reconcile decides what actions must be taken depending on the number of | ||
| // specificed slots and actual running slots. If the actual running slots are | ||
| // fewer than what is requested, it creates new tasks. If the actual running | ||
| // slots are more than requested, then it decides which slots must be removed | ||
| // and sets desired state of those tasks to REMOVE (the actual removal is handled | ||
| // by the task reaper, after the agent shuts the tasks down). | ||
| func (r *Orchestrator) reconcile(ctx context.Context, service *api.Service) { | ||
| runningSlots, deadSlots, err := r.updatableAndDeadSlots(ctx, service) | ||
| if err != nil { | ||
|
|
@@ -157,7 +163,11 @@ func (r *Orchestrator) reconcile(ctx context.Context, service *api.Service) { | |
| r.updater.Update(ctx, r.cluster, service, sortedSlots[:specifiedSlots]) | ||
| err = r.store.Batch(func(batch *store.Batch) error { | ||
| r.deleteTasksMap(ctx, batch, deadSlots) | ||
| r.deleteTasks(ctx, batch, sortedSlots[specifiedSlots:]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| // for all slots that we are removing, we set the desired state of those tasks | ||
| // to REMOVE. Then, the agent is responsible for shutting them down, and the | ||
| // task reaper is responsible for actually removing them from the store after | ||
| // shutdown. | ||
| r.setTasksDesiredState(ctx, batch, sortedSlots[specifiedSlots:], api.TaskStateRemove) | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
|
|
@@ -198,10 +208,24 @@ func (r *Orchestrator) addTasks(ctx context.Context, batch *store.Batch, service | |
| } | ||
| } | ||
|
|
||
| func (r *Orchestrator) deleteTasks(ctx context.Context, batch *store.Batch, slots []orchestrator.Slot) { | ||
| // setTasksDesiredState sets the desired state for all tasks for the given slots to the | ||
| // requested state | ||
| func (r *Orchestrator) setTasksDesiredState(ctx context.Context, batch *store.Batch, slots []orchestrator.Slot, state api.TaskState) { | ||
| for _, slot := range slots { | ||
| for _, t := range slot { | ||
| r.deleteTask(ctx, batch, t) | ||
| err := batch.Update(func(tx store.Tx) error { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not do all the updates in the same txn ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anshulpundir how do you mean?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind. I realized that updates to the store are batched using store.Batch. |
||
| // update desired state | ||
| t.DesiredState = state | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good practice to make sure that the state is being advanced, and never moves backwards. Currently there isn't a state beyond "remove" but we could potentially add one later. |
||
|
|
||
| err := store.UpdateTask(tx, t) | ||
| if err != nil { | ||
| log.G(ctx).WithError(err).Errorf("failed to update task %s desired state to %s", t.ID, state.String()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log statement seems redundant with the one below. |
||
| } | ||
| return err | ||
| }) | ||
| if err != nil { | ||
| log.G(ctx).WithError(err).Errorf("failed to update batch to set task desired state to %s", state.String()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
832for consistency with the others?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 you missed the
ORPHANED = 832below, which makes this correct at halfway betweenREJECTEDandORPHANED.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.
// Remove ...