cassandra中遇到的问题

来源:互联网 发布:java 统计一年月消费 编辑:程序博客网 时间:2024/05/18 02:06

Cassandra问题一览

UnavailableException错误情况


1  
2[default@dtest] set Student['tom]['name']='tom';
3null
4UnavailableException()
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发现:

1create keyspace dtest
2with placement_strategy = 'NetworkTopologyStrategy'
3  and strategy_options = {dc1 :1}
4  and durable_writes =true;

这就发现了很明显的问题,原来默认的strategy_options变化了。于是执行:

1update keyspace dtest
2with 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等方法设置时会出错

原创粉丝点击