Skip to content

Support lease renewal for distributed locks #3272

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

Open
stefanvassilev opened this issue May 5, 2020 · 8 comments
Open

Support lease renewal for distributed locks #3272

stefanvassilev opened this issue May 5, 2020 · 8 comments

Comments

@stefanvassilev
Copy link

Expected Behavior

One should be able to renew lock obtained from lockRegistry, as if one wants to hold onto a lock for longer than TTL.

Current Behavior

Calling jdbcLockRegistry.tryLock() from current thread would update the lock, which seems to renew it, however it would increase the hold's count as well, causing jdbcLock.unlock()' not to release the lock as it would only decrease delegate's hold's by one see:

One can workaround this by using the 'DefaultLockRepository' to require a lock re-acquire a lock, which would update CREATED_DATE of the lock without increasing delegate's hold count.

Context

It would be great if this is supported from jdbcRegistry rather than going over the workaround I mentioned above.

@stefanvassilev stefanvassilev added status: waiting-for-triage The issue need to be evaluated and its future decided type: enhancement labels May 5, 2020
@artembilan
Copy link
Member

Hi @stefanvassilev !

I'm not sure that I fully understood how you workaround it and what the change you would like to do, but it looks more like you are looking for something like this: #3095.
In other words a contract like this: tryLock(long time, TimeUnit unit, long leaseTime, TimeUnit leaseUnit) and lock(long leaseTime, TimeUnit timeUnit);

Please, share more info how we should fix it from your perspective.

Thanks

@artembilan artembilan added status: waiting-for-reporter Needs a feedback from the reporter and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels May 5, 2020
@stefanvassilev
Copy link
Author

hi @artembilan,

thanks for the quick response.

The problem that I'm describing is the following:

Imagine you have two instances which use 'lockRegistry', instance A and instance B.

Instance 'A' acquires lock with name lockA and does some work, which takes more time than the TTL, so when instance 'B' tries to acquire lockA to acquire it it will succeed, as lockA would be expired and will get deleted.

My proposal would be to include a method to renew to the lock from instance A so that instance B won't be able to acquire it, as it won't be expired. The issue you linked would probably solve to a degree my problem, however, from API standpoint one should be probably be able to decide for how long the lock should is maintained.

I hope this clarifies what I'm trying to describe.

@artembilan
Copy link
Member

Hm. Probably it sounds like an addition to the mentioned tryLock(long time, TimeUnit unit, long leaseTime, TimeUnit leaseUnit)API - renewLease(long leaseTime)...

@stefanvassilev
Copy link
Author

seems reasonable to me :-)

@artembilan artembilan added status: waiting-for-triage The issue need to be evaluated and its future decided and removed status: waiting-for-reporter Needs a feedback from the reporter labels May 6, 2020
@artembilan artembilan changed the title Support lock renewal in jdbcLockRegistry Support lease renewal for distributed locks May 6, 2020
@artembilan
Copy link
Member

So, since we agree about this feature, I make it official.
Let's see what we can do for the next 5.4 version!

Probably not all distributed locks could have that feature. I don't see a way in Curator Framework and looks like Hazelcast went a raft algorithm way, so there is no lease in their new FencedLock at all.

@artembilan artembilan added this to the 5.4.x milestone May 6, 2020
@artembilan artembilan removed the status: waiting-for-triage The issue need to be evaluated and its future decided label May 6, 2020
astrubel pushed a commit to astrubel/spring-integration that referenced this issue Jul 1, 2020
astrubel pushed a commit to astrubel/spring-integration that referenced this issue Jul 1, 2020
astrubel pushed a commit to astrubel/spring-integration that referenced this issue Jul 2, 2020
astrubel pushed a commit to astrubel/spring-integration that referenced this issue Jul 3, 2020
@artembilan
Copy link
Member

Reopen since we need to revise all other LockRegistry implementations to be sure that they can support this renewal feature.

@artembilan artembilan reopened this Jul 6, 2020
@lubronzhan
Copy link

Thanks @artembilan
Is there any plan to add this renewLock to this part of logic? https://github.com/spring-projects/spring-integration/blob/master/spring-integration-core/src/main/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiator.java#L400-L408
Or we have to wait for modification on other LockRegistry first?

@artembilan
Copy link
Member

Hm.
I think with a renewable feature we need to have a slightly different logic in that initiator.
Probably the whole main loop should be adjusted respectively.

I didn't think it through yet, but if you have something in mind, feel free to raise a Pull Request and we will look together what and how should be fixed over there to support that RenewableLockRegistry.

Good catch though!

@artembilan artembilan removed this from the 5.4.x milestone Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants