learner
learner

Reputation: 1155

Working of Cassandra-CQL ClusterBuilder's addContactPoints

I am writing one java application that uses cassandra cql driver to get/set data to cassandra. I have 2 nodes in my cluster and want to add both of them in addContactPoints so that requests are handled in case of failover or load sharing.

Can someone tell me more about addContactPoints(String... addresses) as in how does it works? Will only 1 node be used till its down or both of them will be used to balance the nodes? I am not clear with the working on this function and could not find much clarity over web. 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?

Thanks!

Upvotes: 1

Views: 691

Answers (2)

Aaron
Aaron

Reputation: 57788

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

It's important to understand that the contact points are only used to discover the topology of cluster (similar to how seed nodes are used). Once the topology is understood, then the driver can use any node in the cluster (even those not provided as contact points) to satisfy a request. Therefore the the contact points provided really have little bearing on the balancing of requests.

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?

And if one node in your list of contact points is not accessible, it will use another. This is why even though you really only need to provide one node, it is a good idea to provide multiple.

Upvotes: 1

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280102

From the 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.

The default load balancing policy is 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.

It will keep trying other hosts if others can't be reached.

Upvotes: 2

Related Questions