CS 245: Database System Principles Notes 10: More TP

Slides:



Advertisements
Similar presentations
Database Systems Lecture 16 Natasha Alechina
Advertisements

1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme.
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
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
Concurrency Control.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 6: Cascading Rollbacks, Deadlocks, and Long Transactions Professor Chen Li.
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.
Quick Review of Apr 29 material
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 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.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
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.
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.
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
Transactions. What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions developed.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Concurrency Control Introduction Lock-Based Protocols
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.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
CS 245: Database System Principles Notes 10: More TP
Transaction Management
Lecture 3 Concurrency control techniques
CS422 Principles of Database Systems Concurrency Control
Concurrency Control.
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
Part- A Transaction Management
Schedules and Serializability
Transaction Management
Concurrency Control via Validation
Chapter 16: Concurrency Control
Transaction Management
March 9th – Transactions
Concurrency Control Chapter 17
CS 245: Database System Principles Notes 10: More TP
CS162 Operating Systems and Systems Programming Review (II)
Ch 22: Databases Concurrency Control
Database Transactions
Chapter 15 : Concurrency Control
Concurrency Control Chapter 17
Lecture 22: Intro to Transactions & Logging IV
Concurrency Control R&G - Chapter 17
Transaction Management
Concurrency Control Techniques
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 (資料庫系統)
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Presentation transcript:

CS 245: Database System Principles Notes 10: More TP Peter Bailis CS 245 Notes 10

Sections to Skim: Section 18.8 [18.8] Sections 19.2 19.4, 19.5, 19.6 [none, i.e., read all Ch 19] [In the Second Edition, skip all of Chapter 20, and Sections 21.5, 21.6, 21.7, 22.2 through 22.7] CS 245 Notes 10

Chapter 19 [19] More on transaction processing Topics: Cascading rollback, recoverable schedule Deadlocks Prevention Detection View serializability Distributed transactions Long transactions (nested, compensation) CS 245 Notes 10

Concurrency control & recovery Example: Tj Ti Wj(A) ri(A) Commit Ti Abort Tj … … … … … … CS 245 Notes 10

Concurrency control & recovery Example: Tj Ti Wj(A) ri(A) Commit Ti Abort Tj … … … … … …  Non-Persistent Commit (Bad!) CS 245 Notes 10

Concurrency control & recovery Example: Tj Ti Wj(A) ri(A) Commit Ti Abort Tj … … … … … … avoided by recoverable schedules  Non-Persistent Commit (Bad!) CS 245 Notes 10

Concurrency control & recovery Example: Tj Ti Wj(A) ri(A) wi(B) Abort Tj [Commit Ti] … … … … … … CS 245 Notes 10

Concurrency control & recovery Example: Tj Ti Wj(A) ri(A) wi(B) Abort Tj [Commit Ti] … … … … … …  Cascading rollback (Bad!) CS 245 Notes 10

Concurrency control & recovery Example: Tj Ti Wj(A) ri(A) wi(B) Abort Tj [Commit Ti] … … … … … … avoided by avoids-cascading- rollback (ACR) schedules  Cascading rollback (Bad!) CS 245 Notes 10

Schedule is conflict serializable Tj Ti But not recoverable CS 245 Notes 10

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) CS 245 Notes 10

To model this, two new actions: Ci - transaction Ti commits Ai - transaction Ti aborts CS 245 Notes 10

Back to example: Tj Ti Wj(A) ri(A) ... ... Ci  can we commit here? CS 245 Notes 10

Definition Ti reads from Tj in S (Tj S Ti) if (1) wj(A) <S ri(A) (2) aj <S ri(A) (< : does not precede) (3) If wj(A) <S wk(A) <S ri(A) then ak <S ri(A) CS 245 Notes 10

Definition Schedule S is recoverable if whenever Tj S Ti and j  i and Ci  S then Cj <S Ci CS 245 Notes 10

Note: in transactions, reads and writes precede commit or abort  If Ci  Ti, then ri(A) < Ci wi(A) < Ci  If Ai  Ti, then ri(A) < Ai wi(A) < Ai Also, one of Ci, Ai per transaction CS 245 Notes 10

How to achieve recoverable schedules? CS 245 Notes 10

With 2PL, hold write locks to commit (strict 2PL) Tj Ti Wj(A) Cj uj(A) ri(A) ... ... ... ... ... ... ... CS 245 Notes 10

With validation, no change! CS 245 Notes 10

S is recoverable if each transaction commits only after all transactions from which it read have committed. CS 245 Notes 10

S is recoverable if each transaction commits only after all transactions from which it read have committed. S avoids cascading rollback if each transaction may read only those values written by committed transactions. CS 245 Notes 10

S is recoverable if each transaction commits only after all transactions from which it read have committed. S avoids cascading rollback if each transaction may read only those values written by committed transactions. S is strict if each transaction may read and write only items previously written by committed transactions. CS 245 Notes 10

Avoids cascading rollback Relationship of RC, ACR, Strict RC Avoids cascading rollback ST SERIAL ACR CS 245 Notes 10

