CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.

Slides:



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

Transaction Program unit that accesses the database
Database Systems (資料庫系統)
More About Transaction Management Chapter 10. Contents Transactions that Read Uncommitted Data View Serializability Resolving Deadlocks Distributed Databases.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
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.
1 Supplemental Notes: Practical Aspects of Transactions THIS MATERIAL IS OPTIONAL.
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.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
More on transactions…. Dealing with concurrency (OR: how to handle the pressure!) Locking Timestamp ordering Multiversion protocols Optimistic protocols.
Recovery 10/18/05. Implementing atomicity Note, when a transaction commits, the portion of the system implementing durability ensures the transaction’s.
Transaction Management and Concurrency Control
What is a Transaction? Logical unit of work
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.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
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.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
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.
Concurrency Control Concurrency Control By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Concurrency Control II: Locking and Isolation Levels.
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 CSE 480: Database Systems Lecture 24: Concurrency Control.
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
Transaction Management and Recovery, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
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.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
CS 245: Database System Principles Notes 10: More TP
Transaction Management
CS 245: Database System Principles Notes 10: More TP
Concurrency Control.
Chapter 10 Transaction Management and Concurrency Control
CS 245: Database System Principles Notes 10: More TP
Chapter 15 : Concurrency Control
Concurrency Control Chapter 17
Transaction Management
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 (資料庫系統)
Presentation transcript:

CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina

CS 245Notes 102 Sections to Skim: Section 18.8 [18.8] Sections , 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 245Notes 103 Chapter 19 [19] More on transaction processing Topics: Cascading rollback, recoverable schedule Deadlocks –Prevention –Detection View serializability Distributed transactions Long transactions (nested, compensation)

CS 245Notes 104 Example: T j T i W j (A) r i (A) Commit T i Abort T j Concurrency control & recovery … … … … … …

CS 245Notes 105 Example: T j T i W j (A) r i (A) Commit T i Abort T j Concurrency control & recovery … … … … … …  Non-Persistent Commit (Bad!)

CS 245Notes 106 Example: T j T i W j (A) r i (A) Commit T i Abort T j Concurrency control & recovery … … … … … …  Non-Persistent Commit (Bad!) avoided by recoverable schedules

CS 245Notes 107 Example: T j T i W j (A) r i (A) w i (B) Abort T j [ Commit T i] Concurrency control & recovery … … … … … …

CS 245Notes 108 Example: T j T i W j (A) r i (A) w i (B) Abort T j [ Commit T i] Concurrency control & recovery … … … … … …  Cascading rollback (Bad!)

CS 245Notes 109 Example: T j T i W j (A) r i (A) w i (B) Abort T j [ Commit T i] Concurrency control & recovery … … … … … …  Cascading rollback (Bad!) avoided by avoids-cascading- rollback (ACR) schedules

CS 245Notes 1010 Schedule is conflict serializable T j T i But not recoverable

CS 245Notes 1011 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 245Notes 1012 To model this, two new actions: C i - transaction T i commits A i - transaction T i aborts

CS 245Notes Back to example: T j T i W j (A) r i (A) C i  can we commit here?

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

CS 245Notes 1015 Definition Schedule S is recoverable if whenever T j  S T i and j  i and C i  S then C j < S C i

CS 245Notes 1016 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, one of Ci, Ai per transaction

CS 245Notes 1017 How to achieve recoverable schedules?

CS 245Notes 1018  With 2PL, hold write locks to commit (strict 2PL) T j T i W j (A) C j u j (A) r i (A)...

CS 245Notes 1019  With validation, no change!

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

CS 245Notes 1021 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 245Notes 1022 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 245Notes 1023 Relationship of RC, ACR, Strict Avoids cascading rollback RC ACR ST SERIAL

CS 245Notes 1024 Examples Recoverable: –w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 1 c 2 Avoids Cascading Rollback: –w 1 (A) w 1 (B) w 2 (A) c 1 r 2 (B) c 2 Strict: –w 1 (A) w 1 (B) c 1 w 2 (A) r 2 (B) c 2 Assumes w 2 (A) is done without reading

CS 245Notes 1025 Where are serializable schedules? Avoids cascading rollback RC ACR ST SERIAL

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

CS 245Notes 1027 Deadlock Detection Build Wait-For graph Use lock table structures Build incrementally or periodically When cycle found, rollback victim T1T1 T3T3 T2T2 T6T6 T5T5 T4T4 T7T7

CS 245Notes 1028 Resource Ordering Order all elements A 1, A 2, …, A n A transaction T can lock A i after A j only if i > j

CS 245Notes 1029 Resource Ordering Order all elements A 1, A 2, …, A n A transaction T can lock A i after A j only if i > j Problem : Ordered lock requests not realistic in most cases

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

CS 245Notes 1031 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

CS 245Notes 1032 T 1 (ts =10) T 2 (ts =20) T 3 (ts =25) wait Example:

CS 245Notes 1033 T 1 (ts =10) T 2 (ts =20) T 3 (ts =25) wait Example: wait?

