知识库

“Failed to update routing table with server” 错误说明

如果您在 $NEO4J_HOME/logs/debug.log 中遇到类似的 Failed to update routing table with server 错误,类似于

ERROR 1 --- [o4jDriverIO-5-2] LoadBalancer : Failed to update routing table. Current routing table: Ttl 1582554193442, currentTime 1582554193471, routers AddressSet=[], writers AddressSet=[], readers AddressSet=[]

Suppressed: org.neo4j.driver.exceptions.DiscoveryException: Failed to update routing table with server 'server-foo:7687'.

Caused by: org.neo4j.driver.exceptions.ClientException: There is no procedure with the name `dbms.cluster.routing.getRoutingTable` registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.

可以通过检查 DNS 记录来解决此问题。路由驱动是通过 bolt+routing URI 创建的,例如 bolt+routing://graph.example.com:7687。URI 中的地址必须是 CORE 服务器的地址。因此,如果出现上述错误,很可能是因为您使用了一个 DNS 名称来解析 CORE 和 READ REPLICA 节点。READ REPLICA 不应在 DNS 记录中有条目。当主机名解析为 CORE 节点的 IP 地址时,一切正常。但如果主机名解析为 READ REPLICA 的 IP 地址,驱动将无法从该服务器获取路由表,从而导致连接数据库失败。

解决方案

更改 DNS 记录,确保名称解析仅指向 CORE 节点,而不是 READ REPLICA。

如果只想连接到 READ REPLICA,该怎么办?

我们的部分客户有特定需求,只向 READ REPLICA 发送 读取请求。如果您有类似需求,可以按以下步骤操作:

  • 将所有 CORE 节点放在同一个 DNS 名称下,例如 core.graph.example.com

  • 将所有 READ REPLICA 放在另一个(单一)DNS 名称下,例如 rr.graph.example.com

  • 然后可以使用以下 URI 连接 READ REPLICA:bolt://rr.graph.example.com:7687

此方案的优势在于,即使 CORE 节点宕机,应用仍然可以连接到 READ REPLICA。

缺点是每个应用只能使用 bolt 协议连接到单个 READ REPLICA。这可能导致多个应用连接到同一个 READ REPLICA,未能利用所有可用的 READ REPLICA。

Neo4j 驱动手册参考

© . This site is unofficial and not affiliated with Neo4j, Inc.