inplaceUpdate returns the allocs that were updated in-place

This commit is contained in:
Alex Dadgar 2016-05-17 15:37:37 -07:00
parent 76b2c90ae2
commit 117b926e2b
4 changed files with 20 additions and 17 deletions

View File

@ -324,8 +324,7 @@ func (s *GenericScheduler) computeJobAllocs() error {
}
// Attempt to do the upgrades in place
destructiveUpdates := inplaceUpdate(s.ctx, s.eval, s.job, s.stack, diff.update)
inplaceUpdates := diff.update[len(destructiveUpdates):]
destructiveUpdates, inplaceUpdates := inplaceUpdate(s.ctx, s.eval, s.job, s.stack, diff.update)
diff.update = destructiveUpdates
if s.eval.AnnotatePlan {

View File

@ -186,8 +186,7 @@ func (s *SystemScheduler) computeJobAllocs() error {
}
// Attempt to do the upgrades in place
destructiveUpdates := inplaceUpdate(s.ctx, s.eval, s.job, s.stack, diff.update)
inplaceUpdates := diff.update[len(destructiveUpdates):]
destructiveUpdates, inplaceUpdates := inplaceUpdate(s.ctx, s.eval, s.job, s.stack, diff.update)
diff.update = destructiveUpdates
if s.eval.AnnotatePlan {

View File

@ -367,12 +367,13 @@ func setStatus(logger *log.Logger, planner Planner, eval, nextEval *structs.Eval
return planner.UpdateEval(newEval)
}
// inplaceUpdate attempts to update allocations in-place where possible.
// inplaceUpdate attempts to update allocations in-place where possible. It
// returns the allocs that couldn't be done inplace and then those that could.
func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
stack Stack, updates []allocTuple) []allocTuple {
stack Stack, updates []allocTuple) (destructive, inplace []allocTuple) {
n := len(updates)
inplace := 0
inplaceCount := 0
for i := 0; i < n; i++ {
// Get the update
update := updates[i]
@ -441,15 +442,15 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
ctx.Plan().AppendAlloc(newAlloc)
// Remove this allocation from the slice
updates[i] = updates[n-1]
updates[i], updates[n-1] = updates[n-1], updates[i]
i--
n--
inplace++
inplaceCount++
}
if len(updates) > 0 {
ctx.Logger().Printf("[DEBUG] sched: %#v: %d in-place updates of %d", eval, inplace, len(updates))
ctx.Logger().Printf("[DEBUG] sched: %#v: %d in-place updates of %d", eval, inplaceCount, len(updates))
}
return updates[:n]
return updates[:n], updates[n:]
}
// evictAndPlace is used to mark allocations for evicts and add them to the

View File

@ -549,9 +549,9 @@ func TestInplaceUpdate_ChangedTaskGroup(t *testing.T) {
stack := NewGenericStack(false, ctx)
// Do the inplace update.
unplaced := inplaceUpdate(ctx, eval, job, stack, updates)
unplaced, inplace := inplaceUpdate(ctx, eval, job, stack, updates)
if len(unplaced) != 1 {
if len(unplaced) != 1 || len(inplace) != 0 {
t.Fatal("inplaceUpdate incorrectly did an inplace update")
}
@ -594,9 +594,9 @@ func TestInplaceUpdate_NoMatch(t *testing.T) {
stack := NewGenericStack(false, ctx)
// Do the inplace update.
unplaced := inplaceUpdate(ctx, eval, job, stack, updates)
unplaced, inplace := inplaceUpdate(ctx, eval, job, stack, updates)
if len(unplaced) != 1 {
if len(unplaced) != 1 || len(inplace) != 0 {
t.Fatal("inplaceUpdate incorrectly did an inplace update")
}
@ -665,9 +665,9 @@ func TestInplaceUpdate_Success(t *testing.T) {
stack.SetJob(job)
// Do the inplace update.
unplaced := inplaceUpdate(ctx, eval, job, stack, updates)
unplaced, inplace := inplaceUpdate(ctx, eval, job, stack, updates)
if len(unplaced) != 0 {
if len(unplaced) != 0 || len(inplace) != 1 {
t.Fatal("inplaceUpdate did not do an inplace update")
}
@ -675,6 +675,10 @@ func TestInplaceUpdate_Success(t *testing.T) {
t.Fatal("inplaceUpdate did not do an inplace update")
}
if inplace[0].Alloc.ID != alloc.ID {
t.Fatalf("inplaceUpdate returned the wrong, inplace updated alloc: %#v", inplace)
}
// Get the alloc we inserted.
a := ctx.plan.NodeAllocation[alloc.NodeID][0]
if len(a.Services) != 3 {