Presentation is loading. Please wait.

Presentation is loading. Please wait.

Locking Systems with Several Lock Modes

Similar presentations


Presentation on theme: "Locking Systems with Several Lock Modes"— Presentation transcript:

1 Locking Systems with Several Lock Modes
Annapurna Annadatha

2 Why Several Lock Modes ? Lock on database element only to READ and NOT write. Several Transactions could not READ at same time.

3 Several Lock Modes Shared and Exclusive Lock Upgrading Lock
Update Lock Increment Lock

4 Several Lock Modes Shared and Exclusive Lock Upgrading Lock
Update Lock Increment Lock

5 Shared and Exclusive Lock
WRITE database element X requires an EXCLUSIVE Lock on X. READ database element X requires either an EXCLUSIVE or SHARED Lock on X(preferably shared). There could be any number of Shared Locks on X but one or no Exclusive Locks on X.

6 Requirements Consistency of Transaction :
- A Transaction may not Write without holding an Exclusive lock. - A Transaction may not Read without holding any lock. - All locks need to be followed by unlock of same element. Two-Phase Locking of Transaction: - Locking must Precede Unlocking. Legality for Schedules : - An element may be locked exclusively by one transaction or by several transactions in shared mode but not both.

7 Scheduling using Shared and Exclusive Locks …
T1 : sl1(A); r1(A); xl1(B); r1(B); w1(B); u1(A); u1(B); T2 : sl2(A); r2(A); sl2(B); r2(B); u2(A); u2(B);

8 Compatibility Matrices
Describes Lock management policies Rows corresponds to Lock held on an element by another Transaction. Column corresponds to mode of lock requested. Lock Requested Lock Held in Mode S X yes no

9 Several Lock Modes Shared and Exclusive Lock Upgrading Lock
Update Lock Increment Lock

10 Upgrading Locks Suppose Transaction wants to read as well as write :
First acquires shared lock on the element Perform read action on the element When ready to write, granted an exclusive lock. Transactions with unpredicted read write locks could use Upgrading Locks.

11 Indiscriminating use of Upgrading locks could cause deadlocks.
Deadlock Scenario Indiscriminating use of Upgrading locks could cause deadlocks. Example: Both the transactions waiting for upgrade.

12 Several Lock Modes Shared and Exclusive Lock Upgrading Lock
Update Lock Increment Lock

13 Update Locks Solves the Deadlock in Upgrade mode
Transaction in an Update mode can read but not write Update mode can late be converted to Exclusive lock Update lock can only be given if the element has shared locks Therefore the transaction first gets a shared lock and when it wants to write upgrades to an Upgrade lock.

14 Compatibility Matrices
An Update lock is like a shared lock when you are requesting it and is like an exclusive lock when you have it. Lock Requested Lock Held in Mode S X U yes no

15 Scheduling using Update Lock …
T1 : ul1(A); r1(A); xl1(A); w1(A); u1(A); T2 : ul2(A); r2(A); xl2(B); w2(B); u2(A);

16 Several Lock Modes Shared and Exclusive Lock Upgrading Lock
Update Lock Increment Lock

17 Increment Locks Used for only Incrementing & decrementing stored values. Mainly used in banking transactions. Ex: Transfer money from one bank to another, Ticket selling transactions in which number of seats are decremented after each transaction.

18 Compatibility Matrices
Any number of transactions can hold increment lock on an element. Shared and exclusive locks cannot be granted if an increment lock is granted on the element. Lock Requested Lock Held in Mode S X I yes no

19 Scheduling using Increment Locks …
T1 : sl1(A); r1(A); il1(B); inc1(B); u1(A); u1(B); T2 : sl2(A); r2(A); il2(B); inc2(B); u2(A); u2(B);

20 Thank You!


Download ppt "Locking Systems with Several Lock Modes"

Similar presentations


Ads by Google