Академический Документы
Профессиональный Документы
Культура Документы
Chapter 18
D urability:
Motivation
Atomicity:
Durability:
T1
T2
T3
T4
T5
crash!
Assumptions
No Steal
Force
No Force
Steal
Trivial
Desired
#1 guarantees Atomicity.
#2 guarantees Durability.
WAL &
the Log
DB
LSNs
pageLSNs
RAM
flushedLSN
pageLSN
Log tail
in RAM
pageLSN flushedLSN
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke
Log Records
LogRecord fields:
update
records
only
prevLSN
XID
type
pageID
length
offset
before-image
after-image
10
Transaction Table:
One entry per active Xact.
Contains XID, status (running/commited/aborted),
and lastLSN.
11
Strict 2PL.
Write-Ahead Logging.
12
Checkpointing
13
RAM
DB
Data pages
each
with a
pageLSN
Xact Table
lastLSN
status
master record
flushedLSN
14
No crash involved.
15
Abort, cont.
No problem!
You continue logging while you UNDO!!
CLR has one extra field: undonextLSN
Points to the next LSN to undo (i.e. the prevLSN of the record
were currently undoing).
16
Transaction Commit
Commit() returns.
Write end record to log.
17
Smallest
recLSN in
dirty page
table after
Analysis
Last chkpt
CRASH
A R U
18
19
To REDO an action:
Reapply logged action.
Set pageLSN to LSN. No additional logging!
20
21
Example of Recovery
LSN
RAM
Xact Table
lastLSN
status
Dirty Page Table
recLSN
flushedLSN
ToUndo
00
LOG
begin_checkpoint
05
end_checkpoint
10
update: T1 writes P5
20
update T2 writes P3
30
T1 abort
40
45
T1 End
50
update: T3 writes P1
60
update: T2 writes P5
prevLSNs
CRASH, RESTART
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke
22
RAM
Xact Table
lastLSN
status
Dirty Page Table
recLSN
flushedLSN
ToUndo
LOG
begin_checkpoint, end_checkpoint
10
update: T1 writes P5
20
update T2 writes P3
30
T1 abort
40,45
undonextLSN
50
update: T3 writes P1
60
update: T2 writes P5
CRASH, RESTART
70
80,85
90
23
24
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.
25
Summary, Cont.
Checkpointing: A quick way to limit the
amount of log to scan on recovery.
Recovery works in 3 phases:
26