MySQL High Availability Framework - Part I
Tags: mysql, hosting, highavailability, database
Published: 2018-11-29 18:13:49

---
title: MySQL High Availability Framework - Part I
published: true
description: Part I. Learn what High Availability is, the components you need, and the MySQL Hosting HA Framework using semisynchronous replication, Corosync, and Pacemaker.
tags: MySQL, Hosting, High Availability, Database,
canonical_url: https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-1/
---
<link rel="canonical" href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-1/" />

<p style="text-align: justify;"><a href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-1/"><img class="alignnone wp-image-3681 size-full" src="https://scalegrid.io/blog/wp-content/uploads/2018/11/MySQL-High-Availability-Framework-Explained-Part-I-ScaleGrid-Blog.png" alt="MySQL High Availability Framework Explained – Part I - ScaleGrid Blog" width="100%" height="auto" /></a></p>
<p style="text-align: justify;">In this two-part blog series, we will explain the details and functionality of a High Availability (HA) framework for <a style="color: #2da964;" href="https://scalegrid.io/mysql.html" target="_blank">MySQL hosting</a> using MySQL 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. In Part I, we’ll walk you through the basics of High Availability, the components of an HA framework, and then introduce you to the HA framework for MySQL. <a style="color: #2da964;" href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-1/" target="_blank">MySQL High Availability Framework Explained – Part I
</a></p>

<h2 style="padding-top: 15px;">What is High Availability?</h2>
<p style="text-align: justify; padding-bottom: 10px;">The availability of a computer system is the percentage of time its services are up during a period of time. It’s generally expressed as a series of 9's. For example, the table below shows availability and the corresponding downtime measured over one year.</p>

<table style="height: auto;" border="1" width="500">
<tbody>
<tr>
<td style="text-align: center;"><b>Availability %</b></td>
<td style="text-align: center;"><b>Downtime Per Year</b></td>
</tr>
<tr>
<td style="text-align: center;">90% ("<b>one 9</b>")</td>
<td style="text-align: center;">36.53 days</td>
</tr>
<tr>
<td style="text-align: center;">99% ("<b>two 9s</b>")</td>
<td style="text-align: center;">3.65 days</td>
</tr>
<tr>
<td style="text-align: center;">99.9% ("<b>three 9s</b>")</td>
<td style="text-align: center;">8.77 hours</td>
</tr>
<tr>
<td style="text-align: center;">99.99% ("<b>four 9s</b>")</td>
<td style="text-align: center;">52.60 minutes</td>
</tr>
<tr>
<td style="text-align: center;">99.999% ("<b>five 9s</b>")</td>
<td style="text-align: center;">5.26 minutes</td>
</tr>
<tr>
<td style="text-align: center;">99.9999% ("<b>six 9s</b>")</td>
<td style="text-align: center;">31.56 seconds</td>
</tr>
</tbody>
</table>
<p style="text-align: justify; padding-top: 20px;">The meaning of High Availability varies depending on the requirements of your application and business.  For example, if you cannot afford a downtime of more than a few minutes per year in your service, we say that the service needs to have 99.999% High Availability.</p>

<h2 style="padding-top: 15px;">Components of an HA Framework</h2>
<p style="text-align: justify;">The essence of being highly available is the ability to instantaneously recover from failures that can happen in any part of a system. There are four highly essential components in any HA framework that need to work together in an automated fashion to enable this recoverability. Let’s review  these components in detail:</p>

<h3 style="padding-top: 10px; padding-left: 20px;">1. Redundancy in Infrastructure &amp; Data</h3>
<p style="text-align: justify; padding-left: 40px;">For a service to be highly available, we need to ensure that there is a redundancy in the infrastructure hosting as well as an up-to-date redundant copy of data the service uses or provides. This acts as a standby service ready to take over in case the primary is impacted by failures.</p>

<h3 style="padding-top: 10px; padding-left: 20px;">2. Failure Detection &amp; Correction Mechanism</h3>
<p style="text-align: justify; padding-left: 40px;">It’s extremely important to immediately detect any failures in any part of the primary system that may impact its availability. This will enable the framework to either take corrective actions on the same primary system, or failover the services to a standby system.</p>

