Add JobModifyIndex

This commit is contained in:
Alex Dadgar
2016-01-12 09:50:33 -08:00
parent 875bf47687
commit 47fbfd3000
6 changed files with 13 additions and 11 deletions

View File

@@ -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{

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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,

View File

@@ -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,