1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.

Slides:



Advertisements
Similar presentations
Database Systems (資料庫系統)
Advertisements

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.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
4/16/20151 PSU’s CS Concurrency Control and Recovery (only for DBs with updates…..!)- Review  Concurrency Control  Transaction  ACID  Isolation.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Concurrency Control Part 2 R&G - Chapter 17 The sequel was far better than the original! -- Nobody.
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.
1 Concurrency Control. 2 Locking: A Technique for C. C. Concurrency control usually done via locking. Lock info maintained by a “lock manager”: –Stores.
Concurrency Control II R &G - Chapter 17 Lecture 20 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue.
1 Concurrency Control and Recovery Module 6, Lecture 1.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17.
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 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 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.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Concurrency Control, II (R&G ch. 17)
MULTIUSER DATABASES : Concurrency and Transaction Management.
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.
CPSC 461. Outline I. Transactions II. Concurrency control Conflict Serializable Schedules Two – Phase protocol Lock Management Deadlocks detection and.
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 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.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#21: Concurrency Control (R&G ch. 17)
 Concurrent execution of user programs is essential for good DBMS performance. Disk accesses are frequent, and relatively slow. Want to keep the CPU working.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Instructor: Xintao Wu.
Transaction Management: Concurrency Control CS634 Class 18, Apr 9, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
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.
SIMPLE CONCURRENCY CONTROL. Correctness criteria: The ACID properties A A tomicity: All actions in the Xact happen, or none happen. C C onsistency: If.
MULTIUSER DATABASES : Concurrency and Transaction Management.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Database Systems (資料庫系統)
Transaction Management Overview
Concurrency Control More !
Concurrency Control Chapter 17 Modified by Donghui Zhang
Transaction Management Overview
Transaction Management
MULTIUSER DATABASES : Concurrency and Transaction Management
Transaction Management Overview
Anthony D. Joseph and Ion Stoica
Transaction Management
Transaction Management Overview
Lecture#21: Concurrency Control – Part 1
Concurrency Control Chapter 17
Lecture 21: Concurrency & Locking
Concurrency Control Chapter 17
Lecture 22: Intro to Transactions & Logging IV
Concurrency Control R&G - Chapter 17
Transaction Management
Transaction Management Overview
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Transaction Management Overview
Presentation transcript:

1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19

2 Review DBMSs support concurrency, crash recovery with: –ACID Transactions –Log of operations A serial execution of transactions is safe but slow –Try to find schedules equivalent to serial execution One solution for serializable schedules is 2PL

3 Conflict Serializable Schedules Two schedules are conflict equivalent if: – Involve the same actions of the same transactions – Every pair of conflicting actions is ordered the same way Schedule S is conflict serializable if S is conflict equivalent to some serial schedule

4 Example Consider two transactions ( Xacts ): T1:BEGIN A=A+100, B=B-100 END T2:BEGIN A=1.06*A, B=1.06*B END Intuitively, first transaction transfers $100 from B’s account to A’s second credits both accounts with a 6% interest payment. There is no guarantee that T1 will execute before T2 or vice- versa, if both are submitted together. However, the net effect must be equivalent to these two transactions running serially in some order.

5 Example (Contd.) Consider a possible interleaving ( schedule ): T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B This is OK. But what about: T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B The DBMS’s view of the second schedule: T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B)

6 Example A schedule that is not conflict serializable: The cycle in the graph reveals the problem. The output of T1 depends on T2, and vice- versa. T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1T2 A B Dependency graph

7 Dependency Graph Dependency graph : One node per Xact; edge from Ti to Tj if Tj reads/writes an object last written by Ti. (or Ti reads an object which is later on written by Tj) Theorem: Schedule is conflict serializable if and only if its dependency graph is acyclic

8 Review: Strict 2PL Strict Two-phase Locking (Strict 2PL) Protocol : – Each Xact must obtain a S ( shared ) lock on object before reading, and an X ( exclusive ) lock on object before writing. – All locks held by a transaction are released when the transaction completes – If an Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object. (Strict) 2PL allows only schedules whose precedence graph is acyclic

9 Two-Phase Locking (2PL) Two-Phase Locking Protocol – Each Xact must obtain a S ( shared ) lock on object before reading, and an X ( exclusive ) lock on object before writing. – A transaction can not request additional locks once it releases any locks. – If an Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object.

10 View Serializability Schedules S1 and S2 are view equivalent if: – If Ti reads initial value of A in S1, then Ti also reads initial value of A in S2 – If Ti reads value of A written by Tj in S1, then Ti also reads value of A written by Tj in S2 – If Ti writes final value of A in S1, then Ti also writes final value of A in S2 T1: R(A) W(A) T2: W(A) T3: W(A) T1: R(A),W(A) T2: W(A) T3: W(A)

11 Lock Management Lock and unlock requests are handled by the lock manager Lock table entry: – Number of transactions currently holding a lock – Type of lock held (shared or exclusive) – Pointer to queue of lock requests Locking and unlocking have to be atomic operations Lock upgrade: transaction that holds a shared lock can be upgraded to hold an exclusive lock

12 Deadlocks Deadlock: Cycle of transactions waiting for locks to be released by each other. Two ways of dealing with deadlocks: – Deadlock prevention – Deadlock detection

13 Deadlock Prevention Assign priorities based on timestamps. Assume Ti wants a lock that Tj holds. Two policies are possible: – Wait-Die: It Ti has higher priority, Ti waits for Tj; otherwise Ti aborts – Wound-wait: If Ti has higher priority, Tj aborts; otherwise Ti waits If a transaction re-starts, make sure it has its original timestamp

14 Deadlock Detection Create a waits-for graph: – Nodes are transactions – There is an edge from Ti to Tj if Ti is waiting for Tj to release a lock Periodically check for cycles in the waits-for graph

15 Deadlock Detection (Continued) Example: T1: S(A), R(A), S(B) T2: X(B),W(B) X(C) T3: S(C), R(C) X(A) T4: X(B) T1T2 T4T3 T1T2 T4T3

16 Multiple-Granularity Locks Hard to decide what granularity to lock (tuples vs. pages vs. tables). Shouldn’t have to decide! Data “containers” are nested: Tuples Tables Pages Database contains

17 Solution: New Lock Modes, Protocol Allow Xacts to lock at each level, but with a special protocol using new “intention” locks: Before locking an item, Xact must set “intention locks” on all its ancestors. For unlock, go from specific to general (i.e., bottom-up). SIX mode: Like S & IX at the same time. IS IX SIX IS IX SIX      SX  S X  

18 Multiple Granularity Lock Protocol Each Xact starts from the root of the hierarchy. or IX To get S or IS lock on a node, must hold IS or IX on parent node. –What if Xact holds SIX on parent? S on parent? To get X or IX or SIX on a node, must hold IX or SIX on parent node. Must release locks in bottom-up order. Protocol is correct in that it is equivalent to directly setting locks at the leaf levels of the hierarchy.

19 Examples T1 scans R, and updates a few tuples: –T1 gets an SIX lock on R, then get X lock on tuples that are updated. –T2 uses an index to read only part of R: –T2 gets an IS lock on R, and repeatedly gets an S lock on tuples of R. T3 reads all of R: –T3 gets an S lock on R. –OR, T3 could behave like T2; can use lock escalation to decide which.