Distributed Transaction Processing
When data is distributed across multiple database servers, various protection measures are required to ensure that the data is correctly written to all databases. For example, to consider a customer account balance table modified on three separated remote databases, if any database connection fails during the transaction write phase, the database will lose synchronization. How can we detect and correct this situation? Transaction Processing (TP) monitors a process called two-phase commit and solves this problem to some extent.
Real-time transaction processing on distributed systems requires a two-phase commit process to ensure data integrity when transactions are obtained from multiple databases. Each database involved must be authorized when the transaction is committed to any other database. If the transaction is successful, it is committed; otherwise, the transaction should be rolled back. Similar to Fault-Tolerant Systems, two-phase commit protects the system from system errors during transaction writing. It also allows the operator to terminate a transaction unexpectedly and restore the database to its original state. The transaction monitor tracks the transaction process according to the following process.
1. After the write operation command is sent to each database, the transaction monitor waits for a response signal to ensure that all systems are ready for writing. If all systems respond, the transaction will terminate abnormally here.
2. Assuming that all responses are returned, the transaction invigilator instructs the database to start writing, and then waits for a confirmation signal indicating that data writing is successful for each system.
3. If you do not receive all system response signals (due to line or system faults), the transaction invigilator commands all databases to cancel this write operation.
For example, a component running on machine A is one of the components of a single transaction. The component can use SQL Server on machine B to execute database transactions. Another component that makes up transactions is used to execute database transactions on the Oracle server running on machine C. These three machines run four different codes and all of them need to be involved in this transaction.
Even if the details of distributed transactions are hidden through COM +, it is necessary to study and understand the "behind-the-scenes" structure of distributed transactions. Remember that these acid features apply to all types of transactions, regardless of the type or number of databases involved in the transaction.
Two-phase submission using MS DTC
Let's take a look at the above Distributed Transaction example. If the Oracle server is down, how can we ensure the atomicity of transactions. The answer is to use two-phase commit (two-phase commit, 2 PC) and coordination through Microsoft Distributed Transaction Coordinator (ms dtc.
MSDTC is the first integration in SQL Server and has become an essential part of COM +. By adding other factors to transaction processing, ms dtc confirms that all processes are completed and submits them.
Let's further study ms dtc and learn how it works. To use the two-phase commit protocol for coordination, each data source in the transaction must have ms dtc. In these installations, the main coordinator is always at the origin of the transaction. This major coordinator is called the commit coordinator, which is responsible for ensuring the commit or termination of the transaction. Whether the transaction is successfully committed or not
Rollback: submits a report to the Coordinator to the customer application.
In two-phase submission, the first stage is the preparation phase. Each server executes the commands it receives, but all the content that should be written to the disk is buffered, as shown in 1 9-1.
Once the server has executed the command, it notifies the commit Coordinator about the transaction status, as shown in 1 9-2.
The second stage is called the commit stage. If the commit Coordinator receives the "prepare for submission" notification from each data source, commit the transaction, 1 9-3.
However, if a failure message is received from an affected data source, the commit Coordinator will perform a rollback and notify the customer application, as shown in figure 1 9-4.