Cassandra Hector 负载平衡
我最近设置了一个具有两个节点的 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}];
我确信我错过了一些非常微不足道的东西,任何帮助将不胜感激。 谢谢
I have setup a Cassandra cluster with two nodes recently. The replication factor is set to 2 and they both seem to be working well if both the nodes are turned on.
Now how can I use hector in such a way so that it keeps working as far as atleast one node is up? As of now I have something like following.
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);
....
Let's say if host xx.xx.13.22 goes down then I am getting the following message in my console and all my inserts are failing untill that node comes up.
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
This is how my keyspace is defined
update keyspace structspeech with placement_strategy =
'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options =[{replication_factor:2}];
I am sure I am missing something very trivial, any help will be greatly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,Hector 使用 Quorum 的一致性级别,因此如果您的一个节点出现故障,则无法满足此级别的要求。
当 RF = 2 仲裁意味着您需要读取和写入两个节点,因此如果其中一个节点发生故障,您将无法执行。
这是一个很好的在线工具,它演示了 NRW(N = 复制因子,R = 读取一致性,W = 写入一致性)http: //www.ecyrd.com/cassandracalculator/
要在写入/读取时更改一致性级别,例如 AllOneConsistencyLevelPolicy
HFactory.createKeyspace(String, Cluster, ConsistencyLevelPolicy)
By default Hector uses a consistency level of Quorum so if one of your nodes is down this level cannot be satisfied.
When RF = 2 quorum means you need to read and write to both nodes, so if one of them is down you can't execute.
Here's a nice online tool that demonstrates NRW (N = replication factor, R = read consistency and W = write consistency) http://www.ecyrd.com/cassandracalculator/
To change the consistency level while writing/reading use, for example AllOneConsistencyLevelPolicy
HFactory.createKeyspace(String, Cluster, ConsistencyLevelPolicy)
插入时使用什么一致性级别?如果您以 QUORUM 或 ALL 进行写入,则需要两个节点都能够以 2 的复制因子进行写入(2 个节点的仲裁为 2,这就是为什么典型的 cassandra 集群使用奇数作为复制因子)
What consistency level are you using when you insert? If you are writing at QUORUM or ALL, you need both nodes to be up to write with a replication factor of 2 (a quorum for 2 nodes is 2, that's why typical cassandra clusters use an odd number for replication factor)