What is a fencing token, and where does it have to be checked?
Sketch your own answer first, then compare it with the one below.
A strong answer
A fencing token is a number the lock service issues with every grant, and it goes up every time. A client sends the token with each write it makes while holding the lock. Storage keeps the highest token it has seen and rejects any write with a lower one.
A stale holder carries a token from before the lock was reassigned. By the time its late write arrives, storage has seen the newer holder's higher token, so the write is rejected. The holder learns it lost the lock from the rejection.
The check has to be at storage, or wherever the protected resource lives. Checking in the client is not enough, because a stalled client checks and then stalls. The resource must be able to say no on its own.
Sources
- Martin Kleppmann (2016). How to do distributed locking.