Sie sind auf Seite 1von 9

QUESTION1.

Consider the following transactions with data items P and Q


initialized to zero:

T1: read (P) ;


read (Q) ;
if P = 0 then Q : = Q + 1 ;
write (Q) ;
T2: read (Q) ;
read (P) ;
if Q = 0 then P : = P + 1 ;
write (P) ;
A A serializable schedule
B A schedule that is not conflict serializable
C A conflict serializable schedule
D A schedule for which a precedence graph cannot be drawn

SOLUTION: Two or more actions are said to be in conflict if:


1) The actions belong to different transactions.
2) At least one of the actions is a write operation.
3) The actions access the same object (read or write).
The schedules S1 and S2 are said to be conflict-equivalent if the following
conditions are satisfied:
1) Both schedules S1 and S2 involve the same set of transactions (including
ordering of actions within each transaction).
2) The order of each pair of conflicting actions in S1 and S2 are the same.
A schedule is said to be conflict-serializable when the schedule is conflict-equivalent
to one or more serial schedules.
In the given scenario, there are two possible serial schedules:
1) T1 followed by T2
2) T2 followed by T1.
In both of the serial schedules, one of the transactions reads the value written by
other transaction as a first step. Therefore, any non-serial interleaving of T1 and T2
will not be conflict serializable.

QUESTION 2. Which of the following concurrency control protocols ensure


both conflict serialzability and freedom from deadlock? I. 2-phase locking
II. Time-stamp ordering

A I only
B II only
C Both I and II
D Neither I nor II
Question 2 Explanation:
2 Phase Locking (2PL) is a concurrency control method that guarantees
serializability. The protocol utilizes locks, applied by a transaction to data, which
may block (interpreted as signals to stop) other transactions from accessing the
same data during the transactions life. 2PL may be lead to deadlocks that result
from the mutual blocking of two or more transactions. See the following situation,
neither T3 nor T4 can make progress.

Timestamp-based concurrency control algorithm is a non-lock concurrency control


method. In Timestamp based method, deadlock cannot occur as no transaction ever
waits.

QUESTION.Consider the following two phase locking protocol. Suppose a


transaction T accesses (for read or write operations), a certain set of
objects {O1,...,Ok}. This is done in the following manner: Step 1. T
acquires exclusive locks to O1, . . . , Ok in increasing order of their
addresses. Step 2. The required operations are performed. Step 3. All
locks are released. This protocol will

A guarantee serializability and deadlock-freedom


B guarantee neither serializability nor deadlock-freedom
C guarantee serializability but not deadlock-freedom
D guarantee deadlock-freedom but not serializability
Question 3 Explanation:
The above scenario is Conservative 2PL( or Static 2PL). In Conservative 2PL
protocol, a transaction has to lock all the items it access before the transaction
begins execution. It is used to avoid deadlocks. Also, 2PL is conflict serializable,
therefore it guarantees serializability. Therefore option A Advantages of
Conservative 2PL :
No possibility of deadlock.
Ensure serializability.
Drawbacks of Conservative 2PL :
Less throughput and resource utilisation because it holds the resources
before the transaction begins execution.
Starvation is possible since no restriction on unlock operation.
2pl is a deadlock free protocol but it is difficult to use in practice.

Q4.Which of the following statement is/are incorrect?


A: A schedule following strict two phase locking protocol is conflict serializable as
well as recoverable.
B: Checkpoint in schedules are inserted to ensure recoverability.
A Only 1
B Only 2
C Both 1 and 2
D None

Question 4 Explanation:
Basic two phase locking protocol ensures only conflict serializability and strict two
phase locking protocol ensures recoverability as well. So statement A is correct.
Checkpoints are inserted to minimize the task of undo-redo in recoverability. So,
statement B is not correct. Hence correct option B is correct choice.

Question : Which of the following TS order allow to execute the above


schedule using BTSO (Basic Timestamp Ordering) Protocol ? R1(A); R2(B);
W1(C); R3(B); R3(C); W2(B); W3(A) a) (T1,T2,T3) = (10,20,30) b) (T1,T2,T3)
= (30,10,20) c) (T1,T2,T3) = (30,20,10) d) (T1,T2,T3) = (20,30,10) e)
(T1,T2,T3) = (10,30,20).
Solution :
Conflict Pairs in the following schedule :
Conflict Pairs : Dependency :
(i) R1(A); W3(A) T1 T3
(ii) W1(C); R3(C) T1 T3
(iii) R3(B); W2(B) T3 T2

Case (a) : Timestamp Order = (T1,T2,T3) = (10,20,30)


The concurrent execution schedule must have the sequence
based on TS value.
Allowed Conflict Pairs Based on TS value :
(I) T1 T2
(II) T2 T3
(III) T1 T3

Compare the dependencies obtained from the schedule with


the dependencies obtained from Timestamp :
T1 T3 : Dependency is allowed.
T3 T2 : Dependency not allowed. Therefore Rollback T2
Because of W2(B)

Therefore, the schedule is not going to execute according


to the TS :
Timestamp Order = (T1,T2,T3) = (10,20,30)

