Why and How to Implement Galera Cluster for MySQL

by Oct 8, 2019

There are three types of replication that people in the MySQL and MariaDB Server world care about: asynchronous (the default), semi-synchronous, and virtually synchronous. Asynchronous replication is fast, because changes are sent to a primary (master) node, with no guarantee that it is written to a secondary (slave) node, and sometimes you have slave lag. However, it is also the easiest to setup and fastest to get going. There is also semi-synchronous replication to ensure that at least one secondary receives the transaction; this of course increases the commit time, as there is network round-trip time that has to be taken into consideration. With a framework to handle automatic failovers, this can be used at large scale Internet sites.

 The replication we are focusing on is multi-primary, virtually synchronous replication, where all nodes contain the same data, and you do not need a framework to handle any kinds of failures as this is all built-in. The primary purpose of multi-primary (multi-master) replication is increased High Availability and faster server response times. Keep in mind that all members of the cluster are responsive to client read and write queries.

 Does multi-primary solve everything? It solves many problems but naturally also has some tradeoffs so require some additional design constraints. Deploy it when it solves your problems, ensure that your schema has no hot rows, and you will really enjoy its capabilities over regular replication. Galera Cluster provides for shared nothing storage, consistency & isolation (ACID preserved), no geographic limitations, prevents data conflicts, (virtually) synchronous commits across nodes, and is generally transparent to the application.

 What is Galera replication? It is a generic replication plugin for database servers. You can get it distributed via Codership, at GaleraCluster.com (MySQL 5.5, 5.6 and 5.7 is available currently, with 8.0 in the final stages of being released), via MariaDB Server built-in (MariaDB 10.4 also includes Galera version 4, compared to previous releases with 3), or via Percona XtraDB Cluster (PXC) (5.6, 5.7 with Galera 3). It has won the MySQL Community Award of the Year 2014, and has thousands of users and is also included in many mainstream Linux distributions. Naturally Galera Cluster is also optimized to run in cloud based environments.

 Migrating to Galera Cluster is a straightforward process: attach a Galera Cluster node to your current asynchronous setup of primaries and secondaries, build up the cluster to the desired size (so have 3 nodes), then switch over the readers to read from the cluster, then switch over the writers to write to the cluster, and now you're in a situation where you can turn off and deactivate the asynchronous replication setup altogether.

 There are of course some things that you will consider when you are migrating to Galera Cluster from regular replication. For one, make sure that all your tables have a primary key. Ensure you are only using InnoDB as a storage engine of choice. Make sure you don't need distributed transaction (XA) support. Do not use LOCK/UNLOCK TABLES. Always beware high concurrency hot rows and use `wsrep_retry_autocommit=n`. There are of course more, and you could contact Codership for a little consulting!

Idera has a product, SQL Diagnostic Manager for MySQL (formerly known as ‘Monyog’), that can help you before, during, and after your migration to Galera Cluster!

First, you can use this tool for ensuring that all of your nodes are configured identically. A simple screen allows you to compare MySQL configurations across multiple servers.

Second, out-of-the-box monitors are configured to warn you of bad practices or bad behaviors during your set-up or running of Galera Clusters. These monitors can notify you (via email, Slacker, PagerDuty, or SNMP traps) of failed nodes, throttling, or latency in your cluster.

Third, dashboards give you real-time visibility into the performance of your MySQL instances and the health of your Galera Cluster. 

Idera’s SQL Diagnostic Manager for MySQL and MariaDB is available for a free, fully functional 14-day trial. You can get more information and download your trial here. Whether you are using or considering moving to Galera, or if you just a MySQL DBA, it’s well worth checking out.

Overall, we hope you enjoy investigating and deploying Galera Cluster in production and enjoy your multi-primary database setup!

View the webinar replay here: