Distributed transaction
The paper
Distributed transaction means that the operation of the transaction is located on different nodes, so the AICD feature of the transaction must be guaranteed.
Theory of CAP
What are the combinations of CAP? 1. CA: Abandon partition tolerance, strengthen consistency and availability, and design relational databases according to CA. 2. AP: Abandon consistency, enhance availability and partition tolerance, and pursue ultimate consistency. Many NoSQL databases are designed according to AP. Note: The abandonment of consistency here refers to the abandonment of strong consistency, which means that the latest data should be queried immediately after the success of writing. Pursuit of eventual consistency refers to allow temporary data inconsistency, as long as the final in the user data can accept time 3, CP: give up availability, strengthen the consistency and partition tolerance, strong consistency of the requirements of the system design according to CP, an inter-bank transfer, for example, a transfer request to wait for both the banking system to complete the entire transaction is completed. Note: due to network problems may appear to be waiting for the existence of the CP system timeout, if there is no timeout problems sorting system will be blocked summary: in a distributed system design is more, the application of AP, ensure partitioning tolerance and availability, at the expense of the strong consistency of data (read write operation immediately after the latest data), to ensure data consistency in the end. For example: order refund, the refund is successful today, the account arrives tomorrow, as long as the refund transaction is completed within the time acceptable to the predetermined user.Copy the code
The solution
Phase 1, Phase 2 Submission (2PC)
Stage 1: Prepare Stage (Prepare) The coordinator informs participants that they are ready to submit, and participants begin voting. The participant completes the preparation and responds to the coordinator with Yes. Phase 2: Commit/Rollback Phase The coordinator initiates the final commit instruction based on the voting results of the participants. Initiate a rollback command if a participant is not ready.Copy the code
Ii. Transaction Compensation (TCC)
TCC transaction compensation is a business layer transaction control scheme based on 2PC. It is the first letter of Try, Confirm, and Cancel, and has the following meanings: 1. Try check and reserve service resources. 2. Confirm Confirm the service operation and formally execute the reserved resources in the try phase. 3. Cancel Cancels the service operation and releases the resources reserved for the try phase.Copy the code
3. Local message implementation final consistency (asynchronous)
The active application system completes the operation of business data through business operations, and stores the message in the active application system when preparing to send messages, and sends the other one to the real-time message service. The passive application system monitors messages in the real-time message system. After the passive party finishes processing the message, the active party invokes the active party interface to confirm the message. After receiving the message, the active party deletes the message data. If no ACK message is returned within the specified time after the message is received, the message recovery system resends the message.Copy the code
Iv. Best efforts to notify
The active party of the business activity sends a message to the passive party of the business activity after processing, allowing the message to be lost. The passive party of the business activity queries the active party of the business activity based on the scheduled policy to recover the lost business message.Copy the code
This article is formatted using MDNICE