0% found this document useful (0 votes)
6 views12 pages

At2 CP5520

The document outlines two schedules, S1 and S2, detailing the operations of transactions T1, T2, and T3, including read and write operations with their timestamps. It evaluates the serializability of both schedules using serialization graph techniques, concluding that S1 is serializable while S2 is not due to the presence of cycles. Additionally, it discusses the recoverability of both schedules, indicating that S1 is recoverable under strict timestamp ordering while S2 is not.

Uploaded by

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

At2 CP5520

The document outlines two schedules, S1 and S2, detailing the operations of transactions T1, T2, and T3, including read and write operations with their timestamps. It evaluates the serializability of both schedules using serialization graph techniques, concluding that S1 is serializable while S2 is not due to the presence of cycles. Additionally, it discusses the recoverability of both schedules, indicating that S1 is recoverable under strict timestamp ordering while S2 is not.

Uploaded by

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

Solution 3a

S1: r3(X), r3(Z), r1(Y), r1(X), w3(Z), r2(Y), w1(X), r2(X), w2(X), r1(Z), w1(Z), r2(Z),
w2(Y)

T issues a write_tem(X):
If TS(T) ≥ read_TS(X) and TS(T) ≥ write_TS(X)  T can write on X and write_TS(X) =
TS(T). Otherwise, T is aborted. Cascading rollback may occur.

T issues a read_tem(X):
If TS(T) ≥ write_TS(X)  T can read X and read_TS(X) = Max(read_TS(X), TS(T)).
Otherwise, T is aborted. Cascading rollback may occur.

ID Transaction T1 Transaction T2 Transaction T3


1 r3(X)
2 r3(Z)
3 r1(Y)
4 r1(X)
5 r3(Z)
6 r2(Y)
7 w1(X)
8 r2(X)
9 w2(X)
10 r1(Z)
11 w1(Z)
12 r2(Z)
13 w2(Y)

T1 T2 T3
TS 3 6 1

Initial value X Y Z
READ_TS 0 0 0
WRITE_TS 0 0 0

S1 Explanation READ_TS/
WRITE_TS
r3(X) TS(T3) = 1 ≥ write_TS(X) = 0 true  r3(X) is allowed and read_TS(X) = 1
read_TS(X) = Max(read_TS(X), TS(T3)) = Max(0, 1) = 1
r3(Z) TS(T3) = 1 ≥ write_TS(Z) = 0 true  r3(Z) is allowed and read_TS(Z) = 1
read_TS(Z) = Max(read_TS(Z), TS(T3)) = Max(0, 1) = 1
r1(Y) TS(T1) = 3 ≥ write_TS(X) = 0 true  r1(Y) is allowed and read_TS(Y) = 3
read_TS(Y) = Max(read_TS(Y), TS(T1)) = Max(0, 3) = 3
r1(X) TS(T1) = 3 ≥ write_TS(X) = 0 true  r1(X) is allowed and read_TS(X) = 3
read_TS(X) = Max(read_TS(X), TS(T1)) = Max(1, 3) = 3
w3(Z TS(T3) = 1 ≥ read_TS(Z) = 1 true and TS(T3)= 1 ≥ write_TS(X) write_TS(Z) = 1
) = 1 true  w3(Z) is allowed. write_TS(Z) = TS(T3) = 1

