Leadership and failover¶
One replica runs a given reconcile loop at a time, decided by a named lease held in the control plane's own store. Failover is expiry and reacquisition rather than a negotiation between replicas.
The lease¶
lease_name the lease being contended for
owner_instance_id which replica holds it
lease_ttl_seconds how long a claim lasts
A replica claims or renews at the start of every cycle. One that does not hold
the lease returns not-leader and does nothing else that cycle.
Leader election can be disabled, in which case every eligible replica proceeds. That is a single-replica configuration rather than a way to run several.
Failover is expiry¶
flowchart TB
A["Leader renews each cycle"]
B["Leader stops renewing"]
C["Lease expires"]
D["Another replica claims it"]
E["It begins its own cycle"]
A --> B --> C --> D --> E
The lease record¶
flowchart LR
subgraph LR1["LEASE RECORD, in the store"]
direction TB
N1["lease_name"]
N2["owner_instance_id"]
N3["expiry, from lease_ttl_seconds"]
end
H["Holder"]
O["Every other replica"]
H ==>|"renews expiry each cycle"| LR1
O -.->|"reads expiry, claims once past"| LR1
The record is the only thing the replicas share. The holder writes the expiry forward, and the others only read it until it is in the past.
Nothing detects the old leader's absence directly. The lease lapses because it stopped being renewed, and the next replica to claim it becomes the leader.
The gap is bounded by the lease's life: a failed leader costs at most one lease
period of that loop's work, and requests are unaffected throughout because
api replicas hold no lease. A loop with its own lease is unaffected by
another loop's leader failing.
A replica stops between cycles, not mid-write¶
The claim happens at the start of a cycle, and the work of that cycle is bounded: each controller takes a limit and stops at it. A replica that loses leadership finishes or abandons a bounded cycle rather than being interrupted in the middle of an unbounded sweep.
The new leader then begins its own cycle from recorded state. See The controller manager.
What survives a failover¶
| State | Survives because |
|---|---|
| Queued dispatch items | The queue is durable, not in memory |
| Claimed dispatch items | Claims are recorded, with attempts |
| Assignment leases | They live with the assignment, not with the leader |
| Node registrations and cursors | Registrations are recorded in the store, and each node's assignment cursor is on its own volume |
| Run state | It is recorded before it is acted on |
Nothing about leadership is a place where work is held. A leader reads recorded state, advances it, and records the result, so a new leader has everything the old one had.
What a failover costs¶
One lease period of reconcile latency, and a partially completed cycle's work repeated. Because controllers reconcile toward a desired state rather than executing a script, repeating a cycle converges rather than duplicating.
An assignment already claimed by a node is unaffected: the node is executing it and its lease is independent of who leads the control plane.
Diagnosing a quiet control plane¶
A control plane that is not reconciling is answering one of two things, and both name themselves:
service-role-skip this replica's role does not run the phase
not-leader another replica holds the lease
Reading leadership status says which replica is the leader and when its lease expires. See HA topology.