Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix periodic job state #2486

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,15 @@ func (s *StateStore) EvalsByJob(ws memdb.WatchSet, jobID string) ([]*structs.Eva
if raw == nil {
break
}
out = append(out, raw.(*structs.Evaluation))

e := raw.(*structs.Evaluation)

// Filter non-exact matches
if e.JobID != jobID {
continue
}

out = append(out, e)
}
return out, nil
}
Expand Down Expand Up @@ -1619,9 +1627,16 @@ func (s *StateStore) getJobStatus(txn *memdb.Txn, job *structs.Job, evalDelete b
}

hasEval := false
for eval := evals.Next(); eval != nil; eval = evals.Next() {
for raw := evals.Next(); raw != nil; raw = evals.Next() {
e := raw.(*structs.Evaluation)

// Filter non-exact matches
if e.JobID != job.ID {
continue
}

hasEval = true
if !eval.(*structs.Evaluation).TerminalStatus() {
if !e.TerminalStatus() {
return structs.JobStatusPending, nil
}
}
Expand Down
55 changes: 55 additions & 0 deletions nomad/state/state_store_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package state

import (
"fmt"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -494,6 +495,60 @@ func TestStateStore_UpdateUpsertJob_Job(t *testing.T) {
}
}

func TestStateStore_UpdateUpsertJob_PeriodicJob(t *testing.T) {
state := testStateStore(t)
job := mock.PeriodicJob()

// Create a watchset so we can test that upsert fires the watch
ws := memdb.NewWatchSet()
_, err := state.JobByID(ws, job.ID)
if err != nil {
t.Fatalf("bad: %v", err)
}

if err := state.UpsertJob(1000, job); err != nil {
t.Fatalf("err: %v", err)
}

// Create a child and an evaluation
job2 := job.Copy()
job2.Periodic = nil
job2.ID = fmt.Sprintf("%v/%s-1490635020", job.ID, structs.PeriodicLaunchSuffix)
err = state.UpsertJob(1001, job2)
if err != nil {
t.Fatalf("err: %v", err)
}

eval := mock.Eval()
eval.JobID = job2.ID
err = state.UpsertEvals(1002, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}

job3 := job.Copy()
job3.TaskGroups[0].Tasks[0].Name = "new name"
err = state.UpsertJob(1003, job3)
if err != nil {
t.Fatalf("err: %v", err)
}

if !watchFired(ws) {
t.Fatalf("bad")
}

ws = memdb.NewWatchSet()
out, err := state.JobByID(ws, job.ID)
if err != nil {
t.Fatalf("err: %v", err)
}

if s, e := out.Status, structs.JobStatusRunning; s != e {
t.Fatalf("got status %v; want %v", s, e)
}

}

// This test ensures that UpsertJob creates the EphemeralDisk is a job doesn't have
// one and clear out the task's disk resource asks
// COMPAT 0.4.1 -> 0.5
Expand Down