3

I have some fairly simple code written to experiment with astyanax. It works fine when talking to a single node Cassandra db on localhost, but when I write the same schema to a two node cluster (which is definitely accessible from my host), I get a TokenRangeOfflineException.

What am I missing?

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

produces this error:

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)
Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
Eric
  • 31
  • 1
  • 2

2 Answers2

0

Try w/ NodeDiscoveryType.RING_DESCRIBE

Schildmeijer
  • 20,702
  • 12
  • 62
  • 79
  • Thanks, I had tried that without success, but I went back and did it again with a few more changes and it worked (though I don't exactly know why). I'll post what I did separately. – Eric Jan 05 '13 at 15:57
0

Answering my own question, partly. I got it to work by making several changes. I'm not sure why the simple case doesn't work, but the following did.

First, I replaced my keyspace, which was created with defaults (create keyspace foo), like this:

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

That changes the output of "nodetool describering foo" such that endpoint_details has something in it. I had previously stepped through the debugger and noticed that endpoint_details being empty was a cause of some failures once I switched my astyanax config to look like this:

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

I would love to see some documentation that describes configuration options recommended for common cluster/keyspace settings. I'm sure it's obvious to the cognoscenti, but for noobs, it's a little opaque.

Eric
  • 31
  • 1
  • 2
  • fwiw, i have seen this error when creating a keyspace with one consistency level (say CL_ONE), and then from another client getting the keyspace but specifying a different consistency level (say CL_TWO). – Martin Serrano Nov 26 '13 at 22:17