2

我最近设置了一个有两个节点的 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}];

我确信我错过了一些非常微不足道的东西,任何帮助将不胜感激。谢谢

4

2 回答 2

4

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

于 2011-08-02T19:00:28.380 回答
1

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

于 2011-08-02T14:45:51.247 回答