1 CSE544 Transactions: Recovery Thursday, January 27, 2011 Dan Suciu -- 544, Winter 2011.

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.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#23: Crash Recovery – Part 2 (R&G ch.
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.
1 Supplemental Notes: Practical Aspects of Transactions THIS MATERIAL IS OPTIONAL.
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.
ICS 421 Spring 2010 Transactions & Recovery Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 3/4/20101Lipyeow.
Transactions A process that reads or modifies the DB is called a transaction. It is a unit of execution of database operations. Basic JDBC transaction.
Recovery from Crashes. Transactions A process that reads or modifies the DB is called a transaction. It is a unit of execution of database operations.
1 Lecture 4: Transactions Wednesday, October 20, 2010 Dan Suciu -- CSEP544 Fall 2010.
Recovery from Crashes. ACID A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
ACID A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction, may change the DB from.
1 Lecture 12: Transactions: Recovery. 2 Outline Recovery Undo Logging Redo Logging Undo/Redo Logging Book Section 15.1, 15.2, 23, 24, 25.
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.
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.
Chapter 19 Database Recovery Techniques. Slide Chapter 19 Outline Databases Recovery 1. Purpose of Database Recovery 2. Types of Failure 3. Transaction.
1 Crash Recovery Yanlei Diao UMass Amherst April 3 and 5, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
July 16, 2015ICS 5411 Coping With System Failure Chapter 17 of GUW.
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.
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.
CS411 Database Systems Kazuhiro Minami 14: Concurrency Control.
1 Transaction Management. 2 Outline Transaction management –motivation & brief introduction –major issues recovery concurrency control Recovery.
Chapter 16 Recovery Yonsei University 1 st Semester, 2015 Sanghyun Park.
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.
 Introduction  Storage  Failure  Recovery  Logging  Undo Logging  Redo Logging  ARIES.
© Dennis Shasha, Philippe Bonnet 2001 Log Tuning.
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 Lecture 28: Recovery Friday, December 5 th, 2003.
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.
1 Lecture 15: Data Storage, Recovery Monday, February 13, 2006.
Database Applications (15-415) DBMS Internals- Part XIV Lecture 25, April 17, 2016 Mohammad Hammoud.
1 Database Systems ( 資料庫系統 ) January 3, 2005 Chapter 18 By Hao-hua Chu ( 朱浩華 )
DURABILITY OF TRANSACTIONS AND CRASH RECOVERY
ARIES: Algorithm for Recovery and Isolation Exploiting Semantics
CS 440 Database Management Systems
Lecture 13: Recovery Wednesday, February 2, 2005.
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
Database Applications (15-415) DBMS Internals- Part XIII Lecture 22, November 15, 2016 Mohammad Hammoud.
Crash Recovery Chapter 18
Database Applications (15-415) DBMS Internals- Part XIV Lecture 23, November 20, 2016 Mohammad Hammoud.
Database Systems (資料庫系統)
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.
Recovery II: Surviving Aborts and System Crashes
Crash Recovery Chapter 18
Lecture 15 – ARIES Recovery
Kathleen Durant PhD CS 3200 Lecture 11
Crash Recovery, Part 2 R&G - 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.
Chapter 19: Recovery System
RECOVERY MANAGER E0 261 Jayant Haritsa Computer Science and Automation
Introduction to Database Systems CSE 444 Lectures 15-16: Recovery
Crash Recovery Chapter 18
Crash Recovery Chapter 18
Lecture 17: Data Storage and Recovery
Lecture 16: Recovery Friday, November 4, 2005.
Presentation transcript:

1 CSE544 Transactions: Recovery Thursday, January 27, 2011 Dan Suciu , Winter 2011

Buffer Management in a DBMS 2 DB disk page free frame BUFFER POOL READ WRITE INPUT OUTUPT Application (Database server) Large gap between disk I/O and memory  Buffer pool

Page Replacement Policies LRU = expensive –Next slide Clock algorithm = cheaper alternative –Read in the book Both work well in OS, but not always in DB Dan Suciu , Winter 20113

Least Recently Used (LRU) Dan Suciu , Winter P5, P2, P8, P4, P1, P9, P6, P3, P7 Read(P6) ?? Most recentLeast recent

