"All host(s) tried for query failed" Error

Pradyumn picture Pradyumn · Nov 7, 2014 · Viewed 19.7k times · Source

My Java code is as follows:

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Metadata;
import com.datastax.driver.core.Session;

public class CustomerController {

    public void execute() {
        Cluster cluster = Cluster.builder()
                .addContactPoints("172.16.11.126", "172.16.11.130")
                .withPort(9042)
                .build();
        Session session = cluster.connect();
        String command = "drop keyspace if exists bookstore";
        session.execute(command);
        cluster.close();
    }
}

When I run the code, I get the following error:

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /172.16.11.130 (com.datastax.driver.core.TransportException: [/172.16.11.130] Cannot connect), /172.16.11.126 (com.datastax.driver.core.TransportException: [/172.16.11.126] Cannot connect))
at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:195)
at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:78)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1029)
at com.datastax.driver.core.Cluster.init(Cluster.java:120)
at com.datastax.driver.core.Cluster.connect(Cluster.java:197)
at com.pragatisoftware.datastax99.app.CustomerController.execute(CustomerController.java:12)
at com.pragatisoftware.datastax99.app.Application.run(Application.java:10)
at com.pragatisoftware.datastax99.app.Application.main(Application.java:6)

Environment information:

  • Ubuntu machine
  • Eclipse Luna
  • Java 1.7
  • Cassandra 2.0.11

In cassandra.yaml:

native_transport_port: 9042

Cassandra is running on both the IP addresses provided above (172.16.11.130 and 172.16.11.126) and I am able to connect using CQLSH to both the machines.

By the way, the same code (with the appropriate IP address) worked on a Windows machine, using Cassandra 2.0.9.

Answer

Rahul picture Rahul · Oct 19, 2015

Change rpc_address: 0.0.0.0 broadcast_rpc_address: 1.2.3.4 (Should not be 0.0.0.0) . for Cassandra version 2.1.10

Also for any further issue read cassandra.yaml file . lot of things are self explanatory.