diff --git a/nomad/deploymentwatcher/deployment_watcher.go b/nomad/deploymentwatcher/deployment_watcher.go index 6faf133e2..cca75e5de 100644 --- a/nomad/deploymentwatcher/deployment_watcher.go +++ b/nomad/deploymentwatcher/deployment_watcher.go @@ -767,7 +767,7 @@ func (w *deploymentWatcher) getAllocsImpl(ws memdb.WatchSet, state *state.StateS } } - // Use the last index that affected the jobs table + // Use the last index that affected the allocs table if len(stubs) == 0 { index, err := state.Index("allocs") if err != nil { @@ -806,7 +806,7 @@ func (w *deploymentWatcher) jobEvalStatus() (latestIndex uint64, blocked bool, e var max uint64 for _, eval := range evals { - // If we ahve a blocked eval, then we do not care what the index is + // If we have a blocked eval, then we do not care what the index is // since we will not need to make a new eval. if eval.ShouldBlock() { return 0, true, nil diff --git a/nomad/drainer/watch_jobs.go b/nomad/drainer/watch_jobs.go index 4f6b7e9cc..35380cfdb 100644 --- a/nomad/drainer/watch_jobs.go +++ b/nomad/drainer/watch_jobs.go @@ -447,6 +447,7 @@ func (w *drainingJobWatcher) getJobAllocsImpl(ws memdb.WatchSet, state *state.St } // Capture the allocs for each draining job. + var maxIndex uint64 = 0 resp := make(map[structs.NamespacedID][]*structs.Allocation, l) for jns := range draining { allocs, err := state.AllocsByJob(ws, jns.Namespace, jns.ID, false) @@ -455,6 +456,17 @@ func (w *drainingJobWatcher) getJobAllocsImpl(ws memdb.WatchSet, state *state.St } resp[jns] = allocs + for _, alloc := range allocs { + if maxIndex < alloc.ModifyIndex { + maxIndex = alloc.ModifyIndex + } + } + } + + // Prefer using the actual max index of affected allocs since it means less + // unblocking + if maxIndex != 0 { + index = maxIndex } return resp, index, nil diff --git a/nomad/drainer/watch_nodes.go b/nomad/drainer/watch_nodes.go index 65ec06206..7639bc804 100644 --- a/nomad/drainer/watch_nodes.go +++ b/nomad/drainer/watch_nodes.go @@ -235,6 +235,7 @@ func (w *nodeDrainWatcher) getNodesImpl(ws memdb.WatchSet, state *state.StateSto return nil, 0, err } + var maxIndex uint64 = 0 resp := make(map[string]*structs.Node, 64) for { raw := iter.Next() @@ -244,6 +245,15 @@ func (w *nodeDrainWatcher) getNodesImpl(ws memdb.WatchSet, state *state.StateSto node := raw.(*structs.Node) resp[node.ID] = node + if maxIndex < node.ModifyIndex { + maxIndex = node.ModifyIndex + } + } + + // Prefer using the actual max index of affected nodes since it means less + // unblocking + if maxIndex != 0 { + index = maxIndex } return resp, index, nil