@@ -18,7 +18,7 @@ def __init__(self, connection_settings = {}, resume_stream = False, blocking = F
18
18
only_events: Array of allowed events
19
19
'''
20
20
connection_settings ['charset' ] = 'utf8'
21
- self .__stream_connection = pymysql .connect (** connection_settings )
21
+ self ._stream_connection = pymysql .connect (** connection_settings )
22
22
ctl_connection_settings = copy .copy (connection_settings )
23
23
ctl_connection_settings ['db' ] = 'information_schema'
24
24
ctl_connection_settings ['cursorclass' ] = pymysql .cursors .DictCursor
@@ -28,16 +28,17 @@ def __init__(self, connection_settings = {}, resume_stream = False, blocking = F
28
28
self .__blocking = blocking
29
29
self .__only_events = only_events
30
30
self .__server_id = server_id
31
+ self .__log_pos = None
31
32
32
33
#Store table meta informations
33
34
self .table_map = {}
34
35
35
36
def close (self ):
36
- self .__stream_connection .close ()
37
+ self ._stream_connection .close ()
37
38
self .__ctl_connection .close ()
38
39
39
40
def __connect_to_stream (self ):
40
- cur = self .__stream_connection .cursor ()
41
+ cur = self ._stream_connection .cursor ()
41
42
cur .execute ("SHOW MASTER STATUS" )
42
43
(log_file , log_pos ) = cur .fetchone ()[:2 ]
43
44
cur .close ()
@@ -50,24 +51,27 @@ def __connect_to_stream(self):
50
51
command = COM_BINLOG_DUMP
51
52
prelude = struct .pack ('<i' , len (log_file ) + 11 ) \
52
53
+ int2byte (command )
53
- if self .__resume_stream :
54
- prelude += struct .pack ('<I' , log_pos )
54
+ if self .__log_pos is None :
55
+ if self .__resume_stream :
56
+ prelude += struct .pack ('<I' , log_pos )
57
+ else :
58
+ prelude += struct .pack ('<I' , 4 )
55
59
else :
56
- prelude += struct .pack ('<I' , 4 )
60
+ prelude += struct .pack ('<I' , self . __log_pos )
57
61
if self .__blocking :
58
62
prelude += struct .pack ('<h' , 0 )
59
63
else :
60
64
prelude += struct .pack ('<h' , 1 )
61
65
prelude += struct .pack ('<I' , self .__server_id )
62
- self .__stream_connection .wfile .write (prelude + log_file .encode ())
63
- self .__stream_connection .wfile .flush ()
66
+ self ._stream_connection .wfile .write (prelude + log_file .encode ())
67
+ self ._stream_connection .wfile .flush ()
64
68
self .__connected = True
65
69
66
70
def fetchone (self ):
67
71
if self .__connected == False :
68
72
self .__connect_to_stream ()
69
73
while True :
70
- pkt = self .__stream_connection .read_packet ()
74
+ pkt = self ._stream_connection .read_packet ()
71
75
if not pkt .is_ok_packet ():
72
76
return None
73
77
binlog_event = BinLogPacketWrapper (pkt , self .table_map , self .__ctl_connection )
0 commit comments