DB WEEK 13
DB WEEK 13
SYSTEMS (Transaction
Management)
WEEK 13 LECTURE 1& 2
AQSA IFTIKHAR
Topics to Cover
2PL
Time stamping
Deadlocks
Deadlock Prevention
Deadlock Detection
Concurrency Control Techniques
Any transaction that needs to access a data item must first lock the
item, requesting a shared lock for read-only access or an exclusive
lock for both read and write access. If the item is not already locked
by another transaction, the lock will be granted.
This in effect allows a transaction to examine the data first and then
decide whether it wishes to update it. If
Two-phase locking (2PL)
It can then proceed to read the value of balx from the database,
increment it by £100, and write the new value back to the database.
Wait-Die Scheme
In this scheme, if a transaction requests to lock a resource (data
item), which is already held with a conflicting lock by another
transaction, then one of the two possibilities may occur :-
If TS(Ti) < TS(Tj) − that is Ti, which is requesting a conflicting lock, is
older than Tj − then Ti is allowed to wait until the data-item is
available.
If TS(Ti) > TS(tj) − that is Ti is younger than Tj − then Ti dies. Ti is
restarted later with a random delay but with the same
timestamp.
Deadlock Prevention
Wound-Wait Scheme
In this scheme, if a transaction requests to lock a resource (data
item), which is already held with conflicting lock by some
another transaction, one of the two possibilities may occur −
If TS(Ti) < TS(Tj), then Ti forces Tj to be rolled back − that is Ti
wounds Tj. Tj is restarted later with a random delay but with the
same timestamp.
If TS(Ti) > TS(Tj), then Ti is forced to wait until the resource is
available.
Deadlock Detection
Timestamping
How to retrieve updates
due to failures
Log
Checkpoints