Least Recently Used (LRU) Dan Suciu , Winter P5, P2, P8, P4, P1, P9, P6, P3, P7 Read(P6) P6, P5, P2, P8, P4, P1, P9, P3, P7 Most recentLeast recent

Least Recently Used (LRU) Dan Suciu , Winter P5, P2, P8, P4, P1, P9, P6, P3, P7 Read(P6) P6, P5, P2, P8, P4, P1, P9, P3, P7 Read(P10) ?? Most recentLeast recent

Least Recently Used (LRU) Dan Suciu , Winter P5, P2, P8, P4, P1, P9, P6, P3, P7 Read(P6) P6, P5, P2, P8, P4, P1, P9, P3, P7 Input(P10) P10, P6, P5, P2, P8, P4, P1, P9, P3 Read(P10) Most recentLeast recent

8 Atomic Transactions FORCE or NO-FORCE –Should all updates of a transaction be forced to disk before the transaction commits? STEAL or NO-STEAL –Can an update made by an uncommitted transaction overwrite the most recent committed value of a data item on disk? Dan Suciu , Winter 2011 Performance (e.g. LRU): NO-FORCE+STEAL Atomicity: FORCE + NO-STEAL

Atomic Transactions NO-FORCE: Pages of committed transactions not yet written to disk STEAL: Pages of uncommitted transactions already written to disk Dan Suciu , Winter In either case, Atomicity is violated

10 Notations READ(X,t) –copy element X to transaction local variable t WRITE(X,t) –copy transaction local variable t to element X INPUT(X) –read element X to memory buffer OUTPUT(X) –write element X to disk Dan Suciu , Winter 2011

11 Recovery Write-ahead log = A file that records every single action of all running transactions Force log entry to disk After a crash, transaction manager reads the log and finds out exactly what the transactions did or did not Dan Suciu , Winter 2011

12 Example Atomicity: Both A and B are multiplied by 2, or none is. Dan Suciu , Winter 2011 START TRANSACTION READ(A,t); t := t*2; WRITE(A,t); READ(B,t); t := t*2; WRITE(B,t) COMMIT; START TRANSACTION READ(A,t); t := t*2; WRITE(A,t); READ(B,t); t := t*2; WRITE(B,t) COMMIT;

13 ActiontMem AMem BDisk ADisk B INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT Buffer poolDiskTransaction READ(A,t); t := t*2; WRITE(A,t); READ(B,t); t := t*2; WRITE(B,t) READ(A,t); t := t*2; WRITE(A,t); READ(B,t); t := t*2; WRITE(B,t)

Is this bad ? Crash ! ActiontMem AMem BDisk ADisk B INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT

Is this bad ? Crash ! ActiontMem AMem BDisk ADisk B INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT Yes it’s bad: A=16, B=8….

Is this bad ? Crash ! ActiontMem AMem BDisk ADisk B INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT

Is this bad ? Crash ! ActiontMem AMem BDisk ADisk B INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT Yes it’s bad: A=B=16, but not committed

Is this bad ? Crash ! ActiontMem AMem BDisk ADisk B INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT

Is this bad ? Crash ! ActiontMem AMem BDisk ADisk B INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT No: that’s OK

UNDO Log Dan Suciu , Winter

21 ActiontMem AMem BDisk ADisk BUNDO Log INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT

22 Crash ! WHAT DO WE DO ? ActiontMem AMem BDisk ADisk BUNDO Log INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT

23 Crash ! WHAT DO WE DO ? ActiontMem AMem BDisk ADisk BUNDO Log INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT We UNDO by setting B=8 and A=8

24 Crash ! ActiontMem AMem BDisk ADisk BUNDO Log INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT What do we do now ?

25 Crash ! ActiontMem AMem BDisk ADisk BUNDO Log INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT What do we do now ? Nothing: log contains COMMIT

ActiontMem AMem BDisk ADisk BUNDO Log INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT When must we force pages to disk ?

27 ActiontMem AMem BDisk ADisk BUNDO Log INPUT(A)888 READ(A,t)8888 t:=t* WRITE(A,t)16 88 INPUT(B) READ(B,t) t:=t* WRITE(B,t)16 88 OUTPUT(A)16 8 OUTPUT(B)16 COMMIT RULES: log entry before OUTPUT before COMMIT

