Transaction Processing Concepts Concurrency Control and Recovery Part 3
Transaction Processing Concepts Concurrency Control and Recovery Part 3
PART 3
1
Objectives of the Lecture
• Discuss database recovery issues:
– Recovery from catastrophic (like disc crash) failure, and
– recovery from a non-catastrophic failure
Requirements for Database Consistency -
recall
• Concurrency Control
– The concurrent execution of many different transactions submitted by
various users must be organized such that each transaction does not
interfere with another transaction in a way that produces incorrect
results. i.e. the concurrent execution of transactions must be such that
each transaction appears to execute in isolation.
• Recovery
– System failures, either hardware or software, must not result in an
inconsistent database
Transaction as a Recovery Unit
• If any of the below occurs between the begin and end of a
transaction, the database will be inconsistent!
– Computer Failure (system crash)
– A transaction or system error
– Local errors or exception conditions detected by the
transaction
– Concurrency control enforcement
– Disk failure
– Physical problems and catastrophes
• The database is restored to some state from the past so that a
correct state—close to the time of failure—can be reconstructed
from the past state.
• The statements COMMIT and ROLLBACK (or their equivalent)
ensure Transaction Atomicity
Transaction as a Recovery Unit(2)
• A DBMS ensures that if a transaction executes
some updates and then a failure occurs before
the transaction reaches normal termination,
then those updates are undone.
• A DBMS also ensures that if a transaction
executes some updates and commits, then a
failure occurs thereafter, then those updates
are redone.
Why “Database Recovery Techniques”?
System crash
Transaction error
System error
T1 Crash Local error
T2 Disk failure
T3 Catastrophe
Time
T1
T2 Crash
T3
Time
ROLLBACK ROLLBACK
READ, WRITE
terminated
failed
If a system failure occurs, searching the log and rollback the transactions that
have written into the log a
[start_transaction, transaction-id]
[write_item, transaction-id, X, old_value, new_value]
but have not recorded into the log a [commit, transaction-id]
Physical View - How they work - (1)
Memory
Disk
A DBMS cache
copy
(buffers)
B a
flush Directory
(address:A,a,1)
B’
Disk pages/blocks b (address:B,b,0)
Action :
1) Check the directory whether in the cache
2) If none, copy from disk pages to the cache
3) For the copy, old buffers needs to be flushed
from the cache to the disk pages
Physical View - How they work - (2)
Memory
Disk
A DBMS cache
copy
(buffers)
B a update
flush Directory
(address:A,a,1)
B’
Disk pages/blocks b (address:B,b,0)
B’
Disk pages/blocks b
B-b : “shadowing”
Physical View - How they work - (4)
Memory
Disk
DBMS cache
B
copy b update
update
B’ Data Log
Data blocks flush
blocks blocks
Log blocks
cache cache
Can be Used for other
transactions (T3)
Updated
data by T2
Advantage :
buffer space saving
before T2 commits
Basic Concepts: Steal & No-Force (2)
No-Force strategy : a transaction need not be
written to disk immediately
when it commits
T1
commit Advantage :
commit
T2 I/O operations saving
T3
Time
cache cache
If T3 needs the same data, it
Updated must be copied again
data by T2
Force strategy
when T2 commits
Basic Concepts: Checkpointing
At a Checkpoint
- temporarily suspend all transactions
- Force write results of all update operations of committed
transactions from memory to disk
- A record is written into the log file and log force written to disk.
([checkpoint])
- Resume executing transactions
• Periodically done (e.g. every n min. or every n transaction)
Checkpoint
T1 Crash
T2
T3
Time
Transaction Rollback (1)
Rollback / Roll foward
Recovery method
1 : Not necesary
T1
Crash 2 : Roll foward
T2
T3 3 : Rollback
T4 4 : Roll forward
T5 5 : ignore
Time
Checkpoint
Checkpoint Crash
System Log A C
[checkpoint] $10 $30,000
[start_transaction, T1]
[read_item, T1, A] $10
[write_item, T1, A, 10, 2010] $2,010
[start_transaction, T2] - T2 uses value
[read_item, T2, A] $2,010
[write_item, T2, A, 2010, 510]
modified by T1
$510
[read_item, T1, B] (also needs
[read_item, T2, C] $30,000 rollback)
[write_item, T2, C, 1500, 31500] $31,500
~~~ CRASH ~~~~
Categorization of Recovery Algorithm
• Deferred update – the No-UNDO/REDO algorithm
Immediate update –
the UNDO/REDO algorithm
UNDO/No-REDO
Deferred Update
Deferred Update:
– Idea is that no actual update of the database until after a transaction reaches
its commit point
1. During execution updates are recorded in log
2. Just before transaction commit point, all log updates are written to the log
file in disk, and then the transaction commits.
3. After that, update the database
FAILURE!
• REDO committed transaction to database from log entries
• No UNDO necessary because database never altered
Immediate Update
Immediate Update general concept:
– the database may be updated by some operations
of a transaction before it reaches its commit point.
• Thus an update X recorded in log is also leads to an
update X in database
• There are two versions:
– one, where all updates are written to disk before
transaction commits
– Two, where transaction commits before all its
updates are written to disk
Recovery Timeline
Checkpoint Failure
Time
T1
T2
T3
T4
T5
Recovery Processes summary
• Depend on timing of database writes (force or
no-force)
• Immediate update approach:
– Before commit
– Log records written first (write-ahead log protocol)
• Deferred update approach
– After commit
– Undo operations not needed
Other methods for recovery
• Shadow paging – read on your own