1
r2(Y) TS(T2) = 6 ≥ write_TS(Y) = 0 true  r2(Y) is allowed and read_TS(Y) = 6
read_TS(Y) = Max(read_TS(Y), TS(T2)) = Max(0, 6) = 6
w1(X TS(T1) = 3 ≥ read_TS(X) = 3 true and TS(T1) = 3 ≥ write_TS(X) = 3
) write_TS(X) = 3 true  w1(x) is allowed. write_TS(x) = TS(T1)
=3
r2(X) TS(T2) = 6 ≥ write_TS(Y) = 0 true  r2(X) is allowed and read_TS(X) = 6
read_TS(X) = Max(read_TS(X), TS(T2)) = Max(3, 6) = 46
w2(X TS(T2) = 6 ≥ read_TS(X) = 6 true and TS(T2) = 6 ≥ write_TS(X) = 6
) write_TS(X) = 3 true  w2(X) is allowed. write_TS(x) =
TS(T2) = 6
r1(Z) TS(T1) = 3 ≥ write_TS(Z) = 1 true  r1(Z) is allowed and read_TS(Z) = 3
read_TS(Z) = Max(read_TS(Z), TS(T1)) = Max(1, 3) = 3
w1(Z TS(T1) = 3 ≥ read_TS(Z) = 3 true and TS(T1) = 3 ≥ write_TS(Z) write_TS(Z) = 3
) = 1 true  w1(Z) is allowed. write_TS(Z) = TS(T1) = 3
r2(Z) TS(T2) = 6 ≥ write_TS(Z) = 3 true  r2(Z) is allowed and read_TS(Z) = 6
read_TS(Z) = Max(read_TS(Z), TS(T2)) = Max(3, 6) = 6
w2(Y TS(T2) = 6 ≥ read_TS(Y) = 6 true and TS(T2) = 6 ≥ write_TS(Y) = 6
) write_TS(Y) = 0 true  w2(Y) is allowed. write_TS(Y) =
TS(T2) = 6

S1 follows the basic timestamp ordering.

Final value X Y Z
READ_TS 6 6 6
WRITE_TS 6 6 3

S2: r2(X), r3(Y), r2(Z), w3(Y), r1(X), w2(Z), r1(Y), r3(Z), r1(Z), r2(Y), w2(Y), w3(Z),
w1(X), w1(Z)

ID Transaction T1 Transaction T2 Transaction T3


1 r2(X)
2 r3(Y)
3 r2(Z)
4 w3(Y)
5 r1(X)
6 w2(Z)
7 r1(Y)
8 r3(Z),
9 r1(Z)
10 r2(Y)
11 w2(Y)
12 w3(Z)
13 w1(X)
14 w1(Z)

T1 T2 T3

2
TS 5 1 2

Initial value X Y Z
READ_TS 0 0 0
WRITE_TS 0 0 0

S2 Explanation READ_TS/
WRITE_TS
r2(X) TS(T2) = 1 >= write_TS(X) = 0 true  r2(X) is allowed; read_TS(X) = 1
read_TS(X) = max(TS(T2) , read_TS(X)) = max(1, 0) = 1
r3(Y) TS(T3) = 2 >= write_TS(Y) = 0 true  r3(Y) is allowed; read_TS(Y) = 2
read_TS(Y) = max(TS(T3) , read_TS(Y)) = max(2, 0) = 2
r2(Z) TS(T2) = 1 >= write_TS(Z) = 0 true  r2(Z) is allowed; read_TS(Z) = 1
read_TS(Z) = max(TS(T2) , read_TS(Z)) = max(1, 0) = 1
TS(T3) = 2 ≥ read_TS(Y) = 2 true and TS(T3) = 2 ≥ write_TS(Y) = 2
w3(Y) write_TS(Y) = 0 true  w3(Y) is allowed. write_TS(Y) =
TS(T3) = 2
r1(X) TS(T1) = 5 >= write_TS(X) = 0 true  r1(X) is allowed; read_TS(X) = 5
read_TS(X) = max(TS(T1) , read_TS(X)) = max(5, 1) = 5
TS(T2) = 1 ≥ read_TS(Z) = 1 true and TS(T2) = 1 ≥ write_TS(Z) write_TS(Z) = 1
w2(Z) = 0 true  w2(Z) is allowed. write_TS(Z) = TS(T2) = 1
r1(Y) TS(T1) = 5 >= write_TS(Y) = 2 true  r1(Y) is allowed; read_TS(Z) = 5
read_TS(Y) = max(TS(T1) , read_TS(Y)) = max(5, 2) = 5
r3(Z) TS(T3) = 2 >= write_TS(Z) = 1 true  r3(Z) is allowed; read_TS(Z) = 2
read_TS(Z) = max(TS(T3) , read_TS(Y)) = max(2, 2) = 2
r1(Z) TS(T1) = 5 >= write_TS(Z) = 1 true  r1(Z) is allowed; read_TS(Z) = 5
read_TS(Z) = max(TS(T1) , read_TS(Z)) = max(5, 2) = 5
r2(Y) TS(T2) = 1 >= write_TS(Y) = 2 false  r2(Y) is not allowed.
Thus, abort and rollback transaction T2
Cannot finish the execution because T2 is aborted and rollback
w2(Y)
Cannot finish the execution because T2 is aborted and rollback
w3(Z)
Cannot finish the execution because T2 is aborted and rollback
w1(X)
Cannot finish the execution because T2 is aborted and rollback
w1(Z)

