Your lock service has a 12-second session lease and the master fails over in about 20 seconds. How do you design client behaviour so that sessions survive the failover without letting a client act on a lock it has really lost?
Sketch your own answer first, then compare it with the one below.
A strong answer
Treat the lease running out locally as a state of doubt, not a verdict. The client cannot tell whether the session ended or the master is merely unreachable. It should start a grace period longer than a typical failover, such as 45 seconds, during which it tries to reach the new master and keeps the session if a keepalive succeeds.
During that period the client must not act as though the lock is certain. The library should raise a jeopardy event so the application can quiesce: finish or park in-flight work, stop issuing protected writes and flush nothing it cannot undo. If the session survives, a safe event lets it resume without a restart. If the grace period ends first, an expired event tells it the locks are gone.
The service side matters too. The new master must not grant a lock the old master might still consider held, so it should keep the old sessions' locks reserved for the grace period while clients reconnect, and clients' timers should be conservative about the master's clock rate.
None of this removes the paused-client case, where the code that reacts to the event never runs. So pair the session with a sequencer or token the protected resource checks, and consider a lock-delay for resources that cannot check it.
Sources
- Mike Burrows (2006). The Chubby lock service for loosely-coupled distributed systems.