1 CS542 Concurrency Control: Theory and Protocol Professor Elke A. Rundensteiner.

Slides:



Advertisements
Similar presentations
1 Shivnath Babu Concurrency Control (II) CS216: Data-Intensive Computing Systems.
Advertisements

Cs4432concurrency control1 CS4432: Database Systems II Lecture #21 Concurrency Control : Theory Professor Elke A. Rundensteiner.
Database Systems (資料庫系統)
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Database System Principles 18.7 Tree Locking Protocol CS257 Section 1 Spring 2012 Dhruv Jalota ID: 115.
1 Concurrency Control Conflict serializability Two phase locking Optimistic concurrency control Source: slides by Hector Garcia-Molina.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control Professor Elke A. Rundensteiner.
Concurrency Control II
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 2: Enforcing Serializable Schedules Professor Chen Li.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control: Locking-based Protocols Professor Elke A. Rundensteiner.
1 CS216 Advanced Database Systems Shivnath Babu Notes 12: Concurrency Control (II)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
CS4432: Database Systems II Lecture #26 Concurrency Control and Recovery Professor Elke A. Rundensteiner.
Quick Review of Apr 29 material
Conflict-Serializability Bharath Kumar Manur Venkataramana Class ID No:- 110.
Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.
Concurrency Control A.Sri Harsha Enforcing Serializability of Locks.
Concurrency Control R&G - Chapter 17 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book.
Concurrency Control. Example Schedules Constraint: The sum of A+B must be the same Before: After: T1 read(A) A = A -50 write(A) read(B)
Concurrency. Busy, busy, busy... In production environments, it is unlikely that we can limit our system to just one user at a time. – Consequently, it.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transactions or Concurrency Control. Introduction A program which operates on a DB performs 2 kinds of operations: –Access to the Database (Read/Write)
Transactions. Definitions Transaction (program): A series of Read/Write operations on items in a Database. Example: Transaction 1 Read(C) Read(A) Write(A)
Concurrency. Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
Database Management Systems I Alex Coman, Winter 2006
CS 245Notes 091 CS 245: Database System Principles Notes 09: Concurrency Control Hector Garcia-Molina.
Concurrency Control 18.1 – 18.2 Chiu Luk CS257 Database Systems Principles Spring 2009.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #21 Concurrency Control Professor Elke A. Rundensteiner.
CS 277 – Spring 2002Notes 091 CS 277: Database System Implementation Notes 09: Concurrency Control Arthur Keller.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #14.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
Cs4432concurrency control1 CS4432: Database Systems II Concurrency Control.
CS4432: Database Systems II Transaction Management Motivation 1.
Chapter 181 Chapter 18: Concurrency Control (Slides by Hector Garcia-Molina,
CS 245Notes 091 CS 245: Database System Principles Notes 09: Concurrency Control Hector Garcia-Molina.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control: Locking-based Protocols Professor Elke A. Rundensteiner.
1 Notes 09: Transaction Processing Slides are modified from the CS 245 class slides of Hector Garcia- Molina.
CS 245Notes 091 CS 245: Database System Principles Notes 09: Concurrency Control Hector Garcia-Molina.
DBMS 2001Notes 8: Concurrency1 Principles of Database Management Systems 8: Concurrency Control Pekka Kilpeläinen (after Stanford CS245 slide originals.
Transactions Sylvia Huang CS 157B. Transaction A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction.
TRANSACTIONS. Objectives Transaction Concept Transaction State Concurrent Executions Serializability Recoverability Implementation of Isolation Transaction.
CS 162 Discussion Section Week 9 11/11 – 11/15. Today’s Section ●Project discussion (5 min) ●Quiz (10 min) ●Lecture Review (20 min) ●Worksheet and Discussion.
1 CSE232A: Database System Principle Concurrency Control.
1 What we have covered? uIndexing and Hashing uData warehouse and OLAP uData Mining uInformation Retrieval and Web Mining uXML and XQuery uSpatial Databases.
Chapter 9 Concurrency Control. Contents Concurrency Control Concurrency Control by Locks Concurrency Control by Timestamps Concurrency Control by Validation.
1 Concurrency Control II: Locking and Isolation Levels.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Jinze Liu. Option 1: run system, recording P(S); at end of day, check for P(S) cycles and declare if execution was good.
1 Ullman et al. : Database System Principles Notes 09: Concurrency Control.
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
CS 440 Database Management Systems Concurrency Control 1.
Chapter 91 Chapter 9. Concurrency Control Fall 2001 Prof. Sang Ho Lee School of Computing, Soongsil Univ.
CS 540 Database Management Systems Concurrency Control 1.
CS 440 Database Management Systems
Concurrency Control.
Database Systems II Concurrency Control
CS 245: Database System Principles Notes 09: Concurrency Control
CS 245: Database System Principles Notes 09: Concurrency Control
בקרת בו זמניות (concurrency control)
Concurrency Control 11/22/2018.
Yan Huang - CSCI5330 Database Implementation – Concurrency Control
CS162 Operating Systems and Systems Programming Review (II)
Notes 09: Transaction Processing
Transaction Management Overview
CPSC-608 Database Systems
CS 245: Database System Principles Notes 09: Concurrency Control
CPSC-608 Database Systems
Data-Intensive Computing Systems
Lecture 18: Concurrency Control
Presentation transcript:

1 CS542 Concurrency Control: Theory and Protocol Professor Elke A. Rundensteiner

2 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

3 Now for Sd: 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) Sd=r 1 (A)w 1 (A) r 1 (B)w 1 (B)r 2 (A)w 2 (A)r 2 (B)w 2 (B) T1 T2

4 Or, let’s try for Sd: 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) Sd=r 2 (A)w 2 (A)r 2 (B)w 2 (B) r 1 (A)w 1 (A)r 1 (B)w 1 (B) T1 T2

