l ocking s ystems with s everal l ock m odes -parnika achrekar

11
LOCKING SYSTEMS WITH SEVERAL LOCK MODES -PARNIKA ACHREKAR

Upload: godfrey-stevenson

Post on 24-Dec-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

LOCKING SYSTEMS WITH SEVERAL LOCK MODES

-PARNIKA ACHREKAR

Page 2: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

INDEX

18.1 Shared and exclusive locks18.2 Compatibility matrices18.3 Upgrading/updating locks18.4 Incrementing locks

Page 3: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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.

Page 4: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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.

Page 5: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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

Page 6: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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.

Page 7: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

UPGRADING LOCKS (CONT.)

Indiscriminating use of upgrading produces a deadlock.

Example : Both the transactions want to upgrade on the same element

Page 8: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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

Page 9: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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

Page 10: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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.

Page 11: L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR

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