How two phases locking ensures serializable?
2
votes
1
answer
1371
views
I have read many sources , and they say one of the ways to implement serializable in the database is to use two-phase locking. But I don't really understand how two-phase locking could ensure serializable in this example from Jim Gray.
An example is we have two rows in the database, one has the value of **white** and the other one has the value of **black**.
I have two transactions:
- TX1 will update the value of **white** to **black**
- TX2 will update the value of **black** to **white**
If TX1 and TX2 are executed at the same time, then TX1 acquires the lock on the row with the value of **white**, and TX2 acquires the lock on the row with the value of **black**.
So there are no locking conflicts, and eventually, the values are swapped.
Asked by Quốc Khánh Bùi
(25 rep)
Feb 2, 2023, 03:35 PM
Last activity: Oct 8, 2024, 04:45 AM
Last activity: Oct 8, 2024, 04:45 AM