| Elmasri/Navathe (3rd ed.) | Elmasri/Navathe (2nd ed.) | Connolly, Begg (3nd ed.) | McFadden (5th ed.) |
|---|---|---|---|
| Chapter 20 | Chapter 18 | Chapter 19 (19.2) | Chapter 13 |
See the Transaction Processing Performance Council web site for more information.
User A places an exclusive lock on the balance
User A reads the balance
User A deducts $100 from the balance
User B attempts to place a lock on the balance
but fails because A already has an exclusive lock
User B is placed into a wait state
User A writes the new balance of $100
User A releases the exclusive lock on the balance
User B places an exclusive lock on the balance
User B reads the balance
User B deducts $100 from the balance
User B writes the new balance of $100
User A places a shared lock on item raise_rate User A reads raise_rate User A places an exclusive lock on item Amy_salary User A reads Amy_salary User B places a shared lock on item raise_rate User B reads raise_rate User A calculates a new salary as Amy_salary * (1+raise_rate) User B places an exclusive lock on item Bill_salary User B reads Bill_salary User B calculates a new salary as Bill_salary * (1+raise_rate) User B writes Bill_salary User A writes Amy_salary User A releases exclusive lock on Amy_salary User B releases exclusive lock on Bill_Salary User B releases shared lock on raise_rate User A releases shared lock on raise_rate
User A places a shared lock on raise_rate
User B attempts to place an exclusive lock on raise_rate
Placed into a wait state
User A places an exclusive lock on item Amy_salary
User A reads raise_rate
User A releases shared lock on raise_rate
User B places an exclusive lock on raise_rate
User A reads Amy_salary
User B reads raise_rate
User A calculates a new salary as Amy_salary * (1+raise_rate)
User B writes a new raise_rate
User B releases exclusive lock on raise_rate
User A writes Amy_salary
User A releases exclusive lock on Amy_salary
R = Read. W = write. L = Lock. U = Unlock.
Conservative: TLa TLb TLc Tld TRa Twa TUa Rb Wb TUb Rc Wc TUc Rd Wd TUd Strict: TLa TRa Twa TLb TLc Rb Wb TLd Rc Wc Rd Wd TUa TUb TUc TUd
Transaction A places an exclusive lock on item 1001
Transaction B places an exclusive lock on item 2002
Transaction A attempts to place an exclusive lock on item 2002
Transaction A placed into a wait state
Transaction B attempts to place an exclusive lock on item 1001
Transaction B placed into a wait state
...
Under Wait-Die: TS(Tx) < TS(Ty) so Tx will wait for Ty to release the lock.
In other words, since Tx started first, it gets the privilege of waiting.
Under Wound Wait: TS(Tx) < TS(Ty) so Ty will be aborted.
In other words, since Tx started first, it has the privilege of
kicking Ty out of the way by aborting it. So now Tx can proceed.
T1: Ra Wa Rb Wb Rc Wc Rd Wd Re We T2: Re We Ra Wa Rb Wb Rh Wh T3: Rf Wf Rb Wb T1 has done the following: Ra Wa Rb Wb Rc Wc Rd Wd T2 has done the following: Re We T3 has done the following: Rf Wf
Since we see a directed cycle between T1 and T2, we know there is a deadlock condition between those two transactions (note there is no deadlock between T1 and T3).
T1: Ra Wa Rb Wb Rc Wc Rd Wd Re We T2: Re We Ra Wa Rb Wb Rh Wh T3: Rf Wf Rb Wb T1 has done the following: Ra Wa Rb Wb Rc Wc Rd Wd T2 has done the following: Re We Which should we abort? Which has done the most work?
In the above example, suppose we choose to abort T2.
Before T2 gets a chance to start again, T3 executes:
Rf Wf
Can T2 proceed?
In the above example, T2 may be kept waiting forever if other transactions are allowed to go before it.
Note that T2 is never aborted (as is the case in starvation), it just makes no forward progress.
BEGIN
dbms_transaction.begin_discrete_transaction;
UPDATE employee
SET salary = salary * 1.02
WHERE dno = 5;
EXCEPTION
WHEN dbms_transaction.discrete_transaction_failed
THEN
ROLLBACK;
END;
END;