REDO Log Dan Suciu , Winter

29 ActiontMem AMem BDisk ADisk B READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 Crash ! Is this bad ?

30 ActiontMem AMem BDisk ADisk B READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 Crash ! Is this bad ? Yes, it’s bad: A=16, B=8

31 ActiontMem AMem BDisk ADisk B READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 Crash ! Is this bad ?

32 ActiontMem AMem BDisk ADisk B READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 Crash ! Is this bad ? Yes, it’s bad: T committed but A=B=8

33 ActiontMem AMem BDisk ADisk BREDO Log READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16

34 ActiontMem AMem BDisk ADisk BREDO Log READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 Crash ! How do we recover ?

35 ActiontMem AMem BDisk ADisk BREDO Log READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 Crash ! How do we recover ? We REDO by setting A=16 and B=16

36 ActiontMem AMem BDisk ADisk BREDO Log READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 When must we force pages to disk ?

37 ActiontMem AMem BDisk ADisk BREDO Log READ(A,t)8888 t:=t* WRITE(A,t)16 88 READ(B,t) t:=t* WRITE(B,t)16 88 COMMIT OUTPUT(A)16 8 OUTPUT(B)16 RULE: OUTPUT after COMMIT

38 Comparison Undo/Redo Undo logging: OUTPUT must be done early: –Inefficient Redo logging: O UTPUT must be done late: –Inflexible Dan Suciu , Winter 2011

Checkpointing To ensure recovery we must read from the beginning of the log: this is too inefficient Checkpointing: periodically write information to the log to allow us to process only the tail of the log Dan Suciu , Winter

ARIES Recovery Manager A redo/undo log Physiological logging –Physical logging for REDO –Logical logging for UNDO Efficient checkpointing Dan Suciu , Winter Why ?

41 ARIES Recovery Manager Log entryies: -- when T begins Update: –T updates X, old value=u, new value=v –In practice: undo only and redo only entries or CLR’s – we’ll talk about them later. Dan Suciu , Winter 2011

42 ARIES Recovery Manager Rule: If T modifies X, then must be written to disk before OUTPUT(X) We are free to OUTPUT early or late Dan Suciu , Winter 2011

43 LSN = Log Sequence Number LSN = identifier of a log entry –Log entries belonging to the same txn are linked Each page contains a pageLSN: –LSN of log record for latest update to that page –Will serve to determine if an update needs to be redone Dan Suciu , Winter 2011

44 ARIES Data Structures Active Transactions Table –Lists all running txns (active txns) –For each txn: lastLSN = most recent update by txn Dirty Page Table –Lists all dirty pages –For each dirty page: recoveryLSN (recLSN)= first LSN that caused page to become dirty Write Ahead Log –LSN, prevLSN = previous LSN for same txn Dan Suciu , Winter 2011

ARIES Data Structures pageIDrecLSN P5102 P6103 P7101 LSNprevLSNtransIDpageIDLog entry 101-T100P7 102-T200P T200P T100P5 Dirty pagesLog (WAL) transIDlastLSN T T Active transactions P8P2... P5 PageLSN=104 P6 PageLSN=103 P7 PageLSN=101 Buffer Pool W T100 (P7) W T200 (P5) W T200 (P6) W T100 (P5) W T100 (P7) W T200 (P5) W T200 (P6) W T100 (P5)

46 ARIES Normal Operation T writes page P What do we do ? Dan Suciu , Winter 2011

47 ARIES Normal Operation T writes page P What do we do ? Write in the Log pageLSN=LSN lastLSN=LSN recLSN=if isNull then LSN Dan Suciu , Winter 2011

48 ARIES Normal Operation Buffer manager wants to OUTPUT(P) What do we do ? Buffer manager wants INPUT(P) What do we do ? Dan Suciu , Winter 2011

49 ARIES Normal Operation Buffer manager wants to OUTPUT(P) Flush log up to pageLSN Remove P from Dirty Pages table Buffer manager wants INPUT(P) Create entry in Dirty Pages table recLSN = NULL Dan Suciu , Winter 2011

50 ARIES Normal Operation Transaction T starts What do we do ? Transaction T commits/aborts What do we do ? Dan Suciu , Winter 2011

