原创:转载请说明出处谢谢!
上接
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
http://blog.itpub.net/7728585/viewspace-2133502/ 解析MYSQL BINLOG 二进制格式(7)--Xid_log_event/XID_EVENT
这部分在文档interal中并没有找到解析,但是通过翻阅源码class定义找到一些定义
部分可知,部分未知,如果以后找到会补上,如果有误请指出
class:Gtid_log_event
event:GTID_LOG_EVENT
event_code:33
class:Gtid_log_event
event:ANONYMOUS_GTID_LOG_EVENT
event_code:34
class:Previous_gtids_log_event
event:PREVIOUS_GTIDS_LOG_EVENT
event_code:35
首先是GTID_LOG_EVENT和ANONYMOUS_GTID_LOG_EVENT
他们源于一个class
(
ANONYMOUS: gtid_mode [ON ON_PERMISSIVE]
非ANONYMOUS:gtid_mode [OFF OFF_PERMISSIVE]
)
只是ANONYMOUS基本没有填充值,我们来看看源码中对他们的定义:
位置在:
Control_events.h 中
protected:
static const int ENCODED_FLAG_LENGTH= 1;
static const int ENCODED_SID_LENGTH= 16;// Uuid::BYTE_LENGTH;
static const int ENCODED_GNO_LENGTH= 8;
/// Length of typecode for logical timestamps.
static const int LOGICAL_TIMESTAMP_TYPECODE_LENGTH= 1;
/// Length of two logical timestamps.
static const int LOGICAL_TIMESTAMP_LENGTH= 16;
// Type code used before the logical timestamps.
static const int LOGICAL_TIMESTAMP_TYPECODE= 2;
gtid_info gtid_info_struct;
Uuid Uuid_parent_struct;
public:
/// Total length of post header
static const int POST_HEADER_LENGTH=
ENCODED_FLAG_LENGTH /* flags */ 1
ENCODED_SID_LENGTH /* SID length */ 16
ENCODED_GNO_LENGTH /* GNO length */ 8
LOGICAL_TIMESTAMP_TYPECODE_LENGTH /* length of typecode */ 1
LOGICAL_TIMESTAMP_LENGTH; /* length of two logical timestamps */ 16
我们可以明确看出GITD存储的地方ENCODED_SID_LENGTH 16,ENCODED_GNO_LENGTH 8
LOGICAL_TIMESTAMP_LENGTH 两个8字节分别表示 last_committed, sequence_number
,在ANONYMOUS GTID除了 last_committed , sequence_number其他字节为0X00
来具体解析一个:
Gtid_log_event/GTID_LOG_EVENT
# Position Timestamp Type Master ID Size Master Pos Flags
# c2 05 01 9d 58 21 e5 6b 01 00 41 00 00 00 03 01 00 00 00 00
# d5 01 4a 6f 2a 67 5d 87 11 e6 a6 bd 00 0c 29 a8 79 |.Jo.g..........y|
# e5 a3 f0 43 0f 00 00 00 00 00 02 00 00 00 00 00 00 |..C.............|
# f5 00 00 01 00 00 00 00 00 00 00 7d 32 90 b4 |...........2..|
# GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '4a6f2a67-5d87-11e6-a6bd-000c29a879a3:1000432'/*!*/;
01:flags未知
4a 6f 2a 67 5d 87 11 e6 a6 bd 00 0c 29 a8 79 a3: 4a6f2a67-5d87-11e6-a6bd-000c29a879a3
f0 43 0f 00 00 00 00 00 : 小端显示0X0f43f0,1000432
02:length of typecode未知
00 00 00 00 00 00 00 00: last_committed
01 00 00 00 00 00 00 00: sequence_number
7d 32 90 b4 :CRC32校验
那看一个ANONYMOUS的
# at 194
#170214 4:12:30 server id 93157 end_log_pos 259 CRC32 0x0901e014
# Position Timestamp Type Master ID Size Master Pos Flags
# c2 2e 13 a2 58 22 e5 6b 01 00 41 00 00 00 03 01 00 00 00 00
# d5 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
# e5 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 |................|
# f5 00 00 01 00 00 00 00 00 00 00 14 e0 01 09 |..............|
# GTID [commit=yes]
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
除了 last_committed 和 sequence_number作为组提交的标志,其他位基本都为0及没有gtid生成
PREVIOUS_GTIDS_LOG_EVENT:用于表示上一个binlog最后一个gitd的位置,每个binlog只有一个
# at 123
#170214 4:46:24 server id 93157 end_log_pos 194 CRC32 0xd10caea6
# Position Timestamp Type Master ID Size Master Pos Flags
# 7b 20 1b a2 58 23 e5 6b 01 00 47 00 00 00 c2 00 00 00 80 00
# 8e 01 00 00 00 00 00 00 00 4a 6f 2a 67 5d 87 11 e6 |........Jo.g....|
# 9e a6 bd 00 0c 29 a8 79 a3 01 00 00 00 00 00 00 00 |......y.........|
# ae 01 00 00 00 00 00 00 00 05 44 0f 00 00 00 00 00 |.........D......|
# be a6 ae 0c d1 |....|
# Previous-GTIDs
# 4a6f2a67-5d87-11e6-a6bd-000c29a879a3:1-1000452
关于这部分解析位置特别是1-1000452的解析。如果以后知道了补上
只是在源码注释中找到:
/**
@class Previous_gtids_event
@section Previous_gtids_event_binary_format Binary Format
The Post-Header for this event type is empty. The Body has two
components:
*/
但是不知道解析方法。
其他EVENT:
这部分列出的event可以直接参考internals 20章 比较简单就不用再开文章写了
Stop_log_event/STOP_EVENT(03):数据库关闭,或者SLAVE执行了reset slave。
Rotate_log_event/ROTATE_EVENT(04):binlog切换事件,比如超过参数设置。如果服务器CRASH不会记录
Intvar_log_event/INTVAR_EVENT(05):和自增字段有关
Rand_log_event/RAND_EVENT(13):和RAND()函数相关
还有很多和load data infile 有关的event这里就不考虑了。因为平时我们用load data infile 并不多,这里主要考虑
和事物有关的各种的event
上接
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
http://blog.itpub.net/7728585/viewspace-2133502/ 解析MYSQL BINLOG 二进制格式(7)--Xid_log_event/XID_EVENT
这部分在文档interal中并没有找到解析,但是通过翻阅源码class定义找到一些定义
部分可知,部分未知,如果以后找到会补上,如果有误请指出
class:Gtid_log_event
event:GTID_LOG_EVENT
event_code:33
class:Gtid_log_event
event:ANONYMOUS_GTID_LOG_EVENT
event_code:34
class:Previous_gtids_log_event
event:PREVIOUS_GTIDS_LOG_EVENT
event_code:35
首先是GTID_LOG_EVENT和ANONYMOUS_GTID_LOG_EVENT
他们源于一个class
(
ANONYMOUS: gtid_mode [ON ON_PERMISSIVE]
非ANONYMOUS:gtid_mode [OFF OFF_PERMISSIVE]
)
只是ANONYMOUS基本没有填充值,我们来看看源码中对他们的定义:
位置在:
Control_events.h 中
protected:
static const int ENCODED_FLAG_LENGTH= 1;
static const int ENCODED_SID_LENGTH= 16;// Uuid::BYTE_LENGTH;
static const int ENCODED_GNO_LENGTH= 8;
/// Length of typecode for logical timestamps.
static const int LOGICAL_TIMESTAMP_TYPECODE_LENGTH= 1;
/// Length of two logical timestamps.
static const int LOGICAL_TIMESTAMP_LENGTH= 16;
// Type code used before the logical timestamps.
static const int LOGICAL_TIMESTAMP_TYPECODE= 2;
gtid_info gtid_info_struct;
Uuid Uuid_parent_struct;
public:
/// Total length of post header
static const int POST_HEADER_LENGTH=
ENCODED_FLAG_LENGTH /* flags */ 1
ENCODED_SID_LENGTH /* SID length */ 16
ENCODED_GNO_LENGTH /* GNO length */ 8
LOGICAL_TIMESTAMP_TYPECODE_LENGTH /* length of typecode */ 1
LOGICAL_TIMESTAMP_LENGTH; /* length of two logical timestamps */ 16
我们可以明确看出GITD存储的地方ENCODED_SID_LENGTH 16,ENCODED_GNO_LENGTH 8
LOGICAL_TIMESTAMP_LENGTH 两个8字节分别表示 last_committed, sequence_number
,在ANONYMOUS GTID除了 last_committed , sequence_number其他字节为0X00
/* Binlog-specific logical timestamps. */
/*
Store for the transaction's commit parent sequence_number.
The value specifies this transaction dependency with a "parent"
transaction.
The member is assigned, when the transaction is about to commit
in binlog to a value of the last committed transaction's sequence_number.
This and last_committed as numbers are kept ever incremented
regardless of binary logs being rotated or when transaction
is logged in multiple pieces.
However the logger to the binary log may convert them
according to its specification.
*/
int64 last_committed;
/*
The transaction's private logical timestamp assigned at the
transaction prepare phase. The timestamp enumerates transactions
in the binary log. The value is gained through incrementing (stepping) a
global clock.
Eventually the value is considered to increase max_committed_transaction
system clock when the transaction has committed.
*/
int64 sequence_number;
/*
Store for the transaction's commit parent sequence_number.
The value specifies this transaction dependency with a "parent"
transaction.
The member is assigned, when the transaction is about to commit
in binlog to a value of the last committed transaction's sequence_number.
This and last_committed as numbers are kept ever incremented
regardless of binary logs being rotated or when transaction
is logged in multiple pieces.
However the logger to the binary log may convert them
according to its specification.
*/
int64 last_committed;
/*
The transaction's private logical timestamp assigned at the
transaction prepare phase. The timestamp enumerates transactions
in the binary log. The value is gained through incrementing (stepping) a
global clock.
Eventually the value is considered to increase max_committed_transaction
system clock when the transaction has committed.
*/
int64 sequence_number;
来具体解析一个:
Gtid_log_event/GTID_LOG_EVENT
# Position Timestamp Type Master ID Size Master Pos Flags
# c2 05 01 9d 58 21 e5 6b 01 00 41 00 00 00 03 01 00 00 00 00
# d5 01 4a 6f 2a 67 5d 87 11 e6 a6 bd 00 0c 29 a8 79 |.Jo.g..........y|
# e5 a3 f0 43 0f 00 00 00 00 00 02 00 00 00 00 00 00 |..C.............|
# f5 00 00 01 00 00 00 00 00 00 00 7d 32 90 b4 |...........2..|
# GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '4a6f2a67-5d87-11e6-a6bd-000c29a879a3:1000432'/*!*/;
01:flags未知
4a 6f 2a 67 5d 87 11 e6 a6 bd 00 0c 29 a8 79 a3: 4a6f2a67-5d87-11e6-a6bd-000c29a879a3
f0 43 0f 00 00 00 00 00 : 小端显示0X0f43f0,1000432
02:length of typecode未知
00 00 00 00 00 00 00 00: last_committed
01 00 00 00 00 00 00 00: sequence_number
7d 32 90 b4 :CRC32校验
那看一个ANONYMOUS的
# at 194
#170214 4:12:30 server id 93157 end_log_pos 259 CRC32 0x0901e014
# Position Timestamp Type Master ID Size Master Pos Flags
# c2 2e 13 a2 58 22 e5 6b 01 00 41 00 00 00 03 01 00 00 00 00
# d5 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
# e5 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 |................|
# f5 00 00 01 00 00 00 00 00 00 00 14 e0 01 09 |..............|
# GTID [commit=yes]
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
除了 last_committed 和 sequence_number作为组提交的标志,其他位基本都为0及没有gtid生成
PREVIOUS_GTIDS_LOG_EVENT:用于表示上一个binlog最后一个gitd的位置,每个binlog只有一个
# at 123
#170214 4:46:24 server id 93157 end_log_pos 194 CRC32 0xd10caea6
# Position Timestamp Type Master ID Size Master Pos Flags
# 7b 20 1b a2 58 23 e5 6b 01 00 47 00 00 00 c2 00 00 00 80 00
# 8e 01 00 00 00 00 00 00 00 4a 6f 2a 67 5d 87 11 e6 |........Jo.g....|
# 9e a6 bd 00 0c 29 a8 79 a3 01 00 00 00 00 00 00 00 |......y.........|
# ae 01 00 00 00 00 00 00 00 05 44 0f 00 00 00 00 00 |.........D......|
# be a6 ae 0c d1 |....|
# Previous-GTIDs
# 4a6f2a67-5d87-11e6-a6bd-000c29a879a3:1-1000452
关于这部分解析位置特别是1-1000452的解析。如果以后知道了补上
只是在源码注释中找到:
/**
@class Previous_gtids_event
@section Previous_gtids_event_binary_format Binary Format
The Post-Header for this event type is empty. The Body has two
components:
Name | Format | Description |
---|---|---|
buf | unsigned char array | It contains the Gtids executed in the last binary log file. |
buf_size | 4 byte integer | Size of the above buffer |
*/
但是不知道解析方法。
其他EVENT:
这部分列出的event可以直接参考internals 20章 比较简单就不用再开文章写了
Stop_log_event/STOP_EVENT(03):数据库关闭,或者SLAVE执行了reset slave。
Rotate_log_event/ROTATE_EVENT(04):binlog切换事件,比如超过参数设置。如果服务器CRASH不会记录
Intvar_log_event/INTVAR_EVENT(05):和自增字段有关
Rand_log_event/RAND_EVENT(13):和RAND()函数相关
还有很多和load data infile 有关的event这里就不考虑了。因为平时我们用load data infile 并不多,这里主要考虑
和事物有关的各种的event