Neo4j因果集群读写分离

使用Neo4j因果集群,主要是为了高可用、高并发。我们知道,Neo4j 集群 CORE 节点可以 READ 和 WRITE,而其它节点(FOLLOWER 和 READ REPLICA)都只能 READ。
如果您想把 READ 的请求只发送到READ REPLICA,该怎么办?
如果您有类似需求,则可以执行以下操作:
1)单个 DNS 下添加多个 A 项指向所有 CORE 节点,如: http://core.graph.example.com;
2)另一个 DNS 下添加多个 A 项指向所有 READ REPLICA 节点,如: http://read.graph.example.com
3)使用以下 URI 访问 READ REPLICA:“ bolt://http://read.graph.example.com:7687 ”
此方式:

优点:即使 CORE 节点关闭,应用程序仍可以连接到 READ REPLICA。
缺点:客户端访问只读节点时只能使用 BOLT 协议,只能与某个READ REPLICA 通信,没有利用所有可用的 READ REPLICA节点。

在这里插入图片描述
如果您遇到类似以下错误($NEO4J_HOME/logs/debug.log)服务器更新路由表失败

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://http://graph.example.com:7687。URI 中地址必须是 CORE 服务器地址。因此,很可能您遇到上述错误,您可以使用 DNS 解析为CORE和READ REPLICA节点。READ REPLICA 的DNS记录不应包含条目。当主机名解析为 CORE 节点IP地址时,一切正常。但是,当主机名解析为READ REPLICA IP地址时,驱动程序将无法连接到数据库,因为它无法从该服务器获取路由表。
解决方法:
更改DNS,以确保名称解析仅包括CORE节点,而不包括READ REPLICA。
原文链接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章