2016-11-06 117 views
0

我在docker中的我的mac上運行最新版本的cassandra。我在我的Mac上安裝了cassandra開發中心,我可以使用devcenter連接到cassandra,並且可以輕鬆查詢我的表格。使用Astyanax無法連接到Cassandra

http://i.imgur.com/48MztBM.png

http://i.imgur.com/jPKblly.png

我可以看到,對於卡桑德拉所需的所有端口也開放。 (如下所示)

CONTAINER ID  IMAGE    COMMAND     CREATED    STATUS    PORTS                          NAMES 
e698e61e3bac  cassandra:latest "/docker-entrypoint.s" 9 

minutes ago  Up 9 minutes  0.0.0.0:7000->7000/tcp, 0.0.0.0:7199- 
>7199/tcp, 0.0.0.0:9042->9042/tcp, 0.0.0.0:9160->9160/tcp, 7001/tcp cassandra 

我還登錄,進入我卡桑德拉容器並執行以下命令

[email protected]:/# nodetool -h 127.0.0.1 enablethrift 
[email protected]:/# nodetool -h 127.0.0.1 statusthrift 
running 

然而,當我運行下面

val configImpl = new AstyanaxConfigurationImpl() 
configImpl.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) 
configImpl.setCqlVersion("3.4.2") 
configImpl.setTargetCassandraVersion("3.7") 
val poolConfig = new ConnectionPoolConfigurationImpl("MyConnectionPool") 
poolConfig.setPort(9160) 
poolConfig.setMaxConnsPerHost(1) 
poolConfig.setSeeds("192.168.1.169") 

val context = new AstyanaxContext.Builder() 
    .forCluster("localhost") 
    .forKeyspace("movielens_small") 
    .withAstyanaxConfiguration(configImpl) 
    .withConnectionPoolConfiguration(poolConfig) 
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) 
    .buildKeyspace(ThriftFamilyFactory.getInstance()) 
context.start() 
val keyspace = context.getClient() 
val cf = new ColumnFamily[UUID, String]("cf", UUIDSerializer.get, StringSerializer.get()) 
val result = keyspace.prepareQuery(cf).withCql("select name from movies").execute() 
val data = result.getResult.getRows() 
for { 
    row <- data 
    col <- row.getColumns 
} { 
    println(col) 
} 
context.shutdown() 

代碼我得到的以下錯誤

07:32:10,606 INFO ConnectionPoolMBeanManager:53 - Registering mbean: com.netflix.MonitoredResources:type=ASTYANAX,name=MyConnectionPool,ServiceType=connectionpool 
07:32:10,625 INFO CountingConnectionPoolMonitor:194 - AddHost: 192.168.1.169 
07:32:10,748 INFO CountingConnectionPoolMonitor:194 - AddHost: 172.17.0.2 
07:32:10,748 INFO CountingConnectionPoolMonitor:205 - RemoveHost: 192.168.1.169 
[error] (run-main-0) com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException: PoolTimeoutException: [host=172.17.0.2(172.17.0.2):9160, latency=2003(2003), attempts=1]Timed out waiting for connection 
com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException: PoolTimeoutException: [host=172.17.0.2(172.17.0.2):9160, latency=2003(2003), attempts=1]Timed out waiting for connection 
    at com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool.waitForConnection(SimpleHostConnectionPool.java:231) 
    at com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool.borrowConnection(SimpleHostConnectionPool.java:198) 
    at com.netflix.astyanax.connectionpool.impl.RoundRobinExecuteWithFailover.borrowConnection(RoundRobinExecuteWithFailover.java:84) 
    at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:117) 
    at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:352) 
    at com.netflix.astyanax.thrift.AbstractThriftCqlQuery.execute(AbstractThriftCqlQuery.java:41) 
    at com.abhi.CassandraScanner$.delayedEndpoint$com$abhi$CassandraScanner$1(CassandraScanner.scala:41) 
    at com.abhi.CassandraScanner$delayedInit$body.apply(CassandraScanner.scala:19) 
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) 
    at scala.App.$anonfun$main$1$adapted(App.scala:76) 
    at scala.collection.immutable.List.foreach(List.scala:378) 
    at scala.App.main(App.scala:76) 
    at scala.App.main$(App.scala:74) 

回答

0

我能解決這個問題。問題出在NodeDiscoveryType上。我將我的代碼更改爲NodeDiscoveryType.NONE,並且工作完美。儘管我仍然不明白爲什麼NodeDiscoveryType必須爲NULL,以及爲什麼它不能與RING_DESCRIBE一起使用。

希望有人會進一步闡述。