From 47fbfd3000787b22dcfa58ebc61472c47251a826 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 12 Jan 2016 09:50:33 -0800 Subject: [PATCH] Add JobModifyIndex --- nomad/job_endpoint_test.go | 1 + nomad/mock/mock.go | 7 ++++--- nomad/state/state_store.go | 2 ++ nomad/structs/structs.go | 5 +++-- scheduler/util.go | 5 +---- scheduler/util_test.go | 4 ++-- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/nomad/job_endpoint_test.go b/nomad/job_endpoint_test.go index 236028c4b9a..7c313e8d01a 100644 --- a/nomad/job_endpoint_test.go +++ b/nomad/job_endpoint_test.go @@ -532,6 +532,7 @@ func TestJobEndpoint_GetJob(t *testing.T) { } job.CreateIndex = resp.JobModifyIndex job.ModifyIndex = resp.JobModifyIndex + job.JobModifyIndex = resp.JobModifyIndex // Lookup the job get := &structs.JobSpecificRequest{ diff --git a/nomad/mock/mock.go b/nomad/mock/mock.go index 3408e0f972e..38b4a49af58 100644 --- a/nomad/mock/mock.go +++ b/nomad/mock/mock.go @@ -124,9 +124,10 @@ func Job() *structs.Job { Meta: map[string]string{ "owner": "armon", }, - Status: structs.JobStatusPending, - CreateIndex: 42, - ModifyIndex: 99, + Status: structs.JobStatusPending, + CreateIndex: 42, + ModifyIndex: 99, + JobModifyIndex: 99, } job.InitFields() return job diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 338fab7fea5..553bcbf0777 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -295,6 +295,7 @@ func (s *StateStore) UpsertJob(index uint64, job *structs.Job) error { if existing != nil { job.CreateIndex = existing.(*structs.Job).CreateIndex job.ModifyIndex = index + job.JobModifyIndex = index // Compute the job status var err error @@ -305,6 +306,7 @@ func (s *StateStore) UpsertJob(index uint64, job *structs.Job) error { } else { job.CreateIndex = index job.ModifyIndex = index + job.JobModifyIndex = index // If we are inserting the job for the first time, we don't need to // calculate the jobs status as it is known. diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index bbb171f1de9..68b7e6e8d42 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -777,8 +777,9 @@ type Job struct { StatusDescription string // Raft Indexes - CreateIndex uint64 - ModifyIndex uint64 + CreateIndex uint64 + ModifyIndex uint64 + JobModifyIndex uint64 } // InitFields is used to initialize fields in the Job. This should be called diff --git a/scheduler/util.go b/scheduler/util.go index f448687c5ec..29fed93427f 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -92,10 +92,7 @@ func diffAllocs(job *structs.Job, taintedNodes map[string]bool, } // If the definition is updated we need to update - // XXX: This is an extremely conservative approach. We can check - // if the job definition has changed in a way that affects - // this allocation and potentially ignore it. - if job.ModifyIndex != exist.Job.ModifyIndex { + if job.JobModifyIndex != exist.Job.JobModifyIndex { result.update = append(result.update, allocTuple{ Name: name, TaskGroup: tg, diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 7b213da77b5..3ee813090f8 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -38,7 +38,7 @@ func TestDiffAllocs(t *testing.T) { // The "old" job has a previous modify index oldJob := new(structs.Job) *oldJob = *job - oldJob.ModifyIndex -= 1 + oldJob.JobModifyIndex -= 1 tainted := map[string]bool{ "dead": true, @@ -119,7 +119,7 @@ func TestDiffSystemAllocs(t *testing.T) { // The "old" job has a previous modify index oldJob := new(structs.Job) *oldJob = *job - oldJob.ModifyIndex -= 1 + oldJob.JobModifyIndex -= 1 tainted := map[string]bool{ "dead": true,