Working principle of business
Transaction ensures data consistency and recoverability. The working principle of the transaction is shown in Figure 1.
Figure 1 Working principle of transaction
After the start of the transaction, all of the transaction is written in the transaction log. Write the operation in the log, there are generally two: one is actions for the data, one is actions for the task. For data operation, such as insert, deletion, and modification, this is a typical transaction operation, which is a large amount of data. Some operations are for tasks, such as creating an index, which records a logo in the transaction log, which is used to indicate this operation. When such a transaction is canceled, the system automatically performs the anti-operation of this operation to ensure the consistency of the system. The system automatically generates a checkpoint mechanism, which occurs during the checkpoint. The period of the checkpoint is the time interval of the system automatically calculated by the system based on the user-defined time interval and system activity. Checkpoint periodically checking the transaction log. If the transaction is completed in the transaction log, checkpoints submit transactions in the transaction log into the database and make a checkpoint submit tag in the transaction log. If the transaction is not completed in the transaction log, checkpoints do not submit transactions in the transaction log into the database and do a checkpoint in the transaction log. The recovery of the transaction and the complete and recoverable checkpoint protection system, which can be illustrated using the example shown in FIG.
Figure 2 Example of transaction recovery and checkpoint
In this example diagram, there are five transactions: transaction 1, transaction 2, transaction 3, transaction 4, and transaction 5. The box represents the beginning of the transaction and submits. The horizontal direction indicates time. The checkpoint represents the checkpoint mechanism at a certain point in time, and the system failure indicates that the system that occurs due to power failure, system software failure, etc. The completion of transaction 1 occurs between checkpoints, so transaction 1 is submitted to the database. The completion of the transaction 2 and the transaction 4 occur before the system fails, so these two transactions can be submitted to the database by the system. Transaction 3 and transaction 5 are not completed due to the failure of the system, so these two transactions are canceled.