Skip to content

Commit

Permalink
Merge pull request #1522 from hashicorp/b-reconcile-summary
Browse files Browse the repository at this point in the history
Setting job's create index as summary create index during reconciliation
  • Loading branch information
diptanu committed Aug 4, 2016
2 parents ece6251 + cdb4d5e commit f3cd08f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nomad/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ func TestFSM_SnapshotRestore_AddMissingSummary(t *testing.T) {
Queued: 10,
},
},
CreateIndex: latestIndex,
CreateIndex: 1000,
ModifyIndex: latestIndex,
}
if !reflect.DeepEqual(&expected, out1) {
Expand All @@ -1036,7 +1036,7 @@ func TestFSM_SnapshotRestore_AddMissingSummary(t *testing.T) {
Starting: 1,
},
},
CreateIndex: latestIndex,
CreateIndex: 1010,
ModifyIndex: latestIndex,
}
if !reflect.DeepEqual(&expected, out2) {
Expand Down
14 changes: 12 additions & 2 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion nomad/state/state_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ func TestStateStore_ReconcileJobSummary(t *testing.T) {
Lost: 1,
},
},
CreateIndex: 120,
CreateIndex: 100,
ModifyIndex: 120,
}
if !reflect.DeepEqual(&expectedSummary, summary) {
Expand Down

0 comments on commit f3cd08f

Please sign in to comment.