If a host is lost, the datastex Java driver will not connect
If I am not wrong, I can connect to a Cassandra cluster, know that there is at least one node in the cluster, and then I can find other nodes
Suppose I have three nodes (1, 2 and 3) to which I connect, as follows:
. Cluster. Builder () addcontactpoints ("1,2,3". Split (""));
Then, if node 3 drops, for example, and the IP cannot be resolved, this line of code will throw an illegalargumentexception, as described in the document:
@Throws illegalargumentexception, if at least one IP address of {@ code address} is not found
Why does anyone want this behavior? I mean, if one of the nodes is down, I want the application to run because Cassandra can still run normally
I have checked the Cassandra Java driver: how many contact points is reasonable? But this doesn't answer my question, because it can't say any questions about the host, because it can't achieve its goal
What should I do? Maybe this was changed in another version of the Java driver? I am currently using cassandra-driver-core-3.0 three
Solution
This verification is only to ensure that all provided hosts can be solved, and does not even check whether Cassandra server is running on each host So it basically ensures that you don't make any typing errors when providing the host, because it doesn't think it's a normal use case to provide an unresolved host
As a solution to your situation (the host has been deleted from the DNS entry), you can directly call the method addcontactpoint (string address) instead of using addcontactpoints (string... Address) (the following scenario simply calls addcontactpoint (string address) for each provided address) and manage the exceptions yourself
The code might look like this:
Cluster.Builder builder = Cluster.builder(); // Boolean used to check if at least one host Could be resolved boolean found = false; for (String address : "1,3".split(",")) { try { builder.addContactPoint(address); // One host Could be resolved found = true; } catch (IllegalArgumentException e) { // This host Could not be resolved so we log a message and keep going Log.log( Level.WARNING,String.format("The host '%s' is unkNown so it will be ignored",address) ); } } if (!found) { // No host Could be resolved so we throw an exception throw new IllegalStateException("All provided hosts are unkNown"); } Cluster cluster = builder.build();
FYI: I just created a ticket to propose a Java driver https://datastax-oss.atlassian.net/browse/JAVA-1334 The improvement of