我最近设置了一个带有两个节点的Cassandra集群。复制因子设置为2,如果两个节点都打开,它们看起来都工作得很好。现在,我如何才能以这种方式使用hector,使其在至少一个节点处于运行状态时仍能继续工作?到目前为止,我有一些类似下面的东西。
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}];我确信我错过了一些非常琐碎的东西,任何帮助都将不胜感激。谢谢
发布于 2011-08-03 03:00:28
默认情况下,Hector使用Quorum的一致性级别,因此如果您的某个节点关闭,则无法满足此级别的要求。
当RF =2quorum时,意味着您需要对两个节点进行读写,因此如果其中一个节点关闭,则无法执行。
这是一个很好的在线工具,可以演示NRW (N =复制因子,R=读一致性,W=写一致性) http://www.ecyrd.com/cassandracalculator/
要在写入/读取时更改一致性级别,请使用,例如AllOneConsistencyLevelPolicy HFactory.createKeyspace(String, Cluster, ConsistencyLevelPolicy)
发布于 2011-08-02 22:45:51
您在插入时使用的一致性级别是什么?如果您使用QUORUM或ALL进行写入,则需要两个节点的复制因子均为2(2个节点的法定数为2,这就是为什么典型的cassandra群集使用奇数作为复制因子)
https://stackoverflow.com/questions/6907878
复制相似问题