3

我编写了一些相当简单的代码来试验 astyanax。与本地主机上的单个节点 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)
4

2 回答 2

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());

我希望看到一些描述为常见集群/键空间设置推荐的配置选项的文档。我敢肯定这对行家来说是显而易见的,但对于新手来说,它有点不透明。

于 2013-01-05T15:59:35.367 回答
0

尝试使用 NodeDiscoveryType.RING_DESCRIBE

于 2013-01-05T09:27:32.213 回答