【问题标题】:Cassandra Hector Load balancingCassandra Hector 负载均衡
【发布时间】:2011-10-17 23:36:26
【问题描述】:

我最近设置了一个有两个节点的 Cassandra 集群。复制因子设置为 2,如果两个节点都打开,它们似乎都运行良好。 现在我怎样才能以这种方式使用赫克托,以便它在至少一个节点启动时继续工作?截至目前,我有类似以下的内容。

CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator(
       "localhost:9160,xx.xx.13.22:9160");
cassandraHostConfigurator.setMaxActive(20);
cassandraHostConfigurator.setMaxIdle(5);
cassandraHostConfigurator.setCassandraThriftSocketTimeout(3000);
cassandraHostConfigurator.setMaxWaitTimeWhenExhausted(4000);
Cluster cluster = HFactory.getOrCreateCluster("structspeech",
   cassandraHostConfigurator);
Keyspace keyspace = HFactory.createKeyspace("structspeech", cluster);
....

假设如果主机 xx.xx.13.22 出现故障,那么我在控制台中收到以下消息,并且我的所有插入都失败,直到该节点出现。

Downed xx.xx.13.22(xx.xx.13.22):9160 host still appears to be down: Unable to open transport to xx.xx.13.22(xx.xx.13.22):9160 , java.net.ConnectException: Connection refused: connect

这就是我的键空间的定义方式

 update keyspace structspeech with placement_strategy = 
'org.apache.cassandra.locator.SimpleStrategy' 
 and strategy_options =[{replication_factor:2}];

我确信我遗漏了一些非常琐碎的东西,任何帮助将不胜感激。 谢谢

【问题讨论】:

    标签: java cassandra hector


    【解决方案1】:

    默认情况下,Hector 使用 Quorum 的一致性级别,因此如果您的一个节点出现故障,则无法满足此级别。
    当 RF = 2 quorum 意味着您需要读取和写入两个节点,因此如果其中一个节点关闭,您将无法执行。
    这是一个很好的在线工具,它演示了 NRW(N = 复制因子,R = 读取一致性和 W = 写入一致性)http://www.ecyrd.com/cassandracalculator/
    在写入/读取时更改一致性级别使用,例如AllOneConsistencyLevelPolicy HFactory.createKeyspace(String, Cluster, ConsistencyLevelPolicy)

    【讨论】:

      【解决方案2】:

      您在插入时使用什么一致性级别?如果您在 QUORUM 或 ALL 上写入,则需要两个节点都以 2 的复制因子进行写入(2 个节点的法定人数为 2,这就是典型的 cassandra 集群使用奇数作为复制因子的原因)

      【讨论】:

      • 我对这个很陌生,你能告诉我如何设置它吗?两个人一组的理想数字是多少...
      • 这里有一些注释,datastax.com/docs/0.8/consistency/index。什么一致性级别取决于您的用例,但一个好的起点是 3 个集群,复制因子为 3,并以 QUORUM 进行读写,这可以让您在单个节点故障时幸免于难。
      猜你喜欢
      • 2011-12-30
      • 2021-12-07
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 2016-11-29
      • 2013-02-05
      相关资源
      最近更新 更多