Lecture 17: Data Storage and Recovery

Slides:



Advertisements
Similar presentations
1 CS411 Database Systems 12: Recovery obama and eric schmidt sysadmin song
Advertisements

1 Lecture 12: Transactions: Recovery. 2 Outline Recovery Undo Logging Redo Logging Undo/Redo Logging Book Section 15.1, 15.2, 23, 24, 25.
ICS 214A: Database Management Systems Fall 2002
1 CSIS 7102 Spring 2004 Lecture 9: Recovery (approaches) Dr. King-Ip Lin.
1 CPS216: Data-intensive Computing Systems Failure Recovery Shivnath Babu.
CS 245Notes 081 CS 245: Database System Principles Notes 08: Failure Recovery Hector Garcia-Molina.
1 CSIS 7102 Spring 2004 Lecture 8: Recovery (overview) Dr. King-Ip Lin.
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,
1 ICS 214A: Database Management Systems Fall 2002 Lecture 16: Crash Recovery Professor Chen Li.
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.
Cs4432recovery1 CS4432: Database Systems II Database Consistency and Violations?
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.
1 Anna Östlin Pagh and Rasmus Pagh IT University of Copenhagen Advanced Database Technology March 25, 2004 SYSTEM FAILURES Lecture based on [GUW ,
Cs4432recovery1 CS4432: Database Systems II Lecture #20 Failure Recovery Professor Elke A. Rundensteiner.
July 16, 2015ICS 5411 Coping With System Failure Chapter 17 of GUW.
TRANSACTIONS A sequence of SQL statements to be executed "together“ as a unit: A money transfer transaction: Reasons for Transactions : Concurrency control.
1 Recovery Control (Chapter 17) Redo Logging CS4432: Database Systems II.
1 CPS216: Advanced Database Systems Notes 10: Failure Recovery Shivnath Babu.
Lecture 11: DMBS Internals
1 Lecture 14: Transactions in SQL Monday, October 30, 2006.
1 Transaction Management. 2 Outline Transaction management –motivation & brief introduction –major issues recovery concurrency control Recovery.
HANDLING FAILURES. Warning This is a first draft I welcome your corrections.
CMPT 454, Simon Fraser University, Fall 2009, Martin Ester 294 Database Systems II Coping With System Failures.
Chapter 16 Recovery Yonsei University 1 st Semester, 2015 Sanghyun Park.
DMBS Internals I. What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently.
1 CSE544 Transactions: Recovery Thursday, January 27, 2011 Dan Suciu , Winter 2011.
DMBS Internals I February 24 th, What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the.
DMBS Internals I. What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently.
DMBS Architecture May 15 th, Generic Architecture Query compiler/optimizer Execution engine Index/record mgr. Buffer manager Storage manager storage.
1 Ullman et al. : Database System Principles Notes 08: Failure Recovery.
1 Lecture 28: Recovery Friday, December 5 th, 2003.
03/30/2005Yan Huang - CSCI5330 Database Implementation – Recovery Recovery.
1 Lecture 15: Data Storage, Recovery Monday, February 13, 2006.
What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently and safely. Provide.
1 Lecture 16: Data Storage Wednesday, November 6, 2006.
1 Advanced Database Systems: DBS CB, 2 nd Edition Recovery Ch. 17.
Database Recovery Techniques
CS422 Principles of Database Systems Failure Recovery
Recovery Control (Chapter 17)
Transactional Recovery and Checkpoints
Lecture 13: Recovery Wednesday, February 2, 2005.
Advanced Database Systems: DBS CB, 2nd Edition
Recovery 6/4/2018.
Lecture 16: Data Storage Wednesday, November 6, 2006.
CSE544: Transactions Recovery Wednesday, 4/19/2006.
Database Applications (15-415) DBMS Internals- Part XIII Lecture 22, November 15, 2016 Mohammad Hammoud.
CS4432: Database Systems II
File Processing : Recovery
Database System Principles Notes 08: Failure Recovery
CS 245: Database System Principles Notes 08: Failure Recovery
Lecture 11: DMBS Internals
CPSC-608 Database Systems
Database Applications (15-415) DBMS Internals- Part XIII Lecture 25, April 15, 2018 Mohammad Hammoud.
CS 245: Database System Principles Notes 08: Failure Recovery
Lecture 15: Midterm Review Data Storage
Lecture 28 Friday, December 7, 2001.
Recovery System.
Introduction to Database Systems CSE 444 Lectures 15-16: Recovery
Introduction to Database Systems CSE 444 Lecture 14: Transactions in SQL October 26, 2007.
Lecture 5: Transactions in SQL
CPSC-608 Database Systems
Database Applications (15-415) DBMS Internals- Part XIII Lecture 24, April 14, 2016 Mohammad Hammoud.
Lecture 18: DMBS Overview and Data Storage
Data-intensive Computing Systems Failure Recovery
Lecture 16: Recovery Friday, November 4, 2005.
Lecture 15: Data Storage Tuesday, February 20, 2001.
Presentation transcript:

Lecture 17: Data Storage and Recovery Monday, November 8, 2004

Outline Disks Recovery using undo logging 17.2 Redo logging 17.3 Redo/undo 17.4 (probably next lecture)

The Mechanics of Disk Mechanical characteristics: Cylinder Mechanical characteristics: Rotation speed (5400RPM) Number of platters (1-30) Number of tracks (<=10000) Number of bytes/track(105) Spindle Tracks Disk head Sector Unit of read or write: disk block Once in memory: page Typically: 4k or 8k or 16k Arm movement Platters Arm assembly

Disk Access Characteristics Disk latency = time between when command is issued and when data is in memory Disk latency = seek time + rotational latency Seek time = time for the head to reach cylinder 10ms – 40ms Rotational latency = time for the sector to rotate Rotation time = 10ms Average latency = 10ms/2 Transfer time = typically 40MB/s Disks read/write one block at a time

Average Seek Time Suppose we have N tracks, what is the average seek time ? Getting from cylinder x to y takes time |x-y|

Buffer Management in a DBMS Page Requests from Higher Levels READ WRITE BUFFER POOL disk page free frame INPUT OUTUPT MAIN MEMORY DISK DB choice of frame dictated by replacement policy Data must be in RAM for DBMS to operate on it! Table of <frame#, pageid> pairs is maintained. LRU is not always good. 4

Buffer Manager Manages buffer pool: the pool provides space for a limited number of pages from disk. Needs to decide on page replacement policy LRU Clock algorithm Enables the higher levels of the DBMS to assume that the needed data is in main memory.

Buffer Manager Why not use the Operating System for the task?? - DBMS may be able to anticipate access patterns - Hence, may also be able to perform prefetching - DBMS needs the ability to force pages to disk, for recovery purposes

Recovery Type of Crash Prevention Wrong data entry Constraints and Data cleaning Disk crashes Redundancy: e.g. RAID, archive Fire, theft, bankruptcy… Buy insurance, Change jobs… System failures: e.g. power DATABASE RECOVERY Most frequent

System Failures Each transaction has internal state When system crashes, internal state is lost Don’t know which parts executed and which didn’t Remedy: use a log A file that records every single action of the transaction

Transactions Assumption: the database is composed of elements Usually 1 element = 1 block Can be smaller (=1 record) or larger (=1 relation) Assumption: each transaction reads/writes some elements

Primitive Operations of Transactions 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

Example START TRANSACTION READ(A,t); t := t*2; WRITE(A,t); READ(B,t); WRITE(B,t) COMMIT; Atomicity: BOTH A and B are multiplied by 2

Action t Mem A Mem B Disk A Disk B INPUT(A) 8 READ(A,t) t:=t*2 16 Transaction Buffer pool Disk Action t Mem A Mem B Disk A Disk B INPUT(A) 8 READ(A,t) t:=t*2 16 WRITE(A,t) INPUT(B) READ(B,t) WRITE(B,t) OUTPUT(A) OUTPUT(B)

Crash occurs after OUTPUT(A), before OUTPUT(B) We lose atomicity Action t Mem A Mem B Disk A Disk B INPUT(A) 8 READ(A,t) t:=t*2 16 WRITE(A,t) INPUT(B) READ(B,t) WRITE(B,t) OUTPUT(A) OUTPUT(B) Crash ! Crash occurs after OUTPUT(A), before OUTPUT(B) We lose atomicity

The Log An append-only file containing log records Note: multiple transactions run concurrently, log records are interleaved After a system crash, use log to: Redo some transaction that didn’t commit Undo other transactions that didn’t commit Three kinds of logs: undo, redo, undo/redo

Undo Logging Log records <START T> <COMMIT T> transaction T has begun <COMMIT T> T has committed <ABORT T> T has aborted <T,X,v> T has updated element X, and its old value was v

INPUT(B) Action T Mem A Mem B Disk A Disk B Log <START T> INPUT(A) 8 READ(A,t) t:=t*2 16 WRITE(A,t) <T,A,8> INPUT(B) READ(B,t) WRITE(B,t) <T,B,8> OUTPUT(A) OUTPUT(B) COMMIT <COMMIT T>

Crash ! WHAT DO WE DO ? INPUT(B) Action T Mem A Mem B Disk A Disk B Log <START T> INPUT(A) 8 READ(A,t) t:=t*2 16 WRITE(A,t) <T,A,8> INPUT(B) READ(B,t) WRITE(B,t) <T,B,8> OUTPUT(A) OUTPUT(B) COMMIT <COMMIT T> Were we UNDO the changes, writing back A=8, and B=8. The transaction is atomic: none of its actions was executed Crash ! WHAT DO WE DO ?

Crash ! WHAT DO WE DO ? INPUT(B) Action T Mem A Mem B Disk A Disk B Log <START T> INPUT(A) 8 READ(A,t) t:=t*2 16 WRITE(A,t) <T,A,8> INPUT(B) READ(B,t) WRITE(B,t) <T,B,8> OUTPUT(A) OUTPUT(B) COMMIT <COMMIT T> Here we don’t need to do any recovery actions. The transaction is still atomic: both actions have been executed. Crash ! WHAT DO WE DO ?

After Crash In the first example: In the second example We UNDO both changes: A=8, B=8 The transaction is atomic, since none of its actions has been executed In the second example We don’t undo anything The transaction is atomic, since both it’s actions have been executed

Undo-Logging Rules U1: If T modifies X, then <T,X,v> must be written to disk before OUTPUT(X) U2: If T commits, then OUTPUT(X) must be written to disk before <COMMIT T> Hence: OUTPUTs are done early, before the transaction commits

INPUT(B) Action T Mem A Mem B Disk A Disk B Log <START T> INPUT(A) 8 READ(A,t) t:=t*2 16 WRITE(A,t) <T,A,8> INPUT(B) READ(B,t) WRITE(B,t) <T,B,8> OUTPUT(A) OUTPUT(B) COMMIT <COMMIT T>

Recovery with Undo Log After system’s crash, run recovery manager Idea 1. Decide for each transaction T whether it is completed or not <START T>….<COMMIT T>…. = yes <START T>….<ABORT T>……. = yes <START T>……………………… = no Idea 2. Undo all modifications by incomplete transactions

Recovery with Undo Log Recovery manager: Read log from the end; cases: <COMMIT T>: mark T as completed <ABORT T>: mark T as completed <T,X,v>: if T is not completed then write X=v to disk else ignore <START T>: ignore

Recovery with Undo Log Question1 in class: Which updates are undone ? … <T6,X6,v6> <START T5> <START T4> <T1,X1,v1> <T5,X5,v5> <T4,X4,v4> <COMMIT T5> <T3,X3,v3> <T2,X2,v2> Question1 in class: Which updates are undone ? Question 2 in class: How far back do we need to read in the log ? crash

Recovery with Undo Log Note: all undo commands are idempotent If we perform them a second time, no harm is done E.g. if there is a system crash during recovery, simply restart recovery from scratch

Recovery with Undo Log When do we stop reading the log ? We cannot stop until we reach the beginning of the log file This is impractical Instead: use checkpointing

Checkpointing Checkpoint the database periodically Stop accepting new transactions Wait until all current transactions complete Flush log to disk Write a <CKPT> log record, flush Resume transactions

Undo Recovery with Checkpointing … <T9,X9,v9> (all completed) <CKPT> <START T2> <START T3 <START T5> <START T4> <T1,X1,v1> <T5,X5,v5> <T4,X4,v4> <COMMIT T5> <T3,X3,v3> <T2,X2,v2> other transactions During recovery, Can stop at first <CKPT> transactions T2,T3,T4,T5

Nonquiescent Checkpointing Problem with checkpointing: database freezes during checkpoint Would like to checkpoint while database is operational Idea: nonquiescent checkpointing Quiescent = being quiet, still, or at rest; inactive Non-quiescent = allowing transactions to be active

Nonquiescent Checkpointing Write a <START CKPT(T1,…,Tk)> where T1,…,Tk are all active transactions Continue normal operation When all of T1,…,Tk have completed, write <END CKPT>

Undo Recovery with Nonquiescent Checkpointing … <START CKPT T4, T5, T6> <END CKPT> earlier transactions plus T4, T5, T5 During recovery, Can stop at first <CKPT> T4, T5, T6, plus later transactions Answer: because if the system crashes before it writes <END CKPT> then we cannot use the checkpoint. We use <END CKPT> to ensure that the system didn’t crash and the checkpoint terminated. later transactions Q: why do we need <END CKPT> ?

Redo Logging Log records <START T> = transaction T has begun <COMMIT T> = T has committed <ABORT T>= T has aborted <T,X,v>= T has updated element X, and its new value is v

Action T Mem A Mem B Disk A Disk B Log <START T> READ(A,t) 8 t:=t*2 16 WRITE(A,t) <T,A,16> READ(B,t) WRITE(B,t) <T,B,16> <COMMIT T> OUTPUT(A) OUTPUT(B)

Redo-Logging Rules R1: If T modifies X, then both <T,X,v> and <COMMIT T> must be written to disk before OUTPUT(X) Hence: OUTPUTs are done late

Action T Mem A Mem B Disk A Disk B Log <START T> READ(A,t) 8 t:=t*2 16 WRITE(A,t) <T,A,16> READ(B,t) WRITE(B,t) <T,B,16> <COMMIT T> OUTPUT(A) OUTPUT(B)

Recovery with Redo Log After system’s crash, run recovery manager Step 1. Decide for each transaction T whether it is completed or not <START T>….<COMMIT T>…. = yes <START T>….<ABORT T>……. = yes <START T>……………………… = no Step 2. Read log from the beginning, redo all updates of committed transactions

Recovery with Redo Log <START T1> <T1,X1,v1> <COMMIT T2> <T3,X4,v4> <T1,X5,v5> …

Nonquiescent Checkpointing Write a <START CKPT(T1,…,Tk)> where T1,…,Tk are all active transactions Flush to disk all blocks of committed transactions (dirty blocks), while continuing normal operation When all blocks have been written, write <END CKPT>

Redo Recovery with Nonquiescent Checkpointing … <START T1> <COMMIT T1> … <START T4> <START CKPT T4, T5, T6> <END CKPT> <START CKPT T9, T10> Step 2: redo from the earliest start of T4, T5, T6 ignoring transactions committed earlier Step 1: look for The last <END CKPT> All OUTPUTs of T1 are known to be on disk

Comparison Undo/Redo Undo logging: Redo logging OUTPUT must be done early If <COMMIT T> is seen, T definitely has written all its data to disk (hence, don’t need to redo) – inefficient Redo logging OUTPUT must be done late If <COMMIT T> is not seen, T definitely has not written any of its data to disk (hence there is not dirty data on disk, no need to undo) – inflexible Would like more flexibility on when to OUTPUT: undo/redo logging (next)

Undo/Redo Logging Log records, only one change <T,X,u,v>= T has updated element X, its old value was u, and its new value is v

Undo/Redo-Logging Rule UR1: If T modifies X, then <T,X,u,v> must be written to disk before OUTPUT(X) Note: we are free to OUTPUT early or late relative to <COMMIT T>

Can OUTPUT whenever we want: before/after COMMIT Action T Mem A Mem B Disk A Disk B Log <START T> REAT(A,t) 8 t:=t*2 16 WRITE(A,t) <T,A,8,16> READ(B,t) WRITE(B,t) <T,B,8,16> OUTPUT(A) <COMMIT T> OUTPUT(B) Can OUTPUT whenever we want: before/after COMMIT

Recovery with Undo/Redo Log After system’s crash, run recovery manager Redo all committed transaction, top-down Undo all uncommitted transactions, bottom-up

Recovery with Undo/Redo Log <START T1> <T1,X1,v1> <START T2> <T2, X2, v2> <START T3> <T1,X3,v3> <COMMIT T2> <T3,X4,v4> <T1,X5,v5> …