hw5 Sols
hw5 Sols
IMPORTANT:
• Upload this PDF with your answers to Gradescope by 11:59pm on Tuesday Dec 6, 2020.
• Plagiarism: Homework may be discussed with other students, but all homework is to be
completed individually.
• You have to use this PDF for all of your answers.
For your information:
• Graded out of 86 points; 3 questions total
Revision : 2020/12/14 21:24
1
15-445/645 (Fall 2020) Homework #5 Page 2 of 9
Figure 1: WAL
(a) [10 points] What are the values of X, Y, and Z in the database stored on disk before the
DBMS recovers the state of the database?
2 X=1, Y=1, Z=1
2 X=2, Y=1, Z=1
2 X=3, Y=4, Z=4
2 X=3, Y=4, Z=3
2 X=2, Y:4, Z=Not possible to determine
2 X=3, Y:Not possible to determine, Z=4
X=3, Y,Z:Not possible to determine
2 X=2, Y:Not possible to determine, Z=4
2 X=2, Y,Z:Not possible to determine
2 X,Y,Z:Not possible to determine
Question 1 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 3 of 9
Solution: The checkpoint flushed everything to disk, but then the data objects Y,Z were
modified by transactions after the checkpoint.
Since we are using NO-FORCE, any dirty page could be written to disk, so therefore we
don’t know the contents of the database on disk at the crash.
Question 1 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 4 of 9
(b) [5 points] What should be the correct action on T1 when recovering the database from
WAL?
2 undo all of T1’s changes
2 redo all of T1’s changes
do nothing to T1
Solution: T1 committed before the checkpoint. All of its changes were written to disk.
There is nothing to redo or undo.
(c) [5 points] What should be the correct action on T2 when recovering the database from
WAL?
undo all of T2’s changes
2 redo all of T2’s changes
2 do nothing to T2
Solution: T2 never committed. All of its changes should only be undone.
(d) [5 points] What should be the correct action on T3 when recovering the database from
WAL?
2 undo all of T3’s changes
redo all of T3’s changes
2 do nothing to T3
Solution: T3 committed after the checkpont, so that means the DBMS has to redo all
of its changes.
(e) [10 points] Assume that the DBMS flushes all dirty pages when the recovery process
finishes. What are the values of X, Y, and Z after the DBMS recovers the state of the
database from the WAL in Figure 1?
2 X=1, Y=1, Z=1
2 X=1, Y=2, Z=3
X=2, Y=1, Z=3
2 X=2, Y=1, Z=4
2 X=2, Y=3, Z=2
2 X=2, Y=4, Z=4
2 X=3, Y=4, Z=3
2 Not possible to determine
Solution: X = 2 (committed by T1)
Y = 1 (rollback to the beforeValue as T2 never committed)
Question 1 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 5 of 9
Homework #5 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 6 of 9
id val
1 a
2 b
3 c
Table 1: foo(id,val)
For each questions listed below, assume that the following transactions shown in Figure 2 are
executing in the DBMS: (1) Transaction #1 on N ODE A and (2) Transaction #2 on N ODE B.
You can assume that the timestamps for each operation is the real physical time of when it was
invoked at the DBMS and that the clocks on both nodes are perfectly synchronized (again, this
is not a realistic assumption).
(a) Assume that the DBMS is using asynchronous replication with continuous log streaming
(i.e., the master node sends log records to the replica in the background after the trans-
action executes them). Suppose that N ODE A crashes at timestamp 5 before it executes
the COMMIT operation.
i. [10 points] If Transaction #2 is running under READ COMMITTED, what is the return
result of the val attribute for its SELECT query at timestamp 4 ? Select all that are
possible.
2 a
2 aa
2 aaa
b
Question 2 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 7 of 9
2 bb
2 c
2 None of the above
Solution: READ COMMITTED means that the transaction will only see the ver-
sions that were committed. That means at 4 , Transaction #1 has not committed yet
so therefore Transaction #2 cannot see any of its versions.
ii. [10 points] If Transaction #2 is running under the READ UNCOMMITTED isolation
level, what is the return result of the val attribute for its SELECT query at times-
tamp 5 ? Select all that are possible.
2 a
aa
2 aaa
b
bb
2 c
2 None of the above
Solution: READ UNCOMMITTED means that it will read any version of the tuple
that exists in the database. But what version of tuple 1 that the transaction will read
depends on whether the master node shipped the log record over before the query
is executed. Since we are doing continuous log shipping, we have no idea. So it
could read the version of the tuple that existed before Transaction #1 started (i.e.,
“b”) or after Transaction #1 executed the UPDATE query at 2 (i.e., “aa”), or after
Transaction #1 executed the UPDATE query at 4 (i.e., “bb”).
(b) [13 points] Assume that the DBMS is using asynchronous replication with on commit
propagation. Suppose that both N ODE A and N ODE B crash at exactly the same time at
timestamp 6 after executing Transaction #1’s COMMIT operation. You can assume that
the application was notified that the Transaction #1 was committed successfully.
After the crash, you find that N ODE A had a major hardware failure and cannot boot.
N ODE B is able to recover and is elected the new master.
What are the values of the tuples in the database when the system comes back online?
Select all that are possible.
{ (1,a), (2,b), (3,c) }
2 { (1,aa), (2,aa), (3,aa) }
2 { (1,aaa), (2,bb), (3,c) }
{ (1,aaa), (2,bb), (3,aa) }
2 { (1,a), (2,bb), (3,c) }
2 { (1,a), (2,bb), (3,aa) }
2 None of the above
Solution: Asynchronous replication with On Commit propagation means that the replica
only received the log records from the master when Transaction #1 committed but it did
not write them to disk. The master sent the notification to the client that the txn com-
Question 2 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 8 of 9
mitted but it is only guaranteed to be durable on disk on the master and not the replica.
When the system come back on-line, we don’t know whether the txn was also flushed
to disk on the replica. Thus, the only two correct states of the database are if Transac-
tion #1 never executed or if it did execute. There cannot be any partial updates to the
database.
Homework #5 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 9 of 9
(b) [6 points] In ARIES, log records are immediately flushed on the log, as soon as they are
produced.
2 True
False
(c) [6 points] Without checkpoints, the redo phase of ARIES recovery should process the
whole log.
True
2 False
End of Homework #5