15-440 Distributed Systems: Fault Tolerance, Logging and Recovery Thursday Oct 8, 2015
15-440 Distributed Systems: Fault Tolerance, Logging and Recovery Thursday Oct 8, 2015
Lecture 10
Fault Tolerance, Logging and recovery
Thursday Oct 8th, 2015
Logistics Updates
• HW2 released
• Due Oct 13th
• (*No Late Days*) => time to prepare for Mid term
2
Today's Lecture Outline
3
What is Fault Tolerance?
9
Achieving Fault Tolerance in DS
15
Recovery – Stable Storage
17
Goal: Make transactions Reliable
18
Challenges:
19
Shadow Paging Vs WAL
• Shadow Pages
• Provide Atomicity and Durability, “page” = unit of storage
• Idea: When writing a page, make a “shadow” copy
• No references from other pages, edit easily!
• ABORT: discard shadow page
• COMMIT: Make shadow page “real”. Update pointers to
data on this page from other pages (recursive). Can be
done atomically
• Essentially “copy-on-write” to avoid in-place page update
20
Shadow Paging vs WAL
• Write-Ahead-Logging
• Provide Atomicity and Durability
• Idea: create a log recording every update to database
• Updates considered reliable when stored on disk
• Updated versions are kept in memory (page cache)
• Logs typically store both REDO and UNDO operations
• After a crash, recover by replaying log entries to
reconstruct correct state
21
Write-Ahead Logging
22
Write-Ahead Logging
23
Write-Ahead-Logging
• Commit a transaction
• Log file up to date until commit entry
• Don't update actual disk pages, log file has information
• Keep "tail" of log file in memory => not commits
• If the tail gets wiped out (crash), then partially executed
transactions will lost. Can still recover to reliable state
• Abort a transaction
• Locate last entry from TT, undo all updates so far
• Use PrevLSN to revert in-memory pages to start of TXN
• If page on disk needs undo, wait (come back to this)
24
Recovery using WAL – 3 passes
• Analysis Pass
• Reconstruct TT and DPT (from start or last checkpoint)
• Get copies of all pages at the start
• Recovery Pass (redo pass)
• Replay log forward, make updates to all dirty pages
• Bring everything to a state at the time of the crash
• Undo Pass
• Replay log file backward, revert any changes made by
transactions that had not committed (use PrevLSN)
• For each write Compensation Log Record (CLR)
• Once you reach BEGIN TXN, write an END TXN entry
25
WAL can be integrated with 2PC
26
Optimizing WAL
• As described earlier:
• Replay operations back to the beginning of time
• Log file would be kept forever, (entire Database)
• In practice, we can do better with CHECKPOINT
• Periodically save DPT, TT
• Store any dirty pages to disk, indicate in LOG file
• Prune initial portion of log file: All transactions upto
checkpoint have been committed or aborted.
27
Summary
28
Transactions: ACID Properties
30
Transactions: ACID Properties
• Isolation: Also means serializability. Each
transaction executes as if it were the only one with
the ability to RD/WR shared global state.