SIMPLE CONCURRENCY CONTROL. Correctness criteria: The ACID properties A A tomicity: All actions in the Xact happen, or none happen. C C onsistency: If.

Slides:



Advertisements
Similar presentations
Crash Recovery R&G - Chapter 20
Advertisements

Transaction Management: Crash Recovery, part 2 CS634 Class 21, Apr 23, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
CS 440 Database Management Systems Lecture 10: Transaction Management - Recovery 1.
Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke 1 Crash Recovery Chapter 18.
Crash Recovery R&G - Chapter 18.
Crash Recovery, Part 1 If you are going to be in the logging business, one of the things that you have to do is to learn about heavy equipment. Robert.
5/13/20151 PSU’s CS …. Recovery - Review (only for DB with updates…..!)  ACID: Atomicity & Durability  Trading execution time for recovery time.
1 Crash Recovery Chapter Review: The ACID properties  A  A tomicity: All actions of the Xact happen, or none happen.  C  C onsistency: If each.
Introduction to Database Systems1 Logging and Recovery CC Lecture 2.
1 Crash Recovery Chapter Review: The ACID properties  A  A tomicity: All actions in the Xact happen, or none happen.  C  C onsistency: If each.
COMP9315: Database System Implementation 1 Crash Recovery Chapter 18 (3 rd Edition)
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke 1 Crash Recovery Chapter 20 If you are going to be in the logging business, one.
Transaction Management: Crash Recovery CS634 Class 20, Apr 16, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
ICS 421 Spring 2010 Transactions & Recovery Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 3/4/20101Lipyeow.
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.
Crash Recovery Lecture 24 R&G - Chapter 18 If you are going to be in the logging business, one of the things that you have to do is to learn about heavy.
1 Concurrency Control and Recovery Module 6, Lecture 1.
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.
Crash Recovery CS 186 Spring 2006, Lecture 26 & 27 R&G - Chapter 18 If you are going to be in the logging business, one of the things that you have to.
Review Lecture 30. Administrivia Office hours 1:30 – 2:15 today Final Exam May a.m. Location: 22 Warren Topics since Midterm 2 –Transactions,
Database Management Systems 1 Logging and Recovery If you are going to be in the logging business, one of the things that you have to do is to learn about.
1 Crash Recovery Yanlei Diao UMass Amherst April 3 and 5, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Recovery with Aries. Locking Lock and Unlock take DB resources as arguments: DB, a relation, tuple, etc. Lock and Unlock take DB resources as arguments:
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
CPSC 461. Goal Goal of this lecture is to study Crash Recovery which is subpart of transaction management in DBMS. Crash recovery in DBMS is achieved.
Optimistic Concurrency Control & ARIES: Database Logging and Recovery Zachary G. Ives University of Pennsylvania CIS 650 – Implementing Data Management.
DatabaseSystems/COMP4910/Spring03/Melikyan1 Crash Recovery.
DURABILITY OF TRANSACTIONS AND CRASH RECOVERY These are mostly the slides of your textbook !
Logging and Recovery Chapter 18 If you are going to be in the logging business, one of the things that you have to do is to learn about heavy equipment.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
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.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Instructor: Xintao Wu.
1 Crash Recovery Lecture 23 Ramakrishnan - Chapter 20 If you are going to be in the logging business, one of the things that you have to do is to learn.
ARIES: Database Logging and Recovery Zachary G. Ives University of Pennsylvania CIS 650 – Implementing Data Management Systems February 9, 2005 Some content.
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.
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.
Motivation for Recovery Atomicity: –Transactions may abort (“Rollback”). Durability: –What if DBMS stops running? (Causes?) crash! v Desired Behavior after.
Implementation of Database Systems, Jarek Gryz 1 Crash Recovery Chapter 18.
1 Logging and Recovery. 2 Review: The ACID properties v A v A tomicity: All actions in the Xact happen, or none happen. v C v C onsistency: If each Xact.
Database Applications (15-415) DBMS Internals- Part XIV Lecture 25, April 17, 2016 Mohammad Hammoud.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
DURABILITY OF TRANSACTIONS AND CRASH RECOVERY
CS 440 Database Management Systems
Crash Recovery The slides for this text are organized into chapters. This lecture covers Chapter 20. Chapter 1: Introduction to Database Systems Chapter.
Crash Recovery R&G - Chapter 20
Crash Recovery Chapter 18
Database Applications (15-415) DBMS Internals- Part XIV Lecture 23, November 20, 2016 Mohammad Hammoud.
Transaction Management
Crash Recovery R&G - Chapter 20
Crash Recovery Chapter 18
Crash Recovery The slides for this text are organized into chapters. This lecture covers Chapter 20. Chapter 1: Introduction to Database Systems Chapter.
Introduction to Database Systems
Recovery I: The Log and Write-Ahead Logging
Recovery II: Surviving Aborts and System Crashes
Crash Recovery Chapter 18
Kathleen Durant PhD CS 3200 Lecture 11
Crash Recovery, Part 2 R&G - Chapter 18
Transaction Management
Crash Recovery The slides for this text are organized into chapters. This lecture covers Chapter 20. Chapter 1: Introduction to Database Systems Chapter.
Transaction Management
Crash Recovery Chapter 18
Crash Recovery Chapter 18
Presentation transcript:

