ADBMS Chapter 4. Concurreny Control
ADBMS Chapter 4. Concurreny Control
ADBMS Chapter 4. Concurreny Control
CONCURRENCY CONTROL
Concurrency Control
Outline
2
Y N
Write
N N
Notation :
:Li(X) –Transaction Ti requests a lock on database element X
Unlocking is an operation which removes these permissions from the data item.
Notation :
Ui (X): Transaction Ti releases (“unlocks”) its lock on database element X
When we use the shared/exclusive locking scheme, the system must enforce the
following rules:
1. A transaction must issue the operation read_lock(x) or write_lock(x) before any
read_item (x) operation is performed in T
2. A transaction T must issue the operation write_lock(x) before any write_item (x)
operation is performed in T
3. A transaction T must issue the operation unlock_lock(x) after all read_item(x) and
write_item (x) operation are completed in T
4. A transaction will not issue a read_lock(x) operation if it already holds a
read(shared) lock or a write (exclusive) lock on item X
5. A transaction will not issue a write_lock(x) operation if it already holds
read(shared) lock or write(exclusive) lock on item x
6. A transaction T will not issue an unlock(x) operation unless it already holds a
read(shared) lock or a write(exclusive) lock on item x
Lock conversion
Sometimes, it is desirable to relax condition 4 and 5 in the coding list in order
to allow lock conversions. That is :
Under certain conditions, a transaction that already holds a lock on item X
is allowed to convert the lock from one lock state to another.
For example, it is possible for a transaction T to issue a read_lock (X) and
then later on to upgrade the lock by issuing a write_lock(x) operation
If T is the only transaction holding a read lock on x at the time it issues the
write_lock (x) operation, the lock can be upgraded ;otherwise, the
transaction must wait.
It is also possible for a transaction T to issue a write_lock(X) and then later
on to downgrade the lock by issuing a read_lock(X) operation
If Ti has a write-lock (X) (*no transaction can have any lock on X*)
Slide 11
Lock Manager:
Manages locks on data items.
Lock table:
Lock manager uses it to store the identify of transaction that
lock the data item
T1 T2 Result
read_lock (Y); read_lock (X); Initial values: X=20; Y=30
read_item (Y); read_item (X); Result of serial execution
unlock (Y); unlock (X); T1 followed by T2
write_lock (X); Write_lock (Y); X=50, Y=80.
read_item (X); read_item (Y); Result of serial execution
X:=X+Y; Y:=X+Y; T2 followed by T1
write_item (X); write_item (Y); X=70, Y=50
unlock (X); unlock (Y);
T1 T2 Result
It can be proved that the transactions can be serialized in the order of their lock
points (i.e. the point where a transaction acquired its final lock).
T’1 T’2
read_lock (Y); read_lock (X); T’1 and T’2 follow two-phase
read_item (Y); read_item (X); policy but they are subject to
write_lock (X); Write_lock (Y); deadlock
unlock (Y); unlock (X);
read_item (X); read_item (Y);
X:=X+Y; Y:=X+Y;
write_item (X); write_item (Y);
unlock (X); unlock (Y);
T1 T2
read_lock (Y);
read_item (Y);
unlock (y)
read_lock (X);
read_item (X);
unlock (X)
write_lock (X);
write_lock (Y);
Deadlock prevention
1. A transaction locks all the needed data items before it begins execution
If any of the items cannot be obtained, none of the items are locked.
Rather the transaction tries again to lock all the items it needs
Two schemes that prevent dead lock based on time stamp includes wait –die and
wound-wait
Suppose that transaction Ti tries to lock an item X but is not able to do so because X
is locked by some other transaction Tj with a conflicting lock. The rules followed by
these two schemes are as follows:
Wait – die: If TS(Ti) < TS(Tj) i.e Ti is older than Tj, then Ti is allowed to wait ;
other wise, abort Ti (Ti dies) and restart it later with the same time stamp
Wound - wait: If TS(Ti) < TS(Tj), abort Tj (Ti wounds Tj) and restart it later with
the same timestamp; other wise Ti is allowed to wait.
If Tj is not blocked (not waiting for some other locked item), then Ti is
DBMS/ Concurrency
blocked and allowed Control Techniques
to wait; otherwise abort Ti Slide 22
Deadlock and Starvation (cont…)
Starvation
Timestamp (TS)
Time stamp ordering algorithm associates two time stamp values (TS) with each
database item X
1. Read_TS(x) : the read time stamp of x: This is the largest timestamp among all the
timestamps of transactions that have successfully read item x
This approach maintains a number of versions of a data item and allocates the
right version to a read operation of a transaction.
Side effect:
Assume X1, X2, …, Xn are the version of a data item X created by a write
operation of transactions.
write_TS(Xi): The write timestamp of Xi that wrote the value of version Xi.
In this technique, serializability is checked only at the time of commit and transactions
are aborted in case of non-serializable schedules
No checking is done while transaction is executing
In this scheme, updates in the transaction are not applied directly to the database item
until it reaches its commit point
Three phases:
1. Read phase
2. Validation phase
3. Write phase
1. Read phase:
A transaction can read values of committed data items. However, updates are
applied only to local copies (versions) of the data items (in database cache)
Thank you!