nomad: simplify code and improve parameter name

This commit is contained in:
Michael Schurter 2019-03-04 13:44:14 -08:00
parent 05f51499ba
commit e37bbb21a5
1 changed files with 5 additions and 10 deletions

View File

@ -133,7 +133,7 @@ func (e *Eval) Dequeue(args *structs.EvalDequeueRequest,
// invoking the scheduler. The index should be the highest modify index of any
// evaluation for the job. This prevents scheduling races for the same job when
// there are blocked evaluations.
func (e *Eval) getWaitIndex(namespace, job string, curIndex uint64) (uint64, error) {
func (e *Eval) getWaitIndex(namespace, job string, evalModifyIndex uint64) (uint64, error) {
snap, err := e.srv.State().Snapshot()
if err != nil {
return 0, err
@ -144,21 +144,16 @@ func (e *Eval) getWaitIndex(namespace, job string, curIndex uint64) (uint64, err
return 0, err
}
var max uint64
// Since dequeueing evals is concurrent with applying raft messages to
// the state store, initialize to the currently dequeued eval's index
// in case it isn't in the snapshot used by EvalsByJob yet.
max := evalModifyIndex
for _, eval := range evals {
if max < eval.ModifyIndex {
max = eval.ModifyIndex
}
}
// Since dequeueing evals is concurrent with applying raft messages to
// the state store, manually compare the currently dequeued eval's
// index against max in case it wasn't in the snapshot used by
// EvalsByJob yet.
if max < curIndex {
max = curIndex
}
return max, nil
}