370 likes | 1.06k Views
Conflict-Serializability. Bharath Kumar Manur Venkataramana Class ID No:- 110. Conflicts. What do you mean by a conflict in database? Example situation for such a conflict? Online Reservation Systems. 4 situations where conflict cannot happen.
E N D
Conflict-Serializability Bharath Kumar Manur Venkataramana Class ID No:- 110
Conflicts • What do you mean by a conflict in database? • Example situation for such a conflict? Online Reservation Systems. • 4 situations where conflict cannot happen 1) Ri (X) ; Rj (Y) will never conflict, even if database element X=Y. 2) Ri (X) ; Wi (Y) will not conflict for X not equal to Y. 3) Wi (X) ; Rj (Y) will not conflict for X not equal to Y. 4) Wi (X) ; Wj (Y) will not conflict for X not equal to Y.
Conflicts • There are 3 situations where we may not swap the order of actions. They are:- 1) Two actions of the same transactions conflict. 2) Two writes of the same database element by different transactions conflict. 3) A read and a write of the same database element by different transactions also conflict.
Conflict Serializability • Two actions conflict if:- 1) They are issued by different transactions. 2) They operate on the same database element. 3) At least one of them is a write operation. • The 2 schedules S and S1 are conflict-equivalent, if S can be transformed into S1 by a sequence of non-conflicting swaps of adjacent actions. • A schedule is conflict-serializable if it is conflict-equivalent to a serial schedule.
Conflict Serializability (Contd.) • Schedule 1 can be transformed into Schedule 5, a serial schedule where T2 follows T1, by series of swaps of non-conflicting instructions. • Therefore Schedule 1 is conflict serializable. Schedule 1 Schedule 5
Precedence Graphs • A Precedence graph is used to find out whether a schedule is conflict-serializable or not. • There are 2 types of precedence graphs :- • Acyclic Graphs which determines that the Schedule S is conflict-serializable. • Cyclic Graphs which are nothing but the conflict graphs which cannot determine the precedence order for the Schedule S.
Algorithm to produce a Precedence Graph • Add a node for each transaction. • Add a directed edge from Ti to Tj, if Tj reads the value of a database element written by Ti. • Add a directed edge from Ti to Tj, if Tj writes a value into the database element after it has been read by Ti. • If the graph is cyclic, then the Schedule is not Conflict-Serializable.
Acyclic Graphs • An example of a Schedule S. Example Schedule R2(a) R1(b) W2(a) R3(a) W1(b) W3(a) R2(b) W2(b) Precedence Graph T1 T2 T3
Conflict or Cyclic Graphs • An example of a Schedule S. Example Schedule W1(a) R2(a) R3(b) W2(c) R3(c) W3(a) W3(b) R1(b) T1 T2 Precedence Graph T3 Execution is conflict-serializable only if the conflict graph is acyclic.
Test for Conflict-Serializability • Let S be a schedule which consists of action of n transactions, T1 -> T2 -> T3 -> ..... -> Tn -> T1. • The actions of T1 precedes T2 and so on till Tn , but since the action of Tn precedes T1. • Due to Tn -> T1, we find there is a cycle in the precedence graph and the conclusion is that the schedule is not conflict-serializable. • Finally a schedule is conflict serializable if and only if its precedence graph is acyclic.