32.2. Application State and Failover Correctness
Cluster software manages resources; clients experience a service. The gap between those two views is where failover bugs live. This section defines the correctness conditions that the rest of the chapter enforces with configuration and verifies with captured evidence.
32.2.1. Separating Virtual-IP Ownership, Process Health, and Data Consistency
Three facts must be true simultaneously for a single-writer service to be correctly served by exactly one host:
- Address ownership: the virtual IP answers ARP on exactly one host.
- Process health: the daemon is running and passing its monitor on that same host.
- Data consistency: the writable copy the process serves is the authoritative one, and no other host can write it.
Each fact can hold or fail independently. A keepalived instance can hold
the address while the service behind it has died. An nfsd can run on a node
whose DRBD resource was never promoted. A filesystem can be mounted
read-write on two nodes at once, and both services will look healthy right
up until the copies diverge. A failover procedure is only finished when all
three facts are verified on the new owner and refuted on the old one.
The cluster tools differ in which facts they couple. Pacemaker's groups and constraints are designed to couple all three: the address resource is ordered after the filesystem, which is colocated with the promoted DRBD instance, and the monitors keep watching each part. Keepalived couples the address to process liveness through tracking scripts, and to nothing else - it is the right tool when there is no writable state to protect, and the wrong one when there is. Section 32.9.6 returns to that boundary.
32.2.2. Database Primaries, Replication Lag, and Promotion Authority
A replicated database is the most demanding client of failover logic, because replication is usually asynchronous: a transaction can be acknowledged to the client before the standby has received it. If the primary then dies and the standby is promoted, the acknowledged transaction is gone - an RPO failure that no amount of speed in the failover can undo.
Promotion authority is the second problem. Some component must be able to say, once and finally, which copy becomes the new primary, and every other copy must accept that verdict. Two candidate authorities are quorum (the promoted copy must belong to the majority partition) and fencing (the old primary must be proven unable to write before anyone else is promoted). Both are needed: quorum without fencing can leave a stalled old primary still holding the write path, and fencing without quorum has no rule for which survivor to fence toward.
Chapter 34 builds a complete automated failover for PostgreSQL with Patroni, etcd quorum, leader leases, and watchdog-based fencing. The principles there are the same ones this chapter exercises on NFS: one writer, a witness with a vote, promotion only inside the majority, and verification of acknowledged writes after the switch. When an application uses a database for its state, the database layer should own these decisions; do not wrap a database primary in a generic filesystem-style cluster resource without replicating the database's own promotion logic.
32.2.3. Application Sessions, Client Retries, and Duplicate Operations
When a service moves, the interruption reaches the client first. What the client does during the gap determines whether the failover is a brief pause or a data incident.
An NFS client with a hard mount (the default, and what the walkthrough's client uses) blocks on every read and write while the server is unreachable, then continues when the address answers again. Nothing is lost and nothing needs retrying - at the cost of processes that hang until the service returns. A soft mount returns errors instead, which trades hung processes for application-level retry handling, and interrupting a hard mount has its own complications. The mount policy is a client decision, but the server design must support it: a stable virtual address and a stable NFSv4 identity (section 32.6.4) are what let a hard mount transparently survive.
HTTP clients retry on their own - browsers, curl, and SDKs all do - and a
load balancer removing a backend can cause the same request to execute
twice if the retry reaches a different backend. Operations must therefore be
idempotent, or the application must detect duplicates. The walkthrough's
ledger exercise makes the point concrete: after a failover and failback, the
client counts how many times its post-failover line appears in the file with
grep -c, and the correct answer is exactly one. The same check belongs in
any failover test plan: a retry that duplicated a write is a bug, even when
the service stayed "available".
Session state is the last piece. A stateless HTTP tier can fail over freely. A tier with in-memory sessions either pins clients to one backend (sticky sessions, which trade failure behavior for affinity), replicates its session store, or accepts a client-visible logout. Choose deliberately, because the load balancer cannot tell the difference.
32.2.4. Fencing Writers and Checking Application Data After Failover
The complete sequence for moving a single-writer service is a chain of guarantees, each of which removes one way the next step could corrupt data:
Figure 32.2. The failover sequence as a chain of guarantees. Fencing is the
step that converts "we lost contact with the old owner" into "the old owner
provably cannot write". The quorate partition's no-quorum-policy is the
parallel guarantee that a minority side stops instead of serving.
The chain explains what the rest of the chapter configures. Membership (Corosync) detects the failure but proves nothing about the failed node's behavior. Quorum decides which surviving group may act. Fencing - when it is configured - turns the old owner into a provably stopped machine before the new owner takes the write path. Ordering and colocation (Pacemaker) then promote, mount, start, and advertise in that order, stopping in reverse.
The last stage is the one administrators most often skip: verification from
an independent client. The cluster's own status output says the group is
Started on the new node; only a separate host reading, writing, checksum-
ing, locking, and counting duplicates establishes that the service is whole.
Section 32.6.5 performs each of those checks with captured results, and the
rule it follows applies everywhere: a failover is not complete because the
cluster says so; it is complete because a client that owes the cluster
nothing can confirm it.