Skip to content


Reset table map on rotate events since MySQL mapping is not persisten…
Browse files Browse the repository at this point in the history
…t and rotate is best approximation we have of detecting server restarts.
  • Loading branch information
banks committed Jul 7, 2014
1 parent 836934e commit bad28d7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pymysqlreplication/
Expand Up @@ -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

Expand Down

0 comments on commit bad28d7

Please sign in to comment.