Skip to content

Commit 860bb23

Browse files
Freeze schema.
By not supporting alter table we can get huge performance gains. The reason is we can skip parsing TableMapEvent It's an optionnal option
1 parent 5635399 commit 860bb23

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def __init__(self, connection_settings, server_id, resume_stream=False,
3131
blocking=False, only_events=None, log_file=None, log_pos=None,
3232
filter_non_implemented_events=True,
3333
ignored_events=None, auto_position=None,
34-
only_tables = None, only_schemas = None):
34+
only_tables = None, only_schemas = None,
35+
freeze_schema = False):
3536
"""
3637
Attributes:
3738
resume_stream: Start for event from position or the latest event of
@@ -44,6 +45,7 @@ def __init__(self, connection_settings, server_id, resume_stream=False,
4445
auto_position: Use master_auto_position gtid to set position
4546
only_tables: An array with the tables you want to watch
4647
only_schemas: An array with the schemas you want to watch
48+
freeze_schema: If true do not support ALTER TABLE. It's faster. (default False)
4749
"""
4850
self.__connection_settings = connection_settings
4951
self.__connection_settings["charset"] = "utf8"
@@ -55,6 +57,7 @@ def __init__(self, connection_settings, server_id, resume_stream=False,
5557

5658
self.__only_tables = only_tables
5759
self.__only_schemas = only_schemas
60+
self.__freeze_schema = freeze_schema
5861
self.__allowed_events = self._allowed_event_list(only_events, ignored_events, filter_non_implemented_events)
5962

6063
# We can't filter on packet level TABLE_MAP and rotate event because we need
@@ -241,7 +244,8 @@ def fetchone(self):
241244
self.__use_checksum,
242245
self.__allowed_events_in_packet,
243246
self.__only_tables,
244-
self.__only_schemas)
247+
self.__only_schemas,
248+
self.__freeze_schema)
245249

246250
if binlog_event.event_type == TABLE_MAP_EVENT and binlog_event.event is not None:
247251
self.table_map[binlog_event.event.table_id] = \

pymysqlreplication/event.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
class BinLogEvent(object):
1010
def __init__(self, from_packet, event_size, table_map, ctl_connection,
1111
only_tables = None,
12-
only_schemas = None):
12+
only_schemas = None,
13+
freeze_schema = False):
1314
self.packet = from_packet
1415
self.table_map = table_map
1516
self.event_type = self.packet.event_type

pymysqlreplication/packet.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class BinLogPacketWrapper(object):
5151
def __init__(self, from_packet, table_map, ctl_connection, use_checksum,
5252
allowed_events,
5353
only_tables,
54-
only_schemas):
54+
only_schemas,
55+
freeze_schema):
5556
# -1 because we ignore the ok byte
5657
self.read_bytes = 0
5758
# Used when we want to override a value in the data buffer
@@ -91,7 +92,8 @@ def __init__(self, from_packet, table_map, ctl_connection, use_checksum,
9192
self.event = event_class(self, event_size_without_header, table_map,
9293
ctl_connection,
9394
only_tables = only_tables,
94-
only_schemas = only_schemas)
95+
only_schemas = only_schemas,
96+
freeze_schema = freeze_schema)
9597
if self.event._processed == False:
9698
self.event = None
9799

pymysqlreplication/row_event.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,12 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
490490
table_map, ctl_connection, **kwargs)
491491
self.__only_tables = kwargs["only_tables"]
492492
self.__only_schemas = kwargs["only_schemas"]
493+
self.__freeze_schema = kwargs["freeze_schema"]
493494

494495
# Post-Header
495496
self.table_id = self._read_table_id()
496497

497-
if self.table_id in table_map:
498+
if self.table_id in table_map and self.__freeze_schema:
498499
self._processed = False
499500
return
500501

0 commit comments

Comments
 (0)