CAP 定理 - 可用性和分区容限 [英] CAP theorem - Availability and Partition Tolerance

查看:15
本文介绍了CAP 定理 - 可用性和分区容限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图理解 CAP 中的可用性"(A)和分区容差"(P)时,我发现很难理解各种文章的解释.

While I try to understand the "Availability" (A) and "Partition tolerance" (P) in CAP, I found it difficult to understand the explanations from various articles.

我感觉 A 和 P 可以一起走(我知道不是这样,这就是为什么我无法理解!).

I get a feeling that A and P can go together (I know this is not the case, and that's why I fail to understand!).

简单的解释一下,A和P是什么以及它们之间的区别?

Explaining in simple terms, what are A and P and the difference between them?

推荐答案

一致性意味着数据在整个集群中是相同的,因此您可以从任何节点读取或写入并获取相同的数据.

Consistency means that data is the same across the cluster, so you can read or write from/to any node and get the same data.

可用性是指即使集群中的某个节点出现故障也能访问集群的能力.

Availability means the ability to access the cluster even if a node in the cluster goes down.

分区容错意味着即使两个节点之间存在分区"(通信中断)(两个节点都已启动,但无法通信),集群仍继续运行.

Partition tolerance means that the cluster continues to function even if there is a "partition" (communication break) between two nodes (both nodes are up, but can't communicate).

为了同时获得可用性和分区容错性,您必须放弃一致性.考虑在主-主设置中是否有两个节点 X 和 Y.现在,X 和 Y 之间的网络通信中断,因此它们无法同步更新.此时,您可以:

In order to get both availability and partition tolerance, you have to give up consistency. Consider if you have two nodes, X and Y, in a master-master setup. Now, there is a break between network communication between X and Y, so they can't sync updates. At this point you can either:

A) 允许节点不同步(放弃一致性),或

A) Allow the nodes to get out of sync (giving up consistency), or

B) 认为集群关闭"(放弃可用性)

B) Consider the cluster to be "down" (giving up availability)

所有可用的组合是:

  • CA - 所有节点之间的数据是一致的 - 只要所有节点都在线 - 您可以从任何节点读取/写入并确保数据相同,但如果您曾经在节点之间建立分区,数据将不同步(一旦分区解决,将不会重新同步).
  • CP - 数据在所有节点之间保持一致,并通过在节点关闭时变为不可用来保持分区容差(防止数据不同步).
  • AP - 节点保持在线,即使它们无法相互通信,并且会在分区解决后重新同步数据,但不能保证所有节点都具有相同的数据 (在分区期间或之后)
  • 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 系统实际上并不存在(甚至如果某些系统声称是这样).

You should note that CA systems don't practically exist (even if some systems claim to be so).

这篇关于CAP 定理 - 可用性和分区容限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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