mysql5.7 turn enhance the semi-synchronous replication

Provided that the master-slave asynchronous replication environment should be set up well in advance, then turn mysql enhanced semisynchronous

Environment: mysql5.7.26 master-slave asynchronous replication already deployed.

1. Load plugin plugin

Recommendations on the master and slave are all performed (considering the primary MHA automatically switched from the environment)

In the main library installation semisync_master.so and semisync_slave.so plug-ins:

mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

master library on linux server to perform:

root@localhost [(none)]>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
Query OK, 0 rows affected (4.52 sec)
root@localhost [(none)]>INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
Query OK, 0 rows affected (0.07 sec)

slave libraries on linux server to perform:

root@localhost [(none)]>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
ERROR 1125 (HY000): Function 'rpl_semi_sync_master' already exists
root@localhost [(none)]>INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
ERROR 1125 (HY000): Function 'rpl_semi_sync_slave' already exists
root@localhost [(none)]>

Tip: Enhance the slave semi-synchronous plug-in already exists, so the error.
The reason: the automatic synchronization after installation of semi-synchronous enhancement plug on the master to the slave library

2.slave and enhanced half-open master synchronization parameter

Recommendations on the production environment first turn on the enhanced semi-slave synchronization parameter library

set global rpl_semi_sync_slave_enabled =1;
stop  slave io_thread;start  slave io_thread;

Error Log observe master of the moment: Tips opened the Semi-sync replication copy

2019-06-16T20:31:28.923731+08:00 718 [Note] While initializing dump thread for slave with UUID <7659cf56-8e81-11e9-bcbd-842b2b5999d9>, found a zombie dump thread with the same UUID. Master is killing the zombie dump thread(717).
2019-06-16T20:31:28.923838+08:00 717 [Note] Stop asynchronous binlog_dump to slave (server_id: 113306)
2019-06-16T20:31:28.923951+08:00 718 [Note] Start binlog_dump to master_thread_id(718) slave_server(113306), pos(, 4)
2019-06-16T20:31:28.923984+08:00 718 [Note] Start semi-sync binlog_dump to slave (server_id: 113306), pos(, 4)
2019-06-16T20:31:29.189007+08:00 718 [Note] Semi-sync replication switched ON at (mysql-bin.000005, 852045921)

Then turn enhance the semi-synchronous parameters on the master


set global rpl_semi_sync_master_enabled =1
set global rpl_semi_sync_master_timeout        =1000

3.MySQL official website configuration

Official master and slave /etc/my.cnf required to open the following parameters:

rpl_semi_sync_master_enabled        =1                             #    0
rpl_semi_sync_slave_enabled         =1                             #    0
rpl_semi_sync_master_timeout        =1000                          #    1000(1 second) 同步复制中由于网络原因导致复制时间超过1s后,增强半同步复制就变成了异步复制了
rpl_semi_sync_master_wait_for_slave_count=N
plugin_load_add                     =semisync_master.so            #
plugin_load_add                     =semisync_slave.so             #

Restart master and slave databases.

4. The actual production environment configuration

Of course, practice is not recommended parameters rpl_semi_sync_master_enabled and rpl_semi_sync_slave_enabled writing the configuration files directly.
The reason: The parameter is added my.cnf configuration file, hang in slave library, the library reopened slave or a slave library after the restart, it will automatically turn enhance the semi-synchronous replication.
If you disconnect after a long time in the slave master database repository, it is best to open mysql asynchronous replication, allowing the library to catch up on the slave master database, then turn enhance the semi-synchronous replication. This will not wear down the master library. If directly open the enhanced semi-synchronous replication will outlast the main library.
rpl_semi_sync_master_timeout = 1000 ## 1s into the asynchronous replication timeout parameter is written to the configuration file.

The semi-synchronous enhanced presentation timeout is closed

Demonstrate Enhanced semi-synchronous replication than the time set is turned off:

Set the timeout on the master

mysql> set global rpl_semi_sync_master_timeout=20000;  ##为20s

Stop io_thread thread on the slave

mysql> stop slave io_thread;

Then delete a test library on the master library to demonstrate the enhanced semi-synchronous closed:

mysql> drop database test02;  ##删除test02库卡盾超时20s 才执行成功。
Query OK, 0 rows affected (20.00 sec)

During the 20s a shield card, do show proccesslist in the master database, it was found during this period, master library has been waiting for a response in the semi-sync the slave ack of:

mysql>  show processlist;
+-----+-----------------+-----------+------+---------+--------+--------------------------------------+----------------------+
| Id  | User            | Host      | db   | Command | Time   | State                                | Info                 |
+-----+-----------------+-----------+------+---------+--------+--------------------------------------+----------------------+
|   1 | event_scheduler | localhost | NULL | Daemon  | 185099 | Waiting on empty queue               | NULL                 |
| 700 | root            | localhost | NULL | Query   |      3 | Waiting for semi-sync ACK from slave | drop database test02 |
| 703 | root            | localhost | NULL | Query   |      0 | starting                             | show processlist     |
| 709 | root            | localhost | NULL | Sleep   |    999 |                                      | NULL                 |
+-----+-----------------+-----------+------+---------+--------+--------------------------------------+----------------------+
4 rows in set (0.00 sec)

At this point of view the master database error log shut enhanced semi-synchronous replication:

2019-06-16T18:58:38.249020+08:00 0 [ERROR] ./mysqld: Got an error reading communication packets      ###这个报错是slave库 stop  slave io_thread导致的
2019-06-16T18:59:14.870329+08:00 711 [ERROR] Semi-sync master failed on net_flush() before waiting for slave reply
2019-06-16T18:59:14.870409+08:00 711 [Note] Stop semi-sync binlog_dump to slave (server_id: 113306)
2019-06-16T18:59:14.870469+08:00 711 [Note] Aborted connection 711 to db: 'unconnected' user: 'rept' host: '192.168.0.11' (Found net error)
2019-06-16T18:59:34.870253+08:00 703 [Warning] Timeout waiting for reply of binlog (file: mysql-bin.000004, pos: 422036), semi-sync up to file mysql-bin.000004, position 421882.
2019-06-16T18:59:34.870298+08:00 703 [Note] Semi-sync replication switched OFF.

After 20s the set timeout period than the master library, semi-sync enhancement was closed. Waiting for semi-sync ACK from slave disappear

mysql>  show processlist;
+-----+-----------------+-----------+------+---------+--------+------------------------+------------------+
| Id  | User            | Host      | db   | Command | Time   | State                  | Info             |
+-----+-----------------+-----------+------+---------+--------+------------------------+------------------+
|   1 | event_scheduler | localhost | NULL | Daemon  | 185120 | Waiting on empty queue | NULL             |
| 700 | root            | localhost | NULL | Sleep   |      4 |                        | NULL             |
| 703 | root            | localhost | NULL | Query   |      0 | starting               | show processlist |
| 709 | root            | localhost | NULL | Sleep   |   1020 |                        | NULL             |
+-----+-----------------+-----------+------+---------+--------+------------------------+------------------+
4 rows in set (0.00 sec)

Then no longer appears when you remove the card shield test01 library on the master, explained enhance the semi-synchronous replication has been closed

MySQL> Database drop test01;
Query the OK, 2 rows affected (0.00 sec)
at this time to view the current enhancement, there are several semi-synchronous replication slave client in maser, I have found no link client

mysql> show global status like "Rpl_semi_sync_master_clients";
+------------------------------+-------+
| Variable_name                | Value |
+------------------------------+-------+
| Rpl_semi_sync_master_clients | 0     |
+------------------------------+-------+
1 row in set (0.01 sec)

Open io_thread on slave

mysql> start slave io_thread;
Query OK, 0 rows affected (0.00 sec)

