A client checks its own clock before each write to make sure its lease is still valid. Why is that not sufficient, and how does clock drift make it worse?
Sketch your own answer first, then compare it with the one below.
A strong answer
The check happens before the write and the write happens after. Anything between the two, a pause or a slow network hop, can carry the write past the expiry even though the check passed. A check cannot be atomic with an action that happens somewhere else.
Even without a pause, the client's clock is not the lock service's clock. If the client's clock runs slow, it believes the lease has more time than it does. A client that starts its own lease timer when the grant arrives is also already late by the network delay. Both errors push the client to write after the service has moved on.
A careful client subtracts a safety margin that covers its expected drift and delay. That shrinks the window but cannot close it, because the pause can be longer than any margin. The margin is a mitigation. A fencing token is the guarantee.
Sources
- Cary G. Gray, David R. Cheriton (1989). Leases, an efficient fault-tolerant mechanism for distributed file cache consistency.
- Martin Kleppmann (2016). How to do distributed locking.