2018 - Midterm 1 Solution - Spring - LHR - ADB
2018 - Midterm 1 Solution - Spring - LHR - ADB
Q1. (3 points) Given these transactions, find a cascade-free but not strict schedule, if
possible.
T1: r1(A), r1(B), w1(B), w1(A), c1.
T2: r2(B), w2(B), c2.
T3: w3(B), c3.
Ans:
r1(A), r1(B), r2(B), w3(B), w1(B), w2(B), w1(A), c1, c2, c3.
Q2. (6 points)
a) Describe how fuzzy checkpointing is used in ARIES.
b) What is the difference between the UNDO/REDO and the UNDO/NO-REDO algorithms for
recovery with immediate update?
c) Differentiate between non-repeatable read and phantom problems
Ans:
Get from text book.
Ans:
a) S1: r2(X), w3(X), c3, w1(Y), r2(Y), r2(Z), c2, r1(Z), c1.
S1: It is conflict-serializable, view serializable, not strict , not cascadeless, non-
recoverable as T2 read the dirty value of Y which is updated by T1 and T2 commit
before T1. Equivalent serial schedule is T1(Y)T2(X)T3.
Q4. (1+4+1+1= 7 points) Consider the execution shown in below Figure. Assume that the
Dirty Page Table and Transaction Table were empty before the start of the log.
a) What is the value of the LSN stored in the master log record?
b) What is done during Analysis? (Be precise about the points at which Analysis begins and
ends and show the contents of Dirty Page Table and Transaction Table constructed in this
phase.)
c) What is done during Redo? (Be precise about the points at which Redo begins and ends.)
d) What is done during Undo? (Be precise about the points at which Undo begins and ends.)
LSN LOG
1 begin_checkpoint
2 end_checkpoint
3 update: T1 writes C
4 update: T2 writes B
5 T1 commit
6 update: T3 writes A
7 update: T2 writes C
8 T2 commit
CRASH; RESTART
Ans:
a) LSN = 1
b) Analysis phase starts from LSN=2 record until it reaches the end i.e. LSN=8.
The end checkpoint contains the empty transaction table and dirty page table.
The analysis phase will further reconstruct these tables as follows:
c) REDO begins from LSN=3 (smallest LSN in DPT) and proceed with the REDO of
updates. The LSNs {3, 4, 6, 7} corresponding to the updates for pages C, B, A,
and C, respectively, are not less than the LSNs of pages in initial DPT. So those
data pages will be read again and all the updates reapplied from the LOG. At this
point REDO phase is finished and the UNDO phase starts.
d) UNDO is applied only to the active transaction T3. UNDO phase starts at LSN=6
(the last update of active transaction T3) and proceeds backward in the LOG. The
backward chain of updates for T3 (only LSN=6 record) is followed and undone.
Q5. (12 points) For the schedule S: r2(X), w3(X), c3, w1(Y), r2(Y), r2(Z), c2, r1(Z), c1. Show
that the schedule S will be accepted/rejected in exactly the order shown by the below
protocols. Provide proper reason and show your working.
a) Basic 2PL (add locks to the transactions)
b) Basic Timestamp Ordering (Assume T1 < T2 < T3)
c) Strict Timestamp Ordering (Assume T1 < T2 < T3)
d) Optimistic Concurrency Control
Ans:
a) Basic 2PL (Reject);
Here xl3(X) cannot acquire due to sl2(X).
1- ABORT T3 for Deadlock Avoidance using wait-die scheme
2- WAIT T3 for sl2(X) to release for Deadlock Avoidance using wound-wait
scheme
3- WAIT T3 for sl2(X) to release for Deadlock Detection (use wait-for-graph, in
case of deadlock)
b) Basic TO (ACCEPT);
- w3(X) allow as T3 is younger than RTS of X (i.e. TS(T3) > RTS(X) )
- r2(Y) allow as T2 is younger than WTS of Y (i.e. TS(T2) > WTS(Y) )
c) Strict TO (REJECT);
- w3(X) allow as T3 is younger than RTS of X (i.e. TS(T3) > RTS(X) )
- r2(Y) delay until c1/a1; as T2 is younger than WTS of Y (i.e. TS(T2) > WTS(Y) )
d) Optimistic(REJECT);
- T3 Forward Validation fails due to item X conflict with T2; so it may be delay
or abort T3/T2.
- But the validation of T1 & T2 is successful, if T3 abort.