The Schedule S does not follow the basic timestamp ordering technique.
Cascading rollback:
T2 is aborted. It means that w2(Y), w3(Z), 1(X), w1(Z) is undone.

3
Solution 3b
Testing the serializability of S1 and S2 by serialization graph technique
S1: r3(X), r3(Z), r1(Y), r1(X), w3(Z), r2(Y), w1(X), r2(X), w2(X), r1(Z), w1(Z), r2(Z),
w2(Y)

Transaction T1 Transaction T2 Transaction T3

r3(X)
r3(Z)
r1(Y)
r1(X)
w3(Z)
r2(Y)
w1 (X)
r2(X)
w2(X)
r1(Z)
w1(Z)
r2(Z)
w2(Y)

Pair of conflict operations:


r3(X) and w1(X)
r1(X) and w1(X)
r1(X) and w2(X)
r3(Z) and w3(Z)
r3(Z) and w1(Z)
r3(Z) and r1(Z)
r1(Z) and w1(Z)
r2(Z) and w1(Z)
r2(Z) and w2(Z)
r2(X) and w2(X)
r1(Y) and w2(Y)
r2(Y) and w2(Y)

4
Graph

T1
x, y, z
x, z

T2 T3

Conclusion: In this graph, there is no cycle therefore the schedule is serializable.

S2: r2(X), r3(Y), r2(Z), w3(Y), r1(X), w2(Z), r1(Y), r3(Z), r1(Z), r2(Y), w2(Y), w3(Z),
w1(X), w1(Z)

Transaction Transaction Transaction


T1 T2 T3
r2(X)
r3(Y)
r2(Z)
w3(Y)
r1(X)
w2(Z)
r1(Y)
r3(Z),
r1(Z)
r2(Y)
w2(Y)
w3(Z)
w1(X)
w1(Z)

Pair of conflict operations:


r2(X), r1(X)
r2(Z), w2(Z)
r3(Y), w3(Y)
w3(Y), r1(Y)
r1(X), w1(X)
w2(Z), r1(Z)

5
w2(Z), r3(Z)
r2(Y), w2(Y)
w3(Z), r1(Z)
w3(Z), w1(Z)
w2(Y), r2(Y)
w1(X), r1(X)

Graph
T3 → T2, T2 → T3, T3 → T1

Conclusion: Having a cycle, then the schedule is not serializable.

Solution 3c (i)

S1: r3(X), r3(Z), r1(Y), r1(X), w3(Z), r2(Y), w1(X), r2(X), w2(X), r1(Z), w1(Z), r2(Z),
w2(Y)

In Schedule S1, S1 is recoverable because T1 reads Y and X written by other transactions but
does not read any data written by T3 after T3's last operation. T2 reads X and Y but these are
not written after the last operation of any transactions. T3’s write on Z is read by T1, but as
T3 commits right after w3(Z), and T1 commits after that, it's recoverable.

S1 can be executed under the strict timestamp ordering (STO) algorithm.

