1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 6: Cascading Rollbacks, Deadlocks, and Long Transactions Professor Chen Li.

Slides:



Advertisements
Similar presentations
1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme.
Advertisements

Database Systems (資料庫系統)
More About Transaction Management Chapter 10. Contents Transactions that Read Uncommitted Data View Serializability Resolving Deadlocks Distributed Databases.
Wait-die Transactions given a timestamp when they arrive …. ts(T i ) T i can only wait for T j if ts(T i )< ts(T j )...else die T 1 (ts =10) T 2 (ts =20)
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
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 2: Enforcing Serializable Schedules Professor Chen Li.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Concurrency Control.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
CS 728 Advanced Database Systems Chapter 21 Introduction to Protocols for Concurrency Control in Databases.
CS4432: Database Systems II Lecture #26 Concurrency Control and Recovery Professor Elke A. Rundensteiner.
1 More Transaction Management Concurrency control and recovery Resolving deadlocks Logical logging Source: slides by Hector Garcia-Molina.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
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.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
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.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
ACS-4902 R. McFadyen 1 Database Concurrency Control Deadlock Deadlock occurs when each transaction in a set is waiting for another transaction in the set.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Cs4432concurrency control1 CS4432: Database Systems II Concurrency Control with Recovery.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control John Ortiz.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
DBMS2001Notes 9: Transaction Processing1 Principles of Database Management Systems 9: More on Transaction Processing Pekka Kilpeläinen (Partially based.
© 1997 UW CSE 11/13/97N-1 Concurrency Control Chapter 18.1, 18.2, 18.5, 18.7.
Concurrency Control.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
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.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Concurrency Control Techniques Chapter 18
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
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.
Lecture 8- Concurrency Control Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
Timestamp-based Concurrency Control
Concurrency Control The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4th edition,
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:
DBMS Deadlock.
CS 245: Database System Principles Notes 10: More TP
CS 245: Database System Principles Notes 10: More TP
Lecture 3 Concurrency control techniques
Concurrency Control.
Part- A Transaction Management
Transaction Management
Transaction Management
Concurrency Control Chapter 17
CS 245: Database System Principles Notes 10: More TP
Lecture 21: Concurrency & Locking
Basic Two Phase Locking Protocol
Chapter 15 : Concurrency Control
Concurrency Control Chapter 17
Lecture 22: Intro to Transactions & Logging IV
Concurrency Control R&G - Chapter 17
Transaction Management
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Presentation transcript:

1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 6: Cascading Rollbacks, Deadlocks, and Long Transactions Professor Chen Li

ICS214BNotes 062 Topics: Cascading rollback, recoverable schedule Deadlocks –Prevention –Detection

ICS214BNotes 063 Example: T j T i W j (A) r i (A) Commit T i Abort T j Schedule is conflict serializable (Tj  Ti) but not recoverable Cascading rollback (Bad!) Concurrency control & recovery … … … … … …

ICS214BNotes 064 Need to make “final’ decision for each transaction: –commit decision - system guarantees transaction will or has completed, no matter what –abort decision - system guarantees transaction will or has been rolled back (has no effect) Need two more actions: –A i - transaction T i aborts –C i - transaction T i commits

ICS214BNotes 065 Note: in transactions, reads and writes precede commit or abort  If C i  T i, then r i (A) < C i w i (A) < C i  If A i  T i, then r i (A) < A i w i (A) < A i Also, only one of Ci, Ai can appear in a transaction

ICS214BNotes Back to example: T j T i W j (A) r i (A) C i  can we commit here? No, since Ti reads from Tj, which may abort.

ICS214BNotes 067 Definition “read from” T i reads from T j in S (T j  S T i ) if (1) w j (A) < S r i (A) (2) A j < S r i (A) (< : does not precede ) (3) If w j (A) < S w k (A) < S r i (A) then A k < S r i (A)

ICS214BNotes 068 Definition Schedule S is recoverable if each transaction commits only after each transaction from which it has read has committed. Formally: whenever T j  S T i and j  i and C i  S, then C j < S C i

ICS214BNotes 069 Recoverability and serializability are orthogonal Recoverable and serializable: w1(A), w1(B), w2(A), r2(B), C1, C2 Recoverable but not serializable: w2(A),w1(B),w1(A),r2(B), c1, c2 Serializable but not recoverable: w1(A), w1(B), w2(A), r2(B), c2, c1

ICS214BNotes 0610 Question: How to achieve recoverable schedules?

ICS214BNotes 0611 With 2PL, hold write locks to commit (strict 2PL) T j T i W j (A) C j u j (A) r i (A)...

ICS214BNotes 0612 With validation, no change!

ICS214BNotes 0613 S is recoverable (RC) if each transaction commits only after all transactions from which it read have committed. S avoids cascading rollback (ACR) if each transaction may read only those values written by committed transactions. –i.e., forbids reading of uncommitted data Example: –Both RC and ACR: w1(A),w1(B), w2(A), c1, r2(B), c2 –RC but not ACR: w1(A), w1(B), w2(A), r2(B), c2, c1 Every ACR schedule is RC.

ICS214BNotes 0614 S is strict(ST) if each transaction may read and write only items previously written by committed transactions. Every serial schedule is ST Example: ST but not serial w2(B), w1(A), r2(D), c2, r1(C), c1

ICS214BNotes 0615 Containment: Avoids cascading rollback RC ACR ST SERIAL SERIALIZABLE

ICS214BNotes 0616 Next topic: Deadlocks Easy detection: timeout Wait-for graphs Prevention: Resource ordering Detection by timestamps –Wait-die –Wound-wait

ICS214BNotes 0617 Detection: Timeout If transaction waits more than L sec., roll it back! Simple scheme Hard to select L

ICS214BNotes 0618 Wait-for graph An arc from T1 to T2: –T2 is holding a lock on item A –T1 is waiting for a lock on A –T1 cannot get the lock unless T2 releases its lock T1T1 T2T2

ICS214BNotes 0619 Deadlock Detection Build Wait-For graph, check acyclicity Use lock table structures Build incrementally or periodically When cycle found, rollback victims T1T1 T3T3 T2T2 T6T6 T5T5 T4T4 T7T7

ICS214BNotes 0620 Prevention: Resource Ordering Order all elements A 1, A 2, …, A n Transaction T can lock A i after A j only if i > j Problem : Ordered lock requests not realistic in most cases

ICS214BNotes 0621 Detection: Timestamps Transaction Ti is given a timestamp ts(T i ) when arrives Two schemes: –Wait-Die:  Older (earlier) xacts can wait for younger xacts, i.e.,  T i can only wait for T j if ts(T i )< ts(T j ),  Otherwise, Ti needs to “die” (i.e., is rolled back) –Wound-wait  Younger xacts wait for older xacts

ICS214BNotes 0622 T 1 (ts =10) T 2 (ts =20) T 3 (ts =25) wait Wait-Die: Example wait?

ICS214BNotes 0623 T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) Second Example requests A: wait for T 2 or T 3 ? Note: ts between 20 and 25.

