Skip to content

Commit a1b7566

Browse files
authored
Merge pull request #1 from intercom/paulvic-patch-1
Add basic support for `end_log_pos`
2 parents 84f2cda + 7199daf commit a1b7566

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ class BinLogStreamReader(object):
130130
def __init__(self, connection_settings, server_id,
131131
ctl_connection_settings=None, resume_stream=False,
132132
blocking=False, only_events=None, log_file=None,
133-
log_pos=None, filter_non_implemented_events=True,
133+
log_pos=None, end_log_pos=None,
134+
filter_non_implemented_events=True,
134135
ignored_events=None, auto_position=None,
135136
only_tables=None, ignored_tables=None,
136137
only_schemas=None, ignored_schemas=None,
@@ -152,6 +153,7 @@ def __init__(self, connection_settings, server_id,
152153
log_file: Set replication start log file
153154
log_pos: Set replication start log pos (resume_stream should be
154155
true)
156+
end_log_pos: Set replication end log pos
155157
auto_position: Use master_auto_position gtid to set position
156158
only_tables: An array with the tables you want to watch (only works
157159
in binlog_format ROW)
@@ -205,6 +207,7 @@ def __init__(self, connection_settings, server_id,
205207
# Store table meta information
206208
self.table_map = {}
207209
self.log_pos = log_pos
210+
self.end_log_pos = end_log_pos
208211
self.log_file = log_file
209212
self.auto_position = auto_position
210213
self.skip_to_timestamp = skip_to_timestamp
@@ -416,7 +419,8 @@ def __connect_to_stream(self):
416419
self.__connected_stream = True
417420

418421
def fetchone(self):
419-
while True:
422+
should_continue = True
423+
while should_continue:
420424
if not self.__connected_stream:
421425
self.__connect_to_stream()
422426

@@ -470,6 +474,10 @@ def fetchone(self):
470474
elif binlog_event.log_pos:
471475
self.log_pos = binlog_event.log_pos
472476

477+
if self.end_log_pos and self.log_pos >= self.end_log_pos:
478+
# We're currently at, or past, the specified end log position.
479+
should_continue = False
480+
473481
# This check must not occur before clearing the ``table_map`` as a
474482
# result of a RotateEvent.
475483
#

0 commit comments

Comments
 (0)