question

reginahart avatar image
reginahart asked Erick Ramirez answered

How do we configure remote nodes in Java driver 4?

Existing cluster works with driver 2.14 using

Cluster.withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy()))

Please can you advise how to get the equivalent in driver 4+.

The Cluster class does not exist.

In our site we have Cassandra servers across multiple datacenters, clustered. This works using Datastax Cassandra driver 2.1.4 and the Cluster.

In 4.10, using CqlSession, and the default LBP, defining 1 localDatacenter, the Cassandra nodes in the other datacenter cannot be reached.

Using DcInferringLoadBalancingPolicy, there is no need to specify the localDatacenter, but on startup we get exception (nodes and dc names masked)

2021-03-02 09:24:20,824 ERROR Platform startup failed java.lang.IllegalStateException: No local DC was provided, but the contact points are from different DCs: Node(endPoint=xxx.domain.com:9042, hostId=870e71d8-61c5-4eef-8e83-bf5ffb3a9dec, hashCode=13379641)=DC1, Node(endPoint=yyy.domain.com:9042, hostId=26e1b758-f5d6-4016-92df-30663a8b1cf5, hashCode=24359a70)=DC2,…

please set the local DC explicitly (see basic.load-balancing-policy.local-datacenter in the config, or set it programmatically with SessionBuilder.withLocalDatacenter)

at com.datastax.oss.driver.internal.core.loadbalancing.helper.InferringLocalDcHelper.discoverLocalDc(InferringLocalDcHelper.java:79)

How can we wire up the Cassandra CqlSession for our site setup please

java driverload balancing
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

This appears to be the same question you already asked in #10433.

You are correct in that DcInferringLoadBalancingPolicy does not require you to define the local DC because it infers the DC from the contact points. The error you posted states that it couldn't determine the local DC because the contact points belong to 2 different DCs -- DC1 and DC2. As a result, the error is explicitly telling you the contact points are from different DCs (from InferringLocalDcHelper class):

No local DC was provided, but the contact points are from different DCs

The DcInferringLoadBalancingPolicy will only allow the driver to connect to a single DC. You cannot use it for connecting to multiple DCs.

As I explained in your previous question, you need to implement a custom load balancing policy that allows the driver to connect to any DC. You can use the BasicLoadingBalancingPolicy as a reference but we don't recommend you use it. It will work if you use it as your LBP but be aware that it is not recommended or supported for use in production. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.