Skip to content

Commit 7e06114

Browse files
Connect every instance and collect ro info
1 parent 6c58895 commit 7e06114

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tarantool/mesh_connection.py

+37
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def __init__(self, host=None, port=None,
243243

244244
self.strategy_class = strategy_class
245245
self.strategy = strategy_class(addrs)
246+
self.addrs = addrs
246247

247248
addr = self.strategy.getnext()
248249
host = addr['host']
@@ -252,6 +253,9 @@ def __init__(self, host=None, port=None,
252253
self.cluster_discovery_delay = cluster_discovery_delay
253254
self.last_nodes_refresh = 0
254255

256+
self.pool = {}
257+
self.ro = {}
258+
255259
super(MeshConnection, self).__init__(
256260
host=host,
257261
port=port,
@@ -265,11 +269,44 @@ def __init__(self, host=None, port=None,
265269
call_16=call_16,
266270
connection_timeout=connection_timeout)
267271

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+
268293
def connect(self):
269294
super(MeshConnection, self).connect()
270295
if self.connected and self.cluster_discovery_function:
271296
self._opt_refresh_instances()
272297

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+
273310
def _opt_reconnect(self):
274311
'''
275312
Attempt to connect "reconnect_max_attempts" times to each

0 commit comments

Comments
 (0)