Failover and split-brain
Overview
Failover changes the serving primary after failure; switchover is planned. A network partition cannot by itself prove a primary is dead. Split-brain occurs when multiple nodes accept conflicting writes as primary. Safe promotion requires an authority mechanism and fencing of the old writer, checking replica freshness and redirecting clients. Rejoining the old primary requires reconciliation or rebuilding, not blindly resuming writes.
First example
SELECT owner,epoch FROM ra_authority;Observed SQLite result (rows in JSON):
[ [ "primary", 7 ]]How it works
The single SQLite authority row stores owner and epoch; its trigger rejects writes from a stale owner or token. A transaction demonstrates promotion to B with epoch 8 and rollback. This is a centralized fencing invariant, not distributed consensus or a real failover procedure. In a distributed system all write paths must enforce fencing at the protected resource; a token checked only on the failed primary cannot protect a partitioned system.
Practical example
BEGIN;UPDATE ra_authority SET owner='B',epoch=8 WHERE singleton=1;INSERT INTO ra_write VALUES(1,'B',8,'accepted');SELECT node,epoch FROM ra_write;ROLLBACK;Observed SQLite result (rows in JSON):
[ [ "B", 8 ]]Practice and mistakes
Practice: predict acceptance of primary/7 after promotion to B/8. Hint 1: compare both owner and epoch. Hint 2: inspect the trigger. Never practice actual promotion against a production cluster; read-only role checks cannot prove global exclusivity.
PostgreSQL 17 example — NOT RUN
SELECT pg_is_in_recovery() AS in_recovery;Expected result, not executed: "True on a standby in recovery; false on a normal primary. This does not prove exclusive writer authority."