0% found this document useful (0 votes)
35 views15 pages

DBMS31052024

The deferred database modification scheme logs all modifications but defers writes until after a partial commit. It includes examples of transactions and outlines a recovery procedure that involves checkpointing to streamline recovery by maintaining undo and redo lists. The document also presents several questions related to transaction recovery scenarios and their implications.

Uploaded by

Vivek Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views15 pages

DBMS31052024

The deferred database modification scheme logs all modifications but defers writes until after a partial commit. It includes examples of transactions and outlines a recovery procedure that involves checkpointing to streamline recovery by maintaining undo and redo lists. The document also presents several questions related to transaction recovery scenarios and their implications.

Uploaded by

Vivek Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Deferred Database Modification

-The deferred database modification scheme records all modifications


to the log, but defers all the writes to after partial commit.
-- Awrite(X) operation results in a log record<Ti, X, V> being written,
where V is the new value for X
Note: old value is not needed for this scheme. The write is not performed
on X at this time, but is deferred.
• example transactions

T0: read (A) Log Main Memory Disk .


A=1000, B=2000, C=700
A: - A - 50 <T0 start>
Write (A) A=1000
<T0, A, 1000, 950>
read (B)
B=2000
B:- B + 50
<To, B, 2000, 2050>
write (B) <T0 commit>
A = 950
T1 : read (C) B = 2050
<T1 start>
C:- C- 100 C=700
<T1, C, 700, 600>
write (C) BB, BC

<T1 commit>
C = 600
BA
• example transactions

T0: read (A)


A: - A - 50
Write (A)
read (B)
B:- B + 50
write (B)

T1 : read (C)
C:- C- 100
write (C)
NPTEL Question:
Q. Consider the following example of a log of two transactions, where
deferred database modification scheme is used. [CRPQ-5]

Steps Details of log If a crash occurs just after step 6 and the recovery of
1 <T0 start> the system is successfully completed, which of the
2 <T0, A, 950> following action is true?
3 <T0, B, 2050> (a) T0: redo and T1: redo
4 <T1 start>
(b) T0: redo and T1: undo
5 <T1, C, 200>
(c) T0: redo and T1: No action
6 <T1 commit>
(d) T0: No action and T1: redo
NPTEL Question:
Q. Consider the following example of a log of two transactions, where
deferred database modification scheme is used. [CRPQ-7]
Steps Details of log If a crash occurs just after step 7 and the recovery of
1 <T0 start> the system is successfully completed, which of the
2 <T0, A, 500>
following action is true?
3 <T0, B, 1000>
(a) T0: redo and T1: redo
4 <T1 start>
(b) T0: redo and T1: undo
5 <T1, C, 200>
6 <T0 commit> (c) T0: redo and T1: No action
7 <T1 commit> (d) T0: No action and T1: No action
Check Points
• Problems in recovery procedure are,
1. searching the entire log is time-consuming
2. we might unnecessarily redo transactions which have already
output their updates to the database.
• Streamline recovery procedure by periodically performing
checkpointing
1. Output all log records currently residing in main memory onto
stable storage.
2. Output all modified buffer blocks to the disk.
3. Write a log record < checkpoint L> onto stable storage.
When the system recovers from a crash, it first does the following:
1. Initialize undo-list and redo-list to empty
2. Scan the log backwards from the end, stopping when the first
<checkpoint L> record is found.
For each record found during the backward scan:
if the record is <Ti commit>, add Ti to redo-list
if the record is <Ti start>, then if Ti is not in redo-list, add Ti to
undo- list
3. For every Ti in L, if Ti is not in redo-list, add Ti to undo-list
At this point undo-list consists of incomplete transactions which
must be undone, and redo-list consists of finished transactions
that must be redone.
Recovery now continues as follows:
1. Scan log backwards from most recent record, stopping when
<Ti start> records have been encountered for every Ti in undo-
list.
During the scan, perform undo for each log record that
belongs to a transaction in undo-list.
2. Locate the most recent <checkpoint L> record.
3. Scan log forwards from the <checkpoint L> record till the
end of the log.
During the scan, perform redo for each log record that
belongs to a transaction on redo-list
Example of Check points
Tc Tf
T1
T2
T3
T4

checkpoint system failure

T1 can be ignored (updates already output to disk due to checkpoint)


