9 ConcurrencyControl
9 ConcurrencyControl
Control
Concurrency Control Techniques
• Lock Based Protocols:
• A lock is a mechanism to control concurrent access to a data item
• A Lock is a variable assigned to any data item in order to keep track of the status of that
data item so that isolation and non-interference is ensured during concurrent
transactions.
• Two operations:
• lock_item,
• unlock_item
• Binary lock enforces
mutual exclusion on
the data item:
Indivisible units or
critical section or no
interleaving
• The DBMS has a lock manager subsystem to keep track of and control
access to locks
• A transaction T will not issue a write_lock(X) operation of it already holds a read (shared)
lock or write (exclusive) lock on item X – can be upgraded
• A transaction T will not issue an unlock(X) operation unless it already holds a read lock or a
write lock on item X
28-Apr-25 Dept. Of I&CT 12
• Example of a transaction performing locking:
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
• The conservative 2PL must lock all its items before it starts, so once
the transaction starts it is in its shrinking phase;
• The rigorous 2PL does not unlock any of its items until after it
terminates (by committing or aborting), so the transaction is in its
expanding phase until it ends
• A second protocol, involves ordering all the items in the DB and making sure
that a transaction that needs several items will lock them according to that
order.
• This requires that the programmer (or the system) is aware of the chosen order of items
• The algorithm must ensure that, for each item accessed by the conflicting
operations in the schedule, the order in which the item is accessed does not violate
the timestamp order
• write_TS(X): The write timestamp of item X is the largest of all the timestamps of
transactions that have successfully written item X – i.e., write_TS(X) = TS(X), where
T is the youngest transaction that has written X successfully.
• Validation(Ti ), the time when Ti finished its read phase and started its validation phase.
• The set of data items written by Tk does not intersect with the set of data items read by
Ti, and Tk completes its write phase before Ti starts its validation phase (Start(Ti ) <
Finish(Tk ) < Validation(Ti )).