l ocking s ystems with s everal l ock m odes -parnika achrekar
TRANSCRIPT
LOCKING SYSTEMS WITH SEVERAL LOCK MODES
-PARNIKA ACHREKAR
INDEX
18.1 Shared and exclusive locks18.2 Compatibility matrices18.3 Upgrading/updating locks18.4 Incrementing locks
SHARED & EXCLUSIVE LOCKS
Consistency of TransactionsCannot write without Exclusive LockCannot 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 principlesA read action can only proceed a shared or
an exclusive lockA write lock can only proceed a exclusive
lock All locks need to be followed by unlock of the
same element.
SHARED AND EXCLUSIVE LOCKS (CONT.)
Two-phase locking of transactionsMust precede unlocking
Legality of SchedulesAn element may be locked exclusively by
one transaction or by several in shared mode, but not both.
COMPATIBILITY MATRICES
Has a row and column for each lock mode.Rows correspond to a lock held on an
element by another transactionColumns correspond to mode of lock
requested.Example :
LOCK REQUESTEDS X
LOCK S YES NO
HOLD X NO NO
UPGRADING LOCKS
Suppose a transaction wants to read as well as write : It acquires a shared lock on the elementPerforms the calculations on the elementAnd when its ready to write, It is granted a
exclusive lock. Transactions with unpredicted read write
locks can use UPGRADING LOCKS.
UPGRADING LOCKS (CONT.)
Indiscriminating use of upgrading produces a deadlock.
Example : Both the transactions want to upgrade on the same element
UPDATE 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
UPDATE 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 :S X U
S YES NO YES
X NO NO NO
U NO NO NO
INCREMENT LOCKS
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.
INCREMENT 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
S X I
S YES NO NO
X NO NO NO
I NO NO YES