mysql和mariadb对比_MySQL并发复制系列三:MySQL和MariaDB实现对比

MariaDB 10通过@@binlog_commit_wait_count and @@binlog_commit_wait_usec 两个参数设置,既事务commit阶段的时候至少等binlog_commit_wait_usec毫秒直到有binlog_commit_wait_count个数时进行一次组提交,来提高每组事务中的事务数量,并可以通过查询状态变量@@binlog_commit和@@binlog_group_commit来查参数来查看当前binary log group commit比例。

MySQL5.7通过引入 binlog_group_commit_sync_delay和 binlog_group_commit_sync_no_delay_count参数即提高binary log组提交并发数量,既MySQL等待binlog_group_commit_sync_delay毫秒的时间直到binlog_group_commit_sync_no_delay_count个数时进行一次组提交。

实现:

Binary Log Group Commit在MySQL 5.7和MariaDB 10 中是默认开启不需要配置任何信息,且在binary log中标记的组提交信息依赖于GTID,而MySQL和MariaDB的GTID组成和实现方式不一样,这里我们简单梳理下。

在MySQL 5.7版本由于Binary Log Group Commit是默认开启的,所以即使你不开启gtid_mode在配置文件中,binary log的内容中同样也有GTID 信息只不过标记的信息是"ANONYMOUS"

>    show binlog

events in 'mysql-bin.000004';截取一段信息

1.  ...............

| mysql-bin.000004 | 3571 | Anonymous_Gtid |     15112 |

3636 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'          |

2.  | mysql-bin.000004 | 3636 | Query

|     15112 |

3712 | BEGIN

|

3.  | mysql-bin.000004 | 3712 | Rows_query

|     15112 |

3763 | # INSERT INTO t1 () VALUES ()

|

4.  | mysql-bin.000004 | 3763 | Table_map

|     15112 |

3807 | table_id: 108 (db2.t1)

|

5.  | mysql-bin.000004 | 3807 | Write_rows

|     15112 |

3847 | table_id: 108 flags: STMT_END_F

|

6.  | mysql-bin.000004 | 3847 | Xid

|

15112 |

3878 | COMMIT /* xid=33 */

|

.................

>     mysqlbinlog -vvv

mysql-bin.00004 | less

1.  #151231 14:34:03 server id 15112

end_log_pos 2408 CRC32 0x5586fe71     Anonymous_GTID last_committed=6        sequence_number=8

2.  SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;

3.  # at 2408

4.  #151231 14:34:03 server id 15112

end_log_pos 2484 CRC32 0x748efb17     Query   thread_id=11

exec_time=0     error_code=0

5.  SET TIMESTAMP=1451543643/*!*/;

6.  BEGIN

7.  ..

MariaDB的GTID同样也是默认开启且GTID是由Domain ID、Server ID和transaction Sequence Number组成:

76aa4b9cbc8894df13f151be42328d1b.png

图3 MariaDB GTID组成

>    show binlog

events in 'mysql-bin.000003';截取一段信息

1.  .......

| mysql-bin.000003 |  335 | Gtid

|     15102 |         377 | BEGIN GTID 0-15102-64139

|

2.  | mysql-bin.000003 |  377 | Table_map

|     15102 |

434 | table_id: 18 (test.sbtest1)

|

3.  | mysql-bin.000003 |  434 | Write_rows_v1     |

15102 |

657 | table_id: 18 flags: STMT_END_F

|

4.  | mysql-bin.000003 |  657 | Xid

|     15102 |         688 | COMMIT /* xid=16 */

|

5.  | mysql-bin.000003 |  688 | Gtid

|     15102 |         732 | BEGIN GTID 0-15102-64140 cid=20

|

6.  | mysql-bin.000003 |  732 | Table_map

|     15102 |

789 | table_id: 19 (test.sbtest6)

|

7.  | mysql-bin.000003 |  789 | Write_rows_v1     |

15102 |

1012 | table_id: 19 flags: STMT_END_F

|

8.  | mysql-bin.000003 | 1012 | Xid

|     15102 |        1043 | COMMIT /* xid=20 */

|

9.  | mysql-bin.000003 | 1043 | Gtid

|     15102 |        1087 | BEGIN GTID 0-15102-64141 cid=20

|

10. | mysql-bin.000003 | 1087 | Table_map

|     15102 |

1145 | table_id: 20 (test.sbtest12)

|

11. | mysql-bin.000003 | 1145 | Write_rows_v1     |

15102 |

1368 | table_id: 20 flags: STMT_END_F

|

12. | mysql-bin.000003 | 1368 | Xid

|     15102 |        1399 | COMMIT /* xid=21 */

|

......

>    mysqlbinlog

-vvv mysql-bin.00003  | less

1.

.......

2.

# at 1754

3.  #160104 15:16:46 server id 15102

end_log_pos 1798 CRC32 0x26104c0b     GTID 0-15102-64143 cid=20 trans

4.  /*!100001 SET @@session.gtid_seq_no=64143*//*!*/;

5.  BEGIN

6.  /*!*/;

7.  # at 1798

8.  #160104 15:16:46 server id 15102

end_log_pos 1856 CRC32 0x2c994f5a     Table_map:

`test`.`sbtest12` mapped to number 20

9.  # at 1856

10. #160104 15:16:46 server id 15102

end_log_pos 2079 CRC32 0x02b5a694     Write_rows: table id 20

flags: STMT_END_F

11.

12.

BINLOG '

13.

.........

结论:

MySQL

5.7 / MariaDB 10的parallel replication都是基于主库上Binary Log Group Commit。

MySQL:  主库并发提交的事务group commit写入binary log日志中,当事务被标记的last_committed=N的值相同时(通过binlog_group_commit_sync_delay、 binlog_group_commit_sync_no_delay_count参数设置提高并发事务数量),可以在slave节点并发回放主库提交的事务。

MariaDB:

主库并发提交的事务group commit写入binary log日志中,当事务被标记的 cid=N 的值相同时(通过 binlog_commit_wait_count、binlog_commit_wait_usec参数设置提高并发事务数量),可以在slave节点并发回放主库提交的事务。

Reference:http://geek.rohitkalhans.com/2013/09/enhancedMTS-deepdive.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值