9
9
10
10
class BinLogEvent (object ):
11
11
def __init__ (self , from_packet , event_size , table_map , ctl_connection ,
12
+ mysql_version = (0 ,0 ,0 ),
12
13
only_tables = None ,
13
14
ignored_tables = None ,
14
15
only_schemas = None ,
@@ -22,6 +23,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection,
22
23
self .timestamp = self .packet .timestamp
23
24
self .event_size = event_size
24
25
self ._ctl_connection = ctl_connection
26
+ self .mysql_version = mysql_version
25
27
self ._fail_on_table_metadata_unavailable = fail_on_table_metadata_unavailable
26
28
self ._ignore_decode_errors = ignore_decode_errors
27
29
# The event have been fully processed, if processed is false
@@ -60,6 +62,11 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
60
62
self .commit_flag = struct .unpack ("!B" , self .packet .read (1 ))[0 ] == 1
61
63
self .sid = self .packet .read (16 )
62
64
self .gno = struct .unpack ('<Q' , self .packet .read (8 ))[0 ]
65
+ self .lt_type = byte2int (self .packet .read (1 ))
66
+
67
+ if self .mysql_version >= (5 , 7 ):
68
+ self .last_committed = struct .unpack ('<Q' , self .packet .read (8 ))[0 ]
69
+ self .sequence_number = struct .unpack ('<Q' , self .packet .read (8 ))[0 ]
63
70
64
71
@property
65
72
def gtid (self ):
@@ -75,6 +82,9 @@ def gtid(self):
75
82
def _dump (self ):
76
83
print ("Commit: %s" % self .commit_flag )
77
84
print ("GTID_NEXT: %s" % self .gtid )
85
+ if hasattr (self , "last_committed" ):
86
+ print ("last_committed: %d" % self .last_committed )
87
+ print ("sequence_number: %d" % self .sequence_number )
78
88
79
89
def __repr__ (self ):
80
90
return '<GtidEvent "%s">' % self .gtid
@@ -121,8 +131,49 @@ def dump(self):
121
131
print ()
122
132
123
133
134
+ class XAPrepareEvent (BinLogEvent ):
135
+ """An XA prepare event is generated for a XA prepared transaction.
136
+ Like Xid_event it contans XID of the *prepared* transaction
137
+
138
+ Attributes:
139
+ one_phase: current XA transaction commit method
140
+ xid: serialized XID representation of XA transaction
141
+ """
142
+ def __init__ (self , from_packet , event_size , table_map , ctl_connection , ** kwargs ):
143
+ super (XAPrepareEvent , self ).__init__ (from_packet , event_size , table_map ,
144
+ ctl_connection , ** kwargs )
145
+
146
+ # one_phase is True: XA COMMIT ... ONE PHASE
147
+ # one_phase is False: XA PREPARE
148
+ self .one_phase = (self .packet .read (1 ) != b'\x00 ' )
149
+ self .xid_format_id = struct .unpack ('<I' , self .packet .read (4 ))[0 ]
150
+ gtrid_length = struct .unpack ('<I' , self .packet .read (4 ))[0 ]
151
+ bqual_length = struct .unpack ('<I' , self .packet .read (4 ))[0 ]
152
+ self .xid_gtrid = self .packet .read (gtrid_length )
153
+ self .xid_bqual = self .packet .read (bqual_length )
154
+
155
+ @property
156
+ def xid (self ):
157
+ return self .xid_gtrid .decode () + self .xid_bqual .decode ()
158
+
159
+ def _dump (self ):
160
+ print ("One phase: %s" % self .one_phase )
161
+ print ("XID formatID: %d" % self .xid_format_id )
162
+ print ("XID: %s" % self .xid )
163
+
164
+
124
165
class FormatDescriptionEvent (BinLogEvent ):
125
- pass
166
+ def __init__ (self , from_packet , event_size , table_map , ctl_connection , ** kwargs ):
167
+ super (FormatDescriptionEvent , self ).__init__ (from_packet , event_size , table_map ,
168
+ ctl_connection , ** kwargs )
169
+ self .binlog_version = struct .unpack ('<H' , self .packet .read (2 ))
170
+ self .mysql_version_str = self .packet .read (50 ).rstrip (b'\0 ' ).decode ()
171
+ numbers = self .mysql_version_str .split ('-' )[0 ]
172
+ self .mysql_version = tuple (map (int , numbers .split ('.' )))
173
+
174
+ def _dump (self ):
175
+ print ("Binlog version: %s" % self .binlog_version )
176
+ print ("MySQL version: %s" % self .mysql_version_str )
126
177
127
178
128
179
class StopEvent (BinLogEvent ):
0 commit comments