SIMPLE CONCURRENCY CONTROL

Correctness criteria: The ACID properties A A tomicity: All actions in the Xact happen, or none happen. C C onsistency: If each Xact is consistent, and the DB starts consistent, it ends up consistent. I I solation: Execution of one Xact is isolated from that of other Xacts. D D urability: If a Xact commits, its effects persist.

Formal Properties of Schedules Serial schedule: Schedule that does not interleave the actions of different transactions. Equivalent schedules: For any database state, the effect of executing the first schedule is identical to the effect of executing the second schedule. Serializable schedule: A schedule that is equivalent to some serial execution of the transactions. (Note: If each transaction preserves consistency, every serializable schedule preserves consistency. )

Conflicting Operations Need a tool to decide if 2 schedules are equivalent Use notion of “conflicting” operations Definition: Two operations conflict if: – They are by different transactions, – they are on the same object, – and at least one of them is a write.

Anomalies with Interleaved Execution Reading Uncommitted Data (WR Conflicts, “dirty reads”): Unrepeatable Reads (RW Conflicts): T1: R(A), W(A), R(B), W(B), Abort T2:R(A), W(A), C T1:R(A), R(A), W(A), C T2:R(A), W(A), C

Anomalies (Continued) Overwriting Uncommitted Data (WW Conflicts): T1:W(A), W(B), C T2:W(A), W(B), C

Conflict Serializable Schedules Definition: Two schedules are conflict equivalent iff: – They involve the same actions of the same transactions, and – every pair of conflicting actions is ordered the same way Definition: Schedule S is conflict serializable if: – S is conflict equivalent to some serial schedule. Note, some “serializable” schedules are NOT conflict serializable – A price we pay to achieve efficient enforcement.

Conflict Serializability – Intuition A schedule S is conflict serializable if: – You are able to transform S into a serial schedule by swapping consecutive non-conflicting operations of different transactions. Example: R(A)R(B) W(A) W(B) R(A) W(A) R(B) W(B) W(A) R(B) R(A) W(B) W(A) W(B) R(A) R(B) W(A) W(B) R(A) W(A) R(B) W(B)

A Serializable (but not Conflict Serializable) Schedule S1: W(A=1) W(A=0) S2: W(A=2) W(A=0) Why is this not conflict serializable? Why is this serializable?

Dependency Graph Dependency graph: – One node per Xact – Edge from Ti to Tj if: An operation Oi of Ti conflicts with an operation Oj of Tj and Oi appears earlier in the schedule than Oj. Theorem: Schedule is conflict serializable if and only if its dependency graph is acyclic. TiTj

