Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

3. Conformance Protocol 2PC Protocol (ZooKeeper Note)

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

The origin of 2PC and 3PC

In a distributed system, each machine node can clearly know whether its transaction operation is successful (it can be understood as a stand-alone operation), but it can not directly obtain the operation results of other distributed nodes. Therefore, when a transaction operation needs to span multiple distributed nodes, in order to maintain the ACID feature of the transaction, it is necessary to introduce a component called "coordinator" to schedule the execution logic of all distributed nodes uniformly, which we call "participant". Based on this idea, two protocols of 2PC and 3PC are derived.

1. 2PC (Two-Phase Commit) two-phase submission

Phase 1: commit transaction request

Business inquiry.

The coordinator sends transaction content to all participants, asks if the transaction commit operation can be performed, and starts waiting for a response from each participant. Execute a transaction

Each participant performs transaction operations and records undo and redo information in the transaction log. Each participant feedback the response of the transaction inquiry to the coordinator

If the participant successfully performs the transaction operation, feedback the Yes response to the coordinator and vice versa to the No response.

Phase 2: perform transaction commit (the result of phase 1 feedback is Yes)

Send a submission request

The coordinator issues an Commit request to all participant nodes. Transaction commit

After the participant receives the Commit request, the transaction commit operation is formally performed. Feedback on transaction commit results

After completing the transaction commit, the participant sends an ACK message to the coordinator. Complete the transaction

After receiving the ACK messages from all participants, the coordinator completes the transaction.

Phase 2: interrupt the transaction (the result of phase 1 feedback has No or timeout)

Send a rollback request

The coordinator issues an RollBack request to all participant nodes. Transaction rollback

After receiving the RollBack request, the participant uses the undo information in Phase 1 to perform the transaction rollback operation. Feedback the result of transaction rollback

After completing the transaction rollback, the participant sends an ACK message to the coordinator. Interrupt a transaction

After receiving the ACK message from all participants, the coordinator completes the transaction interruption. Advantages

The principle is simple and the realization is convenient. Disadvantage synchronous blocking single point problem data inconsistency is too conservative

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report