NoHostAvailableException经常出现在datastax驱动程序3.0中

时间:2016-05-10 05:42:16

标签: cassandra cassandra-2.0 datastax-java-driver

我正在使用cassandra 2.0.9,最近从2.0.5迁移到datastax java驱动程序版本3.0.0。移动到驱动程序3.0.0后,我经常发生以下异常

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1:9042 (com.datastax.driver.core.exceptions.DriverException: Timeout while trying to acquire available connection (you may want to increase the driver number of per-host connections)))
    at com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:84)
    at com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:37)
    at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
    at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:63)

驱动程序3.0.0中是否存在任何连接问题。我连接cassandra集群的代码是

private static Cluster constructCluster(String hostName,String port) {
        String[] hostNames = hostName.split(",");
        SocketOptions sOptions = new SocketOptions();
        sOptions.setKeepAlive(true);
        QueryOptions qOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM)
                .setFetchSize(500);
        LatencyAwarePolicy loadBalancingPolicy = LatencyAwarePolicy.builder(DCAwareRoundRobinPolicy.builder().withLocalDc(defaultDC).build())
                .build();
        Cluster cluster = Cluster.builder()
                .addContactPoints(hostNames)
                .withLoadBalancingPolicy(loadBalancingPolicy)
                .withPoolingOptions(new PoolingOptions())
                .withQueryOptions(qOptions)
                .withReconnectionPolicy(new ConstantReconnectionPolicy(TimeUnit.SECONDS.toMillis(5)))
                .withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE))
                .withSocketOptions(sOptions)
                .build();
        LOGGER.log(Level.SEVERE, "host name {0}", hostName);
        return cluster;
    }

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

在多个并发请求场景中使用一个集群和一个/几个会话权限。