在astynax客户机中nodediscoverytype作为token\u aware是什么意思?

a1o7rhls  于 2021-06-15  发布在  Cassandra
关注(0)|答案(2)|浏览(269)

我发现 TOKEN_AWARE com.netflix.astynax.connectionpool.nodediscoverytype中cassandra的astynax客户端中的枚举值,我正在尝试了解它的作用?

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 phx中有12个节点 colo/datacenter 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());
}

谁能解释一下 TOKEN_AWARENodeDiscoveryTypeTOKEN_AWAREConnectionPoolType 是?
谢谢你的帮助。
更新的代码
下面是我修改后使用的代码-

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 所以再加一次就没有意义了。我说得对吗?
如果我错了,请纠正我?

syqv5f0l

syqv5f0l1#

说到“节点发现”,nodediscoverytype的token\u aware和connectionpooltype的token\u aware之间的关系是相互关联的,有些混乱。

nodediscoverytype的确定方式如下(通常不是通过setdiscoverytype()):

如果您已经通过setseeds提供种子,并且connectionpooltype是token\u aware,那么nodediscoverytype是ring\u description。
如果您已经通过setseeds提供种子,并且connectionpooltype不是token\u aware,那么将使用您配置的setdiscoverytype。这是唯一一种使用配置的nodediscoverytype(通过setdiscoverytype)的情况。
如果您没有通过setseeds提供种子,并且connectionpooltype是token\u-aware,那么nodediscoverytype是token\u-aware。
如果您没有通过setseeds提供种子,并且connectionpooltype不是token\u aware,那么nodediscoverytype是discovery\u服务。

节点发现

既然我们已经确定了nodediscoverytype是如何设置的,那么让我们看看它是如何影响实际发现节点的。节点发现归结为hostsupplier(即。 Supplier<List<Host>> )已使用。
如果nodediscoverytype(从上面)是discovery\u服务,则必须使用hostsupplier(通过 withHostSupplier ).
如果nodediscoverytype(从上面)是ring\u descripe,则使用ringdescripebhostsupplier。
如果nodediscoverytype(从上面)是token\u aware并且hostsupplier已设置(通过 withHostSupplier )然后将filteringhostsupplier与ringdescribehostsupplier一起使用。
如果nodediscoverytype(从上面)是令牌识别的,并且没有设置hostsupplier,那么使用ringdescribehostsupplier。

描述和使用本地dc

根据您提供的配置,您最终将使用ringdescribehostsupplier。ringdescribehostsupplier允许连接到环中的所有节点,除非您指定了数据中心。因此,在使用connectionpoolconfigurationmpl设置astynaxContext时,您可能希望使用所需的dc设置localdatacenter。这将确保来自其他dc的主机不在连接池中,并且您的请求是本地的。

.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
        .setPort(9160)
        .setMaxConnsPerHost(40)
        .setLocalDatacenter("phx")
        .setSeeds("cdb03.vip.phx.host.com:9160,cdb04.vip.phx.host.com:9160")
    )

连接池类型

您可能还需要将connectionpooltype设置为token\u aware。当该值未设置时,它将默认为循环(使用上述节点发现工作中的节点)。令牌感知connectionpooltype将“跟踪哪些主机拥有哪些令牌,并尝试智能地引导流量”。
对于astyanax配置,我会这样做,除非您提供主机供应商。

.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
        .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    )

池优化

另一个考虑因素是在connectionpoolconfigurationmpl上使用astynax“延迟感知”,但在设置上使用ymmv来优化池的使用。例如:

.setLatencyScoreStrategy(new SmaLatencyScoreStrategyImpl(10000,10000,100,0.50))
// The constructor takes:
//  UpdateInterval: 10000 : Will resort hosts per token partition every 10 seconds
//  ResetInterval: 10000 : Will clear the latency every 10 seconds
//  WindowSize: 100 : Uses last 100 latency samples
//  BadnessThreshold: 0.50 : Will sort hosts if a host is more than 100%

见ASTYNAX配置

tldr公司;

总之,将nodediscoverytype设置为ring\u descripe(如果您不使用hostsupplier),将connectionpooltype设置为token\u aware。另外,使用setlocaldatacenter将请求保持在dc本地,并考虑延迟感知设置。

gv8xihay

gv8xihay2#

实施方面 ConnectionPoolType.TOKEN_AWARE 连接池,由拥有正在操作的令牌的主机对连接进行分区。当一个令牌不可用或已知一个操作跨越多个令牌(如批处理变异或索引查询)时,将使用循环选择主机池。
作为 NodeDiscoveryType.TOKEN_AWARE 在多数据中心场景中重新发现环描述信息。

相关问题