Younger transactions are subject to waiting in Strict Timestamp Ordering. It should meet
BTO requirements and ensure that all read and write operations on a data item by one
transaction are finished before actions on the same data item are started by another
transaction with a later timestamp. But occasionally, an operation might just need to read a
data item—not write anything to it.

S1: r3(X), r3(Z), r1(Y), r1(X), w3(Z), r2(Y), w1(X), r2(X), w2(X), r1(Z), w1(Z), r2(Z),
w2(Y)

an equivalent strict schedule for the above schedule, assuming that a transaction will be
committed or aborted immediately after its last operation.

6
S1: r3(X), r3(Z), r1(Y), r1(X), w3(Z), c3, r2(Y), w1(X), r2(X), w2(X), r1(Z), w1(Z), c1,
r2(Z), w2(Y), c2

An equivalent strict schedule is given below:

S1: r3(X), r3(Z), r1(Y), r1(X), w3(Z), c3, r2(Y), w1(X), r1(Z), w1(Z), c1, r2(X), w2(X),
r2(Z), w2(Y), c2 - S1 is now an STO.
Solution 3c (ii)
S2: r2(X), r3(Y), r2(Z), w3(Y), r1(X), w2(Z), r1(Y), r3(Z), r1(Z), r2(Y), w2(Y), w3(Z),
w1(X), w1(Z)
For the transaction to be recoverable, T1 should not commit until T2 and T3, from which it
reads data, have committed. Given the sequence, each transaction indeed commits or is
assumed to commit right after its last operation.
T1 reads data after T2 and T3 have already written to those data items, assuming the commit
happens right after the last operation in each transaction sequence. Since T2 and T3 would be
considered to commit right after their last operations (w2(Y) and w3(Z), respectively) and
before T1 completes, therefore, the schedule is not recoverable. T1 commits after all
transactions from which it has read data (here it implicitly commits after reading the data
modified by T2 and T3). Additionally, this schedule cannot be executed under the strict
timestamp ordering.

7
Solution 4a (1)
i) CITY(del), CITY(pek), CITY(sgn), CITY(akl), CITY(sin), CITY(bne)
ii) FLIGHT(sin, del), FLIGHT(del, pek), FLIGHT(pek, sgn), FLIGHT(akl, sin),
FLIGHT(bne, akl)
Solution 4a (2)
Rules:
REACHABLE(X, Y) :- CITY(X), CITY(Y), FLIGHT(X, Y)
REACHABLE(X, Y) :- CITY(X), CITY(Z), FLIGHT(X, Z), REACHABLE(Z, Y)

Interpretation
Known Facts:
REACHABLE(sin, del) :- CITY(sin), CITY(del), FLIGHT(sin, del) is true
REACHABLE(del, pek) :- CITY(del), CITY(pek), FLIGHT(del, pek) is true
REACHABLE(pek, sgn) :- CITY(pek), CITY(sgn), FLIGHT(pek, sgn) is true
REACHABLE(akl, sin) :- CITY(akl), CITY(sin), FLIGHT(akl, sin) is true
REACHABLE(bne, akl) :- CITY(bne), CITY(akl), FLIGHT(bne, akl) is true
REACHABLE(X, Y) :- CITY(X), CITY(Y), FLIGHT(X, Y) is false for all other possible
combinations of (X, Y)

Derived Facts:
REACHABLE(bne, sin) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin) is true
REACHABLE(bne, del) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin), REACHABLE(sin, del) is true
REACHABLE(bne, pek) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin), REACHABLE(sin, del), REACHABLE(del, pek) is true

