MySQL的XA_prepare_event类型binlog的解析
为了支持新版的xa事务,MySQL新加了一种binlog event类型:XA_prepare
项目中使用的开源组件mysql-binlog-connector-java无法解析此种binlog event
分析源码后发现第一个问题:
MySQL中一共有39种binlog event
但是mysql-binlog-connector-java组件只写了38种binlog event,少了一种名为TRANSACTION_CONTEXT的binlog event,导致无法解析TRANSACTION_CONTEXT_EVENT/VIEW_CHANGE_EVENT/XA_PREPARE_LOG_EVENT类型的binlog event
修改完本地分支后,顺手向mysql-binlog-connector-java的作者提了一个issue,作者很友好也很迅速的修改了相关的代码
现在mysql-binlog-connector-java可以识别出XA_prepare的binlog event了,但是只是识别出来而已,我还要需要对这种binlog event进行反序列化
网上没有现成的资料,在MySQL的代码库里翻了一通后终于找到了关键代码
XA_prepare_event::
XA_prepare_event(const char* buf,
const Format_description_event *description_event)
: Binary_log_event(&buf, description_event->binlog_version,
description_event->server_version)
{
uint32_t temp= ;
uint8_t temp_byte; buf+= description_event->post_header_len[XA_PREPARE_LOG_EVENT - ];
memcpy(&temp_byte, buf, );
one_phase= (bool) temp_byte;
buf += sizeof(temp_byte);
memcpy(&temp, buf, sizeof(temp));
my_xid.formatID= le32toh(temp);
buf += sizeof(temp);
memcpy(&temp, buf, sizeof(temp));
my_xid.gtrid_length= le32toh(temp);
buf += sizeof(temp);
memcpy(&temp, buf, sizeof(temp));
my_xid.bqual_length= le32toh(temp);
buf += sizeof(temp);
memcpy(my_xid.data, buf, my_xid.gtrid_length + my_xid.bqual_length);
}
从源码中我们可以知道,XA_prepare类型的binlog event的数据部分结构如下:
one_phase : boolean, 1byte
formatID : int, 4byte
gtrid_length : int, 4byte
bqual_length : int, 4byte
data : String, gtrid + bqual, (gtrid_length + bqual_length)byte
例如[0, 123, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 103, 116, 114, 105, 100, 98, 113, 117, 97, 108]
就对应为:
one_phase:false
formatID : 123
gtrid_length : 5
bqual_length : 5
data : "gtridbqual" ---> gtrid = "gtrid", bqual = "bqual"
于是可以很容易的写出XA_prepare类型的binlog event的解析器了
顺手提了个pr,已经被作者合进去了
最新文章
- 重构MVC多条件+分页解决方案
- 使用bootstrap和metroui设计的微网站或手机app界面
- Linux 的多线程编程的高效开发经验
- Ajax 表单验证 实现代码
- PowerDesigner15在生成SQL时报错Generation aborted due to errors detected during the verification of the mod
- java学习之内省
- 原型(Prototype)模式
- Postman 串行传参和动态传参详解
- 中国.NET:各地微软技术俱乐部汇总(更新中...)
- 别人的Linux私房菜(15)磁盘配额与高级文件系统管理
- Linux虚拟内存(swap)调优篇-“swappiness”,“vm.dirty_background_ratio”和“vm.dirty_ratio”
- 软工网络16个人作业2——WordCount
- ShellExecute使用详解
- Tomcat服务器配置https双向认证(使用keytool生成证书)
- Python学习笔记第二十四周(JavaScript补充)
- jQuery的效果
- 【spring boot】【elasticsearch】spring boot整合elasticsearch,启动报错Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8
- linux下串口工具minicom
- Egret第三方库的制作和使用(模块化 第三方库)
- Sharepoint 2013 - 直接显示Doclib中的html page