Canal BinlogChange(mariadb5/10)

本文涉及的产品
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
RDS Agent(兼容OpenClaw),2核4GB
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介:

背景

先前开源了一个开源项目: 【阿里巴巴开源项目: 基于mysql数据库binlog的增量订阅&消费】 

本文主要是介绍一下canal支持mariadb协议上的变化. 

 

协议变化

mariadb5.5

mariadb5.5主要是基于mysql5.5的原型,类型定义基本没啥变化,大体上都保持兼容

主要的变化:

1. QueryLogEvent增加了status变量.    

  • Q_HRNOW  用于记录毫秒的精度,枚举值下标为128

协议解析的时候,需要处理Q_HRNOW,需要跳过3字节的数据.  

ps.  mysql5.6后,新增了Q_MICROSECONDS来支持mariaDb中Q_HRNOW的毫秒精度的功能.  

 

2. binlog事件的变化


1./* New MySQL/Sun events are to be added right above this comment */  
2.MYSQL_EVENTS_END,  
3.  
4.MARIA_EVENTS_BEGIN= 160,  
5./* New Maria event numbers start from here */  
6.ANNOTATE_ROWS_EVENT= 160,  
7.  
8./* Add new MariaDB events here - right above this comment!  */  
9.  
10.ENUM_END_EVENT /* end marker */  


  /* New MySQL/Sun events are to be added right above this comment */
  MYSQL_EVENTS_END,

  MARIA_EVENTS_BEGIN= 160,
  /* New Maria event numbers start from here */
  ANNOTATE_ROWS_EVENT= 160,

  /* Add new MariaDB events here - right above this comment!  */

  ENUM_END_EVENT /* end marker */

新增了mariadb的binlog区间为160开始,ANNOTATE_ROWS_EVENT类型为mysql5.6中的RowsQueryLogEvent,用于记录RBR模式下insert/update/delete中执行的sql.

 

mariadb10

mariadb10主要是基于mysql5.6的原型,类型定义基本没啥变化,大体上都保持兼容(沿用了mysql5.6中TIMESTAMP2等新的时间类型和新的log_event类型)

主要的变化:

1. QueryLogEvent增加了status变量.    

  • Q_HRNOW  用于记录毫秒的精度,枚举值下标为128

协议解析的时候,需要处理Q_HRNOW,需要跳过3字节的数据.  

ps.  mysql5.6后,新增了Q_MICROSECONDS来支持mariaDb中Q_HRNOW的毫秒精度的功能.  

 

2. binlog事件的变化


1.MARIA_EVENTS_BEGIN= 160,  
2.  /* New Maria event numbers start from here */  
3.  ANNOTATE_ROWS_EVENT= 160,  
4.  /* 
5.    Binlog checkpoint event. Used for XA crash recovery on the master, not used 
6.    in replication. 
7.    A binlog checkpoint event specifies a binlog file such that XA crash 
8.    recovery can start from that file - and it is guaranteed to find all XIDs 
9.    that are prepared in storage engines but not yet committed. 
10.  */  
11.  BINLOG_CHECKPOINT_EVENT= 161,  
12.  /* 
13.    Gtid event. For global transaction ID, used to start a new event group, 
14.    instead of the old BEGIN query event, and also to mark stand-alone 
15.    events. 
16.  */  
17.  GTID_EVENT= 162,  
18.  /* 
19.    Gtid list event. Logged at the start of every binlog, to record the 
20.    current replication state. This consists of the last GTID seen for 
21.    each replication domain. 
22.  */  
23.  GTID_LIST_EVENT= 163,  
24.  
25.  /* Add new MariaDB events here - right above this comment!  */  
26.  
27.  ENUM_END_EVENT /* end marker */  


MARIA_EVENTS_BEGIN= 160,
  /* New Maria event numbers start from here */
  ANNOTATE_ROWS_EVENT= 160,
  /*
    Binlog checkpoint event. Used for XA crash recovery on the master, not used
    in replication.
    A binlog checkpoint event specifies a binlog file such that XA crash
    recovery can start from that file - and it is guaranteed to find all XIDs
    that are prepared in storage engines but not yet committed.
  */
  BINLOG_CHECKPOINT_EVENT= 161,
  /*
    Gtid event. For global transaction ID, used to start a new event group,
    instead of the old BEGIN query event, and also to mark stand-alone
    events.
  */
  GTID_EVENT= 162,
  /*
    Gtid list event. Logged at the start of every binlog, to record the
    current replication state. This consists of the last GTID seen for
    each replication domain.
  */
  GTID_LIST_EVENT= 163,

  /* Add new MariaDB events here - right above this comment!  */

  ENUM_END_EVENT /* end marker */

 新增了mariadb自己的gtid处理

 

使用注意

1.  AnnotateRowsEvent使用

  •  mariadb需要在my.cnf中设置binlog_annotate_row_events = true,开启记录annotate事件
  • canal在发送COM_BINLOG_DUMP指令中需要设置binlog_flags |= BINLOG_SEND_ANNOTATE_ROWS_EVENT,不然mariadb默认不会发送AnnotateRowsEvent,而是以空的QueryLogEvent来代替.

2.  新增的binlog类型使用

  • canal需要设置当前session变量

    1.SET @mariadb_slave_capability='" + LogEvent.MARIA_SLAVE_CAPABILITY_MINE + "'"  


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
NoSQL 关系型数据库 MySQL
阿里云RDS关系型数据库大全_MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
阿里云RDS关系型数据库如MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等,NoSQL数据库如Redis、Tair、Lindorm和MongoDB
609 0
|
8月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
1349 152
|
8月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
971 156
|
8月前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。
|
缓存 关系型数据库 MySQL
error: Failed dependencies: mariadb-connector-c-config is obsoleted by mysql-community-server-8.0.36-1.el7.x86_64 问题解决
error: Failed dependencies: mariadb-connector-c-config is obsoleted by mysql-community-server-8.0.36-1.el7.x86_64 问题解决
1148 19
|
关系型数据库 Java MySQL
Linux安装JDK1.8 & tomcat & MariaDB(MySQL删减版)
本教程提供了在Linux环境下安装JDK1.8、Tomcat和MariaDB的详细步骤。这三个组件的组合为Java Web开发和部署提供了一个强大的基础。通过遵循这些简单的指导步骤,您可以轻松建立起一个稳定、高效的开发和部署环境。希望这个指导对您的开发工作有所帮助。
598 8
|
SQL 关系型数据库 MySQL
如何在 MySQL 或 MariaDB 中导入和导出数据库
如何在 MySQL 或 MariaDB 中导入和导出数据库
1375 0
|
SQL Ubuntu 关系型数据库
如何在云服务器上创建和管理 MySQL 和 MariaDB 数据库
如何在云服务器上创建和管理 MySQL 和 MariaDB 数据库
292 0
|
关系型数据库 MySQL 数据库连接
FreeSWITCH通过mod_mariadb原生连接MySQL
FreeSWITCH通过mod_mariadb原生连接MySQL
1367 0
|
NoSQL 关系型数据库 MySQL
阿里云关系型数据库详细介绍MySQL/MariaDB/SQL Server/PolarDB/PostgreSQL等
阿里云关系型数据库详细介绍MySQL/MariaDB/SQL Server/PolarDB/PostgreSQL等,阿里云RDS关系型数据库如MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
549 0

推荐镜像

更多