且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

解析MYSQL BINLOG 二进制格式(7)--Xid_log_event/XID_EVENT

更新时间:2022-05-30 14:59:29

原创:转载请说明出处谢谢!
上接
http://blog.itpub.net/7728585/viewspace-2133188/ 解析MYSQL BINLOG 二进制格式(1)--准备工作 
http://blog.itpub.net/7728585/viewspace-2133189/ 解析MYSQL BINLOG 二进制格式(2)--FORMAT_DESCRIPTION_EVENT 
http://blog.itpub.net/7728585/viewspace-2133321/ 解析MYSQL BINLOG 二进制格式(3)--QUERY_EVENT 
http://blog.itpub.net/7728585/viewspace-2133429/ 解析MYSQL BINLOG 二进制格式(4)--TABLE_MAP_EVENT 
http://blog.itpub.net/7728585/viewspace-2133463/ 解析MYSQL BINLOG 二进制格式(5)--WRITE_ROW_EVENT
http://blog.itpub.net/7728585/viewspace-2133469/ 解析MYSQL BINLOG 二进制格式(6)--UPDATE_ROW_EVENT/DELETE_ROW_EVENT  

class:Xid_log_event
event:XID_EVENT
event_code:16

这个事件是支持事物的存储引擎事物进行了commit,他会生成一个xid 号
但是源码的注释上也说明如下:
  This is the subclass of Xid_event defined in libbinlogevent,
  An XID event is generated for a commit of a transaction that modifies one or
  more tables of an XA-capable storage engine
  Logs xid of the transaction-to-be-committed in the 2pc protocol.
  Has no meaning in replication, slaves ignore it
  The inheritance structure in the current design for the classes is
  as follows
  文档中说明了他生成的方式
  thd->transaction.xid_stae.xid.get_mysq_xid()
  注意这个event并不是 row 格式特有的,statement模式也会有

  这个event的解析很简单
--fixed data
  empty  
--variable data part
  8 bytes:XID号,但是注意这个是和平台相关的也就是和操作系统使用的little-endian和
          big-endian有关,和其他event的数字使用little-endian不一样这里特别说明      
  
  Xid_event 
解析:
# at 445
#170214  3:38:37 server id 93157  end_log_pos 476 CRC32 0x70cfaab6 
# Position  Timestamp   Type   Master ID        Size      Master Pos    Flags 
#      1bd 3d 0b a2 58   10   e5 6b 01 00   1f 00 00 00   dc 01 00 00   00 00
#      1d0 c7 00 00 00 00 00 00 00  b6 aa cf 70             |...........p|
#       Xid = 199
COMMIT/*!*/;

c7 00 00 00 00 00 00 00 :linux little-endian显示,0XC7也就是XID=199
可以看到和mysqlbinlog出来的Xid = 199 一致,一旦出现了这个event代表事物
已经提交了

到此XID_EVENT解析完成