Skip to content

Commit

Permalink
fix updatejobstability to use copy instead of modified reference of job
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Jan 15, 2021
1 parent 76d729e commit 74030f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
17 changes: 2 additions & 15 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4440,28 +4440,15 @@ func (s *StateStore) setJobStatus(index uint64, txn *txn,
}
}

// Fast-path if nothing has changed.
// Fast-path if the job has changed.
// Still update the job summary if necessary.
if oldStatus == newStatus {
updated := job.Copy()
updated.ModifyIndex = index
if err := txn.Insert("jobs", updated); err != nil {
return fmt.Errorf("job insert failed: %v", err)
}
if err := txn.Insert("index", &IndexEntry{"jobs", index}); err != nil {
return fmt.Errorf("index update failed: %v", err)
}
if err := s.setJobSummary(txn, job, index, oldStatus, newStatus, firstPass); err != nil {
return err
}
// initialize job summary
// initialize / update job summary
return nil
}

// TODO (drew)
// not inserting the job again with modify index/status
// prevents job stability test pass

// Copy and update the existing job
updated := job.Copy()
updated.Status = newStatus
Expand Down
12 changes: 3 additions & 9 deletions nomad/state/state_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6839,19 +6839,13 @@ func TestStateStore_UpdateJobStability(t *testing.T) {

// Insert a job twice to get two versions
job := mock.Job()
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1, job); err != nil {
t.Fatalf("bad: %v", err)
}
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1, job))

if err := state.UpsertJob(structs.MsgTypeTestSetup, 2, job); err != nil {
t.Fatalf("bad: %v", err)
}
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 2, job.Copy()))

// Update the stability to true
err := state.UpdateJobStability(3, job.Namespace, job.ID, 0, true)
if err != nil {
t.Fatalf("bad: %v", err)
}
require.NoError(t, err)

// Check that the job was updated properly
ws := memdb.NewWatchSet()
Expand Down

0 comments on commit 74030f7

Please sign in to comment.