知识库

错误“Failed to obtain connection towards WRITE server. Known routing table is: Ttl…”的解释

在 Neo4j 4.0 中,如果您登录到因果集群的 READ_REPLICA 并执行以下命令以登录到 cypher-shell

$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p mypwd

您将遇到此错误

Failed to obtain connection towards WRITE server.
Known routing table is: Ttl 1589334991968, currentTime 1589334691977,
routers AddressSet=[localhost:7637], writers AddressSet=[],
readers AddressSet=[localhost:7637], database '<default database>'
在 4.0 版本之前,上述命令是登录 cypher-shell 的完全有效/正确的命令。

原因是命令中地址 (-a) 参数的默认值为 neo4j://localhost:7687

语法在 cypher-shell 命令行帮助中记录为

$ $NEO4J_HOME/bin/cypher-shell -help
 -a ADDRESS, --address ADDRESS
                         address and port to connect to (default: neo4j://localhost:7687)

默认值 neo4j://localhost:7687 的含义是 cypher-shell 将登录命令解释为

$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p mypwd -a neo4j://localhost:7687
上述命令无效/错误。neo4j URI 方案是 4.0 等效于 bolt+routing 的方案,仅应用于连接到因果集群中的 CORE 服务器之一,而不是连接到任何 READ REPLICA

要解决此错误并登录到 READ_REPLICAcypher-shell,请改用以下命令

$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p mypwd -a bolt://localhost:7687

从不同的 Causal Cluster 成员连接到 READ REPLICA 时,请使用以下命令

$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p mypwd -a bolt://<read-replica-server-ip>:7687
本文的一个关键要点是,如果您使用 neo4jbolt+routing URI 方案,则应连接到 Causal Cluster 中的 CORE 节点,而不是 READ_REPLICA