如何在Cassandra Java驱动程序V4中编程启用跨代码故障转移?
在dataStax驱动程序3.x中,我们获得了DCAWAREROUNDROBIN策略,如果本地数据中心中的节点失败。 DataStax文档,提到:
Cross-datacenter failover is enabled with the following configuration option:
datastax-java-driver.advanced.load-balancing-policy.dc-failover {
max-nodes-per-remote-dc = 2
}
然后,驱动程序将尝试在远程数据中心中打开与节点的连接。但是,在驱动程序中,我们仅指定一个数据中心,以连接到以下:
CqlSession session = CqlSession.builder()
.addContactPoint(new InetSocketAddress("1.2.3.4", 9042))
.addContactPoint(new InetSocketAddress("5.6.7.8", 9042))
.withLocalDatacenter("datacenter1")
.build();
如何处理与远程数据中心的连接?帮助..
In datastax driver 3.x,we've DCAwareRoundRobin policy,which tries to connect to remote nodes if nodes in local datacenter fails.In the datastax drvier 4.x,we donot have that policy and confines to local-only.But,in the datastax docs,it's mentioned as:
Cross-datacenter failover is enabled with the following configuration option:
datastax-java-driver.advanced.load-balancing-policy.dc-failover {
max-nodes-per-remote-dc = 2
}
The driver will then attempt to open connections to nodes in remote datacenter.But,in the driver,we specify only a single datacenter to connect to as below:
CqlSession session = CqlSession.builder()
.addContactPoint(new InetSocketAddress("1.2.3.4", 9042))
.addContactPoint(new InetSocketAddress("5.6.7.8", 9042))
.withLocalDatacenter("datacenter1")
.build();
How the connection to remote datacenter is handled?Please help..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速的答案是您不按编程方式进行操作 - Java驱动程序启用了
Advanced.dadage-load-balancing-policy.dc-failover
。接触点只是驱动程序“联系人”的初始主机,以发现群集拓扑。在收集了有关集群的元数据后,它知道远程DC中的节点。
由于您已经配置了
max-nodes-per-per-emote-dc = 2
,因此驱动程序将从每个远程DC添加2个节点到查询计划的末尾。本地DC中的节点将首先列出,然后列出远程节点。如果驾驶员无法在本地DC中与节点联系,则它将开始在查询计划中与远程节点联系,一次节点直到它用尽节点以触电为止。但是我必须重申我在您的其他问题,我们不建议启用DC-Failover 。对于任何遇到这个答案的人,您都会被警告。干杯!
The quick answer is you don't do it programatically -- the Java driver does it for you after you've enabled
advanced.load-balancing-policy.dc-failover
.The contact points are just the initial hosts the driver "contacts" to discover the cluster topology. After it has collected metadata about the cluster, it knows about nodes in remote DCs.
Since you've configured
max-nodes-per-remote-dc = 2
, the driver will add 2 nodes from each remote DC to the end of the query plan. The nodes in the local DC will be listed first then followed by the remote nodes. If the driver can't contact the nodes in the local DC, then it will start contacting the remote nodes in the query plan, one node at a time until it runs out of nodes to contact.But I have to reiterate what I said in your other question, we do not recommend enabling DC-failover. For anyone else coming across this answer, you've been warned. Cheers!