How should the lock service itself be built so that it does not become the thing that fails? What does a lock service need from consensus?
Sketch your own answer first, then compare it with the one below.
A strong answer
A lock service on one machine is a single point of failure, and a lock service on several machines that do not agree can hand the same lock to two clients. So the service is usually a small replicated state machine over a consensus protocol: a few nodes that agree on the sequence of grants, releases and expiries.
Consensus gives it one agreed order, so the token counter is unique and increasing across failovers, and a client that talks to any replica sees the same holder. The service tolerates a minority of its own nodes failing, and the lease model covers clients failing.
Operations matter as much as design. The service should be small and boring, because every client depends on it. Sessions with keepalives let it detect dead clients, and clients should be told explicitly when their session expired rather than discovering it on a rejected write. Reads of "who holds the lock" should be served with care, because a stale answer here is exactly the problem fencing exists for.
Sources
- Mike Burrows (2006). The Chubby lock service for loosely-coupled distributed systems.