Skip to content

Commit 0d5c012

Browse files
Implement 'MariadbGtidListEvent' replication class
1 parent 964a89f commit 0d5c012

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

examples/mariadb_gtid/read_event.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pymysql
22

33
from pymysqlreplication import BinLogStreamReader, gtid
4-
from pymysqlreplication.event import GtidEvent, RotateEvent, MariadbGtidEvent, QueryEvent
4+
from pymysqlreplication.event import GtidEvent, RotateEvent, MariadbGtidEvent, QueryEvent, MariadbGtidListEvent
55
from pymysqlreplication.row_event import WriteRowsEvent, UpdateRowsEvent, DeleteRowsEvent
66

77
MARIADB_SETTINGS = {
@@ -65,7 +65,8 @@ def query_server_id(self):
6565
RotateEvent,
6666
WriteRowsEvent,
6767
UpdateRowsEvent,
68-
DeleteRowsEvent
68+
DeleteRowsEvent,
69+
MariadbGtidListEvent
6970
],
7071
auto_position=gtid,
7172
is_mariadb=True

pymysqlreplication/binlogstream.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
QueryEvent, RotateEvent, FormatDescriptionEvent,
1515
XidEvent, GtidEvent, StopEvent, XAPrepareEvent,
1616
BeginLoadQueryEvent, ExecuteLoadQueryEvent,
17-
HeartbeatLogEvent, NotImplementedEvent, MariadbGtidEvent)
17+
HeartbeatLogEvent, NotImplementedEvent, MariadbGtidEvent,
18+
MariadbGtidListEvent)
1819
from .exceptions import BinLogNotEnabled
1920
from .row_event import (
2021
UpdateRowsEvent, WriteRowsEvent, DeleteRowsEvent, TableMapEvent)
@@ -600,7 +601,8 @@ def _allowed_event_list(self, only_events, ignored_events,
600601
TableMapEvent,
601602
HeartbeatLogEvent,
602603
NotImplementedEvent,
603-
MariadbGtidEvent
604+
MariadbGtidEvent,
605+
MariadbGtidListEvent
604606
))
605607
if ignored_events is not None:
606608
for e in ignored_events:

pymysqlreplication/event.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,45 @@ def _dump(self):
8989
def __repr__(self):
9090
return '<GtidEvent "%s">' % self.gtid
9191

92+
class MariadbGtidListEvent(BinLogEvent):
93+
"""
94+
GTID List event
95+
https://mariadb.com/kb/en/gtid_list_event/
96+
97+
Attributes:
98+
gtid_length: Number of GTIDs
99+
gtid_list: list of 'MariadbGtidObejct'
100+
101+
'MariadbGtidObejct' Attributes:
102+
domain_id: Replication Domain ID
103+
server_id: Server_ID
104+
gtid_seq_no: GTID sequence
105+
gtid: 'domain_id'+ 'server_id' + 'gtid_seq_no'
106+
"""
107+
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
108+
109+
super(MariadbGtidListEvent, self).__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)
110+
111+
class MariadbGtidObejct(BinLogEvent):
112+
"""
113+
Information class of elements in GTID list
114+
"""
115+
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
116+
super(MariadbGtidObejct, self).__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)
117+
self.domain_id = self.packet.read_uint32()
118+
self.server_id = self.packet.server_id
119+
self.gtid_seq_no = self.packet.read_uint64()
120+
self.gtid = "%d-%d-%d" % (self.domain_id, self.server_id, self.gtid_seq_no)
121+
122+
123+
self.gtid_length = self.packet.read_uint32()
124+
self.gtid_list = [MariadbGtidObejct(from_packet, event_size, table_map, ctl_connection, **kwargs) for i in range(self.gtid_length)]
125+
126+
127+
def _dump(self):
128+
super(MariadbGtidListEvent, self)._dump()
129+
print("GTID length:",self.gtid_length)
130+
print("GTID list: " + ",".join(list(map(lambda x: x.gtid,self.gtid_list))))
92131

93132
class MariadbGtidEvent(BinLogEvent):
94133
"""

pymysqlreplication/packet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class BinLogPacketWrapper(object):
8686
constants.MARIADB_ANNOTATE_ROWS_EVENT: event.NotImplementedEvent,
8787
constants.MARIADB_BINLOG_CHECKPOINT_EVENT: event.NotImplementedEvent,
8888
constants.MARIADB_GTID_EVENT: event.MariadbGtidEvent,
89-
constants.MARIADB_GTID_GTID_LIST_EVENT: event.NotImplementedEvent,
89+
constants.MARIADB_GTID_GTID_LIST_EVENT: event.MariadbGtidListEvent,
9090
constants.MARIADB_START_ENCRYPTION_EVENT: event.NotImplementedEvent
9191
}
9292

0 commit comments

Comments
 (0)