Skip to content

Commit

Permalink
Do not update the job of allocations that are being stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Aug 3, 2016
1 parent 0981036 commit c988db2
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 @@ -961,6 +961,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 := txn.Insert("allocs", alloc); err != nil {
return fmt.Errorf("alloc insert failed: %v", err)
Expand Down

0 comments on commit c988db2

Please sign in to comment.