Cassandra的单点故障

时间:2014-07-28 22:17:09

标签: cassandra

Cassandra上做教程时,讲师提到cassandra没有single point of failure。也就是说,如果节点在群集中关闭,则不应影响客户端访问它的方式。

所以我尝试了以下方法: 关闭我的3节点集群中的一个节点。

然后尝试连接到已关闭的节点。

我被拒绝连接很明显,因为该节点已关闭。但正如教练提到的那样,我期待cassandra以循环方式将连接路由到下一个节点。但事实并非如此。 那是为什么?

ccm status
node1: UP
node3: UP
node2: UP
ccm node2 stop
ccm status
node1: UP
node3: UP
node2: DOWN
ccm node2 cqlsh
Connection error: Could not connect to 127.0.0.2:9160

修改

我注意到的另一件事是我能够进行写操作。但默认操作失败。我没有调整一致性水平。我正在使用默认值。这就是我得到的:

cqlsh> CREATE KEYSPACE example with replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
cqlsh> use example ;
cqlsh:example> CREATE TABLE users(id varchar PRIMARY KEY, email varchar, password varchar, name varchar);
cqlsh:example> INSERT INTO users (id, email, name, password) VALUES ('user1','user1@example.com','foo','foo_pwd');
cqlsh:example> SELECT * from users ;
Unable to complete request: one or more nodes were unavailable.

2 个答案:

答案 0 :(得分:6)

如果节点关闭且您使用的驱动程序未保存状态,则它不知道要连接的节点。如果您使用的是任何新一代驱动程序,即使最初连接的节点发生故障,您仍可以继续执行查询。

DataStax Python驱动程序示例:

from cassandra.cluster import Cluster
sessions = Cluster("127.0.0.1").connect()
session.execute("Select * from ks.tab")

#Turn off Cassandra 127.0.0.1

session.execute("select * from ks.tab") # Will be ok if replication on ks is more than 1 and CL is one   

编辑:

复制级别和一致性级别 这两个都详细描述in this blog post

您所观察到的是:

只要负责其密钥的节点启动,插入就会以默认一致性(one)成功。因此,即使RF为1,一个被击落的节点仍然允许许多写入(和读取)仍然成功。如果你继续尝试其他值,你会看到大约1/3的输入选择哈希到破损的节点,你得到一个不可用的异常。

选择*但需要检查每个节点上的数据,这意味着如果任何节点关闭,此命令将失败(除非RF> 1)

答案 1 :(得分:0)

我有类似的问题。设置' replication_factor'到2而不是1为我修复它。许多示例似乎表明,对于单节点设置,replication_factor为1。

第一步应该是:

cqlsh> CREATE KEYSPACE example with replication = 'class': 'SimpleStrategy', 'replication_factor': 2};

或者,我使用以下步骤来modify the existing keyspace configuration

cqlsh> ALTER KEYSPACE example WITH REPLICATION = {'replication_factor' : 2 };

#using the deprecated Cassandra-cli (this is what I initially found as a solution)
UPDATE KEYSPACE example WITH strategy_options = {replication_factor:2};

然后运行以下命令:

nodetool repair

等待修复过程完成,然后确认:

nodetool status
#should show 'own %' as ~67% for a 3 node setup.
相关问题