Cassandra問題一覽
UnavailableException錯誤情況
2 |
[ default @dtest ] set Student[ 'tom][' name ']=' tom'; |
5 |
at org.apache.cassandra.thrift.Cassandra$insert_result.read(Cassandra.java: 15206 ) |
6 |
at org.apache.cassandra.thrift.Cassandra$Client.recv_insert(Cassandra.java: 858 ) |
7 |
at org.apache.cassandra.thrift.Cassandra$Client.insert(Cassandra.java: 830 ) |
8 |
at org.apache.cassandra.cli.CliClient.executeSet(CliClient.java: 901 ) |
9 |
at org.apache.cassandra.cli.CliClient.executeCLIStatement(CliClient.java: 218 ) |
10 |
at org.apache.cassandra.cli.CliMain.processStatementInteractive(CliMain.java: 220 ) |
11 |
at org.apache.cassandra.cli.CliMain.main(CliMain.java: 348 ) |
當時很驚訝,因爲這麼簡單的命令,不可能出錯啊,但是就是這麼奇怪地報了。經過查看cassandra.thrift中該異常的描述爲在寫入/讀取的過程中,需要操作的節點數少於實際存活的節點數。於是我執行了show shema發現:
2 |
with placement_strategy = 'NetworkTopologyStrategy' |
3 |
and strategy_options = {dc1 : 1 } |
4 |
and durable_writes = true ; |
這就發現了很明顯的問題,原來默認的strategy_options變化了。於是執行:
2 |
with placement_strategy = 'SimpleStrategy' |
3 |
and strategy_options = {replication_factor : 1 } |
4 |
and durable_writes = true ; |
再次插入,發現正常了!
總結:類似的UnavailableException均應該從集羣幾點存活數量這方面考慮。這次的異常是因爲沒注意到創建keyspace的時候由於是測試而太懶惰,沒有寫strategy options,並且默認的該值又有問題導致的。
無法通過eclipse連接遠程主機上的cassandra
conf/cassadnra.yaml中的rpc_address專門用於客戶端的連接
rpc_address
(Default: localhost) The listen address for client connections (Thrift remote procedure calls). Valid values are:
• 0.0.0.0: Listens on all configured interfaces.
• IP address
• hostname
• unset: Resolves the address using the hostname configuration of the node. If left unset, the hostname must resolve to the IP address of this node using /etc/hostname, /etc/hosts, or DNS.
當出現連接被拒絕時,可以通過修改這個配置項來到達連接的目的,如想連接到 IP爲172.28.112.110時可以直接修改這個配置項:
rpc_address:172.28.112.110
連接便可建立
在使用java語言調用API進行keyspace和column family的創建時
ksDef.strategy_options = Collections.singletonMap("replication_factor", "1");來進行keyspace的factor的設置
使用ksDef.replication_factor = 1等方法設置時會出錯