0

I am following kazoo lease recipe. Client creates a znode "/db_leases/hourly_cleanup" and acquire the lease. When the client disconnects from the zookeeper or crashes, I want other client, that is trying to acquire the same lease, able to acquire the it. Since znode is not removed, other client fails to acquire the lease even when no other client holding the lease. How to make sure znode "/db_leases/hourly_cleanup" is removed when client holding the lease exits or crashes.

1 Answers1

0

The other client will not be able to acquire it until the lease expires. Once the time specified by the duration parameter has elapsed, it will be able to acquire the lease.

  • Yes, I understand that part. This setup is running in the public cloud. After instance crash, new instance is launched and it fails to acquire the lock because lease has not been expired. My question: Is there a way to detect this condition that nobody is holding the lease and thus remove the znode so that the new launched instance can acquire the lease or lock? – user2464401 Jan 14 '21 at 17:59
  • The lease contains no information about what the lessee is up to, or whether it is alive or not. It only knows a client id and a duration. If you want to detect lessee failure and fail over, set the duration short and have the lessee reacquire the lease before it expires. If the node then fails, it will expire, and another node can take over. – Lars Albertsson Jan 16 '21 at 15:40
  • It could also be that a lock is more suitable for your use case. If you describe the use case, I might be able to help. BTW, I see that the docs on lease are perhaps not clear enough. I don't use ZK anymore, and won't spend time on it, but if you would like to create a PR, I am happy to review, – Lars Albertsson Jan 16 '21 at 15:42