Question 4. (42 points) Deadlock
The following table presents the lock requests by transactions T1, T2, T3, and T4. S(.) and X(.) stand for 'shared lock' and 'exclusive lock', respectively.
| time | t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8 |
|------|------|------|------|------|------|------|------|------|
| T1 | S(A) | | | | | | | |
| T2 | | | S(D) | X(B) | | | | |
| T3 | X(A) | X(D) | | S(C) | | | | |
| T4 | | | | X(C) | | | | |
A. (18 points) Assume we follow deadlock detection policy and answer these questions:
a. (6 points) For the lock requests in the Table, determine which lock will be granted or blocked by the lock manager. Please write 'grant' in the last row to indicate the lock is granted and 'block' to indicate the lock is blocked.
| time | t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8 |
|------|------|------|------|------|------|------|------|------|
| T1 | S(A) | | | | | | | grant|
| T2 | | | S(D) | X(B) | | | | |
| T3 | X(A) | X(D) | | S(C) | | | | |
| T4 | | | | X(C) | | | | |
b. (8 points) Give the wait-for graph for the lock requests in the above Table.
T1 -> T2
T2 -> T3
T3 -> T4
c. (4 points) Determine whether there exists a deadlock in the lock requests in the above Table, and why.
No, there is no deadlock in the lock requests because there are no cycles in the wait-for graph.
B. (12 points) Now, assume we follow Wait-Die policy with these priorities: T1 > T2 > T3 > T4 (i.e., older transactions have higher priority). For the Wait-Die policy in the Table, determine if a lock will be granted or transaction should wait or aborts by the lock manager. Please write 'grant' in the last row to indicate the lock is granted. Write 'wait' to indicate if a transaction should wait. If a transaction is aborted, specify the name of the aborted transaction.
| time | t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8 |
|------|------|------|------|------|------|------|------|------|
| T1 | S(A) | | | | | | | grant|
| T2 | | | S(D) | X(B) | | | | |
| T3 | X(A) | X(D) | | S(C) | | | | |
| T4 | | | | X(C) | | | | |
C. (12 points) Now, assume we follow Wound-Die policy with these priorities: T1 > T2 > T3 > T4 (i.e., older transactions have higher priority). For the Wait-Die policy in the Table, determine if a lock will be granted or transaction should wait or aborts by the lock manager. Please write 'grant' in the last row to indicate the lock is granted. Write 'wait' to indicate if a transaction should wait. If a transaction is aborted, specify the name of the aborted transaction.
| time | t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8 |
|------|------|------|------|------|------|------|------|------|
| T1 | S(A) | | | | | | | grant|
| T2 | | | S(D) | X(B) | | | | |
| T3 | X(A) | X(D) | | S(C) | | | | |
| T4 | | | | X(C) | | | | |