PoolTimeoutException when connecting to Cassandra via Astyanax
Asked Answered
G

5

7

I am trying to connect to local cassandra using astyanax, but constantly getting PoolTimeoutException. I am able to connect to cassandra using cli or hector client. Any idea what am I doing wrong?

Thanks.

My code:

val context = new AstyanaxContext.Builder()
        .forCluster("cluster")
        .forKeyspace(keyspace)
        .withAstyanaxConfiguration(
                new AstyanaxConfigurationImpl()
                    .setDiscoveryType(NodeDiscoveryType.NONE)
        )
        .withConnectionPoolConfiguration(
                new ConnectionPoolConfigurationImpl("ConnPool")
                    .setPort(9160)
                    .setMaxConnsPerHost(1)
                    .setMaxBlockedThreadsPerHost(1)
                    .setSeeds("127.0.0.1:9160")
                    .setConnectTimeout(10000)
        )
        .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
        .buildKeyspace(ThriftFamilyFactory.getInstance())
    context.start()
    return context.getEntity()

Exception:

Exception in thread "main" java.lang.RuntimeException: com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException: PoolTimeoutException: [host=127.0.0.1(127.0.0.1):9160, latency=10004(10004), attempts=1] Timed out waiting for connection
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$7.getNextBlock(ThriftColumnFamilyQueryImpl.java:652)
at com.netflix.astyanax.thrift.ThriftAllRowsImpl$1.hasNext(ThriftAllRowsImpl.java:61)
at scala.collection.JavaConversions$JIteratorWrapper.hasNext(JavaConversions.scala:574)
at scala.collection.Iterator$class.foreach(Iterator.scala:772)
at scala.collection.JavaConversions$JIteratorWrapper.foreach(JavaConversions.scala:573)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:73)
at scala.collection.JavaConversions$JIterableWrapper.foreach(JavaConversions.scala:587)
at  at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
at scala.App$class.main(App.scala:60)
at Caused by: com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException: PoolTimeoutException: [host=127.0.0.1(127.0.0.1):9160, latency=10004(10004), attempts=1] Timed out waiting for connection
at com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool.waitForConnection(SimpleHostConnectionPool.java:201)
at com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool.borrowConnection(SimpleHostConnectionPool.java:158)
at com.netflix.astyanax.connectionpool.impl.RoundRobinExecuteWithFailover.borrowConnection(RoundRobinExecuteWithFailover.java:60)
at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:50)
at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:229)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$7.getNextBlock(ThriftColumnFamilyQueryImpl.java:623)
Gemoets answered 22/7, 2012 at 6:50 Comment(0)
H
3

Another issue is if you slam data into one node and you have a threadpool of 50 and only 1 connection per host, you will get the same thing so you have to balance the number of threads/ host in certain situations as well.

Halliehallman answered 10/9, 2012 at 2:37 Comment(0)
C
2

We were having this problem as well. For us, it turned out to be a version problem with libthrift. Version 0.7.0 worked. Version 0.6.1 did not. Check your classpath and see... Good luck.

-td

Coulomb answered 8/8, 2012 at 20:30 Comment(1)
"tom d" nice catch, thanks! anyone who upgrades astyanax jar to v1.0.6 without maven, don't forget to upgrade libthrift to 0.7.0Troytroyer
I
1

Trying to connect via the wrong port will also give this error. See this discussion.

Indignity answered 11/6, 2013 at 18:23 Comment(0)
M
0

You need to install Apache Thrift, For me it works installing this applications:

Boost
libevent
Thrift

Happy Coding :)

Mcwilliams answered 1/5, 2016 at 23:40 Comment(0)
A
0

Do the following in the cassandra.yaml

  1. Check the rpc_address
  2. Check the rpc_port
  3. Set start_rpc to true
Argo answered 18/4, 2017 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.