logical_clock 并发复制mysql5.7解决复制延迟问题

Posted 龙二他爹

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了logical_clock 并发复制mysql5.7解决复制延迟问题相关的知识,希望对你有一定的参考价值。

slave-parallel-type=LOGICAL_CLOCK ##默认database ,logical_clock可能还存在bug,5.7.19修复主从不一致bug

     * Replication: In certain cases, the master could write to

       the binary log a last_committed value which was smaller

       than it should have been. This could cause the slave to

       execute in parallel transactions which should not have

       been, leading to inconsistencies or other errors. (Bug

#84471, Bug #25379659)

mysql 5.7.19版本修复
 
slave-parallel-workers=4  # 根据并发度设置,如果不需要并发,设置为0,不要设置为1.  1的性能比0差。
以前的sql单线程变成4个线程 Waiting for an event from Coordinator 
 
mysql> show processlist;
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
| Id | User        | Host      | db   | Command | Time   | State                                                  | Info             |
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
| 18 | system user |           | NULL | Connect | 606530 | Slave has read all relay log; waiting for more updates | NULL             |
| 19 | system user |           | NULL | Connect | 606593 | Waiting for an event from Coordinator                  | NULL             |
| 20 | system user |           | NULL | Connect | 838818 | Waiting for an event from Coordinator                  | NULL             |
| 21 | system user |           | NULL | Connect | 841404 | Waiting for an event from Coordinator                  | NULL             |
| 22 | system user |           | NULL | Connect | 841404 | Waiting for an event from Coordinator                  | NULL             |
| 31 | system user |           | NULL | Connect | 862799 | Waiting for master to send event                       | NULL             |
| 40 | root        | localhost | NULL | Query   |      0 | starting                                               | show processlist |
+----+-------------+-----------+------+---------+--------+--------------------------------------------------------+------------------+
7 rows in set (0.06 sec)

并不是严格要求所有同时进入Prepare阶段的事务都在备库并发执行,因此一组提交的事务中可能存在不同的seq no

可以发现较之原来的二进制日志内容多了last_committed和sequence_number,last_committed表示事务提交的时候,

上次事务提交的编号,如果事务具有相同的last_committed,表示这些事务都在一组内,可以进行并行的回放。

#170623 22:27:43 server id 45  end_log_pos 2781491 CRC32 0x1dcd41fa     GTID    last_committed=816      sequence_number=817
#170623 22:27:43 server id 45  end_log_pos 2785022 CRC32 0x2d28e1b7     GTID    last_committed=816      sequence_number=818
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON

以上是关于logical_clock 并发复制mysql5.7解决复制延迟问题的主要内容,如果未能解决你的问题,请参考以下文章

Mysql随笔-Mysql5.7主从复制

Mysql随笔-Mysql5.7主从复制

mysql 并行复制

听说Mysql你很豪横?-------------MySQL5.7主从同步

DAY7-剖析复制线程

mysql5.5主从同步复制配置