本文介绍了了解cassandra复制因素与一致性水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想澄清Cassandra中复制因素和一致性级别的非常基本的概念。

I want to clarify very basic concept of replication factor and consistency level in Cassandra. Highly appreciate if someone can provide answer to below questions.

RF-复制因子
RC-读一致性
WC-写入一致性

RF- Replication FactorRC- Read ConsistencyWC- Write Consistency

2个cassandra节点(例如:A,B)RF = 1,RC = ONE,WC = ONE或ANY

2 cassandra nodes (Ex: A, B) RF=1, RC=ONE, WC=ONE or ANY


  • 我可以将数据写入节点A并从节点B读取吗?

  • 如果A下降,会发生什么情况?

3个Cassandra节点B,C)RF = 2,RC = QUORUM,WC = QUORUM

3 cassandra nodes (Ex: A, B, C) RF=2, RC=QUORUM, WC=QUORUM


  • 我可以向节点A写入数据,

  • 如果节点A关闭,会发生什么情况?

3 Cassandra节点,B,C)RF = 3,RC = QUORUM,WC = QUORUM

3 cassandra nodes (Ex: A, B, C) RF=3, RC=QUORUM, WC=QUORUM


  • 我可以向节点A写入数据, ?

  • 如果节点A关闭,会发生什么情况?

推荐答案

简短摘要:复制因素描述您的数据存在多少副本。一致性级别描述客户端看到的行为。也许有一个更好的方法来分类这些。

Short summary: Replication factor describes how many copies of your data exist. Consistency level describes the behavior seen by the client. Perhaps there's a better way to categorize these.

作为一个例子,你可以有一个复制因子为2.当你写,两个副本将总是存储,假设足够节点向上。当一个节点关闭时,该节点的写入被存储并写回,除非它足够长,Cassandra决定它已经走了。

As an example, you can have a replication factor of 2. When you write, two copies will always be stored, assuming enough nodes are up. When a node is down, writes for that node are stashed away and written when it comes back up, unless it's down long enough that Cassandra decides it's gone for good.

现在在这个例子中,你写的一致性级别为ONE。在对一个节点进行写入之后,客户端将接收到成功确认,而不等待第二次写入。如果您使用CL的ALL写入,则对客户端的确认将等待,直到写入两个副本。有很多其他一致性级别选项,太多,以涵盖所有的变体。请阅读,但它很好地解释它们。

Now say in that example you write with a consistency level of ONE. The client will receive a success acknowledgement after a write is done to one node, without waiting for the second write. If you did a write with a CL of ALL, the acknowledgement to the client will wait until both copies are written. There are very many other consistency level options, too many to cover all the variants here. Read the Datastax doc, though, it does a good job of explaining them.

在同一示例中,如果您使用一致性级别读取,响应将在单个副本响应后发送到客户端。另一个副本可能具有较新的数据,在这种情况下响应将不是最新的。在许多情况下,这是相当充分。在其他情况下,客户端将需要最新的信息,并在读取时使用不同的一致性级别 - 也许是级别ALL。这样,Cassandra和其他后关系数据库的一致性是可调的,关系数据库通常不是这样。

In the same example, if you read with a consistency level of ONE, the response will be sent to the client after a single replica responds. Another replica may have newer data, in which case the response will not be up-to-date. In many contexts, that's quite sufficient. In others, the client will need the most up-to-date information, and you'll use a different consistency level on the read - perhaps a level ALL. In that way, the consistency of Cassandra and other post-relational databases is tunable in ways that relational databases typically are not.

现在回到你的例子。

示例一:是的,您可以写入A并从B读取,即使B没有自己的副本。 B将代表您的客户请求A.这也适用于您的其他情况,其中节点都在。

Example one: Yes, you can write to A and read from B, even if B doesn't have its own replica. B will ask A for it on your client's behalf. This is also true for your other cases where the nodes are all up. When they're all up, you can write to one and read from another.

对于写入,如果WC = ONE,如果单个副本的节点已启动,并且是你连接到的,写将成功。如果是其他节点,写入将失败。如果你使用ANY,写将成功,假设你正在与正在谈论的节点。我想你也必须有提示切换启用。

For writes, with WC=ONE, if the node for the single replica is up and is the one you're connect to, the write will succeed. If it's for the other node, the write will fail. If you use ANY, the write will succeed, assuming you're talking to the node that's up. I think you also have to have hinted handoff enabled for that. The down node will get the data later, and you won't be able to read it until after that occurs, not even from the node that's up.

在另一个节点中,下一个节点将会获取数据,两个示例,复制因素将影响最终写入多少副本,但不会影响客户端行为超出上面所述。 QUORUM将影响客户端行为,因为您必须有足够数量的节点并响应写入和读取。如果你幸运,并且至少(nodes / 2)+ 1个节点从你需要的节点中出来,那么写入和读取将成功。如果没有足够的节点包含副本,则读取和写入将失败。总的来说,如果一个节点关闭,假设该节点不需要存储您的副本,或者如果它的中断仍然留有足够的副本节点,则一些QUORUM读取和写入可以成功。

In the other two examples, replication factor will affect how many copies are eventually written, but doesn't affect client behavior beyond what I've described above. The QUORUM will affect client behavior in that you will have to have a sufficient number of nodes up and responding for writes and reads. If you get lucky and at least (nodes/2) + 1 nodes are up out of the nodes you need, then writes and reads will succeed. If you don't have enough nodes with replicas up, reads and writes will fail. Overall some QUORUM reads and writes can succeed if a node is down, assuming that that node is either not needed to store your replica, or if its outage still leaves enough replica nodes available.

这篇关于了解cassandra复制因素与一致性水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 00:11