当我试图理解CAP中的“Availability”(A)和“Partition tolerance”(P)时,我发现很难理解各种文章的解释。
我有一种感觉,a和P可以同时出现(我知道事实并非如此,这就是我不能理解的原因!)
简单地解释一下,什么是A和P以及它们之间的区别?
当我试图理解CAP中的“Availability”(A)和“Partition tolerance”(P)时,我发现很难理解各种文章的解释。
我有一种感觉,a和P可以同时出现(我知道事实并非如此,这就是我不能理解的原因!)
简单地解释一下,什么是A和P以及它们之间的区别?
当前回答
我找了很多环节,但是没有一个环节能给我满意的答案,只有一个环节。
因此,我用非常简单的语言描述CAP。
Consistency: Must return same Data, regardless to from which node is it coming. Availability: Node should respond (must be available). Partition Tolerance: Cluster should respond (must be available), even if there is a a partition (i.e. network failure) between nodes. ( Also one main reason it confuses more is bad naming convention of it. If I had right, I might have given DNC theorem instead: Data Consistency, Node Availability, Cluster Availability, where each corresponds to Consistency, Availability and Partition Tolerance respectively )
CP数据库:CP数据库以牺牲可用性为代价提供一致性和分区容忍。当任意两个节点之间发生分区时,系统必须关闭不一致的节点(即使其不可用),直到分区被解决。
AP数据库:AP数据库提供了可用性和分区容忍,但牺牲了一致性。当分区发生时,所有节点仍然可用,但那些在分区错误一端的节点可能返回比其他节点更旧的数据版本。(当分区被解析时,AP数据库通常会重新同步节点,以修复系统中的所有不一致。)
CA数据库:CA数据库提供跨所有节点的一致性和可用性。但是,如果系统中的任意两个节点之间存在分区,则无法做到这一点,因此无法提供容错功能。在分布式系统中,分区是不可避免的。因此,虽然我们可以在理论上讨论CA分布式数据库,但出于所有实际目的,CA分布式数据库可以存在,但不应该存在。
因此,这并不意味着如果需要,就不能为分布式应用程序提供CA数据库。许多关系数据库,如PostgreSQL,提供一致性和可用性,并可以使用复制部署到多个节点。
来源:https://www.ibm.com/cloud/learn/cap-theorem
其他回答
根据上图C是断开的,但A,B, D可以继续工作。现在我们可以调用系统部分工作(分区容忍)。
假设一个特定的事务只需要a、B和d,系统可以执行它而不会产生任何不一致。
但是当C必须参与一个特定的事务时,系统可以以两种方式执行。
1.由于C不可用,A可以拒绝用户请求。
So the system has Partition-Tolerance and consistency (P,C).
But no availability, because of the rejection.
2.A可以将C接收到的消息保存在A的本地内存中,并在C连接回来时传输。
So the system has Partition-Tolerance and availability (P,A).
But no consistency.because C has not updated.
一致性意味着整个集群中的数据是相同的,因此您可以从/写入任何节点并获得相同的数据。
可用性意味着即使集群中的某个节点宕机,也能够访问集群。
分区容忍意味着即使两个节点之间存在“分区”(通信中断)(两个节点都在工作,但不能通信),集群也能继续工作。
为了同时获得可用性和分区容忍,您必须放弃一致性。考虑一下在master-master设置中是否有两个节点X和Y。现在,X和Y之间的网络通信中断了,所以它们不能同步更新。此时你可以:
A)允许节点不同步(放弃一致性),或者
B)认为集群“关闭”(放弃可用性)
所有可用的组合是:
CA - data is consistent between all nodes - as long as all nodes are online - and you can read/write from any node and be sure that the data is the same, but if you ever develop a partition between nodes, the data will be out of sync (and won't re-sync once the partition is resolved). CP - data is consistent between all nodes, and maintains partition tolerance (preventing data desync) by becoming unavailable when a node goes down. AP - nodes remain online even if they can't communicate with each other and will resync data once the partition is resolved, but you aren't guaranteed that all nodes will have the same data (either during or after the partition)
您应该注意,CA系统实际上并不存在(即使有些系统声称存在)。
理解CAP定理的简单方法:
In case of network partition, one needs to choose between perfect availability and perfect consistency. Picking consistency means not being able to answer a client's query as the system cannot guarantee to return the most recent write. This sacrifices availability. Picking availability means being able to respond to a client's request but the system cannot guarantee consistency, i.e., the most recent value written. Available systems provide the best possible answer under the given circumstance.
这个解释来自这篇优秀的文章。希望能有所帮助。
根据CAP定理,分布式系统有三个特征:
一致性(C)表示所有系统组件具有相同的信息。
系统的可用性(A)意味着它不会因为另一个系统故障而停止工作。
分区容差(P)表示在任意网络包丢失的情况下,系统将继续工作。
根据CAP定理,一个系统最多只能有这三个特征中的两个。(ap, cp, ca)
一致性——当我们发送读请求时,如果它正在返回结果,它应该返回客户端请求给出的最近的写。 可用性—您的读/写请求应该总是成功的。 分区容忍度——当网络分区(某些机器相互通信的问题)发生时,系统仍然可以工作。
在分布式环境中,存在网络分区发生的可能性,我们无法避免CAP的“P”。因此,我们在“一致性”和“可用性”之间进行选择。
http://bigdatadose.com/understanding-cap-theorem/