Beruflich Dokumente
Kultur Dokumente
CONCURRENCY CONTROL
Slide 25- 2
Slide 25- 3
Distributed commit:
Distributed deadlock:
Locking
Locking is pessimistic because it assumes that conflicts will
happen.
The concept of locking data items is one of the main techniques
used for controlling the concurrent execution of transactions.
A lock is a variable associated with a data item in the database.
Generally there is a lock for each data item in the database.
A lock describes the status of the data item with respect to
possible operations that can be applied to that item. It is used for
synchronising the access by concurrent transactions to the database
items.
A transaction locks an object before using it
When an object is locked by another transaction, the
requesting transaction must wait
Lock-Based Protocols
data item
Data items can be locked in two modes :
1. exclusive (X) mode. Data item can be both read as
well as written. X-lock is requested using lock-X
instruction.
2. shared (S) mode. Data item can only be read. S-lock
is requested using lock-S instruction.
Lock requests are made to concurrency-control
T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)
Locking as above is not sufficient to guarantee serializability
if A and B get updated in-between the read of A and B, the displayed sum would be
wrong.
A locking protocol is a set of rules followed by all transactions while requesting
and releasing locks.
Locking protocols restrict the set of possible schedules.
deadlocks
Cascading roll-back is possible under two-phase locking.
Lock Conversions
Two-phase locking with lock conversions:
First Phase:
can acquire a lock-S on item
can acquire a lock-X on item
can convert a lock-S to a lock-X (upgrade)
Second Phase:
can release a lock-S
can release a lock-X
can convert a lock-X to a lock-S (downgrade)
This protocol assures serializability. But still relies on the
Lock Table
Black rectangles indicate granted
Graph-Based Protocols
Graph-based protocols are an alternative to two-phase
locking
Impose a partial ordering on the set D = {d1, d2 ,...,
dh} of all data items.
Tree Protocol
What is Timestamping?
Scheduler assign each transaction T a
Timestamp TS(T)
Two methods of generating Timestamps.
Use
Timestamp-Based Protocols
Each transaction is issued a timestamp when it enters the
transaction
with larger
timestamp
read(A)
(validate)
display (A+B)
T15
read(B)
B:- B-50
read(A)
A:- A+50
(validate)
write (B)
write (A)
Multiple Granularity
Allow data items to be of various sizes and define a
Thank You