Skip to content

Commit

Permalink
Merge pull request #1508 from hashicorp/b-dont-update-job
Browse files Browse the repository at this point in the history
Do not update the job of allocations that are being stopped
  • Loading branch information
diptanu committed Aug 3, 2016
2 parents 977bc9d + c988db2 commit 136ee79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nomad/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (n *nomadFSM) applyAllocUpdate(buf []byte, index uint64) interface{} {
// prior to being inserted into MemDB.
if j := req.Job; j != nil {
for _, alloc := range req.Alloc {
if alloc.Job == nil {
if alloc.Job == nil && !alloc.TerminalStatus() {
alloc.Job = j
}
}
Expand Down
9 changes: 6 additions & 3 deletions nomad/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,12 @@ func TestFSM_UpsertAllocs_SharedJob(t *testing.T) {
t.Fatalf("bad: %#v %#v", alloc, out)
}

// Ensure that the original job is used
evictAlloc := new(structs.Allocation)
*evictAlloc = *alloc
job = evictAlloc.Job
job = mock.Job()
job.Priority = 123

evictAlloc.Job = nil
evictAlloc.DesiredStatus = structs.AllocDesiredStatusEvict
req2 := structs.AllocUpdateRequest{
Expand All @@ -604,8 +607,8 @@ func TestFSM_UpsertAllocs_SharedJob(t *testing.T) {
if out.DesiredStatus != structs.AllocDesiredStatusEvict {
t.Fatalf("alloc found!")
}
if out.Job == nil {
t.Fatalf("missing job")
if out.Job == nil || out.Job.Priority == 123 {
t.Fatalf("bad job")
}
}

Expand Down
5 changes: 5 additions & 0 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ func (s *StateStore) UpsertAllocs(index uint64, allocs []*structs.Allocation) er
alloc.AllocModifyIndex = index
alloc.ClientStatus = exist.ClientStatus
alloc.ClientDescription = exist.ClientDescription

// The job has been denormalized so re-attach the original job
if alloc.Job == nil {
alloc.Job = exist.Job
}
}

if err := s.updateSummaryWithAlloc(index, alloc, exist, watcher, txn); err != nil {
Expand Down

0 comments on commit 136ee79

Please sign in to comment.