做几个简单的测试:主库插入一行数据
mysql> select * from test;
+----+--------+
| id | name |
+----+--------+
| 1 | 小明 |
+----+--------+
1 row in set (0.00 sec)
mysql> insert into test values(2,'test');
Query OK, 1 row affected (0.00 sec) #可以看见延迟几乎可以忽略
从库这边,数据正常说明成功了~
12345678 mysql> select * from test;
+----+--------+
| id | name |
+----+--------+
| 1 | 小明 |
| 2 | test |
+----+--------+
2 rows in set (0.00 sec)
模拟下从库故障
mysql> stop slave IO_THREAD;
Query OK, 0 rows affected (0.01 sec)
我们再在主从插入数据
mysql> insert into test values(3,'test');
Query OK, 1 row affected (10.01 sec) #插入时间很久,10秒钟,10秒超时后,自动切换回异步复制了
mysql> show global status like '%rpl_semi%';
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 498 |
| Rpl_semi_sync_master_net_wait_time | 1495 |
| Rpl_semi_sync_master_net_waits | 3 |
| Rpl_semi_sync_master_no_times | 3 |
| Rpl_semi_sync_master_no_tx | 2 |
| Rpl_semi_sync_master_status | OFF | #关闭状态
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 799 |
| Rpl_semi_sync_master_tx_wait_time | 1599 |
| Rpl_semi_sync_master_tx_waits | 2 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 2 |
+--------------------------------------------+-------+
14 rows in set (0.00 sec)
恢复IO线程
mysql> start slave IO_THREAD;
Query OK, 0 rows affected (0.00 sec)
mysql> show global status like '%rpl_semi%';
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 4526 |
| Rpl_semi_sync_master_net_wait_time | 18107 |
| Rpl_semi_sync_master_net_waits | 4 |
| Rpl_semi_sync_master_no_times | 3 |
| Rpl_semi_sync_master_no_tx | 2 |
| Rpl_semi_sync_master_status | ON | #重新开启了
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 799 |
| Rpl_semi_sync_master_tx_wait_time | 1599 |
| Rpl_semi_sync_master_tx_waits | 2 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 2 |
+--------------------------------------------+-------+
14 rows in set (0.00 sec)