ICS214BNotes 0624 T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) Second Example (continued): wait(A) One option: T 1 waits just for T 3, transaction holding lock. But if T 2 gets lock, T 1 will have to die!

ICS214BNotes 0625 T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) Second Example (continued): wait(A) Another option: T 1 only gets A lock after T 2, T 3 complete, so T 1 waits for both T 2, T 3  T 1 dies right away!

ICS214BNotes 0626 T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) Second Example (continued): wait(A) Yet another option: T 1 preempts T 2, so T 1 only waits for T 3 ; T 2 then waits for T 3 and T 1...  T 2 may starve? redundant arc

ICS214BNotes 0627 Wound-wait scheme Younger xacts wait for older xacts T i can wait for T j if ts(T i ) > ts(T j ) Otherwise, Ti “wounds” Tj –Usually the wound is fatal, then Tj releases the lock, and is rolled back –If Tj has finished when Ti wounds Tj, then Tj releases the block, and is NOT rolled back

ICS214BNotes 0628 T 1 (ts =25) T 2 (ts =20) T 3 (ts =10) wait Example: wait When T2 wounds T1 –T1 needs to release the lock –If T1 is not finished  fatal, rolled back –Otherwise, no need to be rolled back

ICS214BNotes 0629 T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) Second Example: requests A: wait for T 2 or T 3 ? Note: ts between 10 and 20.

ICS214BNotes 0630 T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) Second Example (continued): wait(A) One option: T 1 waits just for T 3, transaction holding lock. But when T 2 gets lock, T 1 waits for T 2 and wounds T 2.

ICS214BNotes 0631 T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) Second Example (continued): wait(A) Another option: T 1 only gets A lock after T 2, T 3 complete, so T 1 waits for both T 2, T 3  T 2 wounded right away!

ICS214BNotes 0632 T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) Second Example (continued): wait(A) Yet another option: T 1 preempts T 2, so T 1 only waits for T 3 ; T 2 then waits for T 3 and T 1...  T 2 is spared!

ICS214BNotes 0633 Why do the timestamp-based schemes prevent deadlocks? Reasons: for both schemes, xacts are “ordered” and cycles are prevented in the wait-for graph

ICS214BNotes 0634 Next Topics: Long transactions (nested, compensation)

ICS214BNotes 0635 User/Program commands Lots of variations, but in general Begin_work Commit_work Abort_work

ICS214BNotes 0636 Nested transactions User program: Begin_work; If results_ok, then commit work else abort_work...

ICS214BNotes 0637 Nested transactions User program: Begin_work; If results_ok, then commit work else {abort_work; try something else…} If results_ok, then commit work else abort_work...

ICS214BNotes 0638 Parallel Nested Transactions T 1 : begin-work parallel: T 11 :begin_work commit_work T 12 :begin_work commit_work... T1T1 T 11 T 12 T1T1

ICS214BNotes 0639 Compensating transactions For a transaction A, its compensating transaction A -1 “undo” the effects of A Reason: –Transactions: A, B1, B2 of the same “big” xact –Suppose A commits, B1 commits, but B2 aborts –We need to roll back the effects of A and B by running B1 -1 and A -1 Formally: –Let B1B2…Bn be any sequence of actions and compensating xacts –For any database state D, the following two sequences of actions leave the database in the same state:  B1B2…Bn  A B1B2…Bn A -1 Not all transactions are compensatable.