【发布时间】:2013-05-03 10:26:44
【问题描述】:
我在 com.netflix.astyanax.connectionpool.NodeDiscoveryType 的 Cassandra 的 Astyanax 客户端中找到了 TOKEN_AWARE 枚举值,并试图了解它的作用?
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
}
假设我有 24 个节点 cross colo cluster,其中 12 个节点在 PHX colo/datacenter 和 12 个节点在 SLC 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());
}
谁能解释一下NodeDiscoveryType 的TOKEN_AWARE 和ConnectionPoolType 的TOKEN_AWARE 之间的区别是什么?
感谢您的帮助。
更新代码
以下是我进行更改后目前使用的代码-
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,所以再次添加它没有意义。我说的对吗?
如果我错了,请纠正我?
【问题讨论】:
-
技术我有点困惑。在一篇文章中,您提出了一个问题,而在下一篇文章中,您正在回答相同的问题。
-
@abhi,在我意识到这件事之前,我发布了其他问题。但在发布任何东西之前,我会自己尝试这些东西,并使用 TOKEN_AWARE NODE DISCOVERY 来获取整个数据中心的所有节点。