

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Assignment 3 1
H 1 : r 1 [y] r 1 [x] r 2 [x] w 1 [y] c 1 w 2 [y] c 2
H 1 is normally-strict two-phase locked:
rl 1 [y] r 1 [y] rl 1 [x] r 1 [x] rl 2 [x] r 2 [x] wl 1 [y] w 1 [y] c 1 ru 1 [x] wu 1 [y] wl 2 [y] w 2 [y] c 2 ru 2 [x] wu 2 [y]
Note that ru 1 [y] isn’t needed, since ru 1 [y] was converted into wu 1 [y], i.e., T 1 holds only one lock on y.
H 2 : r 1 [y] r 1 [x] r 2 [x] w 2 [x] w 1 [y] c 1 w 2 [y] c 2
H 2 is two-phase locked, but not strict two-phase locked. To run w 2 [x] , T 1 must have released its read lock on x before w 2 [x], which means it cannot be strict two-phase locked. Moreover, to be two-phase locked, it must have gotten its write lock on y before it released its read lock on x. Thus, we have the following:
rl 1 [y] r 1 [y] rl 1 [x] r 1 [x] rl 2 [x] r 2 [x] wl 1 [y] ru 1 [x] wl 2 [x ] w 2 [x] w 1 [y] c 1 wu 1 [y] wl 2 [y] w 2 [y] c 2 ru 2 [x] wu 2 [y]
H 3 : r 1 [y] r 1 [x] r 2 [x] w 1 [y] w 2 [y] c 2 c 1
H 3 is two-phase locked, but not strict two-phase locked because T 1 must have released its write lock before w 2 [y] executed.
rl 1 [y] r 1 [y] rl 1 [x] r 1 [x] rl 2 [x] r 2 [x] wl 1 [y] w 1 [y] wu 1 [y] wl 2 [y] w 2 [y] c 2 ru 2 [x] wu 2 [y] c 1 ru 1 [x]
H 4 : r 1 [y] r 1 [x] r 2 [x] w 2 [x] r 3 [y] w 1 [y] c 1 w 3 [z] c 3 w 2 [y] c 2
H 4 is not two-phase locked. To see why, consider the following prefix of the history:
rl 1 [y] r 1 [y] rl 1 [x] r 1 [x] rl 2 [x] r 2 [x]
The next operation is w 2 [x]. So as in H 2 , T 1 must have released its read lock on x before w 2 [x], so again the next few operations must have been wl 1 [y] ru 1 [x] wl 2 [x] w 2 [x], as in the following expanded prefix.
Assignment 3 2
rl 1 [y] r 1 [y] rl 1 [x] r 1 [x] rl 2 [x] r 2 [x] wl 1 [y] ru 1 [x] wl 2 [x] w 2 [x]
The next operation is r 3 [y]. To have executed here, T 3 would have to obtain its lock on y, which requires that T 1 had already released its lock on y, which it could not have done at this point because it hasn’t yet executed w 1 [y].
Nevertheless, this history is SR. We have only the following SG edges: T 1 T 2 because (r 1 [x],w 2 [x]) and (w 1 [y], w 2 [y]) T 3 T 1 because (r 3 [y], w 1 [y]) There’s no cycle in the SG, so the history is serializable as T 3 T 1 T 2. Note that there are no transaction handshakes in the input, so there are none to preserve.
Extra credit: Is it possible for a history to be strict two-phase locked but not normally- strict two phase locked? No. To prove it, let H be a strict 2PL history that has been augmented with lock and unlock operations to demonstrate that it’s strict 2PL. We can transform H into a history each of whose lock operations immediately precedes the operation it’s synchronizing, as follows. Suppose that for some operation oi[x] in H, the corresponding lock request oli[x] does not immediately precede oi[x]. The only constraint that prevents moving oli[x] to the right in H so that it immediately precedes oi[x] is an unlock operation by Ti, since that would break 2PL. However, since H is strict 2PL, all of Ti’s unlock operations follow ci. Therefore, it’s possible to move oli[x] to the right in H so that it immediately precedes oi[x]. This can be done for all offending lock operations in H, thereby transforming it into a demonstration that H is normally-strict 2PL-ed.
Consider the following three transactions, each of which is a sequential program: T 1 : r 1 [x] r 1 [y] T 2 : r 2 [x] r 2 [y] T 3 : w 3 [y] w 3 [x] Suppose they start executing as follows: H 1 : r 1 [x] r 2 [x] w 3 [y] So far, T 1 and T 2 each have a read lock on x, and T 3 has a write lock on y. Next, each transaction tries to set a lock for its second operation: r 1 [y], r 2 [y], and w 3 [x]. However, no matter which order the three lock requests are made, none of those lock requests can be granted, because another transaction already owns a conflicting lock. In terms of the waits-for graph, we have: T 1 T 3 because T 1 requests a read lock on y and T 3 owns a write lock on y T 2 T 3 for the same reason as above T 3 T 1 because T 3 requests a write lock on x and T 1 owns a read lock on x T 3 T 2 for the same reason as above.