16 S
16 S
16
Recovery System
Practice Exercises
16.1
Explain why log records for transactions on the undo-list must be processed in reverse order, whereas redo is performed in a forward direction.
Answer: Within a single transaction in undo-list, suppose a data item
is updated more than once, say from 1 to 2, and then from 2 to 3. If the
undo log records are processed in forward order, the final value of the
data item would be incorrectly set to 2, whereas by processing them in
reverse order, the value is set to 1. The same logic also holds for data items
updated by more than one transaction on undo-list.
Using the same example as above, but assuming the transaction committed, it is easy to see that if redo processing processes the records in forward
order, the final value is set correctly to 3, but if done in reverse order, the
final value would be set incorrectly to 2.
16.2
16
Any log record corresponding to a transaction which was active during the most recent checkpoint (i.e. which is part of the <checkpoint
L> entry)
b.
All other log records can be deleted. After each checkpoint, more records
become candidates for deletion as per the above rule.
Deleting a log record while retaining an earlier log record would result in
gaps in the log, and would require more complex log processing. Therefore in practise, systems find a point in the log such that all earlier log
records can be deleted, and delete that part of the log. Often, the log is
broken up into multiple files, and a file is deleted when all log records in
the file can be deleted.
Archival logging: Archival logging retains log records that may be needed
for recovery from media failure (such as disk crashes). Archival dumps are
the equivalent of checkpoints for recovery from media failure. The rules
for deletion above can be used for archival logs, but based on the last
archival dump instead of the last checkpoint. The frequency of archival
dumps would be lesser than checkpointing, since a lot of data has to be
written. Thus more log records would need to be retained with archival
logging.
16.4
Describe how to modify the recovery algorithm of Section 16.4 to implement savepoints, and to perform rollback to a savepoint. (Savepoints are
described in Section 16.8.3.)
Answer: A savepoint can be performed as follows:
a.
Output onto stable storage all log records for that transaction which
are currently in main memory.
b.
Output onto stable storage a log record of the form <savepoint Ti >,
where TI is the transaction identifier.
Practice Exercises
17
b.
If old values are not stored in update log records, transaction undo
is clearly not feasible. How would the redo-phase of recovery have
to be modified as a result?
c.
d.
Answer:
a.
b.
During the redo phase, the undo list need not be maintained any
more, since the stable storage does not reflect updates due to any
uncommitted transaction.
c.
A data item read will first issue a read request on the local memory
of the transaction. If it is found there, it is returned. Otherwise, the
item is loaded from the database buffer into the local memory of the
transaction and then returned.
d.
18
16.6
b.
Answer:
16.7
a.
To begin with, we start with the copy of just the root node pointing to
the shadow-copy. As modifications are made, the leaf entry where
the modification is made and all the nodes in the path from that
leaf node till the root, are copied and updated. All other nodes are
shared.
b.
Practice Exercises
19
16.9
Suppose a transaction deletes a record, and the free space generated thus
is allocated to a record inserted by another transaction, even before the
first transaction commits.
a.
b.
c.
Answer:
a.
20
16.10
b.
If page level locking is used, the free space generated by the first
transaction is not allocated to another transaction till the first one
commits. So this problem will not be an issue if page level locking
is used.
c.
The problem can be solved by deferring freeing of space till after the
transaction commits. To ensure that space will be freed even if there
is a system crash immediately after commit, the commit log record
can be modified to contain information about freeing of space (and
other similar operations) which must be performed after commit.
The execution of these operations can be performed as a transaction
and log records generated, following by a post-commit log record
which indicates that post commit processing has been completed for
the transaction.
During recovery, if a commit log record is found with post-commit
actions, but no post-commit log record is found, the effects of any
partial execution of post-commit operations are rolled back during
recovery, and the post commit operations are reexecuted at the end
of recovery. If the post-commit log record is found, the post-commit
actions are not reexecuted. Thus, the actions are guaranteed to be
executed exactly once.
The problem of clashes on primary key values can be solved by
holding key-level locks so that no other transaction can use the key
till the first transaction completes.
Explain the reasons why recovery of interactive transactions is more difficult to deal with than is recovery of batch transactions. Is there a simple
way to deal with this difficulty? (Hint: Consider an automatic teller machine transaction in which cash is withdrawn.)
Answer: Interactive transactions are more difficult to recover from than
batch transactions because some actions may be irrevocable. For example,
an output (write) statement may have fired a missile, or caused a bank
machine to give money to a customer. The best way to deal with this is to
try to do all output statements at the end of the transaction. That way if
the transaction aborts in the middle, no harm will be have been done.
Output operations should ideally be done atomically; for example, ATM
machines often count out notes, and deliver all the notes together instead
of delivering notes one-at-a-time. If output operations cannot be done
atomically, a physical log of output operations, such as a disk log of
events, or even a video log of what happened in the physical world can be
Practice Exercises
21
b.
c.
Answer:
a.
b.
Identify the latest archival dump, say D, before the log record
< Te , START>. Restore the database using the dump.
Redo all log records starting from the dump D till the log record
< Te , COMMIT>. Some transactionapart from transaction Te
would be active at the commit time of transaction Te . Let S1
be the set of such transactions.
22
information were written for every transaction. To perform logical redo of later transactions, scan the log further starting from
the log record < Te , COMMIT> till the end of the log. Note the
transactions that were started after the commit point of Te . Let
the set of such transactions be S2 . Re-execute the transactions in
set S1 and S2 logically.
c.
Consider again an example from the first item. Let us assume that
both transactions are undone and the balance is reverted back to the
original value $100.
Now we wish to redo transaction T2 . If we redo the log record
< T2 , A, 110, 120 > corresponding to transaction T2 the balance
would become $120 and we would, in effect, redo both transactions,
whereas we intend to redo only transaction T2 .