Skip to content
Browse files

Reset table map on rotate events since MySQL mapping is not persisten…

…t and rotate is best approximation we have of detecting server restarts.
  • Loading branch information
banks committed Jul 7, 2014
1 parent 836934e commit bad28d74e57209a39b6a1dd1f5191e77c721eed1
Showing with 10 additions and 0 deletions.
  1. +10 −0 pymysqlreplication/
@@ -160,6 +160,16 @@ def fetchone(self):
if binlog_event.event_type == ROTATE_EVENT:
self.log_pos = binlog_event.event.position
self.log_file = binlog_event.event.next_binlog
# Table Id in binlog are NOT persistent in MySQL - they are in-memory identifiers
# that means that when MySQL master restarts, it will reuse same table id for different tables
# which will cause errors for us since our in-memory map will try to decode row data with
# wrong table schema.
# The fix is to rely on the fact that MySQL will also rotate to a new binlog file every time it
# restarts. That means every rotation we see *could* be a sign of restart and so potentially
# invalidates all our cached table id to schema mappings. This means we have to load them all
# again for each logfile which is potentially wasted effort but we can't really do much better
# without being broken in restart case
self.table_map = {}
elif binlog_event.log_pos:
self.log_pos = binlog_event.log_pos

0 comments on commit bad28d7

Please sign in to comment.
You can’t perform that action at this time.