Merge pull request #8364 from hashicorp/b-326-multiregion-version-sync

allow version skipping in Job.Register to support version syncing for MRD
This commit is contained in:
Chris Baker 2020-07-06 10:06:32 -05:00 committed by GitHub
commit 07490a7c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -303,7 +303,11 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
// Submit a multiregion job to other regions (enterprise only).
// The job will have its region interpolated.
err = j.multiregionRegister(args, reply)
var existingVersion uint64
if existingJob != nil {
existingVersion = existingJob.Version
}
err = j.multiregionRegister(args, reply, existingVersion)
if err != nil {
return err
}

View File

@ -10,7 +10,9 @@ func (j *Job) enforceSubmitJob(override bool, job *structs.Job) (error, error) {
}
// multiregionRegister is used to send a job across multiple regions
func (j *Job) multiregionRegister(args *structs.JobRegisterRequest, reply *structs.JobRegisterResponse) error {
func (j *Job) multiregionRegister(args *structs.JobRegisterRequest, reply *structs.JobRegisterResponse,
existingVersion uint64) error {
return nil
}

View File

@ -1351,12 +1351,16 @@ func (s *StateStore) upsertJobImpl(index uint64, job *structs.Job, keepVersion b
job.CreateIndex = existing.(*structs.Job).CreateIndex
job.ModifyIndex = index
existingJob := existing.(*structs.Job)
// Bump the version unless asked to keep it. This should only be done
// when changing an internal field such as Stable. A spec change should
// always come with a version bump
if !keepVersion {
job.JobModifyIndex = index
job.Version = existing.(*structs.Job).Version + 1
if job.Version <= existingJob.Version {
job.Version = existingJob.Version + 1
}
}
// Compute the job status