-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add configurable TTL for every Lock #3095
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
Comments
One workaround would be to provide a custom implementation of Have all the methods delegate to the underlying I think I would prefer that approach over changing the leader initiator. |
I wouldn't object to making such a change directly in the |
I missed the option with the custom |
I've just looked at the code, and the problem is that |
Right - that's what I meant by public class HazelcastLockRegistry implements LockRegistry {
private final HazelcastInstance client;
private final long leaseTime;
private final TimeUnit leaseTimeUnit;
public HazelcastLockRegistry(HazelcastInstance hazelcastInstance) {
this(hazelcastInstance, 0, null);
}
public HazelcastLockRegistry(HazelcastInstance hazelcastInstance, long leaseTime, TimeUnit leaseTimeUnit) {
Assert.notNull(hazelcastInstance, "'hazelcastInstance' must not be null");
this.client = hazelcastInstance;
this.leaseTime = leaseTime;
this.leaseTimeUnit = leaseTimeUnit;
}
@Override
public Lock obtain(Object lockKey) {
Assert.isInstanceOf(String.class, lockKey);
ILock lock = this.client.getLock((String) lockKey);
if (this.leaseTimeUnit == null) {
return lock;
}
else {
return new LockWrapper(lock, this.leaseTime, this.leaseTimeUnit);
}
}
private static final class LockWrapper implements Lock {
private final ILock lock;
private final long leaseTime;
private final TimeUnit leaseTimeUnit;
LockWrapper(ILock lock, long leaseTime, TimeUnit leaseTimeUnit) {
this.lock = lock;
this.leaseTime = leaseTime;
this.leaseTimeUnit = leaseTimeUnit;
}
@Override
public void lock() {
this.lock.lock();
}
@Override
public void lockInterruptibly() throws InterruptedException {
this.lock.lockInterruptibly();
}
@Override
public boolean tryLock() {
return this.lock.tryLock();
}
@Override
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
return this.lock.tryLock(time, unit, this.leaseTime, this.leaseTimeUnit);
}
@Override
public void unlock() {
this.lock.unlock();
}
@Override
public Condition newCondition() {
return this.lock.newCondition();
}
}
} |
I think it's time to change a I agree that it may require some internal changes for every single implementation, but we need to align with protocol requirements somehow anyway... Yes, we can start with Hazelcast, but that is already a matter of the Spring Integration Extensions project: https://github.com/spring-projects/spring-integration-extensions/tree/master/spring-integration-hazelcast |
We'd need an integration lock extension like hazelcast's |
From my perspective |
OK. If you both agree that common |
What I see in the So, I guess we are good in this project for all the implementation. Will continue discussion over there. Thanks for understanding! |
Hm... I don't see any big problem with casting a
So, knowing that you deal with I treat this as Works as Designed and will keep it open only until your feedback. Thank you for understanding! |
Moved back to Spring integration since it looks like we need to provide a Move info from the https://jira.spring.io/browse/INT-4399 |
We're using the
LockRegistryLeaderInitiator
mechanism to control leader election in the cluster backed with Hazelcast. I see that it usestryLock(long time, TimeUnit unit)
method without specifying the maximum lease time. In fact, it's possible that without graceful shutdown the instance won't release the lock and then no other leader will be elected. All instances then are loggingAcquiring the lock for LockContext{role=my-app-leader, id={{app-uuid}}, isLeader=false}
Without manually forcing unlock the whole cluster is stuck. I know that the
java.util.concurrent.locks.Lock
doesn't offer locking for a given time, but it's supported for example with thecom.hazelcast.core.ILock.tryLock(long time, TimeUnit unit, long leaseTime, TimeUnit leaseUnit)
method.Maybe simple possibility to override
LeaderSelector.call
lock acquisition part could be extracted so users can override it with and provide max lease time for example? It could be also done for example in thespring-integration-hazelcast
module.The text was updated successfully, but these errors were encountered: