mysql semi-synchronous configuration

Semi-synchronous replication , that is, semi-sync replication, means that after the master library writes the binlog log, it will force the data to be synchronized to the slave library immediately at this time, and after the slave library writes the log to its local relay log, then it will Return an ack to the main library, and the main library will consider the write operation completed after receiving at least one ack from the slave library.
Semi-synchronous replication improves data consistency and security (consistency is not absolutely guaranteed, when the delay exceeds the set timeout period, semi-synchronous will automatically convert to asynchronous execution), but it also causes a certain degree of delay, This delay is at least one TCP/IP round trip time.

Before configuring semi-synchronization, you must first complete the master-slave configuration of the database. For specific configuration methods, see here
mysql semi-synchronization configuration method
1. Install the semisync_master plug-in in the main database:

mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; -- linux
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.dll'; -- windows

2. Install the semisync_slave plug-in in the standby database

mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so'; -- linux
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.dll'; -- windows

3. Modify the my.ini file under Windows, and modify the my.cconf file under Linux.
New parameters for the main library:

rpl_semi_sync_master_enabled=1		#开启半同步复制	

#控制master等待semi-slave ack报文的时间,单位是毫秒,默认是10000,如果master等待超时,则切换为普通的异步复制
rpl_semi_sync_master_timeout=1000	

#rpl_semi_sync_master_wait_no_slave为OFF时,只要master发现Rpl_semi_sync_master_clients小于rpl_semi_sync_master_wait_for_slave_count
#rpl_semi_sync_master_wait_no_slave为ON时,空闲时间(无事务提交)里,即使master发现Rpl_semi_sync_master_clients小于rpl_semi_sync_master_wait_for_slave_count,也不会做任何调整。只要保证在事务超时之前,master收到大于等于rpl_semi_sync_master_wait_for_slave_count值的ACK应答数量,master就一直保持在半同步模式
rpl_semi_sync_master_wait_no_slave=off   

#master提交后所需的应答数量
rpl_semi_sync_master_wait_for_slave_count = 1     

New parameters from the library:

rpl_semi_sync_slave_enabled=1  -- 开启从库半同步设置

After the parameter setting is complete, the database server needs to be restarted

Remarks: After all the settings of the slave library are completed and the database server is repeated, it is necessary to log in to the slave library and restart the slave, namely: stop slave; start slave;

The parameters can also be set dynamically after the mysql server is started.
The main library configuration parameters are set dynamically:

mysql>SET GLOBAL rpl_semi_sync_master_timeout=1000;   -- 单位:ms

mysql>SET GLOBAL rpl_semi_sync_master_wait_no_slave=‘on’;  

These two variables can be set dynamically, but if they are not written in my.cnf, the database restart parameters will restore the default values

4. Verify whether the semi-synchronous configuration is successful
Check whether the main library has enabled the semi-asynchronous synchronization mode:

mysql>show variables like '%rpl_semi_sync_master_enabled%';  -- 为on表示已经开启

Check whether the slave library is semi-synchronous:

mysql>show variables like '%rpl_semi_sync_slave_enabled%';    -- 为on表示已经开启	

Command to query global configuration parameters:

mysql>show variables like '%rpl_semi%';

When the query is running, whether the semi-synchronous configuration is successful and the command is running normally: show status like '%rpl_semi%'
When the master library: the value of Rpl_semi_sync_master_status must be on, it means that the master library semi-asynchronous setting is successful
When it is a slave library: the value of Rpl_semi_sync_slave_status It must be on to indicate that the semi-asynchronous setting of the slave library is successful
If both Rpl_semi_sync_master_status and Rpl_semi_sync_slave_status are on, it proves that the mysql semi-synchronous configuration is successful

The meanings corresponding to the semi-synchronous parameters are as follows:

mysql> show status like '%rpl_semi%';

Rpl_semi_sync_master_clients 1 | #How many Semi-sync standby databases
Rpl_semi_sync_master_net_avg_wait_time 65139| #After the transaction is submitted, the average time to wait for the response from the standby database
Rpl_semi_sync_master_net_wait_time 195419 | #The total number of times waiting for the network response
Rpl_semi_sync_master_net_ waits 3 | #Total network waiting time
Rpl_semi_sync_master_no_times 1 | #A total of several times from Semi-sync to normal status
Rpl_semi_sync_master_no_tx 1 | #Number of transactions that the standby database did not respond in time
Rpl_semi_sync_master_status ON | #Whether Semi-sync on the main database is normally enabled
Rpl_semi_sync_master_timefunc_failures 0 | #Number of times the time function did not work properly
Rpl_semi_sync_master_t x_avg_wait_time 995 | #Enable Semi-sync, the average time that the transaction needs to wait for return
Rpl_semi_sync_master_tx_wait_time 1991 | #The total time that the transaction waits for the response of the standby database
Rpl_semi_sync_master_tx_waits 2 | #The total number of times the transaction waits for the response of the standby database
Rpl_semi_sync_master_wait_pos_backtraverse 0 | #Change the current minimum binary log waiting frequency
Rpl_semi_sync_master_wait_sessions 0 | #Currently there are several threads waiting for the standby database to respond
Rpl_semi_sync_master_yes_tx 2 | #In Semi-sync mode, the number of successful transactions

Guess you like

Origin blog.csdn.net/teamo_m/article/details/105786904