Log-Based Recovery A log is kept on stable storage. The log is a sequence of log records,and maintains a record of update activities on the database. When transaction 7;starts,it registers itself by writing a <T;start>log record Before T;executes write(X),a log record <Ti X,Vi,V2> is written,where Vi is the value of X before the write (the old value), and V2 is the value to be written to X(the new value) When T;finishes it last statement,the log record <T;commit>is written. Two approaches using logs Deferred database modification Immediate database modification Database System Concepts-6th Edition 16.12 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 16.12 ©Silberschatz, Korth and Sudarshan th Edition Log-Based Recovery A log is kept on stable storage. The log is a sequence of log records, and maintains a record of update activities on the database. When transaction Ti starts, it registers itself by writing a <Ti start>log record Before Ti executes write(X), a log record <Ti , X, V1 , V2> is written, where V1 is the value of X before the write (the old value), and V2 is the value to be written to X (the new value). When Ti finishes it last statement, the log record <Ti commit> is written. Two approaches using logs Deferred database modification Immediate database modification
Immediate Database Modification The immediate-modification scheme allows updates of an uncommitted transaction to be made to the buffer,or the disk itself. before the transaction commits Update log record must be written before database item is written We assume that the log record is output directly to stable storage (Will see later that how to postpone log record output to some extent)) Output of updated blocks to stable storage can take place at any time before or after transaction commit Order in which blocks are output can be different from the order in which they are written. The deferred-modification scheme performs updates to buffer/disk only at the time of transaction commit Simplifies some aspects of recovery But has overhead of storing local copy Database System Concepts-6th Edition 16.13 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 16.13 ©Silberschatz, Korth and Sudarshan th Edition Immediate Database Modification The immediate-modification scheme allows updates of an uncommitted transaction to be made to the buffer, or the disk itself, before the transaction commits Update log record must be written before database item is written We assume that the log record is output directly to stable storage (Will see later that how to postpone log record output to some extent) Output of updated blocks to stable storage can take place at any time before or after transaction commit Order in which blocks are output can be different from the order in which they are written. The deferred-modification scheme performs updates to buffer/disk only at the time of transaction commit Simplifies some aspects of recovery But has overhead of storing local copy
Transaction Commit A transaction is said to have committed when its commit log record is output to stable storage all previous log records of the transaction must have been output already Writes performed by a transaction may still be in the buffer when the transaction commits,and may be output later Database System Concepts-6th Edition 16.14 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 16.14 ©Silberschatz, Korth and Sudarshan th Edition Transaction Commit A transaction is said to have committed when its commit log record is output to stable storage all previous log records of the transaction must have been output already Writes performed by a transaction may still be in the buffer when the transaction commits, and may be output later
Immediate Database Modification Example Log Write Output <To start> <T0,A,1000,950> <To,B,2000,2050 A=950 B=2050 <To commit> <T1 start> <T1,C,700,600> Bc output before T1 C=600 commits Ba,Bc <T1 commit> BA BA output after To Note:By denotes block containing X. commits Database System Concepts-6th Edition 16.15 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 6 16.15 ©Silberschatz, Korth and Sudarshan th Edition Immediate Database Modification Example Log Write Output <T0 start> <T0 , A, 1000, 950> <To , B, 2000, 2050 A = 950 B = 2050 <T0 commit> <T1 start> <T1 , C, 700, 600> C = 600 BB , BC <T1 commit> BA Note: BX denotes block containing X. BC output before T1 commits BA output after T0 commits
Concurrency Control and Recovery With concurrent transactions,all transactions share a single disk buffer and a single log A buffer block can have data items updated by one or more transactions We assume that if a transaction Ti has modified an item,no other transaction can modify the same item until T;has committed or aborted i.e.the updates of uncommitted transactions should not be visible to other transactions Otherwise how to perform undo if T1 updates A,then T2 updates A and commits,and finally T1 has to abort? Can be ensured by obtaining exclusive locks on updated items and holding the locks till end of transaction(strict two-phase locking) Log records of different transactions may be interspersed in the log. Database System Concepts-6th Edition 16.16 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 6 16.16 ©Silberschatz, Korth and Sudarshan th Edition Concurrency Control and Recovery With concurrent transactions, all transactions share a single disk buffer and a single log A buffer block can have data items updated by one or more transactions We assume that if a transaction Ti has modified an item, no other transaction can modify the same item until Ti has committed or aborted i.e. the updates of uncommitted transactions should not be visible to other transactions Otherwise how to perform undo if T1 updates A, then T2 updates A and commits, and finally T1 has to abort? Can be ensured by obtaining exclusive locks on updated items and holding the locks till end of transaction (strict two-phase locking) Log records of different transactions may be interspersed in the log