CS 245Notes 1034 T 1 (ts =10) T 2 (ts =20) T 3 (ts =25) wait Example: wait?

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

CS 245Notes 1036 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 245Notes 1037 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.

CS 245Notes 1038 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 when T 2 gets lock, T 1 will have to die!

CS 245Notes 1039 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!

CS 245Notes 1040 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

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

CS 245Notes 1042 T 1 (ts =25) T 2 (ts =20) T 3 (ts =10) wait Example:

CS 245Notes 1043 T 1 (ts =25) T 2 (ts =20) T 3 (ts =10) wait Example: wait

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

CS 245Notes 1045 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.

CS 245Notes 1046 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.

CS 245Notes 1047 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!

CS 245Notes 1048 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!

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

CS 245Notes 1050 Nested transactions User program: Begin_work; If results_ok, then commit work else abort_work...

CS 245Notes 1051 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...

CS 245Notes 1052 Parallel Nested Transactions T 1 : begin-work parallel: T 11 :begin_work commit_work T 12 :begin_work commit_work...

CS 245Notes 1053 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

CS 245Notes 1054 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

CS 245Notes 1055 Locking What are we really locking?

CS 245Notes 1056 Example: T i Read record r 1 Read record r 1 do record locking Modify record r 3...

CS 245Notes 1057 But underneath: Disk pages R3R3 R1R1 R2R2 record id

CS 245Notes 1058 But underneath: Disk pages R3R3 R1R1 R2R2 record id If we lock all data involved in read of R1, we may prevent an update to R2 (which may require reorganization within block)

CS 245Notes 1059 Solution: view DB at two levels Top level: record actions record locks undo/redo actions — logical e.g., Insert record(X,Y,Z) Redo: insert(X,Y,Z) Undo: delete

CS 245Notes 1060 Low level: deal with physical details latch page during action (release at end of action)

CS 245Notes 1061 Note: undo does not return physical DB to original state; only same logical state e.g., Insert R3Undo (delete R3) R1 R2 R1 R2 R3

CS 245Notes 1062 Logging Logical Actions Logical action typically span one block (physiological actions) Undo/redo log entry specifies undo/redo logical action

Question How to deal with spanned record? CS 245Notes 1063 part (a)part (b)part (c)

CS 245Notes 1064 Logging Logical Actions Logical action typically span one block (physiological actions) Undo/redo log entry specifies undo/redo logical action Challenge: making actions idempotent Example (bad): redo insert  key inserted multiple times!

CS 245Notes 1065 Solution: Add Log Sequence Number Log record: LSN=26 OP=insert(5,v2) into P... 3, v1 semlsn= , v1 semlsn= , v2

CS 245Notes 1066 Still Have a Problem! 3, v1 lsn= , v2 3, v1 lsn= , v1 lsn= , v3 T1 Del 4 T2 Ins 5

CS 245Notes 1067 Still Have a Problem! 3, v1 lsn= , v2 3, v1 lsn= , v1 lsn= , v3 T1 Del 4 T2 Ins 5 3, v1 lsn=??... 5, v3 4, v2 undo Del 4

CS 245Notes 1068 Still Have a Problem! 3, v1 lsn= , v2 3, v1 lsn= , v1 lsn= , v3 T1 Del 4 T2 Ins 5 3, v1 lsn=??... 5, v3 4, v2 undo Del 4 Make log entry for undo lsn=27

CS 245Notes 1069 Compensation Log Records Log record to indicate undo (not redo) action performed Note: Compensation may not return page to exactly the initial state

CS 245Notes 1070 At Recovery: Example lsn=21 T1 a1 p1 lsn=35 T1 a2 -1 p2 lsn=27 T1 a2 p2... Log:

CS 245Notes 1071 What to do with p2 (during T1 rollback)? If lsn(p2)<27 then... ? If 27  lsn(p2) < 35 then... ? If lsn(p2)  35 then... ? Note: lsn(p2) is lsn of p copy on disk

CS 245Notes 1072 Recovery Strategy [1] Reconstruct state at time of crash –Find latest valid checkpoint, Ck, and let ac be its set of active transactions –Scan log from Ck to end: For each log entry [lsn, page] do: if lsn(page) < lsn then redo action If log entry is start or commit, update ac

CS 245Notes 1073 Recovery Strategy [2] Abort uncommitted transactions –Set ac contains transactions to abort –Scan log from end to Ck : For each log entry (not undo) of an ac transaction, undo action (making log entry) –For ac transactions not fully aborted, read their log entries older than Ck and undo their actions

CS 245Notes 1074 Example: What To Do After Crash lsn=21 T1 a1 p1 lsn=35 T1 a2 -1 p2 lsn=27 T1 a2 p2... Log:... lsn=29 T1 a3 p3 lsn=31 T1 a3 -1 p3... chk pt

CS 245Notes 1075 During Undo: Skip Undo’s lsn=21 T1 a1 p1 lsn=35 T1 a2 -1 p2 lsn=27 T1 a2 p2... Log:... lsn=29 T1 a3 p3 lsn=31 T1 a3 -1 p3... chk pt pointer to forward action pointer to previous T1 action

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

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