EX: A轉帳 200 給B需要
一個完整的轉帳過程需要 6 個操作全部成功,其中有一個操作失敗就 rollback。 例如第三步失敗後,A的餘額會回到原本得餘額不然就會白扣A200 元
- dirty read, 2. non-repeatable, 3. phantom read.
begin commit ↓ data=2 ↓ t1 -----------------------------------------------> (read)↓ ↑ (set data=3)↓ ↑ data=2 -----------------------------------------------> (read) ↑ ↓ <--------t1 not commit yet t2 -----------------------------------------------> ↑ data=3 begin
begin commit ↓ data=2 ↓ t1 -----------------------------------------------> (read)↓ ↑ (set data=3)↓ ↑ data=2 -----------------------------------------------> (read) ↑ ↓ (read) ↑ ↓ <--------t1 committed t2 -----------------------------------------------> ↑ data=2 <--- different value ---> data=3 begin
begin commit ↓ count(d)=2 ↓ t1 ----------------------------------------------------------> (read)↓ ↑ (insert)↓ ↑ count(d)=2 ----------------------------------------------------------> (read) ↑ ↓ (read) ↑ ↓ <--------t1 committed t2 ----------------------------------------------------------> ↑ count(d)=2 <--- different value ---> count(d)=3 begin
dirty read | non-repeatable | phantom read | |
---|---|---|---|
read-uncommited | V | V | V |
read-commited | X | V | V |
repeatable read | X | X | V |
serializable | X | X | X |