Cassandra-CQL ClusterBuilder 的 addContactPoints 的工作

Working of Cassandra-CQL ClusterBuilder's addContactPoints

我正在编写一个 java 应用程序,它使用 cassandra cql 驱动程序将 get/set 数据传输到 cassandra。我的集群中有 2 个节点,我想将它们都添加到 addContactPoints 中,以便在发生故障转移或负载共享时处理请求。

有人可以告诉我更多有关 addContactPoints(String... addresses) 的信息吗?它是如何工作的?是只使用 1 个节点直到它宕机还是两个节点都用于平衡节点?我不清楚这个功能的工作,也无法通过网络找到更多的清晰度。另外,如果一个节点不可访问,它会自动使用另一个 ip 还是其他一些 属性 也需要设置?

谢谢!

来自javadoc

Note that by default (that is, unless you use the withLoadBalancingPolicy) method of this builder), the first succesfully contacted host will be use to define the local data-center for the client. If follows that if you are running Cassandra in a multiple data-center setting, it is a good idea to only provided contact points that are in the same datacenter than the client, or to provide manually the load balancing policy that suits your need.

默认的负载均衡策略是DCAwareRoundRobinPolicy

In other words, 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.

如果无法联系到其他主机,它将继续尝试其他主机。

Will only 1 node be used till its down or both of them will be used to balance the nodes?

重要的是要了解接触点仅用于发现集群的拓扑结构(类似于种子节点的使用方式)。一旦了解了拓扑结构,驱动程序就可以使用集群中的任何节点(甚至那些未作为接触点提供的节点)来满足请求。因此,提供的联系点对请求的平衡影响不大。

Also in case if one node is not reachable will it automatically use the other ip or some other property also needs to be set?

如果您的联系点列表中的一个节点不可访问,它将使用另一个。这就是为什么即使您真的只需要提供一个节点,但最好提供多个。