diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index b93c04be..da6b4a28 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -16,13 +16,16 @@ class BinLogStreamReader(object): """ def __init__(self, connection_settings={}, resume_stream=False, - blocking=False, only_events=None, server_id=255): + blocking=False, only_events=None, server_id=255, + log_file=None, log_pos=None): """ Attributes: resume_stream: Start for event from position or the latest event of binlog or from older available event blocking: Read on stream is blocking only_events: Array of allowed events + log_file: Set replication start log file + log_pos: Set replication start log pos """ self.__connection_settings = connection_settings self.__connection_settings["charset"] = "utf8" @@ -33,11 +36,11 @@ def __init__(self, connection_settings={}, resume_stream=False, self.__blocking = blocking self.__only_events = only_events self.__server_id = server_id - self.__log_pos = None - self.__log_file = None #Store table meta information self.table_map = {} + self.log_pos = log_pos + self.log_file = log_file def close(self): if self.__connected_stream: @@ -56,35 +59,37 @@ def __connect_to_ctl(self): self.__connected_ctl = True def __connect_to_stream(self): - self._stream_connection = pymysql.connect(**self.__connection_settings) - cur = self._stream_connection.cursor() - cur.execute("SHOW MASTER STATUS") - log_file, log_pos = cur.fetchone()[:2] - cur.close() - - if self.__log_file is None: - self.__log_file = log_file # log_pos (4) -- position in the binlog-file to start the stream with # flags (2) BINLOG_DUMP_NON_BLOCK (0 or 1) # server_id (4) -- server id of this slave # log_file (string.EOF) -- filename of the binlog on the master - command = COM_BINLOG_DUMP - prelude = struct.pack('