From 6dc5b1972c84028fe0161dd481b7abb91013a9d8 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 4 Aug 2016 15:14:01 -0700 Subject: [PATCH] Setting job's create index as summary create index during reconciliation --- nomad/fsm_test.go | 4 ++-- nomad/state/state_store.go | 14 ++++++++++++-- nomad/state/state_store_test.go | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/nomad/fsm_test.go b/nomad/fsm_test.go index 718338b8c..b06816396 100644 --- a/nomad/fsm_test.go +++ b/nomad/fsm_test.go @@ -1017,7 +1017,7 @@ func TestFSM_SnapshotRestore_AddMissingSummary(t *testing.T) { Queued: 10, }, }, - CreateIndex: latestIndex, + CreateIndex: 1000, ModifyIndex: latestIndex, } if !reflect.DeepEqual(&expected, out1) { @@ -1036,7 +1036,7 @@ func TestFSM_SnapshotRestore_AddMissingSummary(t *testing.T) { Starting: 1, }, }, - CreateIndex: latestIndex, + CreateIndex: 1010, ModifyIndex: latestIndex, } if !reflect.DeepEqual(&expected, out2) { diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 21a102e8a..dfe5945ff 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -1219,6 +1219,13 @@ func (s *StateStore) ReconcileJobSummaries(index uint64) error { break } alloc := rawAlloc.(*structs.Allocation) + + // Ignore the allocation if it doesn't belong to the currently + // registered job + if alloc.Job.CreateIndex != job.CreateIndex { + continue + } + tg := summary.Summary[alloc.TaskGroup] switch alloc.ClientStatus { case structs.AllocClientStatusFailed: @@ -1237,9 +1244,12 @@ func (s *StateStore) ReconcileJobSummaries(index uint64) error { summary.Summary[alloc.TaskGroup] = tg } - // Insert the job summary - summary.CreateIndex = index + // Set the create index of the summary same as the job's create index + // and the modify index to the current index + summary.CreateIndex = job.CreateIndex summary.ModifyIndex = index + + // Insert the job summary if err := txn.Insert("job_summary", summary); err != nil { return fmt.Errorf("error inserting job summary: %v", err) } diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 7cd08c1d8..4ee119e68 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -2059,7 +2059,7 @@ func TestStateStore_ReconcileJobSummary(t *testing.T) { Lost: 1, }, }, - CreateIndex: 120, + CreateIndex: 100, ModifyIndex: 120, } if !reflect.DeepEqual(&expectedSummary, summary) {