四时宝库

程序员的知识宝库

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。

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接