Try
↑ ↓ move↵ openesc close
In this lesson · topic 1 of 7
  1. 1. The lock that lies
  2. 2. Leases and fencing tokens
  3. 3. Trusting storage against token storage
  4. 4. What a 5-second lease and a clock check buy
  5. 5. When the lock's safety depends on the clock
  6. 6. Sessions, jeopardy and sequencers in a production lock service
  7. 7. Check the stale write

Topic 1

The lock that lies

4 min read

Why locks expire

A distributed lock stops two clients from touching the same resource at once. The first design is a lock that lasts until its holder releases it. Then the holder crashes. Nobody can release it, and everyone waits forever.

So locks come with an expiry. The holder gets a lease: the right to act for a fixed time, renewable while it is alive. A crashed holder’s lease runs out on its own and the next client gets in. Gray and Cheriton described leases in 1989 for file cache consistency, as a right that fails safe when its holder disappears.

The expiry solves the crash. It opens a different hole.

The hole

A client acquires the lease, does its work, and is about to write. Then it stalls. A garbage collection pause, a page swapped out to disk, a virtual machine frozen for migration, a disk that takes a second to answer. The lease expires at the lock service while the client is stalled. The service cannot tell a stalled client from a dead one, so it gives the lock to the next client, which does its work and writes.

The first client wakes up. From its point of view no time has passed. It sends the write it had ready. Storage accepts it, because storage was never told anything about leases, and the first client’s stale data lands on top of the second client’s.

Predict

The lab runs three clients against one lock and one storage. A quarter of writes are hit by a 1500 ms stall against a 1000 ms lease.

Predict first

Over a minute, what does storage look like if it simply trusts whoever writes?

What the numbers look like

In that setup, seed 7, storage that trusts the lock accepts 17measured writes that land on top of a newer holder’s write, out of 96measured accepted in total, and the lock service expires 23measured leases under stalled clients. The next topic shows the one-number fix.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms