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

Sessions, jeopardy and sequencers in a production lock service

7 min read

One lease for many locks

The lab gives a client a lease per lock. A real lock service avoids renewing hundreds of leases. In Chubby, each client has a session with the service, and every lock and handle it holds hangs off that session. The session has a lease. The client keeps it alive with KeepAlive calls, and when the lease dies, everything hanging off it dies with it.

The paper’s comparison with another system quotes a default lease of 12 s with KeepAlives exchanged about every 7 s. The master holds a KeepAlive call open until the lease is nearly spent, replies with an extended lease, and the client sends the next call straight away. So the lease is renewed well before it runs out.

The client’s own timer

The client keeps a local copy of the lease timeout, started when it sends the call. The paper assumes the master’s clock does not run faster than the client’s by more than a known constant factor. That keeps the client’s view conservative: it never believes the lease lasts longer than the master does.

If the local timeout passes with no reply, the client cannot tell whether the master is gone or the session has expired. It declares the session in jeopardy, empties its cache, and starts a grace period, 45 s by default. If a KeepAlive succeeds before the grace period ends, the session continues. If not, the session is treated as expired.

During a master failover this gives the new master time to appear. Without the grace period, a failover that takes 20 s would expire every session at once and every client would drop its locks and caches.

Predict first

A Chubby master fails and a new one is elected in 20 s. Session lease is 12 s, grace period 45 s. What happens to a client that was sending KeepAlives?

The application is told

The library raises a jeopardy event when the grace period begins, a safe event if the session survives, and an expired event if not. A well-written client stops issuing protected writes after jeopardy and resumes on safe. This closes part of the gap from the first topic: the client hears that its lease is in doubt instead of discovering it from a rejected write.

It does not close all of it. A client that is paused when the lease lapses never runs the code that reacts to the event.

Sequencers

For that case Chubby offers a sequencer. A lock holder asks for one right after acquiring the lock. It is an opaque string containing the lock’s name, the mode it was acquired in and the lock generation number. The client passes it along with requests to other servers, and the server checks that it is still valid, either against the lock service or against the most recent sequencer it has seen. This is the fencing token idea, with the lock’s name added so one server can protect many locks.

Lock-delay for servers that cannot check

Many servers will not be changed to check sequencers. For those, Chubby adds a lock-delay. If a lock is freed because its holder failed or became unreachable, the service refuses to grant it to anyone else for a period, up to one minute. Delayed or reordered requests from the old holder have time to drain. The paper calls this imperfect, but it protects unmodified servers from the everyday problems of message delay and restarts.

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