<h3 style="padding-top: 10px; padding-left: 20px;">3. Failover Mechanism</h3>
<p style="text-align: justify; padding-left: 40px;">This component handles the responsibility to failover the services to your standby infrastructure. Please note that in case there are multiple redundant systems available, this failover mechanism component has to identify the most suitable system among those and promote it as the primary service.</p>

<h3 style="padding-top: 10px; padding-left: 20px;">4. Application/User Redirection Mechanism</h3>
<p style="text-align: justify; padding-left: 40px;">Once the standby systems have taken over as the primary, this component ensures that all of the application and user connections start happening to the new primary.</p>


<h2 style="padding-top: 15px;">The HA Framework for MySQL</h2>
<p style="text-align: justify;">Based on the above model, we use the following HA framework for our MySQL hosting at ScaleGrid:</p>

<ul>
	<li>A 3-Node Master-Slave setup using <a style="color: #2da964;" href="https://scalegrid.io/blog/data-integrity-and-performance-considerations-in-mysql-semisynchronous-replication/" target="_blank">MySQL semisynchronous replication</a> to provide infrastructure and data redundancy.</li>
	<li>The Corosync plus Pacemaker stack to provide failure detection, correction, and failover mechanism.</li>
	<li>A DNS mapping or Virtual IP component to provide the application and user redirection mechanism.</li>
</ul>
<p style="text-align: justify;">Check out the diagram below to visualize the software stack of this architecture:</p>
<p style="text-align: justify;"><a href="https://scalegrid.io/blog/mysql-high-availability-framework-explained-part-1/"><img class="alignnone wp-image-3681 size-full" src="https://mongodb.scalegrid.io/hubfs/Diagram-MySQL-High-Availability-Explained-Part-1.png" alt="MySQL High Availability Diagram of Software Stack Architecture" width="100%" height="auto" /></a>Let's review the functionality of some of the key components in this framework.</p>

<ol type="A">
	<li>
<h4>Corosync</h4>
<p style="text-align: justify;">Corosync provides a communication framework for the nodes with reliable message-passing between them. It forms a cluster ring of nodes, and keeps track of the nodes joining and leaving the cluster through cluster membership. Corosync closely works with Pacemaker to communicate about the node availability so that Pacemaker can take appropriate decisions.</p>
</li>
	<li>
<h4>Pacemaker</h4>
<p style="text-align: justify;">Also known as Cluster Resource Manager (CRM), Pacemaker ensures the high availability for MySQL running on the cluster and detects and handles node-level failures by interfacing with Corosync. It also detects and handles failures of MySQL by interfacing with the <a style="color: #2da964;" href="https://clusterlabs.org/components.html" target="_blank">Resource Agent</a> (RA). Pacemaker configures and manages the MySQL resource through start, stop, monitor, promote, and demote operations.</p>
</li>
	<li>
<h4>Resource Agent</h4>
<p style="text-align: justify;">The Resource Agent acts as an interface between MySQL and Pacemaker. It Implements start, stop, promote, demote, and monitor operations that are invoked by the Pacemaker.  There is a fully-functional Resource Agent called <a style="color: #2da964;" href="https://github.com/Percona-Lab/pacemaker-replication-agents/blob/master/agents/mysql_prm_gtid" target="_blank">Percona Replication Manager</a> (PRM) for MySQL implemented by Percona. This has been enhanced by ScaleGrid and is available on our <a style="color: #2da964;" href="https://github.com/Scalegrid/percona-pacemaker-agents/blob/master/agents/mysql_prm_semisync" target="_blank">GitHub page</a>.</p>
</li>
	<li>
<h4>DNS Mapping Component</h4>
<p style="text-align: justify;">The Resource Agent, on completing a successful failover, invokes this component which updates the DNS records of the master MySQL server with the IP address of the new master. Note that clients always use a master DNS name to connect with the MySQL server, and by managing the mapping of this DNS name to the IP address of the current master, we can ensure that clients do not have to change their connection strings or properties when there is a failover.</p>
</li>
</ol>
<p style="text-align: justify; padding-bottom: 20px;">In Part II of this blog series, you’ll learn about the critical data redundancy component which is achieved using MySQL semisynchronous replication. We’ll also dive deep into the semisynchronous replication details and configurations that we use to achieve our high availability support, and lastly, review various failure scenarios and the way the framework responds and recovers from these conditions.</p>