Skip to content

Minor adjustments #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pymysqlreplication/binlogstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class BinLogStreamReader(object):
'''Connect to replication stream and read event'''

def __init__(self, connection_settings = {}, resume_stream = False, blocking = False, only_events = None, server_id = 255):
def __init__(self, connection_settings={}, resume_stream=False, blocking=False, only_events=None, server_id=255):
'''
resume_stream: Start for latest event of binlog or from older available event
blocking: Read on stream is blocking
Expand Down Expand Up @@ -45,6 +45,7 @@ def __connect_to_ctl(self):
self._ctl_connection_settings['db'] = 'information_schema'
self._ctl_connection_settings['cursorclass'] = pymysql.cursors.DictCursor
self._ctl_connection = pymysql.connect(**self._ctl_connection_settings)
self.__connected_ctl = True
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats the important part. Otherwise there will be a new connection created for every packet.


def __connect_to_stream(self):
self._stream_connection = pymysql.connect(**self.__connection_settings)
Expand All @@ -61,7 +62,7 @@ def __connect_to_stream(self):
# binlog-filename (string.EOF) -- filename of the binlog on the master
command = COM_BINLOG_DUMP
prelude = struct.pack('<i', len(self.__log_file) + 11) \
+ int2byte(command)
+ int2byte(command)
if self.__log_pos is None:
if self.__resume_stream:
prelude += struct.pack('<I', log_pos)
Expand All @@ -80,9 +81,9 @@ def __connect_to_stream(self):

def fetchone(self):
while True:
if self.__connected_stream == False:
if not self.__connected_stream:
self.__connect_to_stream()
if self.__connected_ctl == False:
if not self.__connected_ctl:
self.__connect_to_ctl()
pkt = None
try:
Expand Down
2 changes: 1 addition & 1 deletion pymysqlreplication/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection):
def dump(self):
print("=== %s ===" % (self.__class__.__name__))
print("Position: %d" % self.position)
print("Next binlog file: %d" % self.next_binlog)
print("Next binlog file: %s" % self.next_binlog)
print()


Expand Down