Global Transactions Identifiers are one of the new features regarding replication in MySQL 5.6. They open up a lot of opportunities to make the life of DBAs much easier when having to maintain servers under a specific replication topology. However you should keep in mind some limitations of the current implementation. This post is the first one of a series of articles focused on the implications of enabling GTIDs on a production setup.
The manual describes very nicely how to switch to GTID-based replication, I won’t repeat it.
Basically the steps are:
- Make the master read-only so that the slaves can execute all events and be in sync with the master
- Change configuration for all servers and restart them
CHANGE MASTER TOto instruct all servers to use GTIDs
- Disable read-only mode
This procedure will switch all your servers from regular replication to GTID replication. But if you are running a production system, you will probably want to gradually enable GTID replication for an easier rollback in the event of a problem. And some items in the documentation are not so clear.
- Do we really need to restart all the servers at the same time? Downtime is something we like to avoid!
- Is it necessary to make the master read-only?
- Can we use regular replication for some slaves and GTID replication for other slaves at the same time?
To find an answer to these questions, let’s create a simple replication configuration with one master and two slaves, all running MySQL 5.6 with GTIDs disabled.
First try: configure only one of the servers with GTIDs
Let’s stop slave #2, change configuration and restart it:
mysql> show slave status\G [...] Slave_IO_Running: No Slave_SQL_Running: Yes [...]
The error log tells us why the IO thread has not started:
2013-05-17 13:21:26 3130 [ERROR] Slave I/O: The slave IO thread stops because the master has GTID_MODE OFF and this server has GTID_MODE ON, Error_code: 1593
So unfortunately if you want replication to work correctly, gtid_mode must be ON on all servers or OFF on all servers, but not something in the middle.
What if we try to reconfigure the master? This time, replication on slave #1 will stop:
2013-05-17 13:32:08 2563 [ERROR] Slave I/O: The slave IO thread stops because the master has GTID_MODE ON and this server has GTID_MODE OFF, Error_code: 1593
These simple tests answer the first two questions: replication works only if all servers have the same value for gtid_mode, so you should restart them at the same time, which is best done by making the master read-only. However, “at the same time” means “at the same binlog position”, so you can perfectly restart the servers one by one.
Second try: GTIDs enabled, mixing regular replication and GTID replication
This time, we will enable GTID replication on slave #1, but not on slave #2:
# slave #1 mysql> change master to master_auto_position = 1; mysql> start slave;
and let’s create a new table on the master:
mysql> create table test.t (id int not null auto_increment primary key);
SHOW TABLES FROM test on both slaves shows
that the table has been created everywhere. So once GTIDs are enabled on
all servers, you can have some slaves using file-based positioning and
some other slaves using GTID-based positioning.
This answers the second question: we can have different replication modes on different servers, but only if all servers have gtid_mode set to ON. Could it be interesting to run file-based replication when gtid_mode is ON? I can’t think of any use case, so in practice, you’ll probably use either file-based replication only (gtid_mode=off for all servers) or GTID-based replication only (gtid_mode=on for all servers).
Additional question: how can you know if a slave is using GTID-based replication by inspecting the output of
SHOW SLAVE STATUS? Look at the last field,
# Slave #1 mysql> show slave status\G [...] Auto_Position: 1 -> GTID-based positioning # Slave #2 mysql> show slave status\G [...] Auto_Position: 0 -> File-based positioning
Enabling GTID-based replication can be tricky if your application does not easily tolerate downtime or read-only mode, especially if you have a lot of servers to reconfigure. It would be really nice to be able to mix servers where gtid_mode is ON with servers where gtid_mode is OFF. This would greatly simplify the transition to GTID-based replication and allow easier rollbacks if something goes wrong.