Skip to content

Commit b50dea6

Browse files
Merge pull request julien-duponchelle#85 from baloo/features/parse-gtid
Parse gtid events
2 parents 9de45d5 + 465605f commit b50dea6

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ Other contributors:
286286
* Daniel Gavrila more MySQL error codes https://github.com/danielduduta
287287
* Bernardo Sulzbach code cleanup https://github.com/mafagafo
288288
* Darioush Jalali Python 2.6 backport https://github.com/darioush
289+
* Arthur Gautier gtid https://github.com/baloose
289290

290291
Licence
291292
=======

pymysqlreplication/event.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,32 @@ def _dump(self):
3636
pass
3737

3838

39+
class GtidEvent(BinLogEvent):
40+
"""GTID change in binlog event
41+
"""
42+
def __init__(self, from_packet, event_size, table_map, ctl_connection):
43+
super(GtidEvent, self).__init__(from_packet, event_size, table_map,
44+
ctl_connection)
45+
46+
self.commit_flag = byte2int(self.packet.read(1)) == 1
47+
self.sid = self.packet.read(16)
48+
self.gno = struct.unpack('<Q', self.packet.read(8))[0]
49+
50+
@property
51+
def gtid(self):
52+
"""GTID = source_id:transaction_id
53+
Eg: 3E11FA47-71CA-11E1-9E33-C80AA9429562:23
54+
See: http://dev.mysql.com/doc/refman/5.6/en/replication-gtids-concepts.html"""
55+
gtid = "%s%s%s%s-%s%s-%s%s-%s%s-%s%s%s%s%s%s" %\
56+
tuple("{:02x}".format(ord(c)) for c in self.sid)
57+
gtid += ":%d" % self.gno
58+
return gtid
59+
60+
def _dump(self):
61+
print("Commit: %s" % self.commit_flag)
62+
print("GTID_NEXT: %s" % self.gtid)
63+
64+
3965
class RotateEvent(BinLogEvent):
4066
"""Change MySQL bin log file
4167

pymysqlreplication/packet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BinLogPacketWrapper(object):
3232
constants.FORMAT_DESCRIPTION_EVENT: event.FormatDescriptionEvent,
3333
constants.XID_EVENT: event.XidEvent,
3434
constants.INTVAR_EVENT: event.NotImplementedEvent,
35-
constants.GTID_LOG_EVENT: event.NotImplementedEvent,
35+
constants.GTID_LOG_EVENT: event.GtidEvent,
3636
constants.STOP_EVENT: event.NotImplementedEvent,
3737
# row_event
3838
constants.UPDATE_ROWS_EVENT_V1: row_event.UpdateRowsEvent,

0 commit comments

Comments
 (0)