1 Concurrency Control Chapter 17. 2 Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.

Slides:



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

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 II
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.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 19.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
1 Concurrency Control Yanlei Diao UMass Amherst March 27 and 29, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
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.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17.
Concurrency Control II
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 II R &G - Chapter 19 Lecture 22 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue.
Concurrency Control III R &G - Chapter 17 Lecture 24 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue.
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.
Alternative Concurrency Control Methods R&G - Chapter 17.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Modified by Donghui Zhang.
Concurrency Control.
MULTIUSER DATABASES : Concurrency and Transaction Management.
CPSC 461. Outline I. Transactions II. Concurrency control Conflict Serializable Schedules Two – Phase protocol Lock Management Deadlocks detection and.
Concurrency Control R &G - Chapter 19. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses.
 Concurrent execution of user programs is essential for good DBMS performance. Disk accesses are frequent, and relatively slow. Want to keep the CPU working.
1 Concurrency Control II: Locking and Isolation Levels.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Instructor: Xintao Wu.
Introduction to Database Management Systems, Jarek Gryz1 Transaction Management Overview Chapter 16.
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.
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
Chapter 7: Deadlock Course Administration n Midterm exam next week in class l Closed book n Final exam time changed to during class.
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
Database Applications (15-415) DBMS Internals- Part XII Lecture 23, April 12, 2016 Mohammad Hammoud.
SIMPLE CONCURRENCY CONTROL. Correctness criteria: The ACID properties A A tomicity: All actions in the Xact happen, or none happen. C C onsistency: If.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
Database Systems (資料庫系統)
Concurrency Control Techniques
Concurrency Control More !
Concurrency Control Chapter 17 Modified by Donghui Zhang
Transaction Management
Concurrency Control Chapter 17
MULTIUSER DATABASES : Concurrency and Transaction Management
Database Applications (15-415) DBMS Internals- Part XII Lecture 24, April 11, 2018 Mohammad Hammoud.
Transaction Management
Concurrency Control Chapter 17
Lecture 21: Concurrency & Locking
Concurrency Control Chapter 17
Concurrency Control Chapter 17
Lecture 22: Intro to Transactions & Logging IV
Concurrency Control R&G - Chapter 17
Transaction Management
Temple University – CIS Dept. CIS661 – Principles of Data Management
Concurrency Control Chapter 17
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Presentation transcript:

1 Concurrency Control Chapter 17

2 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

3 Conflict serialiable vs. serialiable  Conflict serializable -> serializable  But not vice versa, e.g. T1: R(A) W(A)Commit T2: W(A)commit T3: W(A)Commit  Equivalent to T1 -> T2 -> T3, but not conflict serializable

4 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 precedence graph

5 Precedence Graph  Precedence graph :  One node per Xact;  An arc from Ti to Tj if an action of Ti precedes and conflicts with one of Tj ’s actions  Capturing all conflicts  Theorem: Schedule is conflict serializable if and only if its precedence graph is acyclic

6 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.  If an Xact holds a lock (S or X) on an object, no other Xact can get an X lock on that object.  Strict 2PL allows only schedules whose precedence graph is acyclic

7 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.  If an Xact holds a lock (S or X) on an object, no other Xact can get an X lock on that object.

8 More on 2PL  Relaxation of strict 2PL  A growing phase: acquiring locks  A shrinking phase: releases locks  2PL -> conflict serializable  Why?  An equivalent serial order of transactions is given by the order in which transactions enter their shrinking phase

9 Strict 2PL vs. 2PL  A schedule is said to be strict if a value written by a transaction T is not read or overwritten by other transactions until T either aborts or commits.  Strict schedules are recoverable, ACA  Strict 2PL -> strict + 2PL ACA + conflict serialiable Strict 2PL most popular, 2PL no practical importance Strict 2PL is actually only one phase New terminology: strict 2PL (S2PL) for strictness + 2PL strong strict 2PL (SS2PL) for our strict 2PL An example schedule allowed by S2PL but not SS2PL?

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  S is view serializable if it is view equivalent to some serial schedule T1: R(A) W(A) T2: W(A) T3:R(A) W(A) T1: R(A)W(A) T2: W(A) T3: R(A)W(A)

11 View serializable vs. conflict serializable  Conflict serialiable -> view serialiable  So, more general condition  The reverse is not true T1: R(A) W(A) T2: W(A) T3: W(A) T1: R(A),W(A) T2: W(A) T3: W(A)

12 Classes of schedules: Venn diagram

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

14 Deadlock Prevention  Assign priorities based on timestamps.  The oldest transaction has the highest priority  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

15 Deadlock Prevention (cont’d)  In wait-die, lower priority transactions never wait for higher priority ones  In wound-wait, higher priority transactions never wait for lower priority ones  Either case, no deadlock cycle  In both schemes, higher priority transaction is never aborted  If a transaction re-starts, make sure it has its original timestamp

16 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

17 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

