|
Solutions for Section 18.1
Solutions for Section 18.2
Solutions for Section 18.3
Solutions for Section 18.4
Solutions for Section 18.5
Solutions for Section 18.6
Solutions for Section 18.7
Solutions for Section 18.8
Solutions for Section 18.9
The total number of serial orders is thus 402.
i. The precedence graph is
T3 -----> T2 -----> T1
ii. The schedule is thus conflict-serializable. The only conflict-equivalent serial schedule is (T3, T2, T1).
iii. No. Assume, for example, that initially each of A, B, and C are 10. T1 sets A and C to 20, T2 sets B to A+B+C, and T3 prints B. Then if T3 does not precede T2, it prints the wrong value, and if T2 does not precede T1, it sets B to the wrong value.
The number of these interleavings is (6 choose 3) = 20. Note that 20 is thus the sum of the first two quantities we need to compute; (i) + (ii).
Now, let us count (ii), the number of consistent, non-two-phase-locked sequences. The only way a consistent sequence is not 2PL is if the unlock at the end of subsequence (1) or (2) above precedes the lock at the beginning of the other subsequence. There are only 2 ways to interleave (1) and (2) so that all of one goes in front of all of the other (put either subsequence first). Thus, (ii) = 2, so (i) = 20 - 2 = 18.
Next, let us count the number of two-phase-locked sequences, which is (i) + (iii). If the sequence is 2PL, then the two locks precede the two unlocks. We can thus pick one of two orders for the locks and one of two orders for the unlocks, for a total of 4 orders of the lock and unlock actions. The r1(A) action can go anywhere. That is, we can choose any of 5 positions in which to insert the read action among the lock and unlock actions, ranging from before all to after all. Having placed the read action, the w1(B) action can now be placed in any of 6 positions among the other five. The total number of 2PL sequences is thus 4*5*6 = 120.
Since (i) + (iii) = 120, and we already know (i) = 18, we deduce that (iii) = 102.
The last step is to compute the total number of sequences, which is the sum of all four categories. The number of sequences of six actions is 6! = 720. As the number of sequences in the first three categories is 18, 2, and 102, respectively, (iv) = 720 - 18 -2 - 102 = 598.
(ii): The first three locks and reads are allowed. However, T1 cannot get a shared lock on B, nor can T2 get a shared lock on C. When T3 requests a shared lock on D it is granted. Thus, T3 can proceed and eventually unlocks C and D.
As soon as C is unlocked, T2 can get its shared lock on C. Thus, T2 completes and releases its locks. As soon as its lock on B is released, T1 can get its lock on A, so it completes.
(iii): sl1(A); r1(A); sl2(B); r2(B); sl3(C); r3(C); sl1(B); r1(B); sl2(C); r2(C); sl3(D); r3(D); xl1(A); w1(A); u1(A); u1(B); xl2(B); w2(B); u2(B); u2(C); xl3(C); w3(C); u3(C); u3(D)
(iv): First, all six shared-lock requests are granted. When T1 requests an exclusive lock on A, it gets it, because it is the only transaction holding a lock on A. T1 completes and releases its locks. Thus, when T2 asks for an exclusive lock on B, it is the only transaction still holding a shared lock on B, so that lock too may be granted, and T2 completes. After T2 releases its locks, T3 is able to upgrade its shared lock on C to exclusive, and it too proceeds. The actions are thus executed in exactly the same order as they are requested; i.e., there are no delays by the scheduler.
(v): ul1(A); r1(A); ul2(B); r2(B); ul3(C); r3(C); sl1(B); r1(B); sl2(C); r2(C); sl3(D); r3(D); xl1(A); w1(A); u1(A); u1(B); xl2(B); w2(B); u2(B); u2(C); xl3(C); w3(C); u3(C); u3(D)
(vi): The update locks prevent the fourth and fifth shared-lock requests, sl1(B) and sl2(C), so T1 and T2 are delayed, while T3 is allowed to proceed. The situation is exactly as for part (ii), where the initial lock requests are for exclusive locks.
Also, inc1(B) must come before r2(B), so the former can either be the fourth action of the schedule, or it can be fifth, coming after r2(A). Thus, there are two serializable schedules equivalent to (T1, T2), and four serializable schedules altogether.
For example, consider the actions (set angle = 90)(set x = 5) applied to the vector (10,0). The first step gives us (0,10), and the second step gives us (5,10).
On the other hand, the reverse order of the actions: (set x = 5)(set angle = 90) starting with (10,0) gives us (0,5), and the second step gives us (5,5).
Thus, the only needed lock modes are exclusive, shared, and increment, which correctly sum up the limitations on access to a given element in the above three situations, respectively.
At step 2, T2 puts an IX lock on the extent and on block 1, both of which are compatible with the IS locks already there. T2 also puts an X lock on O2.
At step 3, T2 puts an IS lock on the extent and on block 2 and an S lock on O3, then releases its locks.
At step 4, T1 puts an IX lock on the extent and on block 2 and an X lock on O4, then releases its locks.
We are then directed to the second leaf. Since that leaf is not full either, we know the insertion will not cause the left child of the root to be changed, so we can release the exclusive lock on that child. As soon as we have rewritten the second leaf to reflect the insertion of 10, we can release the lock on the leaf.
Suppose that T1 locks A first. Then T2 cannot perform any steps until T1 relinquishes the lock. Therefore, T1 must also read B, at the second step of the schedule. Now, T1 can relinquish the lock on A. The remaining step of T1, r1(E), can occur either before all of T2, or after the first or second step of T2. It cannot occur after the last step of T2, r2(B), because T1 can't relinquish its lock on B, until it has locked E. Thus, there are three interleavings in which T1 starts first.
Now, consider what happens if T2 starts first. T2 cannot relinquish its lock on A until it has locked both children B and C. Thus, if T2 starts first, it must finish before T1 starts. We conclude that there are four legal schedules.
When T2 tries to write A, it finds the read-timestamp to be less than the timestamp of T2, so the write may be performed, and T2 can commit. However, when T1 tries to write B, it finds the read-timestamp is greater than its own timestamp, so some transaction read another value of B, when it should have read T1's value. Thus, T1 must abort.
When T4 tries to read A the system finds that T4's timestamp is larger than that of any version of A written. Thus, T4 gets the version with the largest of the timestamps, the one written by T3. That makes sense, because in the hypothetical serial order based on the timestamps of the transactions, T3 would be the last to write A.
T3 validates next. The only other validated transaction is T1, and T1 has not yet finished. Thus, both the read- and write-sets of T3 must be compared with the write-set of T1. However, T1 writes only A, and T3 neither reads nor writes A, so T3's validation succeeds.
Last, T2 validates. Both T1 and T3 finish after T2 started, so we must compare the read-set of T2 with the write-sets of both T1 and T3. Since B is in both W3 and R2, we cannot validate T2. Note that since T3 (but not T1) finishes after T2 validates, we would also compare the write set of T2 with the write set of T3, had we not already found a reason not to validate T2.