1 Concurrency Control II: Locking and Isolation Levels.

Slides:



Advertisements
Similar presentations
CM20145 Concurrency Control
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Database Systems (資料庫系統)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Transaction Management and Concurrency Control
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.
Introduction to Database Systems1 Concurrency Control CC.Lecture 1.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
Concurrency Control II
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
Concurrency Control Enforcing Serializability by Locks
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Lecture 12 Transactions: Isolation. Transactions What’s hard? – ACID – Concurrency control – Recovery.
Concurrency Control Part 2 R&G - Chapter 17 The sequel was far better than the original! -- Nobody.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. –Because disk accesses are.
Transaction Overview and Concurrency Control Chapters 16 & 17.
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
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 R&G - Chapter 17 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book.
Transaction Management and Concurrency Control
1 Concurrency Control and Recovery Module 6, Lecture 1.
1 Transaction Management Overview Yanlei Diao UMass Amherst March 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Final Exam Review Last Lecture R&G - All Chapters Covered The end crowns all, And that old common arbitrator, Time, Will one day end it. William Shakespeare.
Concurrency Control John Ortiz.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
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.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Modified by Donghui Zhang.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
1 Transaction Management Overview Chapter Transactions  A transaction is the DBMS’s abstract view of a user program: a sequence of reads and writes.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Concurrency Control R &G - Chapter 19. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses.
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.
V. Megalooikonomou Concurrency control (based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and Sudarshan) Temple University – CIS.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Instructor: Xintao Wu.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
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.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
Transaction Management Overview
Concurrency Control More !
Concurrency Control.
Transaction Management
Transaction Management Overview
Transaction Management
Transaction Management Overview
Chapter 15 : Concurrency Control
Transaction Management
Temple University – CIS Dept. CIS661 – Principles of Data Management
Transaction Management Overview
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Transaction Management Overview
Presentation transcript:

1 Concurrency Control II: Locking and Isolation Levels

2 Locking: A Technique for C. C. v Concurrency control usually done via locking. v Lock info maintained by a “lock manager”: –Stores (XID, RID, Mode) triples. u This is a simplistic view; suffices for now. –Mode  {S,X} –Lock compatibility table: v If a Xact can’t get a lock, it is suspended on a wait queue. -- SX S X      LOCK REQUESTED LOCKHELDLOCKHELD

3 Two-Phase Locking (2PL) v 2PL: –If T wants to read an object, first obtains an S lock. –If T wants to modify an object, first obtains X lock. –If T releases any lock, it can acquire no new locks! v Locks are automatically obtained by DBMS. v Guarantees serializability! –Why? Time # of locks lock point growing phase shrinking phase

4 Strict 2PL v Strict 2PL: –If T wants to read an object, first obtains an S lock. –If T wants to modify an object, first obtains X lock. –Hold all locks until end of transaction. v Guarantees serializability, and ACA, too! –Thus ensures recoverability! Time # of locks

5 Precedence Graph v A Precedence (or Serializability) graph: –Node for each committed Xact. –Arc from Ti to Tj if an action of Ti precedes and conflicts with an action of Tj. v T1 transfers $100 from A to B, T2 adds 6% –R 1 (A), W 1 (A), R 2 (A), W 2 (A), R 2 (B), W 2 (B), R 1 (B), W 1 (B) T1 T2

6 Conflict Serializability v 2 schedules are conflict equivalent if: –they have the same lists of actions, and –each pair of conflicting actions is ordered in the same way. v A schedule is conflict serializable if it is conflict equivalent to a serial schedule. –Note: Some serializable schedules are not conflict serializable! –Another Note: Some consistent schedules are not serializable!

7 Conflict Serializability & Graphs v Theorem 1: A schedule is conflict serializable iff its precedence graph is acyclic. v Theorem 2: 2PL ensures that the precedence graph will be acyclic! v Strict 2PL improves on this by avoiding cascading aborts, avoiding problems with “undo” in the presence of WW conflicts, and ensuring recoverable schedules.

8 Dynamic Databases v If we relax the assumption that the DB is a fixed collection of objects, even Strict 2PL will not ensure serializability: –T1 locks all pages containing sailor records with rating = 1, and finds oldest sailor (say, age = 71). –Next, T2 inserts a new sailor; rating = 1, age = 96. –T2 also deletes oldest sailor with rating = 2 (and, say, age = 80), and commits. –T1 now locks all pages containing sailor records with rating = 2, and finds oldest (say, age = 63). v No consistent DB state where T1 is “correct”!

9 The Problem v T1 implicitly assumes that it has locked the set of all sailor records with rating = 1. –Assumption only holds if no sailor records are added while T1 is executing! –The sailor with rating 1, age 96 is a phantom tuple –Need some mechanism to enforce this assumption. (Index locking, predicate locking, or table locking.) v Example shows that conflict serializability guarantees serializability only if the set of objects is fixed!

10 Summary of Concurrency Control v Concurrency control key to a DBMS. –More than just mutexes! v Transactions and the ACID properties: –C & I are handled by concurrency control. –A & D coming soon with logging & recovery. v Conflicts arise when two Xacts access the same object, and one of the Xacts is modifying it. v Serial execution is our model of correctness.

11 Summary, cont. v Serializability allows us to “simulate” serial execution with better performance. v 2PL: A simple mechanism to get serializability. –Strict 2PL also gives us recoverability, ACA v Lock manager module automates 2PL so that only the access methods worry about it. –Lock table is a big main-mem hash table v Deadlocks are possible, and typically a deadlock detector is used to solve the problem.

12 Summary, cont.: SQL-92 support