Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add a method to support renewing a lock in LockService class #74

Merged
merged 2 commits into from
Oct 7, 2020

Conversation

ftianli-amzn
Copy link

Issue #, if available:
When locking mechanism is enabled on a ScheduledJob, every execution of the job have to acquire the lock to execute, in order to avoid overlapping execution. The lock will be expired after a fixed period of time, which is defined by the job.

Currently there is no way to give an extension of period for an execution to hold the lock.

Description of changes:

  • Add a method renewLock() in LockService class of the SPI.
  • Add the corresponding integration test

With the new method renewLock(), it makes possible for an execution of a ScheduledJob to be given an extend duration to hold a lock for running the job.

When calling the method, it attempts to renew the lock.

  • The start time of the lock will be updated to the current time when the method get called, and the duration of the lock remains.
  • It works as long as the lock is not acquired by others, and no matter if the lock is expired of not.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

lock, lock.getLockTime(), lock.getLockDurationSeconds());
final LockModel lockToRenew = new LockModel(lock, getNow(), lock.getLockDurationSeconds(), false);
updateLock(lockToRenew, ActionListener.wrap(
renewedLock -> listener.onResponse(renewedLock != null),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be more useful to change this to return the lock itself rather than a boolean as it would be more useful to have the new updated lock in the plugin with the new seqNo/primaryTerm.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I will change to return the lock. I have realized it could be more useful as well during writing the test.

Copy link
Author

Choose a reason for hiding this comment

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

I have changed to return the lock object instead of a boolean value after calling the method, and also simplified the test procedure due to the change.

@ftianli-amzn ftianli-amzn merged commit 893daf0 into opendistro-for-elasticsearch:master Oct 7, 2020
@ftianli-amzn ftianli-amzn deleted the renewlock branch October 8, 2020 04:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants