连接到两个节点集群时,astyanax TokenRangeOfflineException

时间:2013-01-05 01:32:02

标签: cassandra astyanax

我有一些相当简单的代码用于试验astyanax。它与localhost上的单个节点Cassandra db进行通信时工作正常,但是当我将相同的模式写入双节点集群(绝对可以从我的主机访问)时,我得到TokenRangeOfflineException

我错过了什么?

AstyanaxContext.Builder builder = new AstyanaxContext.Builder()
            .forKeyspace("myKeyspace")
            .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                    .setDiscoveryType(NodeDiscoveryType.NONE)
            )
            .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
                    .setPort(9160)
                    .setMaxConnsPerHost(5)
                    .setSeeds("host1.domain.com,host2.domain.com")
            )
            .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());

产生此错误:

Exception in thread "main" com.netflix.astyanax.connectionpool.exceptions.TokenRangeOfflineException: TokenRangeOfflineException: [host=host1.domain.com, latency=59(94), attempts=1]UnavailableException()
    at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:165)
com.netflix.astyanax.connectionpool.exceptions.TokenRangeOfflineException: TokenRangeOfflineException: [host=host1.domain.com, latency=59(94), attempts=1]UnavailableException()
    at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:165)
    at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:60)
    at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.execute(ThriftColumnFamilyQueryImpl.java:200)
    at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:60)

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

部分地回答我自己的问题。我通过做出一些改变让它发挥作用。我不确定为什么简单的情况不起作用,但以下情况确实如此。

首先,我替换了我的密钥空间,它是使用默认值创建的(创建密钥空间foo),如下所示:

create keyspace foo with placement_strategy = 'NetworkTopologyStrategy'
    AND strategy_options={DC1:1};

这会改变“nodetool describering foo”的输出,使得endpoint_details中包含某些内容。我之前已经通过调试器并注意到,当我将astyanax配置切换为这样时,endpoint_details为空是导致某些失败的原因:

 AstyanaxContext.Builder builder = new AstyanaxContext.Builder()
            .forCluster("myCluster")
            .forKeyspace("foo")
            .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                    .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
                    .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
            )
            .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
                    .setPort(9160)
                    .setMaxConnsPerHost(5)
                    .setInitConnsPerHost(1)
                    .setSeeds("host1,host2")
            )
            .withConnectionPoolMonitor(new Slf4jConnectionPoolMonitorImpl());

我希望看到一些描述为常见群集/密钥空间设置推荐的配置选项的文档。我确信这对于认知来说是显而易见的,但对于小号,它有点不透明。