Q: How do you troubleshoot and recover from a Galera cluster split-brain state in MariaDB?
MariaDB interview questions on Galera split-brain: read wsrep status, restore quorum with pc.bootstrap, add garbd, and bootstrap from the most advanced node safely.
Want to master this scenario in a live sandbox? KodeKloud's PostgreSQL Database Administration & High Availability Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: When a panel asks mariadb interview questions about Galera split-brain, they want to hear that I protect data first and restore availability second. Galera uses quorum voting: a component stays Primary only if it holds more than half of the cluster weight. After a network partition, the minority side flips to Non-Primary and refuses queries with 'WSREP has not yet prepared node for application use'. That refusal is the safety mechanism doing its job. My job is to find which side holds the real data, promote exactly one component, and let the rest rejoin through IST or SST.
Read the cluster state on every node before touching anything
I connect to each node and compare wsrep_cluster_status, wsrep_cluster_size, wsrep_local_state_comment and wsrep_ready. A healthy node reports Primary and Synced. A node cut off from the majority reports Non-Primary and usually a cluster size of 1. If two halves both think they are the survivors, I never run bootstrap commands on both sides, because that creates two diverging histories that cannot be merged.
mariadb -e "SHOW GLOBAL STATUS WHERE Variable_name IN ('wsrep_cluster_status','wsrep_cluster_size','wsrep_cluster_conf_id','wsrep_local_state_comment','wsrep_ready','wsrep_cluster_state_uuid');"
# Example output from the isolated node (illustrative)
# wsrep_cluster_status Non-Primary
# wsrep_cluster_size 1
# wsrep_local_state_comment Initialized
# wsrep_ready OFF
Confirm it is a network partition and decide which component has quorum
I check the error log for 'view(view_id(NON_PRIM' lines and test connectivity on the Galera ports 4567, 4568 and 4444 between nodes. In a 3-node cluster, a 2+1 split leaves the pair Primary automatically, so only the single node needs attention once the network heals. In a 2+2 split, or a 2-node cluster, neither side has more than half, so both go Non-Primary and I have to pick a side by hand.
sudo grep -E 'NON_PRIM|PRIMARY|Quorum results|view\(' /var/log/mysql/error.log | tail -20
for h in 10.0.1.12 10.0.1.13; do
for p in 4567 4568 4444; do nc -zv -w2 $h $p; done
done
Force one surviving component back to Primary with pc.bootstrap
On one node of the component that has the most recent data, I promote it with pc.bootstrap. This tells the group communication layer to form a new Primary component from the nodes currently visible to it. I run it on a single node only. Other nodes in the same component follow, and nodes on the other side rejoin after the network heals, taking IST if the gcache still covers their gap or a full SST if it does not.
mariadb -e "SET GLOBAL wsrep_provider_options='pc.bootstrap=YES';"
# Verify the component is Primary again
mariadb -e "SHOW STATUS LIKE 'wsrep_cluster_status';"
# wsrep_cluster_status Primary
Prevent the next split with an odd voter count and garbd
If budget allows only two data nodes, I add a Galera Arbitrator. garbd joins the cluster as a voter with no data, so a 2+1 vote survives one failure. It must sit in a third failure domain, otherwise it dies together with one of the data centers. It stores nothing, but it does receive replication traffic, so I place it where bandwidth is acceptable.
garbd --group my_galera_cluster --address 'gcomm://10.0.1.11,10.0.1.12' --log /var/log/garbd.log --daemon
# Cluster size should now count the arbitrator
mariadb -e "SHOW STATUS LIKE 'wsrep_cluster_size';"
# wsrep_cluster_size 3
Full outage: bootstrap from the most advanced node using grastate.dat
When every node is down, I read grastate.dat on each one. A clean shutdown leaves a real seqno and safe_to_bootstrap: 1 on the last node to stop. After a crash, seqno shows -1 and I run mysqld --wsrep-recover to read the last committed position from InnoDB. I bootstrap from the node with the highest seqno, set safe_to_bootstrap: 1 only there, and start the rest normally.
sudo cat /var/lib/mysql/grastate.dat
# uuid: 5f2a1c3e-0000-0000-0000-000000000000
# seqno: -1
# safe_to_bootstrap: 0
sudo -u mysql mysqld --wsrep-recover 2>&1 | grep 'Recovered position'
# WSREP: Recovered position: 5f2a1c3e-0000-0000-0000-000000000000:48213
# On the node with the highest seqno only
sudo sed -i 's/safe_to_bootstrap: 0/safe_to_bootstrap: 1/' /var/lib/mysql/grastate.dat
sudo galera_new_cluster
# Then on the others
sudo systemctl start mariadb
- Galera keeps a Primary component only while it holds more than half the votes, so a partition leaves the minority side in Non-Primary and refusing queries.
- I compare wsrep_cluster_status and wsrep_cluster_size on every node, then run SET GLOBAL wsrep_provider_options='pc.bootstrap=YES' on exactly one node of the component with the freshest data.
- After a full crash I read grastate.dat, use mysqld --wsrep-recover when seqno is -1, and bootstrap from the highest position with safe_to_bootstrap set to 1.
- To stop it recurring I run an odd number of voters and place a garbd arbitrator in a third failure domain.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Running pc.bootstrap=YES on nodes of both halves Two Primary components form with separate histories. Rejoining then forces a full SST that overwrites one side and silently discards its writes.
- Forcing safe_to_bootstrap: 1 on whichever node starts first If that node is not the most advanced, every later node takes a state transfer from stale data and committed transactions are lost.
- Running a two-node Galera cluster with no arbitrator Any single failure or link loss leaves no majority, so the whole cluster goes read-refusing and needs manual intervention.
- Placing garbd in the same rack or zone as one data node A zone failure removes a data node and the arbitrator together, so quorum is lost anyway.