-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Job revert #2575
Job revert #2575
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one minor comment nit
nomad/job_endpoint.go
Outdated
return fmt.Errorf("job %q not found", args.JobID) | ||
} | ||
|
||
if args.JobVersion == cur.Version { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure JobByID
's docs explain it returns the "latest" or "current" version of a Job ID now that an ID doesn't uniquely identify exactly one *structs.Job
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Done.
|
||
// If the request is enforcing the existing version do a check. | ||
if args.EnforcePriorVersion != nil { | ||
if cur.Version != *args.EnforcePriorVersion { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is racy, and probably should be evaluated inside the FSM. Effectively this is a check-and-set, but multiple concurrent calls to this API will be allowed to make progress depending on the timing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I realized that when implementing this. The register endpoint should push the logic from the RPC layer down into the FSM. This will fix this issue for both this and the register. Just out of scope for this PR. I will put a comment on that part of the code though
nomad/job_endpoint.go
Outdated
return fmt.Errorf("job %q at version %d not found", args.JobID, args.JobVersion) | ||
} | ||
|
||
cur, err := snap.JobByID(ws, args.JobID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would check this first, since you expect to get the "job not found" error before the "job at version" not found error.
} | ||
|
||
reg.EnforceIndex = true | ||
reg.JobModifyIndex = cur.JobModifyIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modify index will get overwritten at Upsert time right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two are the way to do the CAS operation on the register
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
This PR introduces a revert endpoint that allows a job to be reverted to a prior state.