8
REACHABLE(bne, sgn) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin), REACHABLE(sin, del), REACHABLE(del, pek), REACHABLE(pek, sgn) is true
REACHABLE(akl, del) :- CITY(akl), CITY(sin), FLIGHT(akl, sin), REACHABLE(sin, del)
is true
REACHABLE(akl, pek) :- CITY(akl), CITY(sin), FLIGHT(akl, sin), REACHABLE(sin,
del), REACHABLE(del, pek) is true
REACHABLE(akl, sgn) :- CITY(akl), CITY(sin), FLIGHT(akl, sin), REACHABLE(sin,
del), REACHABLE(del, pek), REACHABLE(pek, sgn) is true
REACHABLE(sin, pek) :- CITY(sin), CITY(del), FLIGHT(sin, del), REACHABLE(del,
pek) is true
REACHABLE(sin, sgn) :- CITY(sin), CITY(del), FLIGHT(sin, del), REACHABLE(del,
pek), REACHABLE(pek, sgn) is true
REACHABLE(del, sgn) :- CITY(del), CITY(pek), FLIGHT(del, pek), REACHABLE(pek,
sgn) is true

Solution 4a (3)
No. There is no guarantee of reachability between any 2 cities
Reason: The rule mentioned that no flight in the reverse direction can be automatically
assumed. For example, you cannot fly from Beijing to New Delhi

Solution 4b (1)
Rules:
REACHABLE(X, Y) :- CITY(X), CITY(Y), FLIGHT(X, Y)
REACHABLE(X, Y) :- CITY(X), CITY(Z), FLIGHT(X, Z), REACHABLE(Z, Y)

Interpretation
Known Facts:
REACHABLE(sin, del) :- CITY(sin), CITY(del), FLIGHT(sin, del) is true
REACHABLE(del, pek) :- CITY(del), CITY(pek), FLIGHT(del, pek) is true
REACHABLE(pek, sgn) :- CITY(pek), CITY(sgn), FLIGHT(pek, sgn) is true
REACHABLE(akl, sin) :- CITY(akl), CITY(sin), FLIGHT(akl, sin) is true
REACHABLE(bne, akl) :- CITY(bne), CITY(akl), FLIGHT(bne, akl) is true
REACHABLE(sgn, bne) :- CITY(sgn), CITY(bne), FLIGHT(sgn, bne) is true

9
Derived Facts:
REACHABLE(bne, sin) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin) is true
REACHABLE(bne, del) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin), REACHABLE(sin, del) is true
REACHABLE(bne, pek) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin), REACHABLE(sin, del), REACHABLE(del, pek) is true
REACHABLE(bne, sgn) :- CITY(bne), CITY(akl), FLIGHT(bne, akl), REACHABLE(akl,
sin), REACHABLE(sin, del), REACHABLE(del, pek), REACHABLE(pek, sgn) is true
REACHABLE(akl, del) :- CITY(akl), CITY(sin), FLIGHT(akl, sin), REACHABLE(sin, del)
is true
REACHABLE(akl, pek) :- CITY(akl), CITY(sin), FLIGHT(akl, sin), REACHABLE(sin,
del), REACHABLE(del, pek) is true
REACHABLE(akl, sgn) :- CITY(akl), CITY(sin), FLIGHT(akl, sin), REACHABLE(sin,
del), REACHABLE(del, pek), REACHABLE(pek, sgn) is true
REACHABLE(akl, bne) :- CITY(akl), CITY(sin), FLIGHT(akl, sin), REACHABLE(sin,
del), REACHABLE(del, pek), REACHABLE(pek, sgn), REACHABLE(sgn, bne) is true
REACHABLE(sin, pek) :- CITY(sin), CITY(del), FLIGHT(sin, del), REACHABLE(del,
pek) is true
REACHABLE(sin, sgn) :- CITY(sin), CITY(del), FLIGHT(sin, del), REACHABLE(del,
pek), REACHABLE(pek, sgn) is true
REACHABLE(sin, bne) :- CITY(sin), CITY(del), FLIGHT(sin, del), REACHABLE(del,
pek), REACHABLE(pek, sgn), REACHABLE(sgn, bne), is true
REACHABLE(sin, akl) :- CITY(sin), CITY(del), FLIGHT(sin, del), REACHABLE(del,
pek), REACHABLE(pek, sgn), REACHABLE(sgn, bne), REACHABLE(bne, akl) is true
REACHABLE(del, sgn) :- CITY(del), CITY(pek), FLIGHT(del, pek), REACHABLE(pek,
sgn) is true
REACHABLE(del, bne) :- CITY(del), CITY(pek), FLIGHT(del, pek), REACHABLE(pek,
sgn), REACHABLE(sgn, bne) is true
REACHABLE(del, akl) :- CITY(del), CITY(pek), FLIGHT(del, pek), REACHABLE(pek,
sgn), REACHABLE(sgn, bne), REACHABLE(bne, akl) is true
REACHABLE(del, sin) :- CITY(del), CITY(pek), FLIGHT(del, pek), REACHABLE(pek,
sgn), REACHABLE(sgn, bne), REACHABLE(bne, akl), REACHABLE(akl, sin) is true

