Try
↑ ↓ move↵ openesc close

Locks, leases and fencing lab

Clients take a lease-based lock and write to storage. One stalls past its lease and writes anyway. Compare storage that trusts the lock with storage that checks a fencing token.

lease 1000 mswork ≈ 400 ms, then a 1500 ms stall on 25% of writesclocks run 0% slow

No fencing

Lock service. free

  • client 0idle0 ok
  • client 1idle0 ok
  • client 2idle0 ok

Storage. highest token seen 0 · last writer none

accepted
0
rejected
0
corrupting writes
0
    Corrupting writes accepted over time

    Waiting for data. Press play or step the simulation.

    What to try

    Each one sets up a starting point. Then make the change it describes.

    1. Trust the lock and get corrupted

      Run with no fencing and the defaults. Watch for a client that stalls, then look at the corrupting writes counter.

      Look for. The stalled client’s lease expires, the lock service hands the lock to the next client, which writes. Then the stalled client wakes and writes too. Storage has no way to tell the writes apart, so the older one lands on top of the newer one.

    2. Add fencing tokens

      Switch to Compare all storage rules. Both sides see the same clients, the same stalls and the same lock service.

      Look for. The lock service hands out a token that grows with every grant. Storage remembers the highest token it has seen and rejects anything lower. The corrupting counter on the fencing side stays at zero while the other side climbs.

    3. A lease longer than any stall

      Set the lease to 5000 ms with the stall still at 1500 ms.

      Look for. The lease outlasts the stall, so the lock is rarely reassigned under a client and corruption almost stops. But every time a client crashes while holding the lock, everyone else waits five seconds. Long leases buy safety with availability, and only until a longer stall shows up.

    4. The clock check that lies

      Set stalls to 0%, work to 900 ms with a 1000 ms lease, and clock drift to 15%. Then set drift back to 0 and compare.

      Look for. Clients check their own clock before writing. With a correct clock most late writes are caught and abandoned. With a slow clock the client believes it still has time, writes after the lease expired, and the count of writes accepted after expiry rises.

    5. More contention, more damage

      Raise clients to 6 with no fencing.

      Look for. More clients queue for the lock, so the moment a lease expires someone else takes it at once. Every stall now almost surely overlaps a newer holder’s write. Fencing turns each of those into a rejection instead of a corruption.

    New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.

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