3

How Cassandra behaves when the contact node is dead? I mean to say, Cassandra has the ring structure of "n" nodes, If client is going to access that first node but it is dead. The first node is specified in the java client. I could not understand the failure handling. Could any one help me?

4

2 回答 2

2

如果您只有一个节点,或者只指定一个节点,并且该节点已关闭,则客户端将无法连接(显然);但通常客户端库,如 Hector,将允许您指定一组节点并维护一个连接池,连接到任何可用的节点。

Hector文档更详细,但指定多个节点的最简单方法是CassandraHostConfigurator在创建集群时传递以逗号分隔的主机列表:

String hosts = "node1.example.com:9160, node2.example.com:9160, node3.example.com:9160";
Cluster cluster = HFactory.getOrCreateCluster(CLUSTER_NAME, new CassandraHostConfigurator(hosts));
于 2013-07-12T10:02:20.667 回答
1

这取决于客户,不同的客户会做不同的事情来处理这个问题,但是对于大多数司机,您可以提供多个联系点。

Astyanax使用令牌发现来跟踪集群中的各个节点。完整的文档在这里

主机供应商将连接池与动态主机注册表相关联。连接池将频繁轮询此供应商以获取当前主机列表,并更新其内部主机连接池以考虑新的或已删除的主机。

这是在您设置上下文时配置的:

AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    ...
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
        .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    )
...
context.start();

只要您提供了多个联系点,DataStax java 驱动程序就可以很好地处理故障。如果您有 3 个节点,其 SimpleStrategy 用于复制且复制因子为 3(也就是所有数据都存在于所有 3 个节点上),那么只要 3 个节点之一处于活动状态,您就可以查询。

Cluster cluster = Cluster.builder()
                         .addContactPoint("127.0.0.1")
                         .addContactPoint("127.0.0.2")
                         .addContactPoint("127.0.0.3")
                         .build();
Session session = cluster.connect();
于 2013-07-12T10:07:16.170 回答