Solution 4b (2)

10
R1. REACHABLE(X, Y) :- CITY(X), CITY(Y), FLIGHT(X, Y)
R2. REACHABLE(sgn, akl) :- CITY(sgn), CITY(akl), FLIGHT(sgn, bne),
REACHABLE(bne, akl)
REACHABLE(pek, akl) :- CITY(pek), CITY(akl), FLIGHT(pek, sgn), REACHABLE(sgn,
akl)

Given facts:
1. FLIGHT(pek, sgn)
2. FLIGHT(sgn, bne)
3. FLIGHT(bne, akl)
4. REACHABLE(bne, akl) (apply Rule 1 on the given fact #3)
5. REACHABLE(sgn, akl) (apply R2 on #2and #4)
REACHABLE(sgn, akl) :- CITY(sgn), CITY(akl), FLIGHT(sgn, bne), REACHABLE(bne,
akl)
6. REACHABLE(sgn, akl) (apply R2 on #2and #4)
REACHABLE(pek, akl) :- CITY(pek), CITY(akl), FLIGHT(pek, sgn), REACHABLE(sgn,
akl)

Solution 4b (3)
Yes. There is a guarantee of reachability between any 2 cities with connecting flights
With the introduction of REACHABLE(sgn, bne), the cities are now in a ring form. For
example, to reach Auckland from Singapore, we have
Singapore  New Delhi  Beijing  Saigon  Brisbane  Auckland

Solution 4c (1)
To prove that REACHABLE_AND_DURATION(bne, del, 19) is true.
We have given:
R1. REACHABLE_AND_DURATION(X, Y, Z) :- FLIGHT(X, Y), DURATION(X, Y, Z)
R2. REACHABLE_AND_DURATION(X, Y, Z) :- FLIGHT(X, T), DURATION(X, T, K),
REACHABLE_AND_DURATION(T, Y, H), K+H = Z

11
Given facts
1. DURATION(del, pek, 6)
2. DURATION(sin, del, 5.5)
3. DURATION(sgn, bne, 8)
4. DURATION(pek, sgn, 5)
5. DURATION(bne, akl, 3)
6. DURATION(akl, sin, 10.5)
7. REACHABLE_AND_DURATION(bne, akl, 3) :- FLIGHT(bne, akl), DURATION(bne,
akl, 3) (apply Rule 1 on the given fact
#5)
8. REACHABLE_AND_DURATION(akl, del, 16) :- FLIGHT(akl, sin), DURATION(akl,
sin, 10.5), REACHABLE_AND_DURATION(sin, del, 5.5), 10.5+5.5 = 16
(apply R2 on #6 and #2)

Solution 4c (2)
Beijing, Saigon and Brisbane
Rule:
REACHABLE_AND_DURATION(X, Y, Z) :- FLIGHT(X, Y), DURATION(X, Y, Z), Z <
20
REACHABLE_AND_DURATION(X, Y, Z) :- FLIGHT(X, T), DURATION(X, T, K),
REACHABLE_AND_DURATION(T, Y, H), K+H < 20

Query
REACHABLE_AND_DURATION(del, pek, 6) is true
REACHABLE_AND_DURATION(pek, bne, 13) is true

12

You might also like