2011-08-02 195 views
2

我最近設置了一個Cassandra集羣和兩個節點。複製因子設置爲2,並且如果兩個節點都打開,它們似乎都工作正常。 現在我怎樣才能以這樣的方式使用hector,使它至少能夠在至少一個節點上運行?截至目前,我有如下的東西。Cassandra 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}]; 

我相信我失去了一些東西很瑣碎,任何幫助將不勝感激。 謝謝

回答

4

默認情況下,Hector使用Quorum的一致性級別,因此如果您的某個節點關閉,則無法滿足此級別。
當RF = 2 quorum意味着您需要讀取和寫入兩個節點,因此如果其中一個節點已關閉,則無法執行。
這裏是一個不錯的在線工具,演示NRW(N =複製因子,R =讀一致性和W =寫一致性)http://www.ecyrd.com/cassandracalculator/
要更改的一致性水平,同時寫入/讀取使用,例如AllOneConsistencyLevelPolicyHFactory.createKeyspace(String, Cluster, ConsistencyLevelPolicy)

+0

鏈接真的很有幫助 – Sap

1

插入時使用的是什麼一致性級別?如果您正在QUORUM或ALL中編寫代碼,則需要兩個節點以複製因子2進行寫入(2個節點的法定數爲2,這就是爲什麼典型的cassandra集羣使用奇數複製因子)

+0

我很新的,請告訴我如何設置它,什麼是兩個羣集的理想數字... – Sap

+0

這裏有一些注意事項,http://www.datastax.com/docs/0.8/一致性/指標。什麼樣的一致性級別取決於您的用例,但一個好的起點是一個3的羣集,複製因子爲3,並且在QUORUM中讀寫,這可以讓您在單個節點故障中倖存下來。 – sbridges