A lease grants temporary authority. Expiry changes what the coordinator knows, but a process paused by the operating system cannot observe that change until it resumes. Worse, a request sent before expiry can spend longer than the lease in a network queue. Even perfect handling of the local expiry event cannot recall that request.
The storage service checks the fencing token
After the lease changes hands, the new worker writes with token 8. Storage records 8 as the highest accepted generation.
Why it exists
Imagine a print shop where each editor can publish a new cover. Replacing the editor at the front desk will do little if the printer still accepts jobs from the old editor. The printer must recognize which generation a job belongs to.
View diagram · Publication authorityThe stored fence rejects seven after eight. Full size
Words to know
Lease
A time-limited grant of authority.
Fencing token
An ordered generation a resource can compare against prior owners.
How it works
Step through the idea, or press Play.
Step 1 of 3
Issue generations. Give each new owner an increasing token from a coordinator that orders ownership changes. A timestamp from a worker’s local clock cannot establish that order.
Check at the resource. Store the largest accepted generation with the manifest. Compare the token and update the manifest together. Every mutation path must pass through this check.
Order within a generation. A fence separates owners. If the same owner can issue overlapping updates, add a manifest version check as well. Otherwise its older request can overtake its newer request.
Understand it
Start here
Two editors share a press
A printing press accepts covers from whichever editor owns the current edition. Follow the envelope that editor A sends late, after editor B has already delivered a replacement.
Two editors share a press
Compare and write at the destination.
Structure
Publication authority
Publication authority
The stored fence rejects seven after eight.
The paused publisher
Issue token 7 to A and suspend it just before publication. Let B publish a new manifest with token 8. Resume A. Read the manifest after A’s write attempt: it must still contain B’s contents and token 8. A health check on A would miss this failure.
If storage reads the latest token, releases a lock, and later writes the contents, an older writer can slip between those operations. Put the comparison and mutation in one conditional write. The fence must survive restart with the contents it protects. If a restored store forgets its accepted generation, queued requests from old owners become dangerous again.
A fence has a precise boundary
An increasing token protects a resource once it has observed the newer generation. Merely issuing token eight at the coordinator does not tell a separate store about it. A system requiring immediate revocation needs a stronger coordination path. For ordinary handoff, make installation of the new generation part of the takeover before relying on its effects.
Guard the publication
Compare and write at the destination.
Check before sending
A packet can be delayed after the check.
Summary
The whole topic in one minute.
Ownership changes at the coordinator. Protection takes effect at the resource that checks and persists the generation.