Case (b) : Timestamp Order = (T1,T2,T3) = (30,10,20)


The concurrent execution schedule must have the sequence
based on TS value.

Allowed Conflict Pairs Based on TS value :


(I) T2 T3
(II) T3 T1
(III) T2 T1

Compare the dependencies obtained from the schedule with


the dependencies obtained from Timestamp :
T1 T3 : Dependency is not allowed. Rollback T3.
T3 T2 : Dependency is not allowed. Rollback T2.

Therefore, the schedule is not going to execute according


to the TS :
Timestamp Order = (T1,T2,T3) = (30,10,20)

Case (c) : Timestamp Order = (T1,T2,T3) = (30,20,10)


The concurrent execution schedule must have the sequence
based on TS value.
Allowed Conflict Pairs Based on TS value :
(I) T3 T2
(II) T2 T1
(III) T3 T1

Compare the dependencies obtained from the schedule with


the dependencies obtained from Timestamp :
T1 T3 : Dependency is not allowed. Rollback T3.
T3 T2 : Dependency is allowed.

Therefore, the schedule is not going to execute according


to the TS
Timestamp Order = (T1,T2,T3) = (30,20,10)

Case (d) : Timestamp Order = (T1,T2,T3) = (20,30,10)


The concurrent execution schedule must have the sequence
based on TS value.

Allowed Conflict Pairs Based on TS value :


(I) T3 T1
(II) T1 T2
(III) T3 T2

Compare the dependencies obtained from the schedule with


the dependencies obtained from Timestamp :
T1 T3 : Dependency is not allowed. Rollback T3.
T3 T2 : Dependency is allowed.

Therefore, the schedule is not going to execute according


to the TS :
Timestamp Order = (T1,T2,T3) = (20,30,10)

Case (e) : Timestamp Order = (T1,T2,T3) = (10,30,20)


The concurrent execution schedule must have the sequence
based on TS value.

Allowed Conflict Pairs Based on TS value :


(I) T1 T3
(II) T3 T2
(III) T1 T2

Compare the dependencies obtained from the schedule with


the dependencies obtained from Timestamp :
T1 T3 : Dependency is allowed.
T3 T2 : Dependency is allowed.

Therefore, the schedule is going to execute according to


the TS :
Timestamp Order = (T1,T2,T3) = (10,30,20)

Problem 1: Inconsistency in the database


Below we have one schedule (set of transactions), here we have first given a serial
schedule. i. e. we can either execute T1 before T2 or T2 before T1.

T1: A->B (Transferring 50 rupees to B) T2: Display (B+A)

Lock-x(A)

Read(A)
A=A-50

write(A)

Unlock(A)

Lock-s(B)

Read(B)

Unlock(B)

Lock-s(A)

Read(A)

Unlock(A)

Display(A+B)

Read(B)

Lock-x(B)

B=B+50
write(B)

Unlock(B)

So above we have shown one interleaving and we could understand the data flow by
below example:

Output:

Let say in the start of the schedule A=100 and B=200 so in total we should have 300
always.

But as we see that after Till Display (B+A) we have A=50 and B=200 to total=250 but
it should be 300 to make consistency.

QUESTION: Consider the following two transactions:


T34: read(A);
read(B);
if A = 0 then B := B + 1;
write(B).
T35: read(B);
read(A);
if B = 0 then A := A + 1;
write(A).
Add lock and unlock instructions to transactions T31 and T32, so that
they observe the two-phase locking protocol. Can the execution of these
transactions result in a deadlock?

SOLUTION:
a. Lock and unlock instructions:
T34: lock-S(A)
read(A)
lock-X(B)
read(B)
if A = 0
then B := B + 1
write(B)
unlock(A)
unlock(B)
T35: lock-S(B)
read(B)
lock-X(A)
read(A)
if B = 0
then A := A + 1
write(A)
unlock(B)
unlock(A)
b. Execution of these transactions can result in deadlock. For example, consider the
following partial schedule:

The transactions are now deadlocked.

QUESTION:
Consider the timestamp-ordering protocol, and two transactions, one that
writes two data items p and q, and another that reads the same two data
items. Give a schedule whereby the timestamp test for a write operation
fails and causes the first transaction to be restarted, in turn causing a
cascading abort of the other transaction. Show how this could result in
starvation of both transactions. (Such a situation, where two or more
processes carry out actions, but are unable to complete their task because
of interaction with the other processes, is called a livelock.)

SOLUTION: Consider two transactions T1 and T2 shown below.

Let TS(T1) < TS(T2) and let the timestamp test at each operation except
write(q) be successful. When transaction T1 does the timestamp test for
write(q) it finds that TS(T1) < R-timestamp(q), since TS(T1) < TS(T2) and
R-timestamp(q) = TS(T2). Hence the writeoperation fails and transaction
T1 rolls back. The cascading results in transaction T2 also being rolled back
as it uses the value for item p that is written by transaction T1.
If this scenario is exactly repeated every time the transactions are restarted,
this could result in starvation of both transactions.

Das könnte Ihnen auch gefallen