Cassandra(复制因子:2,节点:3)和轻量级事务 [英] Cassandra (replication factor: 2, nodes: 3) and lightweight transactions

查看:126
本文介绍了Cassandra(复制因子:2,节点:3)和轻量级事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个运行着3个节点且复制因子为2的cassandra集群,也许我们应该从一开始就选择3,但是事实并非如此。

We have a cassandra cluster running with 3 nodes and a replication factor of 2 -> maybe we should have selected 3 from the start, but this is not the case.

因此,我们的法定人数= 2/2 + 1 = 2

Our quorum is therefore = 2/2 + 1 = 2

我们说我们丢失了一个节点-因此现在只有两个cassandra节点在线。

Lets say we lose one node - so now only two cassandra nodes are online.

如果我们将一致性级别设置为 ONE,然后从->读取,则仍然可以从群集中读取数据,因此这不是问题。

We still have the possibility to read from the cluster if we set our consistency level to "ONE" and then read -> so this is not a problem.

我不理解的是以下内容。

The thing I do not understand is the following.

我们仍然有两个正在运行的节点,所以为什么不能做一个串行(轻量级交易)插入我们的密钥空间?我们有两个节点,所以在尝试插入时不应该有定额2的定额吗?

We still have two nodes running, so why is it not possible to do a serial (lightweight transaction) insert into our keyspace? We have two nodes up, so shouldn't it be possible to get a quorum of 2 when trying to insert?

是因为行之一已经放在

推荐答案

当您尝试插入数据时,数据基于令牌值存储(基于

When you are trying to insert a data, the data is stored based on the token values(based on the partitioner configured) and replicated in a circular way.

例如如果要在3节点群集Node1(拥有令牌A),Node2(拥有令牌B)和Node3(拥有令牌C)的复制因子为2的键空间中插入数据X。假设如果将数据X计算为令牌B,那么Cassandra将开始从Node2和Node3插入数据(直到完成副本)。假设如果将数据X计算为令牌C,那么Cassandra将开始从Node3和Node1插入数据。

For e.g. If you are inserting a data X in a keyspace with replication factor of 2 in a 3 node cluster Node1 (owning token A), Node2 (owning token B) and Node3 (Owning token C). Say if the data X is computed to token B, then Cassandra starts inserting data from Node2 and Node3 (till it completes the replicas). Say if the data X is computed to token C, then Cassandra starts inserting data from Node3 and Node1.

因此将一致性级别设置为2意味着必须将数据写入2节点。
在您的情况下,即使您在Node1(令牌A)和Node2(令牌B)上有两个节点,在Node3(令牌C)下有一个节点,如果计算出数据并将其选择为令牌B,则Cassandra会尝试在Node2和Node3中插入,您会遇到一致性错误,因为它无法在Node3中插入。

So setting consistency level of 2 means the data must be written in 2 nodes. In your case even though you have 2 nodes up Node1 (token A) and Node2 (token B) and one node down Node3 (token C), if the data is computed and selected as token B, then Cassandra tries to insert in Node2 and Node3 and you get consistency error as it cannot insert in Node3.

因此要插入,必须将复制增加到3或将一致性降低到1。

So to insert you must either increase replication to 3 or decrease the consistency to 1.

要了解更多信息关于一致性,请参见此文档 https://docs.datastax.com /en/cassandra/2.1/cassandra/dml/dml_config_consistency_c.html

To know more on consistency see this docs https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dml_config_consistency_c.html

这篇关于Cassandra(复制因子:2,节点:3)和轻量级事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