18-Recovery
18-Recovery
Reliability Management
DB
MG
1
DBMS Architecture
SQL INSTRUCTION
OPTIMIZER
CONCURRENCY CONTROL
MANAGEMENT OF ACCESS
METHODS
Index Files
System DATABASE
Catalog
Data Files
2
DB
MG
Reliability Manager
5
DB
MG
Log file
7
DB
MG
Transaction records
Data modifications
Insert I(T, O, AS)
Delete D(T, O, BS)
Update U(T, O, BS, AS)
where
O is the written object (RID)
AS is the After State (state of object O after the
modification)
BS is the Before State (state of object O before the
modification)
8
DB
MG
System records
9
DB
MG
Log example
10
DB
MG
Undoing and redoing actions
Idempotency property
Undo or Redo can be repeated an arbitary number of
times without changing the final outcome
UNDO (UNDO(action)) = UNDO(action)
Useful for managing crashes during the recovery
process
12
DB
MG
Checkpoint
13
DB
MG
Execution of a checkpoint
14
DB
MG
Checkpoint
After a checkpoint
The effect of all committed transactions is
permanently stored on disk
The state of data pages written by active
transactions is unknown
15
DB
MG
Dump
16
DB
MG
Rules for writing the log
17
DB
MG
Write Ahead Log
18
DB
MG
Commit precedence
19
DB
MG
Practical rules for writing the log
20
DB
MG
Practical rules for writing the log
21
DB
MG
Commit record
22
DB
MG
Protocols for writing the log and the database
Log
W(x) W(y)
DB
23
DB
MG
Protocols for writing the log and the database
Log
W(x) W(y)
DB
Log
W(x) W(y)
DB
26
DB
MG
Database Management Systems
Recovery Management
DB
MG
27
Types of failures
System failure
Caused by software problems or power supply
interruptions
It causes losing the main memory content (DBMS
buffer) but not the disk (both database and log)
Media failure
Caused by failure of devices managing secondary
memory
It causes losing the database content on disk, but
not the log content (stored in stable storage)
28
DB
MG
Fail-stop model
STOP
Normal
Operation
RECOVERY
29
DB
MG
Recovery
30
DB
MG
Database Management Systems
Warm Restart
DB
MG
31
Transaction categories
tC tF time
T1
T2
T3
T4
T5
34
DB
MG
Warm restart algorithm
35
DB
MG
Warm restart algorithm
36
DB
MG
Warm restart algorithm
tC tF time
T1
T2
T3
T4
T5
UNDO = {T2,T3}
tC = time of last checkpoint
REDO = { }
DB tF = time of failure 37
MG
Warm restart algorithm
tC t1 tF time
T1
T2
T3
T4
T5
UNDO = {T2,T3,T4}
tC = time of last checkpoint
REDO = { }
DB tF = time of failure 38
MG
Warm restart algorithm
tC t1 t2 tF time
T1
T2
T3
T4
T5
UNDO = {T3,T4}
tC = time of last checkpoint
REDO = {T2}
DB tF = time of failure 39
MG
Warm restart algorithm
tC t1 t2 t3 tF time
T1
T2
T3
T4
T5
UNDO = {T3,T4,T5}
tC = time of last checkpoint
REDO = {T2}
DB tF = time of failure 40
MG
Warm restart algorithm
tC t1 t2 t3 t4 tF time
T1
T2
T3
T4
T5
Final lists
UNDO = {T3,T5}
tC = time of last checkpoint
REDO = {T2,T4}
DB tF = time of failure 41
MG
Warm restart algorithm
3. Data Recovery
a) The log is read backwards from the time of
failure until the beginning of the oldest
transaction in the UNDO list
Actions performed by all transactions in the UNDO
list are undone
For each transaction the begin record should be
reached
even if it is earlier than the last checkpoint
42
DB
MG
Warm restart algorithm
b) The log is read forward from the beginning of the
oldest transaction in the REDO list
Actions of transactions in the REDO list are applied
to the database
For each transaction, the starting point is its begin
record
43
DB
MG
Warm restart example
Log snippet
B(T1) B(T2) U(T2, O1, B1 , A1) I(T1, O2, A2) B(T3)
C(T1) B(T4) U(T3, O2, B3, A3) U(T4, O3, B4, A4)
CK(T2, T3, T4) C(T4) B(T5) U(T3, O3, B5, A5)
U(T5, O4, B6, A6) D(T3, O3, B7) A(T3) C(T5)
I(T2, O6, A8) failure
44
DB
MG
Warm restart example
Log snippet
B(T1) B(T2) U(T2, O1, B1 , A1) I(T1, O2, A2) B(T3)
C(T1) B(T4) U(T3, O2, B3, A3) U(T4, O3, B4, A4)
CK(T2, T3, T4) C(T4) B(T5) U(T3, O3, B5, A5)
U(T5, O4, B6, A6) D(T3, O3, B7) A(T3) C(T5)
I(T2, O6, A8)
1. At the checkpoint
UNDO = {T2,T3,T4}
REDO = { }
45
DB
MG
Warm restart example
B(T1) B(T2) U(T2, O1, B1 , A1) I(T1, O2, A2) B(T3)
C(T1) B(T4) U(T3, O2, B3, A3) U(T4, O3, B4, A4)
CK(T2, T3, T4) C(T4) B(T5) U(T3, O3, B5, A5)
U(T5, O4, B6, A6) D(T3, O3, B7) A(T3) C(T5)
I(T2, O6, A8)
2. Read the log forward
Operation UNDO REDO
CK {T2,T3,T4} {}
46
DB
MG
Warm restart example
B(T1) B(T2) U(T2, O1, B1 , A1) I(T1, O2, A2) B(T3)
C(T1) B(T4) U(T3, O2, B3, A3) U(T4, O3, B4, A4)
CK(T2, T3, T4) C(T4) B(T5) U(T3, O3, B5, A5)
U(T5, O4, B6, A6) D(T3, O3, B7) A(T3) C(T5)
I(T2, O6, A8)
2. Read the log forward
Operation UNDO REDO
CK {T2,T3,T4} {}
C(T4) {T2,T3} {T4}
B(T5) {T2,T3,T5} {T4}
A(T3) {T2,T3,T5} {T4}
Final
C(T5) {T2,T3} {T4,T5} lists 47
DB
MG
Warm restart example
B(T1) B(T2) U(T2, O1, B1 , A1) I(T1, O2, A2) B(T3)
C(T1) B(T4) U(T3, O2, B3, A3) U(T4, O3, B4, A4)
CK(T2, T3, T4) C(T4) B(T5) U(T3, O3, B5, A5)
U(T5, O4, B6, A6) D(T3, O3, B7) A(T3) C(T5)
I(T2, O6, A8)
3. Undo transactions in UNDO = {T2,T3}
a) DELETE O6
b) INSERT O3 = B7
c) O3 = B5
d) O2 = B3
e) O1 = B1
48
DB
MG
Warm restart example
B(T1) B(T2) U(T2, O1, B1 , A1) I(T1, O2, A2) B(T3)
C(T1) B(T4) U(T3, O2, B3, A3) U(T4, O3, B4, A4)
CK(T2, T3, T4) C(T4) B(T5) U(T3, O3, B5, A5)
U(T5, O4, B6, A6) D(T3, O3, B7) A(T3) C(T5)
I(T2, O6, A8)
4. Redo transactions in REDO = {T4,T5}
a) O3 = A4
b) O4 = A6
49
DB
MG
Warm restart example
tC tF time
T1
T2
T3 Abort
T4
T5
REDO = {T4,T5}
tF = time of failure
UNDO = {T2,T3}
50
DB
MG
Database Management Systems
Cold Restart
DB
MG
51
Cold restart
52
DB
MG
Cold restart
53
DB
MG