MySQL High Availability Framework Explained – Part III: Failover Scenarios
Tags: mysql, highavailability, sql, database
Published: 2019-04-16 14:38:51

---
title: MySQL High Availability Framework Explained – Part III: Failover Scenarios
published: true
description: Learn how the ScaleGrid MySQL high availability framework recovers from these 3 failover scenarios, master goes down, slave goes down, and split-brain scenario
tags: MySQL, High Availability, SQL, Database,
canonical_url: https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-3/
---
<link rel="canonical" href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-3/" />

<a href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-3/"><img src="https://scalegrid.io/blog/wp-content/uploads/2019/04/MySQL-High-Availability-Explained-Part-3-ScaleGrid-Blog.jpg" alt="MySQL High Availability Framework Explained – Part III: Failover Scenarios | ScaleGrid Blog" style="width:100%; height:auto;"></a>
<p style="text-align: justify;">In this three-part blog series, we introduced a <a style="color: #2da964;" href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-1/" target="_blank">High Availability (HA) Framework</a> for <a style="color: #2da964;" title="Fully managed MySQL hosting" href="https://scalegrid.io/mysql.html" target="_blank">MySQL hosting</a> in Part I, and discussed the details of <a style="color: #2da964;" href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-2/" target="_blank">MySQL semisynchronous replication</a> in Part II. Now in Part III, we review how the framework handles some of the important <a style="color: #2da964;" href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-3/" target="_blank">MySQL failure scenarios</a> and recovers to ensure high availability.</p>

<h2 style="padding-top: 15px;">MySQL Failover Scenarios</h2>
<h3 style="padding-top: 15px;">Scenario 1 - Master MySQL Goes Down</h3>
<ul>
	<li style="text-align: justify; padding-bottom: 10px;">The <a style="color: #2da964;" href="https://clusterlabs.org/corosync.html" target="_blank">Corosync</a> and <a style="color: #2da964;" href="https://clusterlabs.org/pacemaker/" target="_blank">Pacemaker</a> framework detects that the master MySQL is no longer available. Pacemaker demotes the master resource and tries to recover with a restart of the MySQL service, if possible.</li>
	<li style="text-align: justify; padding-bottom: 10px;">At this point, due to the <a style="color: #2da964;" href="https://scalegrid.io/blog/data-integrity-and-performance-considerations-in-mysql-semisynchronous-replication/" target="_blank">semisynchronous nature of the replication</a>, all transactions committed on the master have been received by at least one of the slaves.</li>
	<li style="text-align: justify; padding-bottom: 10px;">Pacemaker waits until all the received transactions are applied on the slaves and lets the slaves report their promotion scores. The score calculation is done in such a way that the score is ‘0’ if a slave is completely in sync with the master, and is a negative number otherwise.</li>
	<li style="text-align: justify; padding-bottom: 10px;">Pacemaker picks the slave that has reported the 0 score and promotes that slave which now assumes the role of master MySQL on which writes are allowed.</li>
	<li style="text-align: justify; padding-bottom: 10px;">After slave promotion, the <a style="color: #2da964;" href="https://clusterlabs.org/components.html" target="_blank">Resource Agent</a> triggers a DNS rerouting module. The module updates the proxy DNS entry with the IP address of the new master, thus, facilitating all application writes to be redirected to the new master.</li>
	<li style="text-align: justify; padding-bottom: 10px;">Pacemaker also sets up the available slaves to start replicating from this new master.</li>
</ul>
<p style="text-align: justify;">Thus, whenever a master MySQL goes down (whether due to a MySQL crash, OS crash, system reboot, etc.), our HA framework detects it and promotes a suitable slave to take over the role of the master. This ensures that the system continues to be available to the applications.</p>

<h3 style="padding-top: 15px;">Scenario 2 - Slave MySQL Goes Down</h3>
<ul>
	<li style="text-align: justify; padding-bottom: 10px;">The Corosync and Pacemaker framework detects that the slave MySQL is no longer available.</li>
	<li style="text-align: justify; padding-bottom: 10px;">Pacemaker tries to recover the resource by trying to restart MySQL on the node. If it comes up, it is added back to the current master as a slave and replication continues.</li>
	<li style="text-align: justify; padding-bottom: 10px;">If recovery fails, Pacemaker reports that resource as down - based on which alerts or notifications can be generated. If necessary, the ScaleGrid <a style="color: #2da964;" href="mailto:support@scalegrid.io" target="_blank">support team</a> will handle the recovery of this node.</li>
	<li style="text-align: justify; padding-bottom: 10px;">In this case, there is no impact on the availability of MySQL services.</li>
</ul>
<h3 style="padding-top: 15px;">Scenario 3 - Network Partition - Network Connectivity Breaks Down Between Master and Slave Nodes</h3>
<p style="text-align: justify;">This is a classical problem in any distributed system where each node thinks the other nodes are down, while in reality, only the network communication between the nodes is broken. This scenario is more commonly known as split-brain scenario, and if not handled properly, can lead to more than one node claiming to be a master MySQL which in turn leads to data inconsistencies and corruption.</p>
<p style="text-align: justify;">Let’s use an example to review how our framework deals with split-brain scenarios in the cluster. We assume that due to network issues, the cluster has partitioned into two groups - master in one group and 2 slaves in the other group, and we will denote this as [(M), (S1,S2)].</p>

<ul>
	<li style="text-align: justify; padding-bottom: 10px;">Corosync detects that the master node is not able to communicate with the slave nodes, and the slave nodes can communicate with each other, but not with the master.</li>
	<li style="text-align: justify; padding-bottom: 10px;">The master node will not be able to commit any transactions as the semisynchronous replication expects acknowledgement from at least one of the slaves before the master can commit. At the same time, Pacemaker shuts down MySQL on the master node due to lack of quorum based on the Pacemaker setting ‘no-quorum-policy = stop’. Quorum here means a majority of the nodes, or two out of three in a 3-node cluster setup. Since there is only one master node running in this partition of the cluster, the no-quorum-policy setting is triggered leading to the shutdown of the MySQL master.</li>
	<li style="text-align: justify; padding-bottom: 10px;">Now, Pacemaker on the partition [(S1), (S2)] detects that there is no master available in the cluster and initiates a promotion process. Assuming that S1 is up to date with the master (as guaranteed by semisynchronous replication), it is then promoted as the new master.</li>
	<li style="text-align: justify; padding-bottom: 10px;">Application traffic will be redirected to this new master MySQL node and the slave S2 will start replicating from the new master.</li>
</ul>
<p style="text-align: justify;">Thus, we see that the MySQL HA framework handles split-brain scenarios effectively, ensuring both data consistency and availability in the event the network connectivity breaks between master and slave nodes.</p>
<p style="text-align: justify; padding-bottom: 15px;">This concludes our 3-part blog series on the MySQL High Availability (HA) framework using semisynchronous replication and the <a style="color: #2da964;" href="https://clusterlabs.org/corosync.html" target="_blank">Corosync</a> plus <a style="color: #2da964;" href="https://clusterlabs.org/pacemaker/" target="_blank">Pacemaker</a> stack. At ScaleGrid, we offer highly available hosting for <a style="color: #2da964;" href="https://scalegrid.io/mysql/aws.html" target="_blank">MySQL on AWS</a> and <a style="color: #2da964;" href="https://scalegrid.io/mysql/azure.html" target="_blank">MySQL on Azure</a> that is implemented based on the concepts explained in this blog series. Please visit the <a style="color: #2da964;" href="https://console.scalegrid.io/users/register" target="_blank">ScaleGrid Console</a> for a free trial of our solutions.</p>