Concurrency II. Shared/Exclusive Locks Problem: while simple locks + 2PL guarantee conflict­serializability, they do not allow two readers of DB element.

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

CM20145 Concurrency Control
1 Shivnath Babu Concurrency Control (II) CS216: Data-Intensive Computing Systems.
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
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.
Concurrency Control Enforcing Serializability by Locks
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control: Locking-based Protocols Professor Elke A. Rundensteiner.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 4: More on Locks Professor Chen Li.
1 CS216 Advanced Database Systems Shivnath Babu Notes 12: Concurrency Control (II)
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Quick Review of Apr 29 material
Distributed Locking. Distributed Locking (No Replication) Assumptions Lock tables are managed by individual sites. The component of a transaction at a.
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
Concurrency Control A.Sri Harsha Enforcing Serializability of Locks.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Transactions Controlling Concurrent Behavior. Busy, busy, busy... In production environments, it is unlikely that we can limit our system to just one.
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:
Transactions or Concurrency Control. Introduction A program which operates on a DB performs 2 kinds of operations: –Access to the Database (Read/Write)
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
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control John Ortiz.
Transactions Controlling Concurrent Behavior. Why Transactions? Database systems are normally being accessed by many users or processes at the same time.
Chapter 18.5 An Architecture For A Locking Scheduler Steve Ikeoka ID: 113 CS 257 – Spring 2008.
Academic Year 2014 Spring Academic Year 2014 Spring.
L OCKING S YSTEMS WITH S EVERAL L OCK M ODES -PARNIKA ACHREKAR.
Chapter 181 Chapter 18: Concurrency Control (Slides by Hector Garcia-Molina,
Introduction to Data Management CSE 344 Lecture 23: Transactions CSE Winter
V. Megalooikonomou Concurrency control (based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and Sudarshan) Temple University – CIS.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Concurrency control.
Chapter 11 Concurrency Control. Lock-Based Protocols  A lock is a mechanism to control concurrent access to a data item  Data items can be locked in.
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.
SCUJoAnne Holliday11–1 Schedule Today: u Transaction concepts. u Read Sections Next u Authorization and security.
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
Assignment 3 -- Solution 1. Problem 1 H 1 : r 1 [y] r 1 [x] r 2 [x] w 1 [y] c 1 w 2 [y] c 2 H 1 is normally-strict two-phase locked: rl 1 [y] r 1 [y]
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
CONCURRENCY CONTROL Spring Warning This is a first draft I welcome your corrections.
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
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.
11th International Conference on Web-Age Information Management July 15-17, 2010 Jiuzhaigou, China V Locking Protocol for Materialized Aggregate Join Views.
Chapter 91 Chapter 9. Concurrency Control Fall 2001 Prof. Sang Ho Lee School of Computing, Soongsil Univ.
Lecture 3 Concurrency control techniques
Concurrency Control Techniques
Concurrency Control.
CS 257: Principles of Database System
Enforcing Serializability by Locks
Locking Systems with Several Lock Modes
By Donavon Norwood Ankit Patel 112 Aniket Mulye 111
Locks and Locking Mode ( )
Concurrency Control WXES 2103 Database.
Chapter 15 : Concurrency Control
ENFORCING SERIALIZABILITY BY LOCKS
CPSC-608 Database Systems
SQL – Shared and Exclusive Locks
Temple University – CIS Dept. CIS661 – Principles of Data Management
Database Management System
Lecture 18: Concurrency Control
Prepared by: Mudra Patel (113) Pradhyuman Raol(114)
Presentation transcript:

Concurrency II

Shared/Exclusive Locks Problem: while simple locks + 2PL guarantee conflict­serializability, they do not allow two readers of DB element X at the same time. But having multiple readers is not a problem for conflict­ serializability (since read actions commute).

Shared/Exclusive Locks (Cont’d) Solution: Two kinds of locks: 1. Shared lock sl i (X) allows T i to read, but not write X. – It prevents other transactions from writing X but not from reading X. 2. Exclusive lock xl i (X) allows T i to read and/or write X; no other transaction may read or write X.

Consistency of transaction conditions: – A read r i (X) must be preceded by sl i (X) or xl i (X), with no intervening u i (X). – A write w i (X) must be preceded by xl i (X), with no intervening u i (X). Legal schedules: – No two exclusive locks. If xl i (X) appears in a schedule, then there cannot be a xl j (X) until after a u i (X) appears. – No exclusive and shared locks. If xl i (X) appears, there can be no sl j (X) until after u i (X). If sl i (X) appears, there can be no wl j (X) until after u i (X). 2PL condition: – No transaction may have a sl(X) or xl(X) after a u(Y).

Scheduler Rules When there is more than one kind of lock, the scheduler needs a rule that says “if there is already a lock of type A on DB element X, can I grant a lock of type B on X?” The compatibility matrix answers the question. Compatibility Matrix for Shared/Exclusive Locks is:

Exercise r1(A); r2(B); r3(C); r1(B); r2(C); r3(D); w1(A); w2(B); w3(C); T1T2T3 xl(A); r1(A) xl(B); r2(B) xl(C); r3(C) sl(B) denied sl(C) denied sl(D); r3(D); ul(D) w1(A); w2(B); sl(B); r1(B); ul(A); ul(B) w3(C); ul(C) sl(C); r2(C); ul(B); ul(C)

Upgrading Locks Instead of taking an exclusive lock immediately, a transaction can take a shared lock on X, read X, and then upgrade the lock to exclusive so that it can write X. Upgrading Locks allows more concurrent operation: Had T1 asked for an exclusive lock on B before reading B, the request would have been denied, because T2 already has a shared lock on B.

Possibility for Deadlocks Problem: when we allow upgrades, it is easy to get into a deadlock situation. Example:T1 and T2 each reads X and later writes X.

Exercise r1(A); r2(B); r3(C); r1(B); r2(C); r3(D); w1(A); w2(B); w3(C); T1T2T3 sl(A); r1(A) sl(B); r2(B) sl(C); r3(C) sl(B); r1(B) sl(C); r2(C) sl(D); r3(D) xl(A); w1(A); ul(A) xl(B); w2(B); ul(B) xl(C);w3(C); ul(C)

Solution: Update Locks Update lock ul i (X). – Only an update lock (not shared lock) can be upgraded to exclusive lock (if there are no shared locks anymore). – A transaction that will read and later on write some element A, asks initially for an update lock on A, and then asks for an exclusive lock on A. Such transaction doesn’t ask for a shared lock on A. Legal schedules: – read action permitted when there is either a shared or update lock. – An update lock can be granted while there is a shared lock, but the scheduler will not grant a shared lock when there is an update lock. 2PL condition: No transaction may have an sl(X), ul(X) or xl(X) after a u(Y).

Example T1T2T3 sl(A); r(A) ul(A); r(A) sl(A) Denied xl(A) Denied u(A) xl(A); w(A) u(A) sl(A); r(A) u(A)

(No) Deadlock Example T 1 and T 2 each read X and later write X. Deadlock when using sl and xl locks only. Fine when using update locks.

Exercise r1(A); r2(B); r3(C); r1(B); r2(C); r3(D); w1(A); w2(B); w3(C); T1T2T3 ul(A); r1(A) ul(B); r2(B) ul(C); r3(C) sl(B) denied sl(C) denied sl(D); r3(D); xl(A); w1(A); xl(B); w2(B); sl(B); r1(B); ul(A); ul(B) xl(C); w3(C); ul(D); ul(C) sl(C); r2(C); ul(B); ul(C)