Two-Phase Locking (2PL) rules: – Xact must obtain a S (shared) lock before reading, and an X (exclusive) lock before writing. – Xact cannot get new locks after releasing any locks. SX S  – X–– Lock Compatibility Matrix

Two-Phase Locking (2PL), cont. 2PL guarantees conflict serializability time # locks held release phaseacquisition phase But, does not prevent Cascading Aborts.

Strict 2PL Problem: Cascading Aborts Example: rollback of T1 requires rollback of T2! Strict Two-phase Locking (Strict 2PL) protocol: Same as 2PL, except: Locks released only when transaction completes i.e., either: (a) transaction has committed (commit record on disk), or (b) transaction has aborted and rollback is complete. T1: R(A), W(A), R(B), W(B), Abort T2:R(A), W(A)

Strict 2PL (continued) # locks held acquisition phase time release all locks at end of xact

Venn Diagram for Schedules All Schedules Avoid Cascading Abort Serial View Serializable Conflict Serializable

Which schedules does Strict 2PL allow? All Schedules Avoid Cascading Abort Serial View Serializable Conflict Serializable

Lock Management Lock and unlock requests handled by Lock Manager LM keeps an entry for each currently held lock. Entry contains: – List of xacts currently holding lock – Type of lock held (shared or exclusive) – Queue of lock requests

Lock Management, cont. When lock request arrives: – Does any other xact hold a conflicting lock? If no, grant the lock. If yes, put requestor into wait queue. Lock upgrade: – xact with shared lock can request to upgrade to exclusive

Deadlock Detection Create and maintain a “waits-for” graph Periodically check for cycles in graph

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

Deadlock Prevention Assign priorities based on timestamps. Say Ti wants a lock that Tj holds Two policies are possible: Wait-Die: If Ti has higher priority, Ti waits for Tj; otherwise Ti aborts Wound-wait: If Ti has higher priority, Tj aborts; otherwise Ti waits Why do these schemes guarantee no deadlocks? Important detail: If a transaction re-starts, make sure it gets its original timestamp. -- Why?

Multiple-Granularity Locks Shouldn’t have to make same decision for all transactions! Data “containers” are nested: Tuples Tables Pages Database contains

Solution: New Lock Modes, Protocol Allow Xacts to lock at each level, but with a special protocol using new “intention” locks: Still need S and X locks, but before locking an item, Xact must have proper intension locks on all its ancestors in the granularity hierarchy. v IS – Intent to get S lock(s) at finer granularity. v IX – Intent to get X lock(s) at finer granularity. v SIX mode: Like S & IX at the same time. Why useful? Tuples Tables Pages Database

Multiple Granularity Lock Protocol Each Xact starts from the root of the hierarchy. To get S or IS lock on a node, must hold IS or IX on parent node. – What if Xact holds S on parent? SIX 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. Tuples Tables Pages Database

Lock Compatibility Matrix v IS – Intent to get S lock(s) at finer granularity. v IX – Intent to get X lock(s) at finer granularity. v SIX mode: Like S & IX at the same time. IS IX SIX IS IX SIX SX S X   -     Tuples Tables Pages Database

RECOVERY

Motivation Atomicity: – Transactions may abort (“Rollback”). Durability: – What if DBMS stops running? (Causes?) crash! v Desired state after system restarts: –T1 & T3 should be durable. –T2, T4 & T5 should be aborted (effects not seen). T1 T2 T3 T4 T5 Abort Commit

Assumptions Concurrency control is in effect. – Strict 2PL, in particular. Updates are happening “in place”. – i.e. data is overwritten on (deleted from) the actual page copies (not private copies). Can you think of a simple scheme (requiring no logging) to guarantee Atomicity & Durability? – What happens during normal execution (what is the minimum lock granularity)? – What happens when a transaction commits? – What happens when a transaction aborts?

Buffer Management plays a key role Force No Force No Steal Steal No REDO No UNDO UNDO No REDO UNDO REDO No UNDO REDO Force No Force No Steal Steal Slowest Fastest Performance Implications Logging/Recovery Implications

