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

Enables locking on an arbitrary lockID #164

Merged
merged 7 commits into from
Apr 7, 2022

Conversation

downsrob
Copy link
Contributor

@downsrob downsrob commented Apr 4, 2022

Signed-off-by: Clay Downs downsrob@amazon.com

Description

This change allows for locking an arbitrary resource across jobs by repurposing the LockModel job_id to be any user provided lock ID String. The locks are still scoped to the specific job index provided.

Previously, locks could only be acquired by supplying the ScheduledJobParameter and JobExecutionContext. The job index name, job ID, and lock duration would then be extracted from those objects. This change adds a method to acquire a lock with any provided lock ID, and allows for explicitly providing the job index name and lock duration, so the ScheduledJobParameter and JobExecutionContext are no longer required.

Issues Resolved

#166

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

downsrob added 5 commits April 4, 2022 02:24
Signed-off-by: Clay Downs <downsrob@amazon.com>
Signed-off-by: Clay Downs <downsrob@amazon.com>
Signed-off-by: Clay Downs <downsrob@amazon.com>
Signed-off-by: Clay Downs <downsrob@amazon.com>
Signed-off-by: Clay Downs <downsrob@amazon.com>
@downsrob downsrob marked this pull request as ready for review April 4, 2022 18:16
@downsrob downsrob requested review from a team, dbbaughe and thalurur April 4, 2022 18:16
* or else null. Passes {@code IllegalArgumentException} to onFailure if the {@code ScheduledJobParameter} does not
* have {@code LockDurationSeconds}.
*/
public void acquireLockWithId(final ScheduledJobParameter jobParameter,
Copy link
Contributor

Choose a reason for hiding this comment

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

If given a lockId by the caller, I think we should still prefix it with the job index name to preserve namespaces, otherwise if two different plugins using this end up using the same lockId at any point then they'll run into issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am happy to make this change if you want, but that behavior also enables locking resources across plugins. Any plugin that doesn't want this could just prefix their own id to namespace it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a use case for that yet? If not then we can add in support for it when needed, but as of right now relying on the consumers to correctly namespace the lockId leaves room for the developers who are not aware of it to accidentally misuse and cause issues across plugins.

@thalurur Any thoughts on it?

Copy link
Contributor

@thalurur thalurur Apr 4, 2022

Choose a reason for hiding this comment

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

I don't see much benefit in enforcing a global lock since this is not a standard that all plugins need to follow and one plugin assuming that its locking globally using this mechanism might be really not enforcable and I don't think a plugin should assume that.

Keeping it at the a namespace always by job scheduler makes more sense since its contained to that use case and if plugins want to further scope it down they can add more prefixes for the feature in the namespace when creating lock Ids

@@ -88,6 +94,18 @@ public LockModel(String jobIndexName, String jobId, Instant lockTime,
this.primaryTerm = primaryTerm;
}

public LockModel(String jobIndexName, String jobId, String lockId, Instant lockTime,
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we want both jobId and lockId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I think that the only reason to include the job ID would be if we wanted to delete the leftover locks after a job is deleted. If we instead moved to a periodic job deleting stale locks, then I think there is no point in having both. I'll make the change.

Signed-off-by: Clay Downs <downsrob@amazon.com>
@downsrob downsrob requested review from thalurur and dbbaughe April 4, 2022 22:29
Signed-off-by: Clay Downs <downsrob@amazon.com>
@@ -80,6 +80,8 @@ public LockModel(String jobIndexName, String jobId, Instant lockTime,
long lockDurationSeconds, boolean released, long seqNo, long primaryTerm) {
this.lockId = jobIndexName + LOCK_ID_DELIMITR + jobId;
this.jobIndexName = jobIndexName;
// The jobId parameter does not necessarily need to represent the id of a job scheduler job, as it is being used
Copy link
Contributor

Choose a reason for hiding this comment

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

may be create an issue in repo to rename this completely to just lockId everywhere? so the paradigm is changed in job scheduler - cleaning up stale locks and any other refactor needed with this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@downsrob downsrob merged commit 2a49d38 into opensearch-project:main Apr 7, 2022
@downsrob downsrob deleted the arbitrary-job-id branch April 7, 2022 18:02
wuychn pushed a commit to ochprince/job-scheduler that referenced this pull request Mar 16, 2023
* Enables locking on an arbitrary lockID

Signed-off-by: Clay Downs <downsrob@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants