From dccb95a814b8950e34f3f5f0a571420c75422c40 Mon Sep 17 00:00:00 2001 From: Carlos Rios Date: Tue, 22 Mar 2016 00:06:29 -0300 Subject: [PATCH 1/3] Activating IntvarEvent and dealing with servers not configured as master --- pymysqlreplication/binlogstream.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index 56f42a88..8e8b1dca 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -13,7 +13,7 @@ from .event import ( QueryEvent, RotateEvent, FormatDescriptionEvent, XidEvent, GtidEvent, StopEvent, - BeginLoadQueryEvent, ExecuteLoadQueryEvent, + BeginLoadQueryEvent, ExecuteLoadQueryEvent, IntvarEvent, NotImplementedEvent) from .row_event import ( UpdateRowsEvent, WriteRowsEvent, DeleteRowsEvent, TableMapEvent) @@ -260,7 +260,11 @@ def __connect_to_stream(self): if self.log_file is None or self.log_pos is None: cur = self._stream_connection.cursor() cur.execute("SHOW MASTER STATUS") - self.log_file, self.log_pos = cur.fetchone()[:2] + output = cur.fetchone() + if not output: + raise Exception('Server is not master') + cur.close() + self.log_file, self.log_pos = output[:2] cur.close() prelude = struct.pack(' Date: Tue, 22 Mar 2016 01:12:46 -0300 Subject: [PATCH 2/3] updating example --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index db44b856..f2b041db 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ from pymysqlreplication import BinLogStreamReader mysql_settings = {'host': '127.0.0.1', 'port': 3306, 'user': 'root', 'passwd': ''} -stream = BinLogStreamReader(connection_settings = mysql_settings) +stream = BinLogStreamReader(connection_settings = mysql_settings, server_id=2) for binlogevent in stream: binlogevent.dump() @@ -322,5 +322,3 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - - From 82e0760ad597424880a5dedd26a812f2459147ac Mon Sep 17 00:00:00 2001 From: Carlos Rios Date: Tue, 22 Mar 2016 01:13:04 -0300 Subject: [PATCH 3/3] removing connection close --- pymysqlreplication/binlogstream.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index 8e8b1dca..9d7cc1e2 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -470,7 +470,6 @@ def __get_table_information(self, schema, table): except pymysql.OperationalError as error: code, message = error.args if code in MYSQL_EXPECTED_ERROR_CODES: - self._stream_connection.close() self.__connected_ctl = False continue else: