Ramakrishnan and Gehrke Solutions-185-199

.pdf

School

University of California, Berkeley *

*We aren’t endorsed by this school

Course

C200

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

15

Uploaded by UltraSnowBear26

Report
180 Chapter 18 4. WAL Protocol: Whenever a change is made to a database object, the change is first recorded in the log and the log is written to stable storage before the change is written to disk. 5. If a steal policy is in effect, the changes made to an object in the buffer pool by a transaction can be written to disk before the transaction commits. This might be because some other transaction might ”steal” the buffer page presently occupied by an uncommitted transaction. A no-force policy is in effect if, when a transaction commits, we need not ensure that all the changes it has made to objects in the buffer pool are immediately forced to disk. Exercise 18.2 Briefly answer the following questions: 1. What are the properties required of LSNs? 2. What are the fields in an update log record? Explain the use of each field. 3. What are redoable log records? 4. What are the differences between update log records and CLRs? Answer 18.2 Answer omitted. Exercise 18.3 Briefly answer the following questions: 1. What are the roles of the Analysis, Redo, and Undo phases in ARIES? 2. Consider the execution shown in Figure 18.1. (a) What is done during Analysis? (Be precise about the points at which Analysis begins and ends and describe the contents of any tables constructed in this phase.) (b) What is done during Redo? (Be precise about the points at which Redo begins and ends.) (c) What is done during Undo? (Be precise about the points at which Undo begins and ends.) Answer 18.3 The answer to each question is given below. 1. The Analysis phase starts with the most recent begin checkpoint record and pro- ceeds forward in the log until the last log record. It determines (a) The point in the log at which to start the Redo pass
Crash Recovery 181 10 20 30 40 50 60 00 end_checkpoint begin_checkpoint LOG LSN update: T1 writes P5 update: T2 writes P3 update: T3 writes P3 CRASH, RESTART T2 end T2 commit T1 abort 70 Figure 18.1 Execution with a Crash (b) The dirty pages in the buffer pool at the time of the crash. (c) Transactions that were active at the time of the crash which need to be undone. The Redo phase follows Analysis and redoes all changes to any page that might have been dirty at the time of the crash. The Undo phase follows Redo and undoes the changes of all transactions that were active at the time of the crash. 2. (a) For this example, we will assume that the Dirty Page Table and Transaction Table were empty before the start of the log. Analysis determines that the last begin checkpoint was at LSN 00 and starts at the corresponding end checkpoint (LSN 10). We will denote Transaction Table records as (transID, lastLSN) and Dirty Page Table records as (pageID, recLSN) sets. Then Analysis phase runs until LSN 70, and does the following: LSN 20 Adds (T1, 20) to TT and (P5, 20) to DPT LSN 30 Adds (T2, 30) to TT and (P3, 30) to DPT LSN 40 Changes status of T2 to ”C” from ”U” LSN 50 Deletes entry for T2 from Transaction Table LSN 60 Adds (T3, 60) to TT. Does not change P3 entry in DPT LSN 70 Changes (T1, 20) to (T1, 70) The final Transaction Table has two entries: (T1, 70), and (T3, 60). The final Dirty Page Table has two entries: (P5, 20), and (P3, 30). (b) Redo Phase: Redo starts at LSN 20 (smallest recLSN in DPT).
182 Chapter 18 10 20 30 40 50 60 LSN LOG 00 update: T1 writes P1 update: T3 writes P3 70 update: T1 writes P2 update: T2 writes P3 update: T2 writes P5 update: T2 writes P5 T2 abort T3 commit Figure 18.2 Aborting a Transaction LSN 20 Changes to P5 are redone. LSN 30 P3 is retrieved and its pageLSN is checked. If the page had been written to disk before the crash (i.e. if pageLSN > = 30), nothing is re-done otherwise the changes are re-done. LSN 40,50 No action LSN 60 Changes to P3 are redone LSN 70 No action (c) Undo Phase: Undo starts at LSN 70 (highest lastLSN in TT). The Loser Set consists of LSNs 70 and 60. LSN 70: Adds LSN 20 to the Loser Set. Loser Set = (60, 20). LSN 60: Undoes the change on P3 and adds a CLR indicating this Undo. Loser Set = (20). LSN 20: Undoes the change on P5 and adds a CLR indicating this Undo. Exercise 18.4 Consider the execution shown in Figure 18.2. 1. Extend the figure to show prevLSN and undonextLSN values. 2. Describe the actions taken to rollback transaction T 2. 3. Show the log after T 2 is rolled back, including all prevLSN and undonextLSN values in log records. Answer 18.4 Answer omitted. Exercise 18.5 Consider the execution shown in Figure 18.3. In addition, the system
Crash Recovery 183 10 20 30 40 50 60 LSN LOG 00 70 CRASH, RESTART T3 abort update: T1 writes P5 T2 end update: T3 writes P2 T2 commit update: T3 writes P3 update: T2 writes P2 update: T1 writes P1 begin_checkpoint end_checkpoint 80 90 Figure 18.3 Execution with Multiple Crashes crashes during recovery after writing two log records to stable storage and again after writing another two log records. 1. What is the value of the LSN stored in the master log record? 2. What is done during Analysis? 3. What is done during Redo? 4. What is done during Undo? 5. Show the log when recovery is complete, including all non-null prevLSN and un- donextLSN values in log records. Answer 18.5 The answer to each question is given below. 1. LSN 00 is stored in the master log record as it is the LSN of the begin checkpoint record. 2. During analysis the following happens:
184 Chapter 18 LSN 20 Add (T1,20) to TT and (P1,20) to DPT LSN 30 Add (T2,30) to TT and (P2,30) to DPT LSN 40 Add (T3,40) to TT and (P3,40) to DPT LSN 50 Change status of T2 to C LSN 60 Change (T3,40) to (T3,60) LSN 70 Remove T2 from TT LSN 80 Change (T1,20) to (T1,70) and add (P5,70) to DPT LSN 90 No action At the end of analysis, the transaction table contains the following entries: (T1,80), and (T3,60). The Dirty Page Table has the following entries: (P1,20), (P2,30), (P3,40), and (P5,80). 3. Redo starts from LSN20 (minimum recLSN in DPT). LSN 20 Check whether P1 has pageLSN more than 10 or not. Since it is a committed transaction, we probably need not redo this update. LSN 30 Redo the change in P2 LSN 40 Redo the change in P3 LSN 50 No action LSN 60 Redo the changes on P2 LSN 70 No action LSN 80 Redo the changes on P5 LSN 90 No action 4. ToUndo consists of (80, 60). LSN 80 Undo the changes in P5. Append a CLR: Undo T1 LSN 80, set undonextLSN = 20. Add 20 to ToUndo. ToUndo consists of (60, 20). LSN 60 Undo the changes on P2. Append a CLR: Undo T3 LSN 60, set undonextLSN = 40. Add 40 to ToUndo. ToUndo consists of (40, 20). LSN 40 Undo the changes on P3. Append a CLR: Undo T3 LSN 40, T3 end ToUndo consists of (20). LSN 20 Undo the changes on P1. Append a CLR: Undo T1 LSN 20, T1 end
Crash Recovery 185 5. The log looks like the following after recovery: LSN 00 begin checkpoint LSN 10 end checkpoint LSN 20 update: T1 writes P1 LSN 30 update: T2 writes P2 LSN 40 update: T3 writes P3 LSN 50 T2 commit prevLSN = 30 LSN 60 update: T3 writes P2 prevLSN = 40 LSN 70 T2 end prevLSN = 50 LSN 80 update: T1 writes P5 prevLSN = 20 LSN 90 T3 abort prevLSN = 60 LSN 100 CLR: Undo T1 LSN 80 undonextLSN= 20 LSN 110 CLR: Undo T3 LSN 60 undonextLSN= 40 LSN 120,125 CLR: Undo T3 LSN 40 T3 end. LSN 130,135 CLR: Undo T1 LSN 20 T1 end. Exercise 18.6 Briefly answer the following questions: 1. How is checkpointing done in ARIES? 2. Checkpointing can also be done as follows: Quiesce the system so that only check- pointing activity can be in progress, write out copies of all dirty pages, and include the dirty page table and transaction table in the checkpoint record. What are the pros and cons of this approach versus the checkpointing approach of ARIES? 3. What happens if a second begin checkpoint record is encountered during the Anal- ysis phase? 4. Can a second end checkpoint record be encountered during the Analysis phase? 5. Why is the use of CLRs important for the use of undo actions that are not the physical inverse of the original update? 6. Give an example that illustrates how the paradigm of repeating history and the use of CLRs allow ARIES to support locks of finer granularity than a page. Answer 18.6 Answer omitted. Exercise 18.7 Briefly answer the following questions: 1. If the system fails repeatedly during recovery, what is the maximum number of log records that can be written (as a function of the number of update and other log records written before the crash) before restart completes successfully?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help