0% found this document useful (0 votes)
33 views9 pages

hw5 Sols

The document discusses homework questions about write-ahead logging and database replication. It includes a question about the values of database objects after recovery from a write-ahead log and a question about the results of transactions running under different isolation levels on a replicated database.

Uploaded by

m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views9 pages

hw5 Sols

The document discusses homework questions about write-ahead logging and database replication. It includes a question about the values of database objects after recovery from a write-ahead log and a question about the results of transactions running under different isolation levels on a replicated database.

Uploaded by

m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

C ARNEGIE M ELLON U NIVERSITY

C OMPUTER S CIENCE D EPARTMENT


15-445/645 – DATABASE S YSTEMS (FALL 2020)
P ROF. A NDY PAVLO

Homework #5 (by Preetansh Goyal) – Solutions


Due: Tuesday Dec 6, 2020 @ 11:59pm

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

Question Points Score


Write-Ahead Logging 35
Replication 33
Miscellaneous 18
Total: 86

1
15-445/645 (Fall 2020) Homework #5 Page 2 of 9

Question 1: Write-Ahead Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [35 points]


Consider a DBMS using write-ahead logging with physical log records with the STEAL and
NO-FORCE buffer pool management policy. Assume the DBMS executes a non-fuzzy check-
point where all dirty pages are written to disk.
Its transaction recovery log contains log records of the following form:
<txnId, objectId, beforeValue, afterValue>
The log also contains checkpoint, transaction begin, and transaction commit records.
The database contains three objects (i.e., X, Y, and Z).
The DBMS sees records as in Figure 1 in the WAL on disk after a crash.

LSN WAL Record


1 <T1 BEGIN>
2 <T1, X, 1, 2>
3 <T2 BEGIN>
4 <T2, Y, 1, 2>
5 <T1 COMMIT>
6 <T2, Y, 2, 3>
7 <T3 BEGIN>
8 <T3, Z, 1, 2>
9 <T2, X, 2, 3>
10 <CHECKPOINT>
11 <T2, Y, 3, 4>
12 <T3, Z, 2, 3>
13 <T3 COMMIT>
14 <T2, Z, 3, 4>

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

Z = 3 (rollback to the afterValue made by T3)

Homework #5 continues. . .
15-445/645 (Fall 2020) Homework #5 Page 6 of 9

Question 2: Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [33 points]


Consider a DBMS using active-passive, master-replica replication with multi-versioned con-
currency control. All read-write transactions go to the master node (N ODE A), while read-only
transactions are routed to the replica (N ODE B). You can assume that the DBMS has “instant”
fail-over and master elections. That is, there is no time gap between when the master goes
down and when the replica gets promoted as the new master. For example, if N ODE A goes
down at timestamp 1 then N ODE B will be elected the new master at 2 . Note that this is not
a realistic assumption but we’re using it to simplify the problem setup.
The database has a single table foo(id,val) with the following tuples:

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).

time operation time operation


1 BEGIN; 2 BEGIN READ ONLY;
2 UPDATE foo SET val = ‘aa’; 3 SELECT val FROM foo WHERE id = 1;
3 UPDATE foo SET val = ‘aaa’ WHERE id = 1; 4 SELECT val FROM foo WHERE id = 2;
4 UPDATE foo SET val = ‘bb’ WHERE id = 2; 5 SELECT val FROM foo WHERE id = 2;
5 COMMIT; 6 COMMIT;
(a) Transaction #1 – N ODE A (b) Transaction #2 – N ODE B

Figure 2: Transactions executing in the DBMS.

(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

Question 3: Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [18 points]


(a) [6 points] Under the NO-STEAL policy, a DBMS will need to store the whole table in
RAM if a transaction updates all the records of that table.
 True
2 False

(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

You might also like