Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Lock expiration (feature request) #297
*** Can you add timeToLive support for locks? ***
I am using Hazelcast 184.108.40.206 in a commercial application. The application supports application clustering via a shared database. It had distributed lock and sequence subsystems backed by shared tables in the shared database. I replaced the implementation with Hazelcast, but Hazelcast is missing one piece of functionality that would be useful to a broad audience.
If one of my Tomcat nodes acquires a lock and restarts (or crashed), the lock persists forever. I cannot destroy it, and it does not expire on its own.
If there is an existing workaround I would be open to using it. For example:
My application clusters have multiple Tomcats grabbing a lock to execute critical sections for the cluster. If a Tomcat in the cluster grabs a lock and:
Correction. Hazelcast releases locks created by a member that leaves the cluster. I still need timeToLive for locks though. Possible scenarios include grabbing a lock and forgetting to release it, or grabbing a lock and hanging forever without releasing it such as during access of a third-party application or DB.
I also think this feature would be very nice, not only for "fat" getLock() but also for IMap locks, having them with expiration would be amazing - even more if this expiration could be event-handled!
In an ideal world, locks should be unlocked after each protected operation is finished but, in reality, bugs happen, and in some other complex scenarios it's easy to leave locks unintendedly locked. By having a "timeout" for locks and being able to handle them, these scenarios can be found easily and, when you find them in production, it's nice if they are mitigated by the timeout.
Maybe I'm misunderstanding the solution given in 3.0, but what tryLock looks like now is:
boolean tryLock(K key, long time, TimeUnit timeunit) throws InterruptedException;
What I'm looking for would be:
boolean tryLock(K key, long time, TimeUnit timeunit, long lockExpirationTime, TimeUnit lockExpirationTimeunit)