将DNS故障转移用作多DC故障转移策略吗?

时间:2018-07-19 23:46:18

标签: cassandra datastax-enterprise datastax-java-driver

如果我有一个多DC群集,则 DC1 DC2 ,其中DC2仅用于故障转移。在客户端的驱动程序中,我使用域名(foo1.net, foo2.net, and foo3.net)定义了接触点。我有foo *指向DC1,如果我检测到DC1有任何错误,我将使DNS路由foo *指向DC2。

这种方法似乎可以在纸上使用,但实际上可以使用吗?这种方法有什么问题吗?

1 个答案:

答案 0 :(得分:2)

在DataStax Java驱动程序3.x的情况下,由于仅在Cluster实例化开始时才对DNS进行评估,因此这将不起作用。

使用DNS通过InetAddress.getAllByName中的Cluster.Builder.addContactPoint解析提供的联系点:

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);
    }
}

如果在Cluster的生命周期中更改了DNS,除非您构造一个新的Cluster.Builder实例并从中创建一个新的Cluster,否则驱动程序将不会意识到这一点。 / p>

我更喜欢将数据中心故障转移推到应用程序范围之外并进入体系结构更高级别的设计。不要让客户端应用程序负责故障转移,而应该运行在每个C *数据中心中共存的客户端实例。当数据中心不可用时,您的应用程序负载平衡器/路由器/ DNS可以将流量定向到其他数据中心中的应用程序实例。

相关问题