
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Database Sys Implement; Subject: Computer Science; University: Georgia Institute of Technology-Main Campus; Term: Unknown 1989;
Typology: Exams
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















1
Ling Liu Associate Professor College of Computing, Georgia Tech
DB20 (^) Midterm 2 Review
z skim 9.
z Read 10.1, 10.2, 10. z skim 10.4, 10.5, 10.6, 10.
z Skim 11.
3
Failure Modes
z Local: caught by parity checks on sectors, main memory z Disk crash: handled by RAID
z Problem is that memory loss wipes out process state and data – what if the process had already made some modifications to the database?
DB20 (^) Midterm 2 Review
How can we prevent/fix violations?
Correctness (informally)
7
Logging Schemes
z Log entries contain only old values z A crash before transaction finishes, the log tells us how to restore old values for any DB elements changed on disk z Important Principle: WAL Æ log records for an item X must be on disk before any DB modification to X is flushed to disk ÆBefore commit record flushed to disk, all DB modifications must be flushed to disk.
z Undo log cannot bring backup DB copies to date
DB20 (^) Midterm 2 Review
Logging Schemes
z Log entries contain only new values z Before writing modifications to disk, transaction must be committed and COMMIT record must be written to log z Before writing modifications to disk, flush all log records involving X (including commit) to disk.
z Redo logging need to keep all modified blocks in memory until commit.
9
Checkpointing
Problem: In principle recovery requires looking at entire log Simple solution: occasional checkpoint operation z Stop accepting new transactions z Wait for all current transactions commit or abort z Flush log to disk and all DB updates in memory buffer to disk z Enter checkpoint record in the log record and flush to disk. Advantage: z If recovery is necessary after this point, all transactions prior to a checkpoint have committed and need not be undone.
DB20 (^) Midterm 2 Review
Exercise 1: what to do at recovery?
<T1,A,8> <T1,commit> Checkpoint<T2,B,8> <T2,commit>
<T3,C,8>
Crash ... ... ... ... ... ...
<T1,A,16> <T1,commit> Checkpoint<T2,B,17> <T2,commit> <T3,C,21>
Crash ... ... ... ... ... ...
Undo cannot bring backup DB copies up to date
Redo need to keep all DB blocks in memory until commit
13
Exercise 2 Examine the schedule given below. There are three transactions, T1, T2, and T3. Initially, salary = 1 and tax = 2. The assignments happen within the local memory space of the transactions and the effects of these assignments are not reflected in the database until the WRITE operation.
--------------------------------------------------------------------^ T1^ T2^ T 01 startREAD tax (^23) start tax := tax + 1 45 READ salarysalary := salary + 1 67 WRITE taxcommit 89 startREAD tax 1011 READ salarytax := tax + salary 1213 WRITE taxcommit 1415 ------------------- checkpoint start --------------------------READ tax 16 tax := tax + salary 1817 WRITE salary------------------- checkpoint end -------------------------- 19 commit a) Show the undo/redo log file entries that would be generated by this execution. For each log entry, indicate what line above generates it.
<0, T3, start> <3, T1, start> <6, T3, tax, 2, 3> <7, T3, commit> <8, T2, start> <12, T2, tax, 3, 4> <13, T2, commit> <14, checkpoint start , T1 is still active> <17, T1, salary, 1, 2> <18, checkpoint end> <19, T1, commit>
DB20 (^) Midterm 2 Review
Exercise 2 (Cont)
z b.1) Which transactions would have to be undone?
z b.2) Which transactions would have to be redone?
Answer: T
Answer: T
15
Exercise 2 (Cont)
z c.1) Which transactions would have to be undone?
z c.2) Which transactions would have to be redone?
Answer: T
Answer: None
DB20 (^) Midterm 2 Review
Concepts
19
Exercise 3:
DB20 (^) Midterm 2 Review
Question(a): is this schedule conflict serializable? Which serial schedule it is equivalent to?
T1 T Read(A); A ← A+ Write(A);
Write(A); Read(B); B ← B+100; Write(B);
Write(B);
Answer: Yes. It is equivalent to serial schedule of T proceeding T
21
A Serial Schedule
Read(A); A ← A+ Write(A); Read(B); B ← B+100; Write(B);
Write(A);
Write(B);
DB20 (^) Midterm 2 Review
Question (b): is this schedule conflict serializable? Which serial schedule it is equivalent to?
T1 T Read(A); A ← A+ Write(A); Read(A);A ← A×2; Write(A); Read(B);B ← B×2; Write(B); Read(B); B ← B+100; Write(B);
Answer: Not serializable, and it is NOT equivalent to any serial schedule
25
Conflict-Serializable Schedule
(Three Rules 1, 2, 3)
Rule #3 Two phase locking (2PL) for transactions Ti = ……. li(A) ………... ui(A) ……...
no unlocks no locks
Rule #1: Well-formed transactions Ti: … li(A) … pi(A) … ui(A) ...
Rule #2 Legal scheduler
S = …….. li(A) ………... ui(A) ……...
no lj(A)
DB20 (^) Midterm 2 Review
Two-phase Locking (2PL) Protocol To guarantee serializability:
Obtain lock Release lock
Lock point
Phase 1 Phase 2 BEGIN END
27
Deadlock Avoidance: Conservative 2 PL
Conservative 2 PL (static) : requires a transaction T to
Obtain lock Release lock
BEGIN END
Transaction period of duration data item use
No. of locks
Phase 1 Phase 2
DB20 (^) Midterm 2 Review
Strict 2 PL In addition to the Basic 2 PL , and Conservative 2 PL , there is another version of 2 PL: Strict 2 PL :
Obtain lock Release lock
BEGIN (^) period of END Transactionduration data item use
No. of locks
31
Exercise 4
--------------------------------------------------------------------^ T1^ T2^ T3^ T 1 READ tax 2 READ salary 3 WRITE tax 4 READ tax 5 WRITE tax 6 READ tax 7 WRITE salary 8 READ salary 9 WRITE tax 10 WRITE salary 11 READ salary 12 WRITE salary
DB20 (^) Midterm 2 Review
Questions/Answers
33
Exercise 4 (d)
--------------------------------------------------------------------^ T1^ T2^ T3^ T 1 READ tax 2 READ salary 3 WRITE tax 4 READ tax 5 WRITE tax 6 READ tax 7 WRITE salary 8 READ salary 9 WRITE tax 10 WRITE salary 11 READ salary 12 WRITE salary
DB20 (^) Midterm 2 Review
Questions/Answers a) Draw the precedence graph for this schedule. Answer: T1 Æsalary T3 Æsalary T4 Ætax T2 Æ tax T
b) What is the equivalent serialization order for this schedule? If no order is possible, then state 'none'. Answer: None, the conflict graph has a cycle.
c) Assume that transaction T4 did not run at all. What is the precedence graph in this case? Answer: T2 Æ tax T1 Æsalary T3,
d) What is the equivalent serialization order for this second schedule? If no order is possible, then state 'none'. Answer: T2 T1 T
37
Key idea
Make validation atomic If T1, T2, T3, … is validation order, then resulting schedule will be conflict equivalent to S s = T 1 T 2 T3...
To implement validation, system keeps two sets: FIN = transactions that have finished phase 3 (and are all done) VAL = transactions that have successfully finished phase 2 (validation)
DB20 (^) Midterm 2 Review
time
start
validated
validated
start
39
finish phase 3
time
start
validated
validated
start
start
DB20 (^) Midterm 2 Review
time
validated
validated finish T 2