diff --git a/README.md b/README.md index 9060cdd2..041d1b07 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,15 @@ The project is test with: It's not tested in real production situation. +TESTING +======= + +Make sure you have the following configuration set in your mysql config file (usually my.cnf on development env): + +log-bin=mysql-bin +server-id=1 +binlog_do_db=pymysqlreplication_test + Limitations ============= diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index da6b4a28..d54b1b44 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -9,7 +9,7 @@ from .packet import BinLogPacketWrapper from .constants.BINLOG import TABLE_MAP_EVENT, ROTATE_EVENT - +from .event import NotImplementedEvent class BinLogStreamReader(object): """Connect to replication stream and read event @@ -17,7 +17,7 @@ class BinLogStreamReader(object): def __init__(self, connection_settings={}, resume_stream=False, blocking=False, only_events=None, server_id=255, - log_file=None, log_pos=None): + log_file=None, log_pos=None, filter_non_implemented_events=True): """ Attributes: resume_stream: Start for event from position or the latest event of @@ -35,6 +35,7 @@ def __init__(self, connection_settings={}, resume_stream=False, self.__resume_stream = resume_stream self.__blocking = blocking self.__only_events = only_events + self.__filter_non_implemented_events = filter_non_implemented_events self.__server_id = server_id #Store table meta information @@ -132,6 +133,9 @@ def fetchone(self): return binlog_event.event def __filter_event(self, event): + if self.__filter_non_implemented_events and isinstance(event, NotImplementedEvent): + return True + if self.__only_events is not None: for allowed_event in self.__only_events: if isinstance(event, allowed_event): diff --git a/pymysqlreplication/constants/BINLOG.py b/pymysqlreplication/constants/BINLOG.py index 0661a1bb..353e6381 100644 --- a/pymysqlreplication/constants/BINLOG.py +++ b/pymysqlreplication/constants/BINLOG.py @@ -35,4 +35,4 @@ DELETE_ROWS_EVENT_V2 = 0x20 GTID_LOG_EVENT = 0x21 ANONYMOUS_GTID_LOG_EVENT = 0x22 -PREVIOUS_GTIDS_LOG_EVENT = 0x23 +PREVIOUS_GTIDS_LOG_EVENT = 0x23 \ No newline at end of file diff --git a/pymysqlreplication/event.py b/pymysqlreplication/event.py index e86ff009..d14c6e5c 100644 --- a/pymysqlreplication/event.py +++ b/pymysqlreplication/event.py @@ -110,4 +110,4 @@ class NotImplementedEvent(BinLogEvent): def __init__(self, from_packet, event_size, table_map, ctl_connection): super(NotImplementedEvent, self).__init__( from_packet, event_size, table_map, ctl_connection) - self.packet.advance(event_size) + self.packet.advance(event_size) \ No newline at end of file diff --git a/pymysqlreplication/packet.py b/pymysqlreplication/packet.py index 021d0b7a..c38dd11c 100644 --- a/pymysqlreplication/packet.py +++ b/pymysqlreplication/packet.py @@ -42,6 +42,12 @@ class BinLogPacketWrapper(object): constants.WRITE_ROWS_EVENT_V2: row_event.WriteRowsEvent, constants.DELETE_ROWS_EVENT_V2: row_event.DeleteRowsEvent, constants.TABLE_MAP_EVENT: row_event.TableMapEvent, + #5.6 GTID enabled replication events + constants.INTVAR_EVENT: event.NotImplementedEvent, + constants.GTID_LOG_EVENT: event.NotImplementedEvent, + constants.ANONYMOUS_GTID_LOG_EVENT: event.NotImplementedEvent, + constants.PREVIOUS_GTIDS_LOG_EVENT: event.NotImplementedEvent + } def __init__(self, from_packet, table_map, ctl_connection): diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index 6f1073ff..1e259e56 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -59,6 +59,7 @@ def test_connection_stream_lost_event(self): self.stream.fetchone() event = self.stream.fetchone() + self.assertIsInstance(event, QueryEvent) self.assertEqual(event.query, query)