I found TOKEN_AWARE
enum value in Astyanax client for Cassandra in com.netflix.astyanax.connectionpool.NodeDiscoveryType and am trying to understand what it does?
package com.netflix.astyanax.connectionpool;
public enum NodeDiscoveryType {
/**
* Discover nodes exclusively from doing a ring describe
*/
RING_DESCRIBE,
/**
* Discover nodes exclusively from an external node discovery service
*/
DISCOVERY_SERVICE,
/**
* Intersect ring describe and nodes from an external service. This solve
* the multi-region ring describe problem where ring describe returns nodes
* from other regions.
*/
TOKEN_AWARE,
/**
* Use only nodes in the list of seeds
*/
NONE
}
Suppose if I have 24 nodes cross colo cluster
with 12 nodes in PHX colo/datacenter
and 12 nodes in SLC colo/datacenter
.
And I am connecting to Cassandra using Astyanax client as follows:
private CassandraAstyanaxConnection() {
context = new AstyanaxContext.Builder()
.forCluster(ModelConstants.CLUSTER)
.forKeyspace(ModelConstants.KEYSPACE)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160)
.setMaxConnsPerHost(40)
.setSeeds("cdb03.vip.phx.host.com:9160,cdb04.vip.phx.host.com:9160")
)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2")
.setDiscoveryType(NodeDiscoveryType.TOKEN_AWARE))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getEntity();
emp_cf = ColumnFamily.newColumnFamily(
ModelConstants.COLUMN_FAMILY,
StringSerializer.get(),
StringSerializer.get());
}
Can anyone explain me what the difference between TOKEN_AWARE
of NodeDiscoveryType
vs TOKEN_AWARE
of ConnectionPoolType
is?
Thanks for the help.
Updated Code
Below is the code I am using so far after making changes-
private CassandraAstyanaxConnection() {
context = new AstyanaxContext.Builder()
.forCluster(ModelConstants.CLUSTER)
.forKeyspace(ModelConstants.KEYSPACE)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160)
.setMaxConnsPerHost(40)
.setSeeds("cdb03.vip.phx.host.com:9160,cdb04.vip.phx.host.com:9160")
.setLocalDatacenter("phx")
)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2")
.setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getEntity();
emp_cf = ColumnFamily.newColumnFamily(
ModelConstants.COLUMN_FAMILY,
StringSerializer.get(),
StringSerializer.get());
}
You mentioned in your example that you will be using-
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
.setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
these two together right? But I believe TOKEN_AWARE ConnectionPoolType
by default uses RING_DESCRIBE
so it doesn't make sense to add it again. Am I right?
Correct me if I am wrong?