Distributed systemsfencing tokenstonithnode fencingepoch number

Fencing

Definition

Fencing is any mechanism that prevents a node which has lost its role from still changing shared state: a fencing token is a monotonically increasing number checked by the resource, and STONITH ("shoot the other node in the head") cuts power or access to the old node.

In practice

Timeouts cannot tell a dead node from a slow one. A process paused by garbage collection can wake up after its lock or leadership expired and write as if nothing happened. With fencing tokens, each new lock grant or leader term gets a higher number, and the storage layer rejects writes carrying a number lower than the highest it has seen.

Token fencing only works if the protected resource checks the token; a lock service alone cannot enforce it. STONITH-style node fencing is cruder but works for resources that cannot check tokens, such as a shared disk. Without some form of fencing, leases and locks are only advisory.

Example

Client A holds lock token 33 and pauses for 20 seconds; client B gets token 34 and writes. When A wakes up and writes with token 33, the storage service rejects it because it has already seen 34.