From 74030f724e691fe2ec820618ae12c5d69b96cf73 Mon Sep 17 00:00:00 2001 From: Drew Bailey Date: Fri, 15 Jan 2021 09:10:16 -0500 Subject: [PATCH] fix updatejobstability to use copy instead of modified reference of job --- nomad/state/state_store.go | 17 ++--------------- nomad/state/state_store_test.go | 12 +++--------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 8416b0bb811..bcbc6c16787 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -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 diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 10f43ac6ad5..1c42e677f1c 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -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()