L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR
INDEX 18.1 Shared and exclusive locks 18.2 Compatibility matrices 18.3 Upgrading/updating locks 18.4 Incrementing locks
S HARED & E XCLUSIVE L OCKS Consistency of Transactions Cannot write without Exclusive Lock Cannot read without holding some lock i.e., it needs to put a lock on the element to read or write This basically works on 2 principles A read action can only proceed a shared or an exclusive lock A write lock can only proceed a exclusive lock All locks need to be followed by unlock of the same element.
S HARED AND EXCLUSIVE LOCKS ( CONT.) Two-phase locking of transactions Must precede unlocking Legality of Schedules An element may be locked exclusively by one transaction or by several in shared mode, but not both.
C OMPATIBILITY M ATRICES Has a row and column for each lock mode. Rows correspond to a lock held on an element by another transaction Columns correspond to mode of lock requested. Example : LOCKREQUESTED SX LOCKSYESNO HOLDXNO
U PGRADING L OCKS Suppose a transaction wants to read as well as write : It acquires a shared lock on the element Performs the calculations on the element And when its ready to write, It is granted a exclusive lock. Transactions with unpredicted read write locks can use UPGRADING LOCKS.
U PGRADING LOCKS ( CONT.) Indiscriminating use of upgrading produces a deadlock. Example : Both the transactions want to upgrade on the same element
U PDATE LOCKS Solves the deadlock occurring in upgrade lock method. A transaction in an update lock can read but cant write. Update lock can later be converted to exclusive lock. An update lock can only be given if the element has shared locks. Therefore first the transaction gets a shared lock and when it wants to write it upgrades itself to upgrade lock
U PDATE LOCKS ( CONT.) An update lock is like a shared lock when you are requesting it and is like a exclusive lock when you have it. Compatibility matrix : SXU SYESNOYES XNO U
I NCREMENT L OCKS Mainly used in banking transactions Used for incrementing & decrementing stored values. E.g. - Transfer money from one bank to another, Ticket selling transactions in which number seats are decremented after each transaction.
I NCREMENT LOCK ( CONT.) A increment lock does not enable read or write locks on element. Any number of transaction can hold increment lock on element Shared and exclusive locks can not be granted if an increment lock is granted on element SXI SYESNO X I YES