DCAwareRoundRobinPolicy 与 RoundRobinPolicy

DCAwareRoundRobinPolicy Vs RoundRobinPolicy

我对 DCAwareRoundRobinPolicy 和 RoundRobinPolicy 感到困惑

根据文档,DCAwareRoundRobinPolicy 首先联系本地 DC 的节点,然后再联系远程 DC 的节点。

如果我不设置 withUsedHostsPerRemoteDc & allowRemoteDCsForLocalConsistencyLevel。 如果回退,所有 java 客户端应用程序是否仍会转到远程 DC??

我目前正在使用以下代码:

    DCAwareRoundRobinPolicy.builder().withLocalDc(cassandraConfig.getLocalDC())
.withUsedHostsPerRemoteDc(cassandraConfig.getUsedHostsPerRemoteDc())
.allowRemoteDCsForLocalConsistencyLevel();

我在当前生产集群中添加新 DC 时遇到问题。由于上面的代码,我可以看到 Reads/Writes 也在 Remote DC 上启动,我只是在添加。尽管新 DC 没有为它们设置任何复制因子。我仍然可以看到这种交通。因为重建新节点需要数小时才能完成,所以我无法让所有应用程序到达新节点。 最后我需要停用新节点来暂时停止这种行为。

删除 withUsedHostsPerRemoteDc & allowRemoteDCsForLocalConsistencyLevel 之后一切看起来都不错。

Datastax 文档也说 https://docs.datastax.com/en/latest-java-driver-api/com/datastax/driver/core/policies/DCAwareRoundRobinPolicy.Builder.html#allowRemoteDCsForLocalConsistencyLevel--

It is however inadvisable to do so in almost all cases, as this would potentially break consistency guarantees

如果以上是真的那么DCAwareRoundRobinPolicy有什么用为什么RoundRobinPolicy不好???

默认情况下,在设置您提到的选项之前,DCAwareRoundRobinPolicy 不会转到远程 DC。但这只会发生在一致性级别 LOCAL_ONELOCAL_QUORUM 上。如果您使用非 LOCAL_ 一致性级别,那么请求也可以发送到远程 DC。但它应该只发生在 QUORUMEACH_QUORUM 或以下时间:

this policy guarantees that no host in a remote data center will be queried unless no host in the local data center can be reached.

尽管看到这个很奇怪因为你说:

Although New DCs are not having any Replication Factor set for them.

我建议通过 JMX 检查它是否真的到达了远程 DC 中的表?