View the error log on the master database:

2019-06-16T19:10:46.656964+08:00 713 [Note] Start binlog_dump to master_thread_id(713) slave_server(113306), pos(, 4)
2019-06-16T19:10:46.657003+08:00 713 [Note] Start semi-sync binlog_dump to slave (server_id: 113306), pos(, 4)
2019-06-16T19:10:46.670872+08:00 0 [Note] Semi-sync replication switched ON at (mysql-bin.000004, 422366)

Tip enhance semisynchronous have opened.

master View semisynchronous added a link state:

mysql> show global status like "Rpl_semi_sync_master_clients";
+------------------------------+-------+
| Variable_name                | Value |
+------------------------------+-------+
| Rpl_semi_sync_master_clients | 1     |
+------------------------------+-------+
1 row in set (0.00 sec)

mysql> 

6. observe the master database error log

6.1 slave library is closed io thread, then close the semi-synchronous replication, and then turn the slave of io_thread thread

mysql> stop slave io_thread;
Query OK, 0 rows affected (0.00 sec)

mysql> set global rpl_semi_sync_slave_enabled=0 ;
Query OK, 0 rows affected (0.00 sec)

mysql> start slave io_thread;
Query OK, 0 rows affected (0.00 sec)
mysql> 

Now observe the error log master database:

2019-06-16T20:35:14.463978+08:00 0 [ERROR] ./mysqld: Got an error reading communication packets
2019-06-16T20:35:44.309080+08:00 719 [Note] While initializing dump thread for slave with UUID <7659cf56-8e81-11e9-bcbd-842b2b5999d9>, found a zombie dump thread with the same UUID. Master is killing the zombie dump thread(718).
2019-06-16T20:35:44.309252+08:00 718 [Note] Stop semi-sync binlog_dump to slave (server_id: 113306)
2019-06-16T20:35:44.309724+08:00 719 [Note] Start binlog_dump to master_thread_id(719) slave_server(113306), pos(, 4)
2019-06-16T20:35:44.309740+08:00 719 [Note] Start asynchronous binlog_dump to slave (server_id: 113306), pos(, 4)

6.2 slave library is closed io thread, wait 20s and then close the semi-synchronous replication, and then turn the slave of io_thread thread

Now observe the error log master database:

2019-06-16T20:39:18.806715+08:00 0 [ERROR] ./mysqld: Got an error reading communication packets

2019-06-16T20:39:58.854194+08:00 720 [Note] Stop semi-sync binlog_dump to slave (server_id: 113306)
2019-06-16T20:39:58.854305+08:00 720 [Note] Aborted connection 720 to db: 'unconnected' user: 'rept' host: '192.168.0.11' (failed on flush_net())

2019-06-16T20:41:06.636868+08:00 721 [Note] Start binlog_dump to master_thread_id(721) slave_server(113306), pos(, 4)
2019-06-16T20:41:06.636902+08:00 721 [Note] Start asynchronous binlog_dump to slave (server_id: 113306), pos(, 4)

6.1 and 6.2 log errors are found or there are different places

7. Case

When running MySQL online enhancements semi-synchronous replication architecture, when one of a slave library should hang up how to properly re-added to enhance the original semi-synchronous replication architecture? ?

The correct approach is as follows:

1. 此2个参数rpl_semi_sync_master_enabled  和rpl_semi_sync_slave_enabled  不要直接写入到my.cnf配置文件开启。
2.在slave库上先 stop slave io_thread ;set global  rpl_semi_sync_slave_enabled=0 关闭此参数。然后start slave io_thread 或者start slave 开启异步复制,让slave库追赶上master库。
3.然后在slave库 set global  rpl_semi_sync_slave_enabled=1 ;stop  slave io_thread;start  slave  io_thread;

To demonstrate here, welcome to leave a message with the exchange of learning.

Guess you like

Origin blog.51cto.com/wujianwei/2409754