You are on page 1of 3

South China Agricultural University Computing Science 2005-2006 Database Systems Tutorial Set 2 (ANSWERS)

Tutorial Questions (Concurrency Control and Recovery)


1. Describe each of the following locking protocols: 2PL, Strict 2PL. Ans: 2PL: a way DBMS to ensure only serializable schedules are allowed. The rules are: Each transaction must get an S-lock on an object before reading it; Each transaction must get an X-lock on an object before writing it; Once a transaction releases a lock, it can not acquire any new locks. Strict 2PL: besides all the rules mentioned above, there is one additional rule to ensure only 'safe' interleavings of transactions are allowed, which is: All locks held by a transaction are released when the transaction is completed. 2. What benefit is provided by Strict 2PL? What disadvantages result? Ans: Because it produces only cascadeless schedules, recovery is very easy. But the set of schedules obtainable is a subset of those obtainable from plain two phase locking, thus concurrency is reduced. 3. Show that there are schedules that are possible under 2PL but are not possible under the timestamp protocol, and vice versa. Ans: A schedule which is allowed in the two-phase locking protocol but not in the timstamp protocol is Step T0 T1 1 lock-s(A) 2 read(A) 3 lock-x(B) 4 write(B) 5 unlock(B) 6 lock-s(B) 7 read(B) 8 unlock(A) 9 unlock(B) This schedule is not allowed in the timestamp protocol because at step 7, the Wtimestamp of B is 1

A schedule which is allowed in the timestamp protocol but not in the two phase locking is Step T0 T1 T2 1 write(A) 2 write(A) 3 write(B) 4 write(B) 5 write(B) This schedule cannot have lock instructions added to make it legal under two phase locking protocol because T1 must unlock A between step 2 and 3 and must lock B between steps 4 and 5 4. Compare the deferred-modification and immediate-modification version of the log-based recovery schemes, in terms of ease of implementation and overhead cost. Ans: The advantages of the deferred modification schemes are: The scheme is easier and simpler to implement since fewer operations and routines are needed, ie. No UNDO The scheme requires less overhead since no extra I/O operations need to be done until commit time as log records can be kept in memory the entire time. Since the old values of data do not have to be present in the log-records, this scheme requires less log storage space The disadvantages of the deferred modification schemes are: When a data item needs to be accessed, the transaction can no longer directly read the correct page from the database buffer, because a previous write by the same transaction to the same data item may not have been propagated to the database yet. It might have updated a local copy of the data item and deferred the actual database modification. Therefore, finding the correct version of a data item becomes more expensive. This scheme allows less concurrency than recovery scheme with immediate updates. This is because write locks are held by transactions till commit time. For long transaction with many updates, the memory space occupied by log records and local copies of data items may become too high. 5. Explain the purpose of the checkpoint mechanism. How often should checkpoints be performed? How does the frequency of checkpoints affect. a. System performance when no failure occurs b. The time it takes to recover from a system crash c. The time it takes to recover from a disk crash Ans: Checkpointing is done with log-based recovery schemes to reduce the time required for recovery after a crash. If there is no checkpointing, the entire log much be searched after a crash, and all transactions undone/redone from the log. If checkpointing had been performed, then most of the log-records prior to the checkpoint can be ignored at the time of recovery.

Another reason to perform checkpoints is to clear log-records from stable storage as it gets full. Since checkpoints cause some loss in performance while they are being taken, their frequency should be reduced if fast recovery is not critical. If we need fast recovery checkpointing frequency should be increased. If the amount of stable storage available is less, frequent checkpointing is unavoidable. Checkpoints have no effect on recovery from a disk crash; archival dumps are the equivalent of checkpoints for recovery from disk crashes. 6. When the system recovers from a crash, it constructs an undo-list and a redo-list. Explain why log records for transactions on the undo-list must be processed in reverse order while those log records for transactions on the redo-list are processed in a forward direction. Ans: The first phase of recovery is to undo the changes done by the failed transactions, so that all data items which have been modified by them get back the values they had before the first of the failed transactions started. If several of the failed transactions had modified the same data item, forward processing of log-records for undo-list transactions would make the data item get the values which it had before the last failed transaction to modify that data item started. This is clearly wrong, and we can see that reverse processing gets us the desired result. The second phase of recovery is to redo the changes done by committed transactions, so that all data items which have been modified by them are restored to the value they had after the last of the committed transactions finished. It can be seen that only forward processing of log-records belonging to redo-list transactions can guarantee this.

You might also like