为了支持新版的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,已经被作者合进去了

最新文章

  1. 重构MVC多条件+分页解决方案
  2. 使用bootstrap和metroui设计的微网站或手机app界面
  3. Linux 的多线程编程的高效开发经验
  4. Ajax 表单验证 实现代码
  5. PowerDesigner15在生成SQL时报错Generation aborted due to errors detected during the verification of the mod
  6. java学习之内省
  7. 原型(Prototype)模式
  8. Postman 串行传参和动态传参详解
  9. 中国.NET:各地微软技术俱乐部汇总(更新中...)
  10. 别人的Linux私房菜(15)磁盘配额与高级文件系统管理
  11. Linux虚拟内存(swap)调优篇-“swappiness”,“vm.dirty_background_ratio”和“vm.dirty_ratio”
  12. 软工网络16个人作业2——WordCount
  13. ShellExecute使用详解
  14. Tomcat服务器配置https双向认证(使用keytool生成证书)
  15. Python学习笔记第二十四周(JavaScript补充)
  16. jQuery的效果
  17. 【spring boot】【elasticsearch】spring boot整合elasticsearch,启动报错Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8
  18. linux下串口工具minicom
  19. Egret第三方库的制作和使用(模块化 第三方库)
  20. Sharepoint 2013 - 直接显示Doclib中的html page

热门文章

  1. 权限组件(15):rbac的使用文档和在业务中的应用
  2. B1020 月饼(25 分)
  3. Vs2012 打开项目 自动关闭 并停止工作 解决方法
  4. 使用 Dom4j 将 XML 转换为 MAP
  5. 某面试公司出的面试题---用JS比较两个版本号高低
  6. 62、在app遇到全局异常时避免直接退出,如何让app接管异常处理?
  7. Windows下MySQL8.0.11.0安装教程
  8. python-day4-装饰器的使用
  9. Adaboost和GBDT的区别以及xgboost和GBDT的区别
  10. schema.xml属性概念