write isolation
Before committing a local transaction in the first phase, it is necessary to ensure that the global lock is obtained first. If the global lock cannot be obtained, local transactions cannot be submitted. The attempt to take the global lock is limited to a certain range, and if it exceeds the range, it will give up, roll back the local transaction, and release the local lock. Examples are as follows:
Two global transactions tx1 and tx2 update the m field of table a respectively, and the initial value of m is 1000.
tx1 starts first, starts the local transaction, gets the local lock, and updates m=1000-100=900. Before the local transaction commits, first obtain the global lock of the record, and the local commit releases the local lock. Start after tx2, start the local transaction, get the local lock, and update the operation m=900-100=800. Before the local transaction is committed, try to get the global lock of the record. Before tx1 is globally committed, the global lock of the record is held by tx1, and tx2 needs to retry and wait for the global lock.

tx1 two-phase global commit, release the global lock. tx2 gets the global lock and submits the local transaction.

If the two-stage global rollback of tx1, then tx1 needs to re-acquire the local lock of the data, perform the update operation of reverse compensation, and realize the rollback of the branch. At this time, if tx2 is still waiting for the global lock of the data while holding the local lock, the branch rollback of tx1 will fail. The rollback of the branch will be retried until the global lock of tx2 times out, the global lock is given up and the local transaction is rolled back to release the local lock, and the branch of tx1 is rolled back
Last updated