Try
↑ ↓ move↵ openesc close
In this lesson · topic 4 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 4

What a 5-second lease and a clock check buy

5 min read

These counts are simulator output for one seed, pinned by tests. Hover any of them to see the exact setup.

Trusting the lock

Three clients, a 1000 ms lease, about 400 ms of work per write, and a 1500 ms stall on a quarter of writes, for one minute on seed 7. Storage that trusts the lock accepts 17measured writes carrying a token older than one it had already seen, each of them landing on top of a newer holder’s data. Storage that checks the token accepts 0measured and rejects 17measured instead. Same clients, same stalls, same lock service.

A longer lease

Raise the lease to 5000 ms with the same stalls and corruption without fencing drops to 0measured, because a 1500 ms stall no longer outlasts the lease. The lock service expires 0measured leases in that minute against 23measured with the short lease. It looks like a fix until the first stall longer than five seconds. It also costs availability: when a holder crashes, everyone else waits up to five seconds for the lock. The problem has moved, not gone.

The clock check

Clients in the lab check their own clock before writing and give up if the lease looks spent. With no stalls, work close to the lease length and a correct clock, over six seeds that check abandons 129measured writes and storage still accepts 8measured after their lease had expired, because the write was in flight when the expiry passed. With client clocks running 15 percent slow, the same setup lets 72measured through. The check is only as good as the clock and as the gap between the check and the write.

What fencing does not fix

Fencing protects a resource that can compare tokens. It does nothing for a resource that cannot, and it does nothing for a write that was already sent to several resources with only some of them checking. It also does not make the operation atomic across resources: a client can write to storage A with a valid token and then be fenced at storage B, leaving half a change behind. That is a transaction problem, not a lock problem.

Fencing also assumes the token is monotonic across the lock service’s own failures. A lock service on one machine that restarts and reissues token 1 defeats it. That is why the service needs consensus underneath it.

What the model leaves out

The simulator uses one resource, writes that replace the whole value, and a lock service that never fails. Clients renew nothing and hold the lease for one write. Real clients renew leases in the background, hold them across many operations, and get told when their session expires, which closes some of the gaps the lab leaves open and opens others when the renewal itself is late.

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