Reputation: 693
I am using cassandra 2.0.9 and recently moved to datastax java driver version 3.0.0 from 2.0.5. I have following exception occurs frequently after moving to driver 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)
Is there any connection problem in driver 3.0.0. My code to connect cassandra cluster is
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;
}
Can anyone help me?
Upvotes: 0
Views: 947
Reputation: 1
use one cluster and one/few Session instence in multiple concurrent requests scene .
Upvotes: 0