T2 and T3 redone.
T4 undone
Example of Recovery
<T0 start>
<T0, A, 0, 10>
<T0 commit>
<T1 start>
<T1, B, 0, 10>
<T2 start>
<T2, C, 0, 10>
<T2, C, 10, 20>
<checkpoint {T1, T2}>
<T3 start>
<T3, A, 10, 20>
<T4 start>
<T4, E, 100, 200>
<T3, D, 0, 10>
<T3 commit>
NPTEL Question:
Q. Consider the following log and Assume an immediate database modification scheme.
Steps Details of log If there is a crash just after step 12 and the recovery of the
1 <T0 start> system is successfully completed, identify the correct action
2 <T0, A, 100, 200> for the above scenario. [MSQ] [CRPQ-7]
3 <T0, A, 200, 300> (a) Redo list contains transaction {T2} and undo list contains
4 < T0 commit>
{T3, T1}.
5 <T1 start>
(b) After recovery completion, the value of B will be 500 and
6 <T1, B, 500, 400>
value of A will be 1500 and the value of C will be 1000.
7 <checkpoint {T1}>
8 <T2 start>
(c) First, complete the undo operation of all transactions from
9 <T2, A, 300, 1500> the undo list then perform the redo operation of all
10 <T2 commit> transactions from the redo list.
11 <T3 start> (d) After recovery completion, the value of B will be 400 and
12 <T3, C, 1000, 2000> value of A will be 1500 and the value of C will be 1000
NPTEL Question:
Q. Assume an immediate database modification scheme. Consider the
following log records for transactions T0, T1, T2 and T3: [CRPQ-8]
Steps Details of log
If there is a crash just after step 10 and the recovery of the system is
1 <T0 start> successfully completed, identify the incorrect action for the above scenario
2 <T0, X, 300, 400>
3 <T1 start> (a) Redo list contains transaction {T2} and undo list contains {T3, T1, T0}
4 <T1, Y, 600, 200> (b) After recovery completion, the value of P will be 900 and value of Z will
5 <checkpoint {T0, T1}> be 1500 and the value of Y will be 600 and value of X will be 300
6 <T2 start> (c) After recovery completion, the value of P will be 900 and value of Z will
be 500 and the value of Y will be 600 and value of X will be 300
7 <T2, Z, 500, 1500>
(d) First, complete the undo operation of all transactions from the undo list
8 <T2 commit>
then perform the redo operation of all transactions from the redo list
9 <T3 start>
10 <T3, P, 900, 1200>
Previous GATE Question
Q. Suppose a database system crashes again while recovering from a
previous crash. Assume check pointing is not done by the database
either during the transactions or during recovery.
Which of the following statements is/are correct?
(Gate-21-Set1) (MSQ) [CRPQ-9]
(a) The system cannot recover any further
(b) All the transactions that are already undone and redone will not
be recovered again
(c) The same undo and redo list will be used while recovering again
(d) The database will become inconsistent

Ramesh Masuna-ACE Academy-9700123473


Previous GATE Question
Q. Consider the following log sequence of two transactions on bank account, with initial
balance 12000, that transfer 2000 to a mortgage payment and then apply a 5% interest.
Suppose the database system crashes just before log record 7 is written.
1. T1 start When the system is restarted, which one statement is true of the
2. T1 B old = 12000 new = 10000 recovery procedure? (GATE-06) [CRPQ-10]
(a) We must redo log record 6 to set B to 10500
3. T1 M old = 0 new = 2000
(b) We must undo log record 6 to B to 10000 and then redo log record
4. T1 commit
2 and 3
5. T2 start (c) We need not redo log records 2 and 3 because transaction T1 has
6. T2 B old = 10000 new = 10500 committed
7. T2 commit (d) We can apply redo and undo operations in arbitrary order because
they are idempotent

Ramesh Masuna-ACE Academy-9700123473


Previous GATE Question
Q. Consider a simple checkpointing protocol and the following set of operations in the log.

(start, T4); If a crash happens now the system tries to


(write, T4, y, 2, 3); recover using both undo and redo operations,
(start, T1); what are the contents of the undo list and the
(commit, T4); redo list?
(write, T1, z, 5, 7); (GATE-15-Set2)
(checkpoint);
(start, T2); (a) Undo: T3, T1; Redo: T2
(write, T2, x, 1, 9); (b) Undo: T3, T1; Redo: T2, T4
(commit, T2); (c) Undo: none; Redo; T2, T4, T3, T1
(start, T3), (d) Undo: T3, T1, T4; Redo: T2
(write, T3, z, 7, 2);

You might also like