@@ -130,7 +130,8 @@ class BinLogStreamReader(object):
130
130
def __init__ (self , connection_settings , server_id ,
131
131
ctl_connection_settings = None , resume_stream = False ,
132
132
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 ,
134
135
ignored_events = None , auto_position = None ,
135
136
only_tables = None , ignored_tables = None ,
136
137
only_schemas = None , ignored_schemas = None ,
@@ -152,6 +153,7 @@ def __init__(self, connection_settings, server_id,
152
153
log_file: Set replication start log file
153
154
log_pos: Set replication start log pos (resume_stream should be
154
155
true)
156
+ end_log_pos: Set replication end log pos
155
157
auto_position: Use master_auto_position gtid to set position
156
158
only_tables: An array with the tables you want to watch (only works
157
159
in binlog_format ROW)
@@ -205,6 +207,7 @@ def __init__(self, connection_settings, server_id,
205
207
# Store table meta information
206
208
self .table_map = {}
207
209
self .log_pos = log_pos
210
+ self .end_log_pos = end_log_pos
208
211
self .log_file = log_file
209
212
self .auto_position = auto_position
210
213
self .skip_to_timestamp = skip_to_timestamp
@@ -416,7 +419,8 @@ def __connect_to_stream(self):
416
419
self .__connected_stream = True
417
420
418
421
def fetchone (self ):
419
- while True :
422
+ should_continue = True
423
+ while should_continue :
420
424
if not self .__connected_stream :
421
425
self .__connect_to_stream ()
422
426
@@ -470,6 +474,10 @@ def fetchone(self):
470
474
elif binlog_event .log_pos :
471
475
self .log_pos = binlog_event .log_pos
472
476
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
+
473
481
# This check must not occur before clearing the ``table_map`` as a
474
482
# result of a RotateEvent.
475
483
#
0 commit comments