Examples Recoverable: Avoids Cascading Rollback: Strict: w1(A) w1(B) w2(A) r2(B) c1 c2 Avoids Cascading Rollback: w1(A) w1(B) w2(A) c1 r2(B) c2 Strict: w1(A) w1(B) c1 w2(A) r2(B) c2 Assumes w2(A) is done without reading CS 245 Notes 10

Deadlocks Detection Prevention Wait-for graph Resource ordering Timeout Wait-die Wound-wait CS 245 Notes 10

Deadlock Detection Build Wait-For graph Use lock table structures Build incrementally or periodically When cycle found, rollback victim T5 T2 T1 T7 T4 T6 T3 CS 245 Notes 10

Resource Ordering Order all elements A1, A2, …, An A transaction T can lock Ai after Aj only if i > j CS 245 Notes 10

Resource Ordering Order all elements A1, A2, …, An A transaction T can lock Ai after Aj only if i > j Problem : Ordered lock requests not realistic in most cases CS 245 Notes 10

Timeout If transaction waits more than L sec., roll it back! Simple scheme Hard to select L CS 245 Notes 10

Wait-die Transactions given a timestamp when they arrive …. ts(Ti) Ti can only wait for Tj if ts(Ti)< ts(Tj) ...else die CS 245 Notes 10

Example: T1 (ts =10) T2 (ts =20) T3 (ts =25) wait wait CS 245 Notes 10

Example: T1 (ts =10) T2 (ts =20) T3 (ts =25) wait? wait wait CS 245 Notes 10

Example: T1 (ts =10) T2 (ts =20) T3 (ts =25) wait? wait wait CS 245 Notes 10

Starvation with Wait-Die When transaction dies, re-try later with what timestamp? original timestamp new timestamp (time of re-submit) CS 245 Notes 10

Starvation with Wait-Die Resubmit with original timestamp Guarantees no starvation Transaction with oldest ts never dies A transaction that dies will eventually have oldest ts and will complete... CS 245 Notes 10

Second Example: T1 (ts =22) T2 (ts =20) T3 (ts =25) requests A: wait for T2 or T3? Note: ts between 20 and 25. wait(A) CS 245 Notes 10

Second Example (continued): One option: T1 waits just for T3, transaction holding lock. But when T2 gets lock, T1 will have to die! T1 (ts =22) T2 (ts =20) T3 (ts =25) wait(A) wait(A) CS 245 Notes 10

Second Example (continued): Another option: T1 only gets A lock after T2, T3 complete, so T1 waits for both T2, T3  T1 dies right away! T1 (ts =22) T2 (ts =20) T3 (ts =25) wait(A) wait(A) wait(A) CS 245 Notes 10

Second Example (continued): Yet another option: T1 preempts T2, so T1 only waits for T3; T2 then waits for T3 and T1...  T2 may starve? T1 (ts =22) T2 (ts =20) T3 (ts =25) wait(A) wait(A) wait(A) redundant arc CS 245 Notes 10

Wound-wait Transactions given a timestamp when they arrive … ts(Ti) Ti wounds Tj if ts(Ti)< ts(Tj) else Ti waits “Wound”: Tj rolls back and gives lock to Ti CS 245 Notes 10

Example: T1 (ts =25) T2 (ts =20) T3 (ts =10) wait wait CS 245 Notes 10

Example: T1 (ts =25) T2 (ts =20) T3 (ts =10) wait wait wait CS 245 Notes 10

Starvation with Wound-Wait When transaction dies, re-try later with what timestamp? original timestamp new timestamp (time of re-submit) CS 245 Notes 10

Second Example: T1 (ts =15) T2 (ts =20) T3 (ts =10) requests A: wait for T2 or T3? Note: ts between 10 and 20. wait(A) CS 245 Notes 10

Second Example (continued): One option: T1 waits just for T3, transaction holding lock. But when T2 gets lock, T1 waits for T2 and wounds T2. T1 (ts =15) T2 (ts =20) T3 (ts =10) wait(A) wait(A) CS 245 Notes 10

Second Example (continued): Another option: T1 only gets A lock after T2, T3 complete, so T1 waits for both T2, T3  T2 wounded right away! T1 (ts =15) T2 (ts =20) T3 (ts =10) wait(A) wait(A) wait(A) CS 245 Notes 10

Second Example (continued): Yet another option: T1 preempts T2, so T1 only waits for T3; T2 then waits for T3 and T1...  T2 is spared! T1 (ts =15) T2 (ts =20) T3 (ts =10) wait(A) wait(A) wait(A) CS 245 Notes 10

User/Program commands Lots of variations, but in general Begin_work Commit_work Abort_work CS 245 Notes 10

Related idea: Sagas Long running activity: T1, T2, ... Tn Each step/trasnaction Ti has a compensating transaction Ti-1 Semantic atomicity: execute one of T1, T2, ... Tn T1, T2, ... Tn-1 T-1n-1, T-1n-2, ... T-11 T1, T2, ... Tn-2 T-1n-2, T-1n-3, ... T-11 T1, T-11 nothing ... CS 245 Notes 10

Summary Cascading rollback Recoverable schedule Deadlock Prevention Detectoin Nested transactions Multi-level view CS 245 Notes 10