Concurrency Control & Recovery
Concurrency Control & Recovery
Concurrency Control & Recovery
•Concurrency control
Lock based protocol
2 phase locking protocol
•Failure Classification
• Storage Structure
• Log-Based Recovery
Deferred Update
Immediate Update
• Check points
•Shadow Paging
Concurrency Control
• A database must provide a mechanism that will ensure that all possible
schedules are
– either conflict or view serializable, and
• A policy in which only one transaction can execute at a time generates serial
schedules, but provides a poor degree of concurrency
• Goal – to develop concurrency control protocols that will assure serializability.
• Concurrency control and locking is the mechanism used by DBMSs for the
sharing of data. Atomicity, consistency, and isolation are achieved through
concurrency control and locking.
• When many people may be reading the same data item at the same time, it is
usually necessary to ensure that only one application at a time can change a data
item.
• Locking is a way to do this. Because of locking, all changes to a particular data
item will be made in the correct order in a transaction.
Lock-Based Protocols
• A lock is a mechanism to control concurrent access to a data item
• Data items can be locked in two modes :
1. exclusive (X) mode. Data item can be both read as well as
written. X-lock is requested using lock-X instruction.
2. shared (S) mode. Data item can only be read. S-lock is
requested using lock-S instruction.
• Lock requests are made to concurrency-control manager. Transaction can proceed
only after request is granted.
Lock-Based Protocols (Cont.)
• Lock-compatibility matrix
Transaction T1 Log
C = 2800
Deferred Database Modification (Example)
• Redo(Ti)
which sets the value of all data items updated by transaction Ti
to the new values in the order of log records.
• Determine which transactions need to redo (Failure 발생시 )
(1) redo :
The log contains both the record <T1, start > and the record
< T1, commit >.
This transaction may be or may not be stored disk physically.
(2) Reexecute transaction :
Other case.
Deferred Database Modification (Example)
• Example of the System Crash before the Completion of the Transactions
<T1, start> <T1, start> <T1, start>
<T1, A , 900> <T1, A , 900> <T1, A , 900>
<T1, B , 2100> <T1, B , 2100> <T1, B , 2100>
<T1, commit> <T1, commit>
<T2, start> <T2, start>
<T2, C , 2800> <T2, C , 2800>
<T2, commit>
(a) (b) (c)
• Undo(Ti)
which restores the value of all data items updated by transaction
Ti to the old values.
Immediate Database Modification (Example)
• State of log and database
- A result of the execution T1 and T2, Note that the value of A is
changed in database before partially committed :
Log Database
<T1, start>
<T1, A , 1000, 900>
A = 900
<T1, B , 2000, 2100>
B = 2100 uncommitted update,
<T1, commit> if transaction is aborted,
<T2, start> new values must be recovered
<T1, C , 3000, 2800> old values.
C = 2800
<T2, commit>
Immediate Database Modification (Example)
• Two Recovery Schemes :
(1) Undo(Ti) :
If the log contains the record <Ti, start > but does not contain
the record < Ti, commit >.
This transaction is crashed during execution. Thus transaction Ti
needs to be undone.
(2) Redo(Ti) :
If the log contains both the record <Ti, start > and the record
< Ti, commit >.
This transaction is crashed just after partially committed.
Thus transaction Ti needs to be undone.
Immediate Database Modification (Example)
• Example of the System Crash before the Completion of the Transactions
<T1, start> <T1, start> <T1, start>
<T1, A , 1000, 900> <T1, A , 1000, 900> <T1, A , 1000, 900>
<T1, B , 2000, 2100> <T1, B , 2000, 2100> <T1, B , 2000, 2100>
<T1, commit> <T1, commit>
<T2, start> <T2, start>
<T1, C , 3000, 2800> <T1, C , 3000, 2800>
<T2, commit>
(a) (b) (c)