【问题标题】:Will using DNS failover work as a Multi-DC failover strategy?将 DNS 故障转移用作多 DC 故障转移策略吗?
【发布时间】:2018-12-28 05:08:17
【问题描述】:
如果我有一个多 DC 集群,DC1 和 DC2,其中 DC2 仅用于故障转移。在客户端的驱动程序中,我使用域名(foo1.net, foo2.net, and foo3.net) 定义联系点。我有 foo* 指向 DC1,如果我检测到 DC1 有任何错误,我会让 DNS 路由 foo* 指向 DC2。
这种方法似乎在纸面上有效,但它真的有效吗?这种方法有什么问题吗?
【问题讨论】:
标签:
cassandra
datastax-enterprise
datastax-java-driver
【解决方案1】:
在 DataStax Java Driver 3.x 的情况下,这将不起作用,因为 DNS 仅在 Cluster 实例化的开头进行评估。
所提供的联系点通过InetAddress.getAllByName in Cluster.Builder.addContactPoint 使用DNS 解析:
public Builder addContactPoint(String address) {
// We explicitly check for nulls because InetAdress.getByName() will happily
// accept it and use localhost (while a null here almost likely mean a user error,
// not "connect to localhost")
if (address == null)
throw new NullPointerException();
try {
addContactPoints(InetAddress.getAllByName(address));
return this;
} catch (UnknownHostException e) {
throw new IllegalArgumentException("Failed to add contact point: " + address, e);
}
}
如果 DNS 在 Cluster 的生命周期内发生更改,驱动程序将不会意识到这一点,除非您构造一个新的 Cluster.Builder 实例并从中创建一个新的 Cluster。
我更喜欢将数据中心故障转移推到应用程序范围之外并进入更高层次架构的设计。与其让客户端应用程序负责故障转移,不如在每个 C* 数据中心运行客户端实例。当数据中心不可用时,您的应用程序负载均衡器/路由器/DNS 可以将流量引导到其他数据中心中的应用程序实例。