Skip to content

Commit 0308b85

Browse files
Support decoding rotate event
1 parent b0d3deb commit 0308b85

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pymysqlreplication/event.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,24 @@ def _dump(self):
3131
'''Core data dumped for the event'''
3232
pass
3333

34-
3534
class RotateEvent(BinLogEvent):
36-
pass
35+
"""
36+
Change MySQL bin log file
37+
38+
Attributes:
39+
position: Position inside next binlog
40+
next_binlog: Name of next binlog file
41+
"""
42+
def __init__(self, from_packet, event_size, table_map, ctl_connection):
43+
super(RotateEvent, self).__init__(from_packet, event_size, table_map, ctl_connection)
44+
self.position = struct.unpack('<Q', self.packet.read(8))[0]
45+
self.next_binlog = self.packet.read(event_size - 8).decode()
46+
47+
def dump(self):
48+
print("=== %s ===" % (self.__class__.__name__))
49+
print("Position: %d" % self.position)
50+
print("Next binlog file: %d" % self.next_binlog)
51+
print()
3752

3853

3954
class FormatDescriptionEvent(BinLogEvent):

pymysqlreplication/tests/test_basic.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def test_read_query_event(self):
1111
self.execute(query)
1212

1313
#RotateEvent
14-
self.stream.fetchone()
14+
event = self.stream.fetchone()
15+
self.assertEqual(event.position, 4)
16+
self.assertEqual(event.next_binlog, "mysql-bin.000001")
17+
1518
#FormatDescription
1619
self.stream.fetchone()
1720

0 commit comments

Comments
 (0)