“All host(s) tried for query failed” Error

不打扰是莪最后的温柔 提交于 2019-11-29 14:06:45

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/26795479/all-hosts-tried-for-query-failed-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!