Mysql replication is completed asynchronously by default. The semi-Sync Mode is a patch developed by google for mysql. This function has been integrated in Mysql 5.5 or later versions. Semi-sync means that the MASTER only needs to receive the returned information of one of the SLAVE, and then commit; otherwise, wait until the timeout time is reached and switch to asynchronous mode before committing. This operation reduces the latency of data in the Master/Slave database, and improves data security with minimal performance loss.
Enabling semi-sync is simple. You need to install and enable the semi-sync plug-in on both the master and slave.
Check whether semi-sync is used for mysql replication,
Mysql> show variables like 'rpl % ';
+ ----------------- + ------- +
| Variable_name | Value |
+ ----------------- + ------- +
| Rpl_recovery_rank | 0 |
+ ----------------- + ------- +
1 row in set (0.00 sec)
Or use show status like 'rpl % ';
Enable semi-Sync Mode:
Run on master
Mysql> install plugin rpl_semi_sync_master soname 'semisync _ master. so ';
Query OK, 0 rows affected (0.03 sec)
Mysql> set global rpl_semi_sync_master_enabled = 0;
Query OK, 0 rows affected (0.00 sec)
Mysql> show variables like 'rpl % ';
+ ------------------------------------ + ------- +
| Variable_name | Value |
+ ------------------------------------ + ------- +
| Rpl_recovery_rank | 0 |
| Rpl_semi_sync_master_enabled | OFF |
| Rpl_semi_sync_master_timeout | 10000 |
| Rpl_semi_sync_master_trace_level | 32 |
| Rpl_semi_sync_master_wait_no_slave | ON |
+ ------------------------------------ + ------- +
5 rows in set (0.00 sec)
Mysql> set global rpl_semi_sync_master_enabled = 1;
Query OK, 0 rows affected (0.00 sec)
Mysql> show variables like 'rpl % ';
+ ------------------------------------ + ------- +
| Variable_name | Value |
+ ------------------------------------ + ------- +
| Rpl_recovery_rank | 0 |
| Rpl_semi_sync_master_enabled | ON |
| Rpl_semi_sync_master_timeout | 10000 |
| Rpl_semi_sync_master_trace_level | 32 |
| Rpl_semi_sync_master_wait_no_slave | ON |
+ ------------------------------------ + ------- +
The value of rpl_semi_sync_master_enabled is 0 (on) or 1 (off). The default value is 1.
The default value of rpl_semi_sync_master_timeout is 10000 (10 s)
5 rows in set (0.00 sec)
Perform the following operations on slave:
Mysql> install plugin rpl_semi_sync_slave soname 'semisync _ slave. so ';
Query OK, 0 rows affected (0.03 sec)
Mysql> set global rpl_semi_sync_slave_enabled = 1;
Query OK, 0 rows affected (0.00 sec)
Mysql> show variables like 'rpl % ';
+ --------------------------------- + ------- +
| Variable_name | Value |
+ --------------------------------- + ------- +
| Rpl_recovery_rank | 0 |
| Rpl_semi_sync_slave_enabled | ON |
| Rpl_semi_sync_slave_trace_level | 32 |
+ --------------------------------- + ------- +
3 rows in set (0.00 sec)
Mysql> show status like 'rpl % ';
+ ---------------------------- + ------------- +
| Variable_name | Value |
+ ---------------------------- + ------------- +
| Rpl_semi_sync_slave_status | ON |
| Rpl_status | AUTH_MASTER |
+ ---------------------------- + ------------- +
2 rows in set (0.01 sec)
Mysql> stop slave io_thread;
Query OK, 0 rows affected (0.00 sec)
Mysql> start slave io_thread;
Query OK, 0 rows affected (0.00 sec)
The value of rpl_semi_sync_slave_enabled is 0 (on) or 1 (off). The default value is 1.