Distributed theory: is the cap a triple-pick two? __java

Source: Internet
Author: User

What cap is.
Cap theory, dubbed the [hat theory]. Cap theory was presented by Eric Brewer at the ACM Symposium, and then Cap was hailed as an important theory in the Distributed field [1].

CAP Theory for Distributed systems: first, the three characteristics of distributed systems are summarized as follows:
Consistency (C): All data backups in a distributed system have the same value at the same time. (equivalent to all nodes accessing the same latest copy of data)

Availability (A): Whether the cluster as a whole can respond to the client's read and write requests after a subset of nodes fail in the cluster. (High availability for data updates)

Partitioning tolerance (P): In practical terms, partitioning is equivalent to a time limit for communication. If the system fails to achieve data consistency within the time frame, it means that partitioning occurs, and a choice must be made between C and A for the current operation. (The partition state can be understood as part of the machine is not connected, such as Machine hung, busy lost response, single room failure, etc.)

Partition literal meaning is the network partition, that is, because the network factor separates the system into several separate parts, one may say, the probability of the network partition is very small, is not to consider P, guarantee CA good. To understand p, we look back at the definition of p in the CAP proof:

In order to model partition tolerance, the network would be allowed to lose arbitrarily many messages sent from one node to Another

The situation of the network partition conforms to this definition, the situation that the network loses a packet also conforms to the above definition, another node is down, the packet that other node sends to the downtime node also will lose, this kind of situation also conforms to the definition. In reality, we are facing an unreliable network, a certain probability of downtime equipment, these two factors will lead to Partition, so the distributed system implementation P is a must, but not optional.

High availability and data consistency are the goals of many system designs, but partitioning is an unavoidable thing. Let's take a look at the case of owning the CA, CP, and AP separately.

CA without P: if p is not required (partitions are not allowed), C (strong consistency) and a (availability) are guaranteed. But in fact partitions are not what you want to do, but always exist, the CA system is basically a stand-alone system, such as stand-alone database. 2PC is a concrete means to achieve strong consistency.

CP without a: If you do not require a (available), the equivalent of each request to a strong consistency between the Server, and P (partition) can cause the synchronization time indefinitely extended, so the CP is also guaranteed. Many traditional database distributed transactions belong to this pattern.

AP wihtout C: To be highly available and allow partitioning, you need to discard consistency. Once partitions occur, nodes may lose contact, and for high availability, each node can only serve local data, which can result in inconsistencies in global data. Many NoSQL now belong to this category.

Proof of CAP theory

The theory was brewer out, 2 years later, 2002 years, and Lynch and others proved the brewer conjecture, thus raising the CAP to a theorem. However, it only proves that CAP three cannot be satisfied at the same time, and there is no proof that either of them can be satisfied, so the proof is considered a narrow result.

Lynch's proof is relatively simple: the use of the contrary, if the three can be met at the same time, because the existence of allow P, there must be a packet loss between the Server, so can not guarantee C, proof concise and rigorous.

In the proof, the definition of the CAP was more clearly stated:
* C: Consistency is called an atomic object, and any read and write should look "atomic" or serial. Write the following reading must be able to read the previous written content. All read and write requests seem to be sorted globally.
* A: For any non-failed node, the requested response should be given within a limited time. (Termination of the request)
* P: Allows any number of messages to be lost between nodes, and messages between nodes may be completely lost when a network partition occurs.

For the CAP further case explanation

The 2010 article, brewers-cap-theorem-on-distributed-systems/, uses three examples to illustrate caps, respectively, example1: Single point of Mysql;example2: two MySQL, but different MySQL stores different subsets of data, equivalent to Sharding;example3: Two MySQL, an insert operation on a, which needs to be performed successfully on B to consider the operation complete (similar to a replica set). The author believes that strong consistency can be guaranteed on both example1 and example2, but it does not guarantee usability; In Example3 This example, because of the presence of partitions (partition), there is a trade-off between consistency and availability. For replication, strong consistency is not pursued in many scenarios. For example, when a user pays, the transaction is landed, but there is a delay in the synchronization of the messages that may be consumed, such as blocked messages. In the financial business, similar to the two central structure, often may take local data and remote room data to write a successful return of the same way. This gives the loss of performance and the response time becomes longer. But the computer room failure, can ensure that the data can be read and written, ensure consistency.

CAP theory clarifies

[CAP Theory 12-year review: "The rules have changed]" a text starting in Computer magazine, after the joint presentation by InfoQ and IEEE, very exciting [2], the article expressed several views.

"Three-choice two" is a pseudo proposition

Not for P (partition tolerance), to choose between A and C. Partitions rarely appear, and caps allow perfect C and A for most of the time. However, when a partition exists or can perceive its impact, it is necessary to prepare a strategy to detect the partition and explicitly handle its impact. Such a strategy should be divided into three steps: probing

Knowledge partitioning occurs, entering explicit partitioning mode to restrict certain operations, initiating recovery process to recover data
Consistency and compensates for errors that occurred during partitioning.

"The scope of consistency" in fact reflects the idea that within a certain boundary state is consistent, but beyond the boundaries of the impossible to talk about. For example, in a primary partition to ensure complete consistency and availability, while outside the partition service is not available. Paxos Algorithms and Atomic Multicast (atomic multicast) systems generally conform to such scenarios. Google's general approach is to place the primary partition in a single datacenter, and then hand it over to the Paxos algorithm to solve the cross-regional problem, while ensuring that global consensus is consensus, such as Chubby, to achieve high availability of persistent storage such as Megastore.

ACID, BASE, CAP

ACID and BASE, both of which are well written and imprecise, have a more pronounced sense of the late BASE hard scrape, which is "basically Available, Soft state, eventually consistent (basic usable, soft, final consistency ) "Acronym for the first letter. The soft state and final consistency of these two techniques are adept at dealing with partitions and therefore high availability.

The relationship between CAP and ACID is more complex and therefore leads to more misunderstandings. One reason for this is that the ACID C and a letters represent concepts different from those of CAP C and a. Another reason is that selection of availability only partially affects ACID constraints.

After looking at [partitioning] further

Use this diagram [quote from Link 2], in the state S when the partition state, and the partition mode evolved out of the S1,S2, then the problem, after the partition recovery, the state is how much? There are several solutions.

Partition recovery strategy: Interchangeable multiple replica data types Note that scenarios that support this type of processing are limited.
RIAK_DT is such a guarantee of the final consistency of the data structure, which is divided into operation-based Crdts, state-based Crdts 2 of forms.
RIAK_DT link See link [3].

Partition recovery strategy: Playback merge in the process of partition recovery, designers must solve two problems:
* The states on both sides of the partition must eventually remain consistent
* and must compensate for errors generated during partition.

As shown in the figure above, for the state of the partition recovery s* can start with the state S when not partitioned, and then [replay] The corresponding change event in the order [to advance a series of operations on both sides of the partition in a specific way and maintain a consistent state throughout the process. ]。 Bayou[link 4] is the implementation mechanism that rolls back the database to the right time and performs all operations again in a unambiguous, deterministic order, eventually bringing all nodes to the same state.

For conflict situations, such as version management software CVS, there is a process strategy for human intervention and conflict elimination.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.