@@ -37,10 +37,9 @@ class SentinelManagedConnection(Connection):
37
37
def __init__ (self , ** kwargs ):
38
38
self .connection_pool = kwargs .pop ("connection_pool" )
39
39
# To be set to True if we want to prevent
40
- # the sentinel managed connection to connect
41
- # to the most relevant sentinel in the pool and just
42
- # connect to the current self.host and self.port
43
- self ._is_address_fixed = False
40
+ # the connection to connect to the most relevant sentinel
41
+ # in the pool and just connect to the current host and port
42
+ self ._is_address_set = False
44
43
super ().__init__ (** kwargs )
45
44
46
45
def __repr__ (self ):
@@ -54,9 +53,13 @@ def __repr__(self):
54
53
s += host_info
55
54
return s + ")>"
56
55
57
- def fix_address (self , address ):
56
+ def set_address (self , address ):
57
+ """
58
+ By setting the address, the connection will just connect
59
+ to the current host and port the next time connect is called.
60
+ """
58
61
self .host , self .port = address
59
- self ._is_address_fixed = True
62
+ self ._is_address_set = True
60
63
61
64
async def connect_to (self , address ):
62
65
self .host , self .port = address
@@ -70,15 +73,13 @@ async def _connect_retry(self):
70
73
if self ._reader :
71
74
return # already connected
72
75
# If address is fixed, it means that the connection
73
- # is not rotating to the next slave (if the connection pool is in replica mode)
74
- if self ._is_address_fixed :
76
+ # just connect to the current host and port
77
+ if self ._is_address_set :
75
78
await self .connect_to ((self .host , self .port ))
76
79
return
77
80
await self ._connect_to_sentinel ()
78
81
79
82
async def _connect_to_sentinel (self ):
80
- # If same_server is False, connnect to master in master mode
81
- # and rotate to the next slave in slave mode
82
83
if self .connection_pool .is_master :
83
84
await self .connect_to (await self .connection_pool .get_master_address ())
84
85
else :
@@ -246,7 +247,7 @@ async def get_connection(
246
247
host = server_host , port = server_port
247
248
)
248
249
# If not, make a new dummy connection object, and set its host and
249
- # port to the one that we want later in the call to ``connect_to_address ``
250
+ # port to the one that we want later in the call to ``set_address ``
250
251
if not connection :
251
252
connection = self .make_connection ()
252
253
assert connection
@@ -261,7 +262,7 @@ async def get_connection(
261
262
# connect to the previous replica.
262
263
# This will connect to the host and port of the replica
263
264
else :
264
- connection .fix_address ((server_host , server_port ))
265
+ connection .set_address ((server_host , server_port ))
265
266
await self .ensure_connection (connection )
266
267
except BaseException :
267
268
# Release the connection back to the pool so that we don't
0 commit comments