Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update the job of allocations that are being stopped #1508

Merged
merged 1 commit into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test in FSM where job is actually nil if the allocation is not for the currently registered job with the same ID?

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