Presentation on theme: "Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control Professor Elke A. Rundensteiner."— Presentation transcript:
cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control Professor Elke A. Rundensteiner
cs4432concurrency control2 Chapter 9Concurrency Control T1T2…Tn DB (consistency constraints)
cs4432concurrency control3 Concepts Transaction: sequence of r i (x), w i (x) actions Conflicting actions: r 1(A) w 2(A) w 1(A) w 2(A) r 1(A) w 2(A) Schedule: represents chronological order in which actions are executed Serial schedule: no interleaving of actions or transactions
cs4432concurrency control4 A ReCap Examples of Main Concepts are given next.
cs4432concurrency control5 Example: T1:Read(A)T2:Read(A) A A+100A A 2Write(A)Read(B) B B+100B B 2Write(B) Constraint: A=B
cs4432concurrency control6 Schedule C T1T2 Read(A); A A+100 Write(A); Read(A);A A 2; Write(A); Read(B); B B+100; Write(B); Read(B);B B 2; Write(B); AB
cs4432concurrency control8 Returning to Sc Sc=r 1 (A)w 1 (A)r 2 (A)w 2 (A)r 1 (B)w 1 (B)r 2 (B)w 2 (B) T 1 T 2 T 1 T 2 no cycles Sc is “equivalent” to a serial schedule, I.e., in this case (T 1,T 2 ).
cs4432concurrency control9 Schedule D T1T2 Read(A); A A+100 Write(A); Read(A);A A 2; Write(A); Read(B);B B 2; Write(B); Read(B); B B+100; Write(B); AB
cs4432concurrency control12 For Schedule D: Sd=r 1 (A)w 1 (A)r 2 (A)w 2 (A) r 2 (B)w 2 (B)r 1 (B)w 1 (B) there seems to be no save way to transform this S-D into an equivalent serial schedule?
cs4432concurrency control13 For Schedule D: Sd=r 1 (A)w 1 (A)r 2 (A)w 2 (A) r 2 (B)w 2 (B)r 1 (B)w 1 (B) T 1 T 2 T 2 T 1 T 1 T 2 Sd cannot be rearranged into serial schedule
cs4432concurrency control14 Definition S 1, S 2 are conflict equivalent schedules if S 1 can be transformed into S 2 by a series of swaps on non-conflicting actions.
cs4432concurrency control15 Definition A schedule is conflict serializable if it is conflict equivalent to some serial schedule.
cs4432concurrency control16 Answer: A Precedence Graph ! How determine this ?
cs4432concurrency control17 Nodes: transactions in S Arcs: Ti Tj whenever - p i (A), q j (A) are actions in S - p i (A) < S q j (A) - at least one of p i, q j is a write Precedence graph P(S) (S is schedule )
cs4432concurrency control18 Exercise: What is P(S) for S = w 3 (A) w 2 (C) r 1 (A) w 1 (B) r 1 (C) w 2 (A) r 4 (A) w 4 (D) Is S serializable?
cs4432concurrency control19 Another Exercise: What is P(S) for S = w 1 (A) r 2 (A) r 3 (A) w 4 (A) ? Is S serializable?
cs4432concurrency control20 Lemma S 1, S 2 conflict equivalent P(S 1 )=P(S 2 ) Proof: Assume P(S 1 ) P(S 2 ) T i : T i T j in S 1 and not in S 2 S 1 = …p i (A)... q j (A)… p i, q j S 2 = …q j (A)…p i (A)... conflict S 1, S 2 not conflict equivalent
cs4432concurrency control21 Note: P(S 1 )=P(S 2 ) S 1, S 2 conflict equivalent Counter example: S 1 =w 1 (A) r 2 (A) w 2 (B) r 1 (B) S 2 =r 2 (A) w 1 (A) r 1 (B) w 2 (B)
cs4432concurrency control22 Theorem P(S 1 ) acyclic S 1 conflict serializable ( ) Assume S 1 is conflict serializable S s : S s, S 1 conflict equivalent P(S s ) = P(S 1 ) P(S 1 ) acyclic since P(S s ) is acyclic
cs4432concurrency control23 ( ) Assume P(S 1 ) is acyclic Transform S 1 as follows: (1) Take T 1 to be transaction with no incident arcs (2) Move all T 1 actions to the front S 1 = ……. q j (A)……. p 1 (A)….. (3) we now have S 1 = (4) repeat above steps to serialize rest! T 1 T 2 T 3 T 4 Theorem P(S 1 ) acyclic S 1 conflict serializable
cs4432concurrency control24 How to enforce serializable schedules? Next Time …