18 Multiple-Granularity Locking  Hard to decide what granularity to lock (tuples vs. pages vs. tables).  Locking overhead  Data “containers” are nested: Tuples Tables Pages Database contains

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

20 Multiple Granularity Lock Protocol  Each Xact starts from the root of the hierarchy.  To get S or X lock on a node, must hold IS or IX on parent node.  To get IX or SIX on a node, must hold IX or SIX on parent node.  Must release locks in bottom-up order.

21 Examples  T1 scans R, and updates a few tuples:  T1 gets an SIX lock on R, then repeatedly gets an S lock on tuples of R, and occasionally upgrades to X on the tuples.  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.  Lock escalation dynamically asks for coarser-grained locks when too many low level locks acquired -- ISIX -- IS IX      SX   S X      

22 Optimistic CC  Locking is a conservative/pessimistic approach in which conflicts are prevented.  Disadvantages:  Lock management overhead.  Deadlock detection/resolution.  Lock contention for heavily used objects.  If conflicts are rare, we might be able to gain concurrency by not locking, and instead checking for conflicts before Xacts commit.

23 Kung-Robinson Model  Xacts have three phases:  READ: Xacts read from the database, but make changes to private copies of objects.  VALIDATE: Check for conflicts. If there’s a possible conflict, abort and restart  WRITE: Make local copies of changes public.  If lots of conflicts, cost of repeatedly restarting transactions hurts performance

24 Validation  Test conditions that are sufficient to ensure that no conflict occurred.  Each Xact is assigned a numeric id.  Just use a timestamp.  To validate Tj, need to check all committed Ti with Ti < Tj  One of the following 3 validation conditions must hold

25 Validating Tj: Test 1  Ti completes before Tj begins. Ti Tj RVW RVW

26 Validating Tj: Test 2  Ti completes before Tj begins its Write phase  Ti does not write any db object read by Tj Ti Tj RVW RVW

27 Validating Tj: Test 3  Ti completes Read phase before Tj does  Ti does not write any db object read by Tj  Ti does not write any db object written by Tj Ti Tj RVW RVW

28 Timestamp CC  Idea: Determine an equivalent serial order of Xacts in advance, e.g., by submission time, called the timestamp order  At execution time, ensure that every pair of conflicting actions follows the timestamp ordering.  If this is violated by the next action from Xact T, T is aborted and restarted with a new, larger timestamp.  If restarted with same TS, T will fail again! Contrast use of timestamps in 2PL for ddlk prevention

29 Timestamp CC  TS(T): the timestamp assigned to Xact T when starts (enters the system)  RTS(O): the read timestamp for object O, set to the largest time-stamp of any transaction that has executed read(O) successfully.  WTS(O): the write timestamp for object O, set to the largest time-stamp of any transaction that has executed write(O) successfully.

30 When Xact T wants to read Object O  If TS(T) < WTS(O)  read(O) of T comes too late, someone with larger TS already wrote O  this is a WR conflict violating the predefined timestamp order  So, abort T and restart it with a new, larger TS  If TS(T) > WTS(O):  Allow T to read O.  Reset RTS(O) to max(RTS(O), TS(T))

31 When Xact T wants to Write Object O  If TS(T) < RTS(O)  write(O) of T comes too late, someone with larger TS already read O  this is a RW conflict violating the predefined timestamp order  abort and restart T.  If TS(T) < WTS(O)  write(O) of T comes too late, someone with larger TS already write O  this is a WW conflict violating the predefined timestamp order  Naïve approach: abort T  However, write(O) of T should be overwritten anyway, so …  Thomas Write Rule: We can safely ignore such outdated writes; need not restart T!  Else, allow T to write O and set WTS(O) to TS(T)  why not max(WTS(O), TS(T))?

32 Thomas write rule (watch out text)  Naïve: allows only conflict serializable schedules  Thomas write rule: some schedules are allowed, which are seriliable but not conflict serializable  The Thomas Write Rule relies on the fact that T1's write on object A is never seen by any transaction  T1’s write is ignored T1 T2 R(A) W(A) Commit W(A) Commit T1 T2 R(A) W(A) Commit W(A) Commit

33 Timestamp CC and Recoverability  Unfortunately, unrecoverable schedules are allowed  Timestamp CC can be modified to allow only recoverable schedules T1 T2 W(A) R(A) W(B) Commit

34 Summary  There are several lock-based concurrency control schemes (Strict 2PL, 2PL). Conflicts between transactions can be detected in the dependency graph  The lock manager keeps track of the locks issued. Deadlocks can either be prevented or detected.

35 Summary (Contd.)  Multiple granularity locking reduces the overhead involved in setting locks for nested collections of objects (e.g., a file of pages)  Optimistic CC aims to minimize CC overheads in an ``optimistic’’ environment where reads are common and writes are rare.  Optimistic CC has its own overheads however; most real systems use locking.

36 Summary (Contd.)  Timestamp CC is another alternative to 2PL; allows some serializable schedules that 2PL does not  converse is also true  Ensuring recoverability with Timestamp CC requires ability to block Xacts, which is similar to locking.