Skip to content

Commit bad28d7

Browse files
committed
Reset table map on rotate events since MySQL mapping is not persistent and rotate is best approximation we have of detecting server restarts.
1 parent 836934e commit bad28d7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ def fetchone(self):
160160
if binlog_event.event_type == ROTATE_EVENT:
161161
self.log_pos = binlog_event.event.position
162162
self.log_file = binlog_event.event.next_binlog
163+
# Table Id in binlog are NOT persistent in MySQL - they are in-memory identifiers
164+
# that means that when MySQL master restarts, it will reuse same table id for different tables
165+
# which will cause errors for us since our in-memory map will try to decode row data with
166+
# wrong table schema.
167+
# The fix is to rely on the fact that MySQL will also rotate to a new binlog file every time it
168+
# restarts. That means every rotation we see *could* be a sign of restart and so potentially
169+
# invalidates all our cached table id to schema mappings. This means we have to load them all
170+
# again for each logfile which is potentially wasted effort but we can't really do much better
171+
# without being broken in restart case
172+
self.table_map = {}
163173
elif binlog_event.log_pos:
164174
self.log_pos = binlog_event.log_pos
165175

0 commit comments

Comments
 (0)