17 Transaction Processing
17 Transaction Processing
17.16 Add the operation commit at the end of each of the transactions T1 and T2 from
Figure 17.2; then list all possible schedules for the modified transactions.
Determine which of the schedules are recoverable, which are cascadeless, and
which are strict.
Answer:
T1 T2
read_item(X); read_item(X);
X := X – N; X := X + M;
write_item(X); write_item(X);
read_item(Y); commit T2;
Y := Y + N;
write_item(Y);
commit T1;
In general, given m transactions with number of operations n1, n2, ..., nm, the number
of possible schedules is: (n1 + n2+ ... + nm)! / (n1! * n2! * ... * nm!), where ! is the
factorial function. In our case, m =2, n1 = 5 and n2 = 3, so the number of possible
schedules is:
(5+3)! / (5! * 3!) = 8*7*6*5*4*3*2*1/ 5*4*3*2*1*3*2*1 = 56.
Below are the 56 possible schedules, and the type of each schedule:
This material has been taken from draft Pre-Publication Material, Copyright AWL2004
2 Exercises of May 4, 2006
This material has been taken from draft Pre-Publication Material, Copyright AWL2004
Exercises of May 4, 2006 3
17.17 List all possible schedules for transactions T1 and T2 from figure 17.2, and
determine which are conflict serializable (correct) and which are not.
Answer:
T1 T2
read_item(X); read_item(X);
X := X - N X := X + M;
write_item(X); write_item(X);
read_item(Y);
Y := Y + N;
write_item(Y);
Below are the 15 possible schedules, and the type of each schedule:
S1 : r1(X); w1(X); r1(Y); w1(Y); r2(X); w2(X); serial(and hence also serializable)
S2 : r1(X); w1(X); r1(Y); r2(X); w1(Y); w2(X); (conflict) serializable
S 3 : r1(X); w1(X); r1(Y); r2(X); w2(X); w1(Y); (conflict) serializable
S 4 : r1(X); w1(X); r2(X); r1(Y); w1(Y); w2(X); (conflict) serializable
S 5 : r1(X); w1(X); r2(X); r1(Y); w2(X); w1(Y); (conflict) serializable
S 6 : r1(X); w1(X); r2(X); w2(X); r1(Y); w1(Y); (conflict) serializable
S 7 : r1(X); r2(X); w1(X); r1(Y); w1(Y); w2(X); not(conflict) serializable
S 8 : r1(X); r2(X); w1(X); r1(Y); w2(X); w1(Y); not(conflict) serializable
S 9 : r1(X); r2(X); w1(X); w2(X); r1(Y); w1(Y); not(conflict) serializable
S10 : r1(X); r2(X); w2(X); w1(X); r1(Y); w1(Y); not(conflict) serializable
S11 : r2(X); r1(X); w1(X); r1(Y); w1(Y); w2(X); not(conflict) serializable
S12 : r2(X); r1(X); w1(X); r1(Y); w2(X); w1(Y); not(conflict) serializable
S13 : r2(X); r1(X); w1(X); w2(X); r1(Y); w1(Y); not(conflict) serializable
S14 : r2(X); r1(X); w2(X); w1(X); r1(Y); w1(Y); not(conflict) serializable
S15 : r2(X); w2(X); r1(X); w1(X); r1(Y); w1(Y); serial(and hence also serializable)
Hint: construct dependency graph, if it contains a cycle, the schedule is NOT serializable.
This material has been taken from draft Pre-Publication Material, Copyright AWL2004
4 Exercises of May 4, 2006
17.22 Which of the following schedules is (conflict) serializable? For each serializable
schedule, determine the equivalent serial schedules.
Answer:
Let there be three transactions T1, T2, and T3. They are executed concurrently and produce
a schedule S. S is serializable if it can be reproduced (i.e. if it is conflict equivalent) as at
least one serial schedule (T1 T2 T3, or T1 T3 T2, or T2 T1 T3, or T2 T3 T1, or T3 T1 T2 or
T3 T2 T1).
(a) This schedule is not serializable because T1 reads X (r1(X)) before T3 but T3 reads X
(r3(X)) before T1 writes X (w1(X)), where X is a common data item. The operation r2(X) of
T2 does not affect the schedule at all so its position in the schedule is irrelevant. In a serial
schedule T1 T2 T3, the operation w1(X) comes before r3(X), which does not happen in the
question. If we turn the order of T1 and T3 around, like in the serial schedule T3 T2 T1, then
the w3(X) comes before the r1 (X), which is not the case either in our schedule Sa.
Another way of showing this is to construct the dependency graph. r1(X) precedes w3(X),
hence (Algorithm 17.1, clause 3), hence we have an edge T1 -> T3. Similarly, r3 (X)
precedes w1(X), hence we have an edge T3 -> T1. This results in a cycle, so the schedule is
not serializable.
(b) This schedule is not serializable because r1(X) comes before w3(X) (so the precedence
graph has an edge T1 -> T3) but w3(X) comes before w1(X) (hence, the precedence graph
also has an edge T3 -> T1).The operation r2(X) of T2 does not affect the schedule at all so
its position in the schedule is irrelevant.
(c) This schedule is serializable because all conflicting operations of T3 happen before all
conflicting operation of T1. T2 has only one operation, which is a read on X (r2(X)), which
does not conflict with any other operation. Thus this serializable schedule is equivalent to
r2(X); r3(X); w3(X); r1(X); w1(X) (e.g., T2 T3 T1) serial schedule.
Note that the precedence graph only has one edge, T3 -> T1, which shows us as well that
this schedule is serializable.
(d) This is not a serializable schedule because r3(X) comes before r1(X) (hence, T3 -> T1)
but r1(X) happens before w3(X) (hence T1 -> T3).
This material has been taken from draft Pre-Publication Material, Copyright AWL2004
Exercises of May 4, 2006 5
17.23 Consider the three transactions T1, T2, and T3, and the schedules S1 and S2 given
below. Draw the serializibility (precedence) graphs for S1 and S2 and state whether each
schedule is serializable or not. If a schedule is serializable, write down the equivalent serial
schedule(s).
S1: r1(x); r2(z); r1(x); r3(x); r3(y); w1(x); w3(y); r2(y); w2(z); w2(y)
S2: r1(x); r2(z); r3(x); r1(z); r2(y); r3(y); w1(x); w2(z); w3(y); w2(y)
Answers:
(Note that the pictures should contain also an edge T3 –X--> T1, because the r3(x) comes
before w1(x))
This material has been taken from draft Pre-Publication Material, Copyright AWL2004
6 Exercises of May 4, 2006
17.24 Consider schedules S3, S4, and S5 below. Determine whether each schedule is strict,
cascadeless, recoverable, or nonrecoverable. (Determine the strictest recoverability
condition that each schedule satisfies.)
S3: r1(x); r2(z); r1(z); r3(x); r3(y); w1(x); c1; w3(y); c3; r2(y); w2(z); w2(y);c2
S4: r1(x); r2(z); r1(z); r3(x); r3(y); w1(x); w3(y); r2(y); w2(z); w2(y); c1; c2; c3;
S5: r1(x); r2(z); r3(x); r1(z); r2(y); r3(y); w1(x); w2(z); w3(y); w2(y); c1; c3; c2;
Answer:
Schedule S3 is not strict because w1(X) comes after r3(X), but the the commit of T1
comes before the commit of T3.
Schedule S4 is not strict because w1(X) comes after r3(X), but the the commit of T1
comes before the commit of T3.
Schedule S5 is not strict because w1(X) comes after r3(X), but the the commit of T1
comes before the commit of T3.
NOTE: According to the definition of cascadeless schedules S3, S4, and S4 are not
cascadeless. However, T3 is not affected if T1 is rolled back in any of the schedules, that is,
T3 does not have to roll back if T1 is rolled back. The problem occurs because these
schedules are not serializable.
NOTE: Ci > Cj means Ci happens before Cj. Ai denotes abort Ti. To test if a schedule is
recoverable one has to include abort operations. Thus in testing the recoverability abort
operations will have to used in place of commit one at a time. Also the strictest condition is
where a transaction neither reads nor writes to a data item, which was written to by a
transaction that has not committed yet.
If A1>C3>C2, then S3 is recoverable because rolling back of T1 does not affect T2 and
T3. If C1>A3>C2. S3 is not recoverable because T2 read the value of Y (r2(Y)) after
T3 wrote X (w3(Y)) and T2 committed but T3 rolled back. Thus, T2 used non- existent
value of Y. If C1>C3>A3, then S3 is recoverable because roll back of T2 does not
affect T1 and T3. Strictest condition of S3 is C3>C2.
If A1>C2>C3, then S4 is recoverable because roll back of T1 does not affect T2 and
T3. If C1>A2>C3, then S4 is recoverable because the roll back of T2 will restore the
value of Y that was read and written to by T3 (w3(Y)). It will not affect T1. If
C1>C2>A3, then S4 is not recoverable because T3 will restore the value of Y which was
not read by T2. Strictest condition of S4 is C3>C2, but it is not satisfied by S4.
If A1>C3>C2, then S5 is recoverable because neither T2 nor T3 writes to X, which is
written by T1. If C1>A3>C2, then S5 is not recoverable because T3 will restore the
value of Y, which was not read by T2. Thus, T2 committed with a non-existent value of
Y. If C1>C3>A2, then S5 is recoverable because it will restore the value of Y to the
value, which was read by T3. Thus, T3 committed with the right value of Y. Strictest
condition of S3 is C3>C2, but it is not satisfied by S5.
This material has been taken from draft Pre-Publication Material, Copyright AWL2004
Exercises of May 4, 2006 7
This material has been taken from draft Pre-Publication Material, Copyright AWL2004