51 ARIES Normal Operation Transaction T starts Write in the log New entry T in Active TXN; lastLSN = null Transaction T commits/aborts Write Flush log up to this entry Dan Suciu , Winter 2011

52 Checkpoints Write into the log Entire active transactions table Entire dirty pages table Dan Suciu , Winter 2011 Recovery always starts by analyzing latest checkpoint Background process periodically flushes dirty pages to disk

53 ARIES Recovery 1.Analysis pass –Figure out what was going on at time of crash –List of dirty pages and active transactions 2.Redo pass (repeating history principle) –Redo all operations, even for transactions that will not commit –Get back to state at the moment of the crash 3.Undo pass –Remove effects of all uncommitted transactions –Log changes during undo in case of another crash during undo Dan Suciu , Winter 2011

54 ARIES Method Illustration [Figure 3 from Franklin97] Dan Suciu , Winter 2011 First undo and first redo log entry might be in reverse order

55 1. Analysis Phase Goal –Determine point in log where to start REDO –Determine set of dirty pages when crashed Conservative estimate of dirty pages –Identify active transactions when crashed Approach –Rebuild active transactions table and dirty pages table –Reprocess the log from the checkpoint Only update the two data structures –Compute: firstLSN = smallest of all recoveryLSN Dan Suciu , Winter 2011

1. Analysis Phase (crash) Checkpoint Dirty pages Active txn Log pageIDrecLSNpageID transIDlastLSNtransID firstLSN= ??? Where do we start the REDO phase ?

1. Analysis Phase (crash) Checkpoint Dirty pages Active txn Log pageIDrecLSNpageID transIDlastLSNtransID firstLSN=min(recLSN)

1. Analysis Phase (crash) Checkpoint Dirty pages Active txn Log pageIDrecLSNpageID transIDlastLSNtransID pageIDrecLSNpageID transIDlastLSNtransID Replay history firstLSN

2. Redo Phase Main principle: replay history Process Log forward, starting from firstLSN Read every log record, sequentially Redo actions are not recorded in the log Needs the Dirty Page Table Dan Suciu , Winter

60 2. Redo Phase: Details For each Log entry record LSN: Re-do the action P=u and WRITE(P) But which actions can we skip, for efficiency ? Dan Suciu , Winter 2011

61 2. Redo Phase: Details For each Log entry record LSN: If P is not in Dirty Page then no update If recLSN > LSN, then no update INPUT(P) (read page from disk): If pageLSN > LSN, then no update Otherwise perform update Dan Suciu , Winter 2011

62 2. Redo Phase: Details What happens if system crashes during REDO ? Dan Suciu , Winter 2011

63 2. Redo Phase: Details What happens if system crashes during REDO ? We REDO again ! Each REDO operation is idempotent: doing it twice is the as as doing it once. Dan Suciu , Winter 2011

3. Undo Phase Main principle: “logical” undo Start from end of Log, move backwards Read only affected log entries Undo actions are written in the Log as special entries: CLR (Compensating Log Records) CLRs are redone, but never undone Dan Suciu , Winter

3. Undo Phase: Details “Loser transactions” = uncommitted transactions in Active Transactions Table ToUndo = set of lastLSN of loser transactions Dan Suciu , Winter

3. Undo Phase: Details While ToUndo not empty: Choose most recent (largest) LSN in ToUndo If LSN = regular record : –Undo v –Write a CLR where CLR.undoNextLSN = LSN.prevLSN If LSN = CLR record: –Don’t undo ! if CLR.undoNextLSN not null, insert in ToUndo otherwise, write in log Dan Suciu , Winter

67 3. Undo Phase: Details [Figure 4 from Franklin97] Dan Suciu , Winter 2011

68 3. Undo Phase: Details What happens if system crashes during UNDO ? Dan Suciu , Winter 2011

69 3. Undo Phase: Details What happens if system crashes during UNDO ? We do not UNDO again ! Instead, each CLR is a REDO record: we simply redo the undo Dan Suciu , Winter 2011

70 Physical v.s. Logical Loging Why are redo records physical ? Why are undo records logical ? Dan Suciu , Winter 2011

71 Physical v.s. Logical Loging Why are redo records physical ? Simplicity: replaying history is easy, and idempotent Why are undo records logical ? Required for transaction rollback: this not “undoing history”, but selective undo Dan Suciu , Winter 2011