Since transactions need to achieve ACID, that is, atomicity, consistency, isolation, and durability, a certain mechanism must be used to ensure that, usually in a staged submission method.
XA: XA protocol. Specifies the transaction manager and resource manager interfaces. A two-phase commit protocol is used.
One-Phase Commit Protocol
The one-phase commit protocol is relatively simple. For example the following picture:
Of course, the premise is that the transaction is opened, and then after the application makes a commit/rollback request, the database runs the operation, and then returns the success/failure to the application. The program continues to run.
The one-phase commit protocol is relatively simple. The advantage of simplicity is that it no longer has to interact with other objects. It saves inference steps and time, so performance is better in the phase-commit protocol.
two-phase commit protocol
The one-phase commit protocol has its advantages, but its disadvantages are also very obvious:
- The database has taken a long time to confirm running transactions. The possibility of problems increases accordingly.
- Assuming there are multiple data sources, the one-phase commit protocol cannot coordinate their relationship.
So on the basis of a one-phase agreement. With the Phase 2 protocol, the advantage of the Phase 2 protocol is the addition of a manager role, such as the following:
very obvious. The phase two protocol works by turning two layers into three. An intermediate manager role is added to coordinate the relationship between multiple data sources. The two-phase commit protocol is divided into two phases.
The first stage
The application calls the commit method of the transaction manager. The first stage is then divided into two steps:
- The transaction manager notifies the various resource managers participating in the transaction. Notify them to start preparing the transaction.
- After the resource manager receives the message, it starts the preparation phase, writes the transaction log and runs the transaction, but does not commit it, and then returns the message of readiness to the transaction manager (at this time, most of the transaction has been completed, and the future content takes very little time).
second stage
The second stage is also divided into two steps:
- After accepting each message, the transaction manager begins to analyze, assuming that any one of them fails. Send a rollback command, otherwise send a commit command.
- After each resource manager receives the command, it runs (very little time-consuming). and return a commit message to the transaction manager.
Transactions and Agreements
external transaction manager, and can be utilized when only one resource is
involved. Local transactions only support one phase commit, because they only
reference one EIS.……