Locks and Locking Mode ( )

Slides:



Advertisements
Similar presentations
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Chapter 16 : Concurrency.
Advertisements

Database Systems (資料庫系統)
Concurrency II. Shared/Exclusive Locks Problem: while simple locks + 2PL guarantee conflict­serializability, they do not allow two readers of DB element.
1 Concurrency Control Conflict serializability Two phase locking Optimistic concurrency control Source: slides by Hector Garcia-Molina.
Concurrency Control II
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 2: Enforcing Serializable Schedules Professor Chen Li.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control: Locking-based Protocols Professor Elke A. Rundensteiner.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.
Enforcing Serializability By LOCKS
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
Concurrency Control A.Sri Harsha Enforcing Serializability of Locks.
Concurrency Control R &G - Chapter 19 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book.
Concurrency Control By Donavon Norwood Ankit Patel Aniket Mulye 1.
1 Concurrency Control: 18.4 Locking Systems with Several Lock Modes CS257 Spring/2009 Professor: Tsau Lin Student: Suntorn Sae-Eung ID: 212.
Concurrency. Busy, busy, busy... In production environments, it is unlikely that we can limit our system to just one user at a time. – Consequently, it.
Concurrency Control: 18.4 Locking Systems with Several Lock Modes CS257 Spring/2009 Professor: Tsau Lin Student: Suntorn Sae-Eung ID:
Concurrency. Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
Chapter 18 Concurrency control Section 18.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID
Transactions Controlling Concurrent Behavior. Why Transactions? Database systems are normally being accessed by many users or processes at the same time.
L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR.
Chapter 181 Chapter 18: Concurrency Control (Slides by Hector Garcia-Molina,
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Concurrency control In production environments, it is unlikely that we can limit our system to just one user at a time. – Consequently, it is possible.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Transaction Management and Recovery, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
1 Concurrency Control By Ankit Patel. 2 INTRODUCTION Enforcing serializability by locks Locks Locking scheduler Two phase locking Locking systems with.
Transaction Management
Database Systems (資料庫系統)
Transaction Management Overview
CS216: Data-Intensive Computing Systems
Database Systems (資料庫系統)
CS 257: Principles of Database System
Transaction Management
Enforcing Serializability by Locks
Transaction Management Overview
Cse 344 March 25th – Isolation.
March 21st – Transactions
Locking Systems with Several Lock Modes
By Donavon Norwood Ankit Patel 112 Aniket Mulye 111
18.5 An Architecture for Locking Scheduler
Transaction Management
Transaction Management Overview
March 9th – Transactions
Lecture 21: Concurrency & Locking
Yan Huang - CSCI5330 Database Implementation – Concurrency Control
CS162 Operating Systems and Systems Programming Review (II)
6.830 Lecture 12 Transactions: Isolation
ENFORCING SERIALIZABILITY BY LOCKS
Atomic Commit and Concurrency Control
Lecture 21: Intro to Transactions & Logging III
Lecture 22: Intro to Transactions & Logging IV
CPSC-608 Database Systems
Transaction Management
Temple University – CIS Dept. CIS661 – Principles of Data Management
CPSC-608 Database Systems
Transaction Management Overview
Locks.
Database Systems (資料庫系統)
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Transaction Management Overview
Presentation transcript:

Locks and Locking Mode (18.3-18.4) CS257 Spring/2009 Professor Tsau Lin Student: Suntorn Sae-Eung

Review 18.1 and 18.2 Concurrency Control Schedules Serial Schedules Serializable Schedules Transaction Sematics Notation Conflict-Serializability Precedence Graphs and a Test for Conflict-Serializability

18.3 Enforcing Serializability by Locks “Locks”-the most common scheduler Protects unserializable behavior Prevents other transactions access database elements at the same time

requests from transactions 18.3.1 Locks Scheduler uses a lock table. Request locks to DB elements Perform Operation: R/W Release the locks lock table Schedule requests from transactions

Locks (cont.) Desired results of lock usage Consistency of Transactions: Actions and locks must relate in the expected ways: A transaction can R/W an element if it was previously granted a lock on the element and has not yet released the lock. If a transaction locks an element, it must later unlock that element. Legality of Schedules: Locks must have their intended meaning

Consistency Condition Locks (cont.) Notation extension li (X) : Transaction Ti requests a lock on element X ui (X) : Transaction Ti releases its lock on element X ri (X) : Ti reads on X wi (X) : Ti writes on X Consistency Condition li (X) ri (X)/wi (X) ui (X)

18.3.2 The Locking Scheduler Jobs base on lock requests If a request is not granted, the transaction is delayed. “Lock table” tells scheduler--every database element currently holds a lock on that element.

The Locking Scheduler (cont.) T1: l1 (A); r1(A); A:=A+100; w1(A); l1 (B); u1(A); r1(B); B:=B+100; w1(B); u1(B); T2: l2 (A); r2(A); A:=A*2; w2(A); l2 (B); u2(A); r2(B); B:=B*2; w2(B); u2(B);

18.3.3 Two-Phrase Locking (2PL) Guarantees a legal schedule is conflict serializable: Any transactions, all lock actions precede all unlock actions. A transaction obeys 2PL condition is a “two-phrase-locked transaction” or 2PL transaction.

18.3.4 Why 2PL Works Proved by an induction of n transactions in schedule S First, consider only actions without locks Claim that Ti can move to beginning of S without conflicting reads/write to another transactions Restore locks and obviously, Ti is not 2PL, as assumed The conclusion It is possible to move a non-conflicting transaction (Ti), to the beginning of S follow by tails. Therefore, schedule S is conflict-serializable.

A Risk of Deadlock

18.4 Locking System with Several Lock Modes In 18.3, a transaction must lock a database element (X) either reads or writes. No reason why several transactions could not read X at the same time, as long as none write X. Introduce Shared lock– for reading Exclusive lock– for writing

18.4.1 Shared and Exclusive Locks Consider lock for writing is “stronger” than for reading. Notation: sli (X)– Ti requests shared lock on DB element X xli (X)– Ti requests exclusive lock on DB element X ui (X)– Ti relinguishes whatever lock on X Example 

Shared and Exclusive Locks (cont.)

18.4.2 Compatibility Matrices A convenient way to describe lock-management policies Lock requested S X Lock held S Yes No in mode X No No

18.4.3 Upgrading Locks A transaction (T) taking a shared lock is friendly toward other transaction. T wants to read and write a new value X At first, take a shared lock on X T performs operations on X (may spend long time) When T is ready to write a new value, “Upgrade” lock to exclusive lock on X.

Upgrading Locks (cont.) Observe the example T1 cannot take an exclusive lock on B until all locks on B are released.

Upgrading Locks (cont.) The worse case, which upgrading can simply cause a “Deadlock”

18.4.Update Locks The third lock mode preventing the deadlock problem on upgrading lock. Only the “Update lock” can be upgraded to a write lock later; a read lock cannot do. An update lock can be granted on X when there are already shared locks on X, Once there is an update lock, it prevents additional any kinds of lock. Notation: uli (X)

Update Locks (cont.) Compatibility matrix (asymmetric) S X U Lock requested S X U Lock held S Yes No Yes in mode X No No No U No No No

Update Locks (cont.) Example

18.4.5 Increment Locks A kind of lock which is useful for increasing/decreasing transactions. e.g. money transfer between bank accounts. If 2 transactions add constants to the same database element It doesn’t matter which goes first, but no reads are allowed in between transaction processing Let see on following exhibits

Increment Locks (cont.) CASE 1 A=7 T1: INC (A,2) T2: INC (A,10) A=5 A=17 T2: INC (A,10) A=15 T1: INC (A,2) CASE 2

Increment Locks (cont.) What if A=7 T2: INC (A,10) T1: INC (A,2) A=5 A=15 A=15 T2: INC (A,10) A != 17 T1: INC (A,2) A=5 A=7

Increment Locks (cont.) INC (A, c): is increment action of write constant ‘c’ to database element A stands for an atomic execution of READ(A,t); t=t+c; WRITE(A,t); Notation: ili (X)– action of Ti requesting an increment lock on X inci (X)– action of Ti increments X by some constant; don’t care about the value of the constant.

Increment Locks (cont.) Compatibility matrix Lock requested S X I Lock held S Yes No No in mode X No No No I No No Yes

Increment Locks (cont.) Example

Question & Answers

For your attention

Reference [1] H. Garcia-Molina, J. Ullman, and J. Widom, “Database System: The Complete Book,” second edition: p.897-913, Prentice Hall, New Jersy, 2008