Skip to content

Commit b5c157d

Browse files
state store: remove reschedulable check when getting job status (#25081)
1 parent 87741dd commit b5c157d

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

nomad/state/state_store.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5679,15 +5679,9 @@ func (s *StateStore) getJobStatus(txn *txn, job *structs.Job, evalDelete bool) (
56795679
// If there is a non-terminal allocation, the job is running.
56805680
hasAlloc := false
56815681
for alloc := allocs.Next(); alloc != nil; alloc = allocs.Next() {
5682-
a := alloc.(*structs.Allocation)
5683-
if !a.TerminalStatus() {
5682+
if !alloc.(*structs.Allocation).TerminalStatus() {
56845683
return structs.JobStatusRunning, nil
56855684
}
5686-
// if there exists a terminal, non-reschedulable alloc,
5687-
// mark this job as possibly dead
5688-
if !isReschedulable(a) {
5689-
hasAlloc = true
5690-
}
56915685
}
56925686

56935687
evals, err := txn.Get("evals", "job_prefix", job.Namespace, job.ID)
@@ -5697,18 +5691,8 @@ func (s *StateStore) getJobStatus(txn *txn, job *structs.Job, evalDelete bool) (
56975691

56985692
hasEval := false
56995693
for raw := evals.Next(); raw != nil; raw = evals.Next() {
5700-
e := raw.(*structs.Evaluation)
5701-
5702-
// Handles restarting stopped jobs and rescheduled allocs, or else they
5703-
// are briefly marked dead. We don't always want to skip these evaluations,
5704-
// like in the case of rescheduled or stopped jobs, but we handle both
5705-
// those cases in elsewhere in this function.
5706-
if e.JobModifyIndex < job.ModifyIndex {
5707-
continue
5708-
}
5709-
57105694
hasEval = true
5711-
if !e.TerminalStatus() {
5695+
if !raw.(*structs.Evaluation).TerminalStatus() {
57125696
return structs.JobStatusPending, nil
57135697
}
57145698
}
@@ -7421,13 +7405,6 @@ func (s *StateStore) ScalingPoliciesByIDPrefix(ws memdb.WatchSet, namespace stri
74217405
return iter, nil
74227406
}
74237407

7424-
func isReschedulable(a *structs.Allocation) bool {
7425-
if a.Job.Type != structs.JobTypeService {
7426-
return false
7427-
}
7428-
return a.RescheduleTracker.RescheduleEligible(a.ReschedulePolicy(), time.Now())
7429-
}
7430-
74317408
// scalingPolicyNamespaceFilter returns a filter function that filters all
74327409
// scaling policies not targeting the given namespace.
74337410
func scalingPolicyNamespaceFilter(namespace string) func(interface{}) bool {

nomad/state/state_store_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7896,7 +7896,7 @@ func TestStateStore_GetJobStatus(t *testing.T) {
78967896
exp: structs.JobStatusPending,
78977897
},
78987898
{
7899-
name: "batch job has all terminal allocs, with no evals",
7899+
name: "batch job has all terminal allocs and terminal evals",
79007900
setup: func(t *testing.T, txn *txn) *structs.Job {
79017901
j := mock.Job()
79027902
j.Type = structs.JobTypeBatch
@@ -7908,6 +7908,12 @@ func TestStateStore_GetJobStatus(t *testing.T) {
79087908

79097909
err := txn.Insert("allocs", a)
79107910
must.NoError(t, err)
7911+
7912+
e := mock.Eval()
7913+
e.JobID = j.ID
7914+
e.Status = structs.EvalStatusComplete
7915+
err = txn.Insert("evals", e)
7916+
must.NoError(t, err)
79117917
return j
79127918
},
79137919
exp: structs.JobStatusDead,
@@ -7984,6 +7990,12 @@ func TestStateStore_GetJobStatus(t *testing.T) {
79847990

79857991
err = txn.Insert("allocs", a2)
79867992
must.NoError(t, err)
7993+
7994+
e := mock.Eval()
7995+
e.JobID = j.ID
7996+
e.Status = structs.EvalStatusComplete
7997+
err = txn.Insert("evals", e)
7998+
must.NoError(t, err)
79877999
return j
79888000
},
79898001
exp: structs.JobStatusDead,

0 commit comments

Comments
 (0)