我在com.netflix.astyanax.connectionpool.NodeDiscoveryTypeTOKEN_AWARE
的 Cassandra 的 Astyanax 客户端中找到了枚举值,并试图了解它的作用?
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
}
假设我有 24cross colo cluster
个节点,其中 PHX 中有colo/datacenter
12 个节点, SLC中有 12 个节点colo/datacenter
。
我正在使用 Astyanax 客户端连接到 Cassandra,如下所示:
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());
}
谁能解释一下of和of的TOKEN_AWARE
区别NodeDiscoveryType
是TOKEN_AWARE
什么ConnectionPoolType
?
谢谢您的帮助。
更新代码
以下是我在进行更改后使用的代码 -
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());
}
您在示例中提到您将使用-
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
.setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
这两个在一起对吧?但我相信TOKEN_AWARE ConnectionPoolType
默认情况下使用RING_DESCRIBE
,所以再次添加它没有意义。我对吗?
如果我错了,请纠正我?