Two-segment submission and three-paragraph submission

Source: Internet
Author: User

Cap theorem

In July 2000, Professor Eric Brewer of the University of California, Berkeley, presented the CAP conjecture, which was proved two years later.

The CAP theory tells us that a distributed system cannot meet the three basic requirements of consistency (c,consistency), availability (a,availability), and partition fault tolerance (p,partition tolerance) at the same time, up to only two of them at the same time.

Consistency: In a distributed system, when the update to one data is successful, all other users can read [the latest value], then the system is strong consistency.

Availability: [within limited time] [return result]

Partition fault tolerance: In the case of any network partition failure, the distributed system still needs to be able to provide services that meet the consistency and availability beyond the pillow-securing embankment.

In fact, the cap theorem is a theory, the real system scenario of the cap may not really give up one of the not to do, but we can focus on the guarantee of the other two, while the remaining one as far as possible to ensure.

In some interviews, interviewers are more interested in asking questions if they guarantee a distributed transaction. The more famous solution is the two-segment submission protocol, the three-stage commit protocol, and the Paxos algorithm.

The [ two-segment commit protocol ] is a process that divides the commit process of a transaction into two stages, which are executed as follows:

Phase one: Commit a transaction request:

1, the business inquiry. The coordinator sends transactional content to all participants, asking if the transaction can be committed and then starting to wait for the participant's response.

2, the implementation of the transaction. Each participant node executes the transaction Austrian, and the undo and redo information is logged in the transaction log.

3, each participant feedback the response of the transaction inquiry to the coordinator.

Phase II: Execution Transaction commit:

If the coordinator receives the feedback from all participants as Yes, then the transaction commit is performed.

1, send the request for submission.

2, the transaction commits.

3, the feedback transaction submits the result. The contributor sends an ACK message to the coordinator after the transaction is committed.

4, complete the transaction.

Interrupt transaction:

1. Send rollback request. The facilitator issues a rollback request to the participant.

2, transaction rollback. The participant receives the Roolback request to perform a transaction rollback action using the undo information of a record in the stage.

3, feedback transaction rollback results.

4, interrupt the transaction.

Advantages and disadvantages of the two-segment submission protocol:

Advantages: Simple principle, easy to achieve;

Cons: Synchronous blocking, single-point problems, brain fissures (such as the coordinator's message being sent only to a subset of participants in the event of a network anomaly), too conservative.

[Three-stage submission agreement] In fact, in the two-segment basis on the two-segment of the shortcomings of the improvement.

Phase One: Cancommit

1, the business inquiry.

2, the participants to coordinate the response of this feedback transaction inquiry.

Stage Two: Precommit

Assuming that the coordinator obtains a Yes response from all participants, the transaction is pre-committed.

1, send the pre-submission request. The coordinator issues a PRECOMMIT request to all participant nodes and enters the prepared phase.

2, the transaction pre-submission. The participant receives the PRECOMMT request, performs a transaction erase, and logs the Undo and redo information to the transaction log.

3. Each participant responds to the coordinator by responding to the transaction submission.

If any participant feeds the coordinator with no response, the Coordinator is not able to get the response from all participants after waiting for the timeout, then the transaction will be interrupted.

1, send the terminal request. The coordinator issues an abort request to all participants.

2, interrupt the transaction. The participant interrupts the transaction regardless of whether it receives an abort request or waits for a timeout in the coordinator request process.

Stage Three: Docommit

This phase will make a real transaction commit:

Execute commit

1, send the request for submission. Entering this phase, assuming that the coordinator is working from a normal state and receiving an ACK response from all participants, it will transition from the pre-commit state to the commit state and send the DOCOMMIT request to all participants.

2, the transaction commits. After the participant receives the DOCOMMIT request, it formally executes the transaction commit operation. and releases the transaction resources that were occupied during the execution of the entire transaction after the commit.

3, the feedback transaction submits the result. After the contributor completes the transaction submission, an ACK message is sent to the coordinator.

4, complete the transaction. The coordinator receives an ACK message from all participants to complete the transaction.

Interrupt Transaction

A 4-step operation that interrupts a transaction is exactly the same as a commit transaction, except that it becomes a transaction rollback from the commit transaction.

Advantages and disadvantages of the three-stage submission protocol:

The biggest advantage is that it lowers the blocking range of the participants and can continue to agree after a single point of failure.

The disadvantage is the introduction of a new problem in the case of blocking, that is, the participant received the PRECOMMIT message, then the network problems, the participants and the Coordinator can not communicate, in which case, the participants will still perform the transaction submission.

----

This article is from Supher's "from Paxos to Zookeeper"

Two-segment submission and three-paragraph submission

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.