5 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 D cannot be rearranged into serial schedule

6 Idea: Swap non-conflicting operation pairs to see if you can go to a serial schedule.

7 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.

8 Definition A schedule is conflict serializable if it is conflict equivalent to some (any) serial schedule.

9 One Answer: A Precedence Graph ! How determine this ?

10 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 )

11 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 conflict serializable?

12 Another Exercise: What is P(S) for S = w 1 (A) r 2 (A) r 3 (A) w 4 (A) ? Is S conflict serializable?

13 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

14 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) P(S 1 )=P(S 2 )  S 1, S 2 conflict equivalent ?? Note: P(S 1 )=P(S 2 )  S 1, S 2 conflict equivalent

15 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

16 (  ) 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

17 How to enforce serializable schedules?

18 How to enforce serializable schedules? Option 1 : try all possible swaps of non-conflicting operation pairs to determine if the schedule can be turned into a serial one, i.e., if the schedule is ‘good’.

19 How to enforce serializable schedules? Option 2: a) run system, recording P(S); b) at end of day, check for P(S) cycles c) and declare if execution was good

20 Option 3: prevent P(S) cycles from occurring T 1 T 2 …..T n Scheduler DB How to enforce serializable schedules?

21 A locking protocol Two new actions: lock (exclusive):l i (A) unlock:u i (A) scheduler T 1 T 2 lock table

22 Rule #1: Well-formed transactions T i : … l i (A) … p i (A) … u i (A)...

23 Rule #2 Legal scheduler S = …….. l i (A) ………... u i (A) ……... no l j (A)

24 What schedules are legal? What transactions are well-formed? S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B) r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B) l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B) S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B) l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) Exercise:

25 What schedules are legal? What transactions are well-formed? S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B) r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B) l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B) S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B) l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B) Exercise:

26 Schedule F : Adding locking ! How? T1 T2 l 1 (A);Read(A) A A+100;Write(A);u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);u 2 (A) l 2 (B);Read(B) B Bx2;Write(B);u 2 (B) l 1 (B);Read(B) B B+100;Write(B);u 1 (B) Legal ? Well-formed ?

27 Schedule F : Adding locking ! How? T1 T2 l 1 (A);Read(A) A A+100;Write(A);u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);u 2 (A) l 2 (B);Read(B) B Bx2;Write(B);u 2 (B) l 1 (B);Read(B) B B+100;Write(B);u 1 (B) AB

28 Rule #3 Two phase locking (2PL) for transactions T i = ……. l i (A) ………... u i (A) ……... no unlocks no locks

29 # locks held by Ti Time Growing Shrinking Phase Phase 2 Phase Locking Protocol

30 Schedule F : Can 2PL fix it ? T1 T2 l 1 (A);Read(A) A A+100;Write(A);u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);u 2 (A) l 2 (B);Read(B) B Bx2;Write(B);u 2 (B) l 1 (B);Read(B) B B+100;Write(B);u 1 (B)

31 Schedule G T1 T2 l 1 (A);Read(A) A A+100;Write(A) l 1 (B); u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);

32 Schedule G delayed

33 Schedule G delayed

34 Schedule G delayed

35 We Got the GOOD Schedule !!!! 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

36 Schedule H (T 2 reversed) What’s happening ?

37 Schedule H (T 2 reversed) delayed

38 Deadlocked transactions can arise in ‘good’ schedules (generated due to 2PL locking). We assume that when they are rolled back: –They have no effect –They do not appear in schedule E.g., Schedule H = This space intentionally left blank!

39 Correctness of 2PC Protocol : Show that rules #1,2,3  Conflict-serializable schedules

40 Conflict rules for l i (A), u i (A): l i (A), l j (A) conflict l i (A), u j (A) conflict

41 Theorem Rules #1,2,3  conflict (2PL) serializable schedule To help in proof: Definition Shrink(Ti) = SH(Ti) = first unlock action of Ti

42 Lemma Ti  Tj in S  SH(Ti) < S SH(Tj) Proof of lemma: Ti  Tj means that S = … p i (A) … q j (A) …; p,q conflict By rules 1,2: S = … p i (A) … u i (A) … l j (A)... q j (A) … SH(Ti) SH(Tj) By rule 3: So, SH(Ti) < S SH(Tj)

43 Proof: (1) Assume P(S) has cycle T 1  T 2  …. T n  T 1 (2) By lemma: SH(T 1 ) < SH(T 2 ) <... < SH(T 1 ) (3) Impossible, so P(S) acyclic (4)  S is conflict serializable Theorem Rules #1,2,3  conflict (2PL) serializable schedule

44 Beyond this simple 2PL protocol, it is all a matter of improving performance and allowing yet more concurrency…. –Shared locks –Multiple granularity –Inserts, deletes and phantoms –Other types of C.C. mechanisms