【发布时间】:2016-09-04 22:25:18
【问题描述】:
我正在使用 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;
}
谁能帮帮我?
【问题讨论】:
标签: cassandra cassandra-2.0 datastax-java-driver