How to MySQL 5.6 MTS? Some tips and tests…
In terms of new features, MTS extrapolate conceptually all the expectations seeing that it is a feature that will elevate (or at leaf will try it) all the stress that we’ve been seeing for years, having a slave server behind master in some way, files or seconds. The first thing that blink on my mid is the red mark I used to have on my personal server’s dashboard control which has called out my attention always when a slave server hangs while the master still working well. Many of time, I’ve seeing IO problems that will make slave hangs within the relay log rotation time or when executing a long report – at least four times a day, I must go and check what’s going on. BTW, due to all of that I believe that the exchange the model of single-thread for that with multiples threads will elevate the problem – I hope to have the slave servers not hanging too much anymore.
Having said that, I’ve been seeing some cases in which after implementing the MySQL 5.6 in production, properly adjusting the worker threads variable (slave_parallel_wrokers) and starting the slave, not often it’s being worked as promised. The first action when it’s not working properly is to check all the necessary configuration to get it working well, it’s not just raise up the previous mentioned and put it to run – you make sure about some small details:
- make sure the master and slaves are MySQL 5.6++, there some information shipped with binary log events which will be read by the slaves, being executed by more than once thread (slave_parallel_threads > 1);
- make sure slave_parallel_threads is configured with a value > 1;
- make sure to enable Crash-Safe Replication to make it more reliable, adding master_info_repository = TABLE, relay_log_info_repository = TABLE and relay_log_recovery = ON to my.cnf file;
- it’s going to work with binlog_format as statement or row;
There is no problem in using the bin log format as statement or row, both formats will work well since on both one can observe the entries on binary log file of all the necessary information for the workers. Another advice is that, once you’ve started MySQL replicating in a crash-safe mode, it’s not possible to alter dynamically the repositories for relay and master info on runtime for a busy server due to the workers info being stored on tables and if you change this information’s location, workers might be a little bit out of reference.
First of all, I did a test considering a customer environment where they’re running a MySQL 5.5.37 on all the master and slave servers. the strategy is to replace slave servers until we hit the master, doing finally a switchover to another server in order to upgrade the master server to MySQL 5.6 – a normal and reasonable strategy to avoid risks on production. If you get a error on any project step, time will be welcomed to study a little bit more what’s happening and then, take another step towards another task. Another point to take into account is the old_passwords (removed in 5.7) that is still available in 5.6 and must be used when users in mysql.user table remain using 16-bytes passwords. It’s a good maneuver while updating all the account’s passwords to keep old_passwords=1 configuration to give sometime to map all the accounts used by the applications to avoid problems with access denied (while taking with account’s passwords updates, configure log_warnings=2 to get all the login failed attempts and try to correct it).
Test Scenario: confirming that mysql 5.5 (master) and mysql 5.6 (slave) does not replicate with mts
As this is the scenario I’ve been see as much on many of customers I’ve visited, I decided to spend sometime and stress the possibilities around the MTS replication having a 5.5 master and a new comer, mysql 5.6 as slave. Some discussions on the internet made me believe that at some level of configuration this scenario will become possible – but, it’s not supported. After speaking to guys on MySQL Central, we discussed a lot many scenarios but some high level guys known as developers said that 5.6 used to ship some additional information on binary logs and then, the mts on slave get to know how to proceed splitting up queries (binlog_format=statement) or updates (binlog_format=row) by workers (threads) – this job is done actually by a coordinator that is a thread as well that executes stuff read from the relay logs on slave side. BTW, this all I’ve got to know after testing the environment which I raised up using Vagrant as below.
Files you’ll need to create/copy/paste – make sure you have a centos65-x86_64 box added on your vagrant boxes or alter the value of mysql55.vm.box and mysql56.vm.box in Vagrantfile configs.
wagnerbianchi02:mysql55_and_mysql56 root# ls -lh total 24 drwxr-xr-x 3 root wheel 102B Oct 6 12:53 .vagrant -rw-r--r-- 1 root wheel 760B Oct 6 12:53 Vagrantfile -rw-r--r-- 1 root wheel 681B Oct 6 12:52 setup_env55.sh -rw-r--r-- 1 root wheel 343B Oct 6 12:42 setup_env56.sh
Vagrantfile, which you can just copy/paste:
# -*- mode: ruby -*- # vi: set ft=ruby : file_to_disk = './tmp/galera_disk.vdi' # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.define "mysql55" do |mysql55| mysql55.vm.box = "centos65-x86_64" mysql55.vm.network :"private_network", virtualbox__intnet: "mysql55_and_mysql56", ip: "192.168.50.100" mysql55.vm.provision "shell", path: "setup_env55.sh" end config.vm.define "mysql56" do |mysql56| mysql56.vm.box = "centos65-x86_64" mysql56.vm.network :"private_network", virtualbox__intnet: "mysql55_and_mysql56", ip: "192.168.50.101" mysql56.vm.provision "shell", path: "setup_env56.sh" end end
If you get an error like this below, review the boxes you’ve got added to your Vagrant boxes:
wagnerbianchi01:mysql55_and_mysql56 root# vagrant up Bringing machine 'mysql55' up with 'virtualbox' provider... Bringing machine 'mysql56' up with 'virtualbox' provider... ==> mysql55: Box 'centos65-x86_64' could not be found. Attempting to find and install... mysql55: Box Provider: virtualbox mysql55: Box Version: >= 0 ==> mysql55: Adding box 'centos65-x86_64' (v0) for provider: virtualbox mysql55: Downloading: centos65-x86_64 An error occurred while downloading the remote file. The error message, if any, is reproduced below. Please fix this error and try again. Couldn't open file /opt/vagrant_projects/mysql55_and_mysql56/centos65-x86_64
Setup scripts that you can use to create others machines:
#!/usr/bin/env bash
#: script name: setup_env55.sh
#
sudo echo "nameserver 8.8.8.8" > /etc/resolv.conf
sudo echo "nameserver 8.8.4.4" >> /etc/resolv.conf
sudo yum -y install wget vim
sudo yum -y remove mysql-libs-5.1.71-1.el6.x86_64
sudo rpm -Uvi https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
sudo wget http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-5.5.39-2.el6.x86_64.rpm-bundle.tar
sudo tar xvf MySQL-5.5.39-2.el6.x86_64.rpm-bundle.tar
sudo rpm -ivh install MySQL-{server,shared,client}*
sudo /etc/init.d/mysql start
#!/usr/bin/env bash
#: script name: setup_env56.sh
#
sudo echo "nameserver 8.8.8.8" > /etc/resolv.conf
sudo echo "nameserver 8.8.4.4" >> /etc/resolv.conf
sudo yum -y install wget vim
sudo rpm -Uvi https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
sudo yum-config-manager --enable mysql56-community
sudo yum -y install mysql-server
sudo service mysqld start
Following this so is the command vagrant up and machines up & running.
wagnerbianchi01:mysql55_and_mysql56 root# vagrant status Current machine states: mysql55 running (virtualbox) mysql56 running (virtualbox) This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`.
Setting up additional things like classic or GTID replication (where once can do using MySQL Utilities), it’s going to be possible to execute the tests. In addition of regular and initial variables the come mainly with the 5.5 configuration file, on 5.6 I added the server_id, server_id=200, slave_worker_threads = 2, master_info_repository = TABLE, relay_log_info_repository = TABLE and relay_log_recovery = ON, for Crash-Safe Replication configurations as the 5.6 will be the slave.
mysql> mysql> select @@server_id, @@slave_parallel_workers, @@master_info_repository, -> @@relay_log_info_repository, @@master_info_repository, @@relay_log_recovery\G *************************** 1. row *************************** @@server_id: 200 @@slave_parallel_workers: 2 @@master_info_repository: TABLE @@relay_log_info_repository: TABLE @@master_info_repository: TABLE @@relay_log_recovery: 1 1 row in set (0.00 sec)
Checking the replication status:
Slave_IO_Running: Yes Slave_SQL_Running: Yes
Now, the test proposed on the Luis’ blog sometime ago to explain MTS is, on the master server:
mysql> create database db1; create database db2; Query OK, 1 row affected (0.00 sec) Query OK, 1 row affected (0.00 sec)
On slave side, check the content of the table mysql.slave_worker_info – this table will register all the movement around the MTS replication. Below you can see that, as we haven’t executed anything directly on databases yet, threads haven’t worked yet.
mysql> select * from mysql.slave_worker_info\G *************************** 1. row *************************** Id: 1 Relay_log_name: Relay_log_pos: 0 Master_log_name: Master_log_pos: 0 Checkpoint_relay_log_name: Checkpoint_relay_log_pos: 0 Checkpoint_master_log_name: Checkpoint_master_log_pos: 0 Checkpoint_seqno: 0 Checkpoint_group_size: 64 Checkpoint_group_bitmap: *************************** 2. row *************************** Id: 2 Relay_log_name: Relay_log_pos: 0 Master_log_name: Master_log_pos: 0 Checkpoint_relay_log_name: Checkpoint_relay_log_pos: 0 Checkpoint_master_log_name: Checkpoint_master_log_pos: 0 Checkpoint_seqno: 0 Checkpoint_group_size: 64 Checkpoint_group_bitmap: 2 rows in set (0.00 sec)
Coming back on the master, enter some inserts:
mysql> create table db1.t1(a int); create table db2.t1(a int); Query OK, 0 rows affected (0.01 sec) Query OK, 0 rows affected (0.00 sec) mysql> insert into db1.t1 values (1),(2),(3); insert into db2.t1 values (1),(2),(3); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0
And then, we again go over mysql.slave_worker_info to check if those two listed threads have worked or not:
mysql> select * from mysql.slave_worker_info\G *************************** 1. row *************************** Id: 1 Relay_log_name: ./mysqld-relay-bin.000002 Relay_log_pos: 1171 Master_log_name: master-bin.000001 Master_log_pos: 1007 Checkpoint_relay_log_name: ./mysqld-relay-bin.000002 Checkpoint_relay_log_pos: 797 Checkpoint_master_log_name: master-bin.000001 Checkpoint_master_log_pos: 633 Checkpoint_seqno: 1 Checkpoint_group_size: 64 Checkpoint_group_bitmap: *************************** 2. row *************************** Id: 2 Relay_log_name: Relay_log_pos: 0 Master_log_name: Master_log_pos: 0 Checkpoint_relay_log_name: Checkpoint_relay_log_pos: 0 Checkpoint_master_log_name: Checkpoint_master_log_pos: 0 Checkpoint_seqno: 0 Checkpoint_group_size: 64 Checkpoint_group_bitmap: 2 rows in set (0.00 sec)
Just one thread working!! Yes, we confirmed that this does not work when you have a master on 5.5 and slaves on 5.6, regardless of the binlog_format and bla bla bla. A good point for a discussion at this point is that MySQL 5.6 has received lots of improvements regarding its engine, many other related with InnoDB and many others on many other things. Maybe it’s a good time to start upgrading 5.5 to 5.6 on slaves until we hit the master and then, upgrade all the database machines, even having MySQL 5.6 MTS disable for this moment.
Test Scenario: confirming that mysql 5.6 (master) and mysql 5.6 (slave) replicates with mts, even with binlog_format=statement
To make this new test, we just need to remove the 5.5’s RPM packages and add 5.6 from the repository and then, start slave. The final step is to execute the tests again and check the mysql.slave_worker_info table’s content on slave server.
[root@mysql55 ~]# service mysql stop Shutting down MySQL. SUCCESS! [root@mysql55 ~]# rpm -e MySQL-shared-5.5.39-2.el6.x86_64 MySQL-client-5.5.39-2.el6.x86_64 \ > MySQL-shared-compat-5.5.39-2.el6.x86_64 MySQL-server-5.5.39-2.el6.x86_64 \ > MySQL-shared-compat-5.5.39-2.el6.x86_64 [root@mysql55 ~]# yum -y install mysql-server [...] Setting up Install Process [...] Installed size: 329 M Downloading Packages: [...] Complete!
With the 5.6 on master side, next step is to add to the my.cnf the thread_stack=256K to avoid this reported misconfiguration. After it, it time to put those two configured worker threads to work…
On master:
[root@mysql55 ~]# service mysqld start Starting mysqld: [ OK ] [root@mysql55 ~]# mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.21-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> insert into db1.t1 values (1),(2),(3); insert into db2.t1 values (1),(2),(3); Query OK, 3 rows affected (0.01 sec) Records: 3 Duplicates: 0 Warnings: 0 Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0
Checking the worker threads on slave:
mysql> select * from mysql.slave_worker_info\G *************************** 1. row *************************** Id: 1 Relay_log_name: ./mysqld-relay-bin.000004 Relay_log_pos: 976 Master_log_name: master-bin.000002 Master_log_pos: 816 Checkpoint_relay_log_name: ./mysqld-relay-bin.000004 Checkpoint_relay_log_pos: 554 Checkpoint_master_log_name: master-bin.000002 Checkpoint_master_log_pos: 394 Checkpoint_seqno: 1 Checkpoint_group_size: 64 Checkpoint_group_bitmap: *************************** 2. row *************************** Id: 2 Relay_log_name: ./mysqld-relay-bin.000004 Relay_log_pos: 765 Master_log_name: master-bin.000002 Master_log_pos: 605 Checkpoint_relay_log_name: ./mysqld-relay-bin.000004 Checkpoint_relay_log_pos: 554 Checkpoint_master_log_name: master-bin.000002 Checkpoint_master_log_pos: 394 Checkpoint_seqno: 0 Checkpoint_group_size: 64 Checkpoint_group_bitmap: 2 rows in set (0.00 sec)
Yes, it’s working and confirmed that MTS is a feature present just on 5.6, using ROW or STATEMENT as binlog_format. BTW, i like to blog things considering all the small details, because, as our MySQL friend said on MySQL Central @ OOW14, “do not underestimate the importance of the small things“.
All the best,
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply