Cassandra NoHostAvailableException Java-CQLDriver [英] Cassandra NoHostAvailableException Java-CQLDriver

查看:1164
本文介绍了Cassandra NoHostAvailableException Java-CQLDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cassandra的CQL驱动程序在Java中构建应用程序。我能够正确运行,当我使用本地cassandra服务器。然而,同样的代码,当我尝试运行不工作的远程cassandra服务器。它在初始化期间给出以下错误: -

I am building an application in java using Cassandra's CQL driver. I am able to run it properly when I use local cassandra server. However the same code when I try to run is not working for remote cassandra server. It gives the following error during initialization :-

以下是我用于CQL驱动程序的maven依赖: -

Following are the maven dependecy that I am using for CQL driver:-

<dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>2.1.3</version>
    </dependency>

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-mapping</artifactId>
        <version>2.1.2</version>
    </dependency>

以下是错误: -

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: yyyy.yyy.yyy.yyy.yyy-yyy.net/yy.yy.yy.yy:9160 (com.datastax.driver.core.ConnectionException: [yyyy.yyy.yyy.yyy.yyy-yyy.net/yy.yy.yy.yy:9160] Unexpected error during transport initialization (com.datastax.driver.core.ConnectionException: [yyyy.yyy.yyy.yyy.yyy-yyy.net/yy.yy.yy.yy:9160] Operation timed out)), 
    Unexpected error during transport initialization      (com.datastax.driver.core.ConnectionException: [xxxx.xxx.xxx.xxx.xxx-xxx.net/xx.xx.xx.xx:9160] Operation timed out)))
         at   com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:220)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:78)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1231)
    at com.datastax.driver.core.Cluster.init(Cluster.java:158)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:246)

一切正常的本地cassandra服务器是: -



The local cassandra server on which everything works fine is:-

cqlsh 4.1.1, Cassandra 2.0.7 , CQL spec: 3.1.1, Thrift Protocol 19.39.0

连接超时的远程cassandra服务器是:

The remote cassandra server on which connection is getting timed out is:-

cqlsh 3.1.8 | Cassandra 1.2.12 | CQL spec 3.0.0 | Thrift protocol 19.36.1

我使用以下代码连接。有人可以评论远程连接情况下出现什么问题吗?

I am using the following code to connect. Can someone comment what is going wrong in the remote connection case?

clusterOBJECT = Cluster.builder().addContactPointsWithPorts(addrs)
                .withQueryOptions(new     QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE))
                .withProtocolVersion(1).withoutJMXReporting()
                .withPort(port)
                .withSocketOptions(options)
                .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
                .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy())).build();
        session = clusterOBJECT.connect();

我在addContactPointsWithPorts中提供有效的主机名以及端口(9160)。

I am providing valid hostname along with port(9160) in addContactPointsWithPorts. Also the hostnames are pingable.

PS: - 以下属性已在cassandra.yaml中设置。

PS:- The following properties are already set in cassandra.yaml.

start_native_transport: true
native_transport_port: 9042

]
将端口更改为9042后,我能够连接到Cassandra。但是我看到连接正在被这个异常在后被丢弃。

After changing the port to 9042, I was able to connect to Cassandra. BUT I see that the connection is getting dropped by this exception soon after.

com.datastax.driver.core.TransportException: [/xx.xx.xxx.xx:9042] Cannot connect
    at com.datastax.driver.core.Connection.<init>(Connection.java:106)
    at com.datastax.driver.core.PooledConnection.<init>(PooledConnection.java:35)
    at com.datastax.driver.core.Connection$Factory.open(Connection.java:528)
    at com.datastax.driver.core.DynamicConnectionPool.<init>(DynamicConnectionPool.java:74)
    at com.datastax.driver.core.HostConnectionPool.newInstance(HostConnectionPool.java:33)
    at com.datastax.driver.core.SessionManager.replacePool(SessionManager.java:270)
    at com.datastax.driver.core.SessionManager.access$400(SessionManager.java:39)
    at com.datastax.driver.core.SessionManager$3.call(SessionManager.java:303)
    at com.datastax.driver.core.SessionManager$3.call(SessionManager.java:295)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
 Caused by: java.net.ConnectException: Connection refused: /xx.xx.xxx.xx:9042
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
    at org.jboss.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:150)
    at org.jboss.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
    at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
    at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
    ... 3 more

谢谢。

推荐答案

我认为这里的关键是local和remote。我问过这个问题,但没有收到答案,但我怀疑有两个问题:

I think that the key here is "local" and "remote". I've asked the question, but did not receive an answer, but I suspect that there is one of 2 issues:


  1. 防火墙阻止来自客户端的端口9160和9042。你试过telnet到端口9160和9042的节点?

  1. Firewall is blocking ports 9160 and 9042 from the client. Have you tried to telnet to to the nodes to the ports 9160 and 9042?

存在私人/公共地址问题,通常在群集位于专用网络内部时遇到,并且客户端尝试使用外部IP地址。在这种情况下,集群不知道由基础结构分配的公共IP。在这种情况下,司机有责任进行这种地址翻译。
例如,Java驱动程序具有名为AddressTranslater的策略,您可以实施该策略以执行从内部IP到外部的转换 - 例如通过使用AWS API。 http://www.datastax.com /drivers/java/2.0/com/datastax/driver/core/policies/AddressTranslater.html
这里是一个实现的链接(我没有自己使用它): http://docs.hazelcast.org/docs/3.3/ javadoc / com / hazelcast / client / spi / impl / AwsAddressTranslator.html

There is a private/public address issue, that is usually observed when the cluster is inside of the private network, and the client trying to access the cluster using external IP addresses. In this case cluster has no idea about the public IPs, which are assigned by an infrastructure. In this case it is driver's responsibility to do this address translation. For example, Java driver has a policy called AddressTranslater that you can implement to perform translation from internal IP to external - for example by using AWS API. http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/AddressTranslater.html Here is a link to an implementation (I haven't used it myself): http://docs.hazelcast.org/docs/3.3/javadoc/com/hazelcast/client/spi/impl/AwsAddressTranslator.html

这篇关于Cassandra NoHostAvailableException Java-CQLDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