Write-Ahead Logging (WAL) The Write-Ahead Logging Protocol: 1.Must force the log record for an update before the corresponding data page gets to disk. 2.Must force all log records for a Xact before commit. #1 (with UNDO info) helps guarantee Atomicity. #2 (with REDO info) helps guarantee Durability. This allows us to implement Steal/No-Force Exactly how is logging (and recovery!) done? – We’ll look at the ARIES algorithm from IBM.

WAL & the Log Each log record has a unique Log Sequence Number (LSN). – LSNs always increasing. Each data page contains a pageLSN. – The LSN of the most recent log record for an update to that page. System keeps track of flushedLSN. – The max LSN flushed so far. WAL: For a page i to be written must flush log at least to the point where: pageLSN i  flushedLSN LSNs DB pageLSNs RAM flushedLSN pageLSN Log records flushed to disk “Log tail” in RAM flushedLSN

The Big Picture: What’s Stored Where DB Data pages each with a pageLSN Xact Table lastLSN status Dirty Page Table recLSN flushedLSN RAM LSN prevLSN XID type length pageID offset before-image after-image LogRecords LOG Master record

Crash Recovery: Big Picture v Start from a checkpoint (found via master record). v Three phases. Need to do: –Analysis - Figure out which Xacts committed since checkpoint, which failed. –REDO all actions. (repeat history) –UNDO effects of failed Xacts. Oldest log rec. of Xact active at crash Smallest recLSN in dirty page table after Analysis Last chkpt CRASH A RU

Recovery: The Analysis Phase Re-establish knowledge of state at checkpoint. – via transaction table and dirty page table stored in the checkpoint Scan log forward from checkpoint. – End record: Remove Xact from Xact table. – All Other records: Add Xact to Xact table, set lastLSN=LSN, change Xact status on commit. – also, for Update records: If page P not in Dirty Page Table, Add P to DPT, set its recLSN=LSN. At end of Analysis… – transaction table says which xacts were active at time of crash. – DPT says which dirty pages might not have made it to disk

Phase 2: The REDO Phase We Repeat History to reconstruct state at crash: – Reapply all updates (even of aborted Xacts!), redo CLRs. Scan forward from log rec containing smallest recLSN in DPT. Q: why start here? For each update log record or CLR with a given LSN, REDO the action unless: – Affected page is not in the Dirty Page Table, or – Affected page is in D.P.T., but has recLSN > LSN, or – pageLSN (in DB)  LSN. (this last case requires I/O) To REDO an action: – Reapply logged action. – Set pageLSN to LSN. No additional logging, no forcing!

Phase 3: The UNDO Phase A Naïve solution: – The xacts in the Xact Table are losers. – For each loser, perform simple transaction abort. – Problems?

Phase 3: The UNDO Phase ToUndo={lastLSNs of all Xacts in the Xact Table} a.k.a. “losers” Repeat: – Choose (and remove) largest LSN among ToUndo. – If this LSN is a CLR and undonextLSN==NULL Write an End record for this Xact. – If this LSN is a CLR, and undonextLSN != NULL Add undonextLSN to ToUndo – Else this LSN is an update. Undo the update, write a CLR, add prevLSN to ToUndo. Until ToUndo is empty. NOTE: This is simply a performance optimization on the naïve solution to do it in one backwards pass of the log!

Summary of Logging/Recovery Recovery Manager guarantees Atomicity & Durability. Use WAL to allow STEAL/NO-FORCE w/o sacrificing correctness. LSNs identify log records; linked into backwards chains per transaction (via prevLSN). pageLSN allows comparison of data page and log records.

Summary, Cont. Checkpointing: A quick way to limit the amount of log to scan on recovery. Recovery works in 3 phases: – Analysis: Forward from checkpoint. – Redo: Forward from oldest recLSN. – Undo: Backward from end to first LSN of oldest Xact alive at crash. Upon Undo, write CLRs. Redo “repeats history”: Simplifies the logic!