@@ -243,6 +243,7 @@ def __init__(self, host=None, port=None,
243
243
244
244
self .strategy_class = strategy_class
245
245
self .strategy = strategy_class (addrs )
246
+ self .addrs = addrs
246
247
247
248
addr = self .strategy .getnext ()
248
249
host = addr ['host' ]
@@ -252,6 +253,9 @@ def __init__(self, host=None, port=None,
252
253
self .cluster_discovery_delay = cluster_discovery_delay
253
254
self .last_nodes_refresh = 0
254
255
256
+ self .pool = {}
257
+ self .ro = {}
258
+
255
259
super (MeshConnection , self ).__init__ (
256
260
host = host ,
257
261
port = port ,
@@ -265,11 +269,44 @@ def __init__(self, host=None, port=None,
265
269
call_16 = call_16 ,
266
270
connection_timeout = connection_timeout )
267
271
272
+ self .pool [self ._addr_key (addr )] = self
273
+
274
+ for addr in self .addrs :
275
+ key = self ._addr_key (addr )
276
+ if key not in self .pool :
277
+ self .pool [key ] = Connection (
278
+ host = addr ['host' ],
279
+ port = addr ['port' ],
280
+ user = user ,
281
+ password = password ,
282
+ socket_timeout = socket_timeout ,
283
+ reconnect_max_attempts = reconnect_max_attempts ,
284
+ reconnect_delay = reconnect_delay ,
285
+ connect_now = connect_now ,
286
+ encoding = encoding ,
287
+ call_16 = call_16 ,
288
+ connection_timeout = connection_timeout )
289
+
290
+ def _addr_key (_ , addr ):
291
+ return f"{ addr ['host' ]} :{ addr ['port' ]} "
292
+
268
293
def connect (self ):
269
294
super (MeshConnection , self ).connect ()
270
295
if self .connected and self .cluster_discovery_function :
271
296
self ._opt_refresh_instances ()
272
297
298
+ for key in self .pool :
299
+ conn = self .pool [key ]
300
+
301
+ if not conn .connected :
302
+ conn .connect ()
303
+ if not conn .connected :
304
+ warn ("can't connect to instance to get rw/ro state" , ClusterDiscoveryWarning )
305
+ continue
306
+
307
+ # box.cfg was called at least once since we can connect.
308
+ self .ro [key ] = conn .eval ("return box.info.ro" )
309
+
273
310
def _opt_reconnect (self ):
274
311
'''
275
312
Attempt to connect "reconnect_max_attempts" times to each
0 commit comments