3030from neo4j .v1 .exceptions import SessionExpired
3131from neo4j .v1 .security import SecurityPlan
3232from neo4j .v1 .session import BoltSession
33+ from neo4j .util import ServerVersion
3334
3435
3536class RoundRobinSet (MutableSet ):
@@ -152,14 +153,23 @@ class RoutingConnectionPool(ConnectionPool):
152153 """ Connection pool with routing table.
153154 """
154155
155- routing_info_procedure = "dbms.cluster.routing.getServers"
156+ call_get_servers = "CALL dbms.cluster.routing.getServers"
157+ get_routing_table_param = "context"
158+ call_get_routing_table = "CALL dbms.cluster.routing.getRoutingTable({" + get_routing_table_param + "})"
156159
157- def __init__ (self , connector , initial_address , * routers ):
160+ def __init__ (self , connector , initial_address , routing_context , * routers ):
158161 super (RoutingConnectionPool , self ).__init__ (connector )
159162 self .initial_address = initial_address
163+ self .routing_context = routing_context
160164 self .routing_table = RoutingTable (routers )
161165 self .refresh_lock = Lock ()
162166
167+ def routing_info_procedure (self , connection ):
168+ if ServerVersion .from_str (connection .server .version ).at_least_version (3 , 2 ):
169+ return self .call_get_routing_table , {self .get_routing_table_param : self .routing_context }
170+ else :
171+ return self .call_get_servers , None
172+
163173 def fetch_routing_info (self , address ):
164174 """ Fetch raw routing info from a given router address.
165175
@@ -170,8 +180,9 @@ def fetch_routing_info(self, address):
170180 if routing support is broken
171181 """
172182 try :
173- with BoltSession (lambda _ : self .acquire_direct (address )) as session :
174- return list (session .run ("CALL %s" % self .routing_info_procedure ))
183+ connection = self .acquire_direct (address )
184+ with BoltSession (lambda _ : connection ) as session :
185+ return list (session .run (* self .routing_info_procedure (connection )))
175186 except CypherError as error :
176187 if error .code == "Neo.ClientError.Procedure.ProcedureNotFound" :
177188 raise ServiceUnavailable ("Server {!r} does not support routing" .format (address ))
@@ -313,6 +324,7 @@ def __init__(self, uri, **config):
313324 self .initial_address = initial_address = SocketAddress .from_uri (uri , DEFAULT_PORT )
314325 self .security_plan = security_plan = SecurityPlan .build (** config )
315326 self .encrypted = security_plan .encrypted
327+ routing_context = SocketAddress .parse_routing_context (uri )
316328 if not security_plan .routing_compatible :
317329 # this error message is case-specific as there is only one incompatible
318330 # scenario right now
@@ -321,7 +333,7 @@ def __init__(self, uri, **config):
321333 def connector (a ):
322334 return connect (a , security_plan .ssl_context , ** config )
323335
324- pool = RoutingConnectionPool (connector , initial_address , * resolve (initial_address ))
336+ pool = RoutingConnectionPool (connector , initial_address , routing_context * resolve (initial_address ))
325337 try :
326338 pool .update_routing_table ()
327339 except :
0 commit comments