Interview FAQ manufacturers, distributed basic theoretical knowledge -2pc agreement, will be watching

Preface:

Distributed Transaction topic has been the focus of the interview, this article mainly discuss the distributed transaction 2pc protocol. If you've seen the CAP and BASE theory, this article will have a greater understanding of help. End of the article there are benefits Oh friends Share

First, what is 2pc protocol

2PC i.e., two-phase commit protocol, the entire transaction is a two-stage process, the preparation phase (Prepare phase), the commit phase (commitphase), 2 means that two phases, P refers to a preparation phase, C refers to a commit phase.

How to understand it? For example, class reunion, AA system.

(1) preparation phase: Each person pays

(2) commit phase: Qian Qi payment

In the maybe stage, any one part of an error, the entire transaction will be abortion. In a typical relational database to support the 2pc protocol. For example, the famous mysql database.

(1) preparation phase (Prepare phase): Transaction Manager sent to each participant Prepare message, each participant in the local database to perform a transaction, and write local Undo / Redo logs, did not submit the transaction at this time.

(2) commit phase (commit phase): If the transaction manager had before it a participant fails or times out messages sent directly rollback (Rollback) message to each participant;

The following is a success: Phase 1 is the preparatory stage, Stage 2 submission stage

4c4cc823d7ef4c42ab135674c3f5e3ec



The following is a case of failure.


d0b13c5c7e2849fe9af2cbfd1909ae72


This is the case of failure.

Second, the use seata achieve 2pc Affairs

This seata is distributed transaction framework provided by Ali. Seata a distributed transaction to be understood as a global transaction includes a number of branch transactions. Responsibility is to coordinate global transaction branch affairs under the jurisdiction of the agreement, either successfully submitted together or fail together rollback. In addition, the transaction branch itself is usually a relational database of local affairs, following diagram is a graph of global transaction branch transactions:


29f9905ab9fe4f4b84ff7d2ac53027b8


Seata defines the three components of a distributed transaction processing protocol.


4bf1bf25a4b1497d96243606691b8808


(1) Transaction Manager (TM): Transaction Manager, TM need to embed applications work, it is responsible for opening a global transaction, and ultimately to initiate a global TC commit or roll back global instruction.

(2) Transaction Coordinator (TC): transaction coordinator, which is independent of middleware, requires a separate deployment run, it maintains the operating state of the global transaction, submission and rollback the receiving TM instruction is initiated global transaction, is responsible for coordinating communication with RM Calvary branch commit or roll back the transaction.

(3) Resource Manager (RM): Control affairs branch, the branch is responsible for registration, status reports, and receive instruction transaction coordinator TC, commit and rollback drive branch (local) transaction.

These concepts seem a bit ignorant force, give you an example: Take for example the new user registration send integration process Seata of distributed transactions


9621e1c46a9a4d3fa7081daaeaca2837


Specific implementation process is as follows:

(1) customer service TC TM to request the opening of a global transaction, the global transaction is successfully created and generate a globally unique XID.

(2) RM TC registered users and services transaction branch, the branch in the user transaction service execution logic new users, and incorporated into the corresponding global transaction XID jurisdiction.

(3) the implementation of customer service branch affairs, insert a record into the user table.

(4) to a remote invocation logic performs integration service (XID propagating in the context of the micro-service call link). RM integration services registered branch transactions to TC, the branch increased transaction execution logic integration, and included in the jurisdiction of the XID corresponding to the global transaction.

(5) integration service execution branch affairs, insert a record to record points table, after the implementation of return users.

(6) customer service branch transaction is finished.

(7) TM launched the TC committed or rolled back against the global resolution of XID.

(8) under the jurisdiction of all branch transaction completion XID TC scheduling request commit or rollback.

Readers Benefits:

To smooth to get the interview questions that will offer light is not enough, or that the light will issue a technical point is not enough, be sure to rain descends Yeah my friends, so I will give you a detailed collation of large plant face questions data, this pdf documentation up to more than four hundred pages, one can imagine that he is really very comprehensive very comprehensive, sub-themes finishing and hit your knowledge blind spot, you may say, to prove safety offer

I am concerned about the number of jobs Java Zhou person can receive

efb23102d6cd46808b25697487893696


b0801c1d3ece4706a3df495292ba213b


5db53aa444744eb7952eef1cff387d49




Guess you like

Origin blog.51cto.com/14456091/2471520