From e37bbb21a5304c500e545e9440ab0ac8c3ac53b8 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 4 Mar 2019 13:44:14 -0800 Subject: [PATCH] nomad: simplify code and improve parameter name --- nomad/eval_endpoint.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/nomad/eval_endpoint.go b/nomad/eval_endpoint.go index 0f1595c0b..6e6c0d809 100644 --- a/nomad/eval_endpoint.go +++ b/nomad/eval_endpoint.go @@ -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 }