为了支持新版的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= 0;
  uint8_t temp_byte;

  buf+= description_event->post_header_len[XA_PREPARE_LOG_EVENT - 1];
  memcpy(&temp_byte, buf, 1);
  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);
}
View Code

相关文章:

  • 2021-12-18
  • 2022-01-25
  • 2021-05-20
  • 2021-09-27
  • 2021-08-28
  • 2021-07-29
  • 2022-12-23
猜你喜欢
  • 2022-01-15
  • 2021-10-27
  • 2022-02-25
  • 2022-12-23
  • 2021-04-03
  • 2021-09-03
  • 2022-03-07
相关资源
相似解决方案