1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Advertisements

Database Systems (資料庫系統)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Transaction Management and Concurrency Control
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Introduction to Database Systems1 Concurrency Control CC.Lecture 1.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
Concurrency Control Part 2 R&G - Chapter 17 The sequel was far better than the original! -- Nobody.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. –Because disk accesses are.
Transaction Overview and Concurrency Control Chapters 16 & 17.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Concurrency Control R &G - Chapter 19 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
Transaction Management and Concurrency Control
1 Concurrency Control and Recovery Module 6, Lecture 1.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
1 Transaction Management Overview Yanlei Diao UMass Amherst March 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Final Exam Review Last Lecture R&G - All Chapters Covered The end crowns all, And that old common arbitrator, Time, Will one day end it. William Shakespeare.
1 Lecture 08: Transaction management overview
Transaction Management and Concurre cy Overview R & G Chapter There are three side effects of acid. Enhanced long term memory, decreased short term.
Concurrency Control R &G - Chapter 19 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Modified by Donghui Zhang.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Transaction Management Overview Chapter Transactions  A transaction is the DBMS’s abstract view of a user program: a sequence of reads and writes.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Concurrency Control R &G - Chapter 19. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
1 Transaction Processing Chapter Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data.
1 Concurrency Control II: Locking and Isolation Levels.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Instructor: Xintao Wu.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
Overview of Transaction Management
Transaction Management and Recovery, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
1 Database Systems ( 資料庫系統 ) December 27/28, 2006 Lecture 13 Merry Christmas & New Year.
CS 440 Database Management Systems Concurrency Control 1.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
SIMPLE CONCURRENCY CONTROL. Correctness criteria: The ACID properties A A tomicity: All actions in the Xact happen, or none happen. C C onsistency: If.
MULTIUSER DATABASES : Concurrency and Transaction Management.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Database Systems (資料庫系統)
Transaction Management Overview
Database Systems (資料庫系統)
Transaction Management Overview
Transaction Management
Transaction Management Overview
Transaction Management Overview
Transaction Management
Transaction Management Overview
Lecture 21: Concurrency & Locking
Transaction Management
Database Management systems Subject Code: 10CS54 Prepared By:
Temple University – CIS Dept. CIS661 – Principles of Data Management
Transaction Management Overview
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Transaction Management Overview
Presentation transcript:

1 Concurrency Control

2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While one processes is doing a disk read, another can be using the CPU or reading another disk.  DANGER DANGER!  DANGER DANGER! Concurrency could lead to incorrectness! –Must carefully manage concurrent data access. –There’s (much!) more here than the usual OS tricks!

3 Transactions v Basic concurrency/recovery concept: a transaction (Xact). –A sequence of many actions which are considered to be one atomic unit of work. v DBMS “actions”: –reads, writes –Special actions: commit, abort

4 ACID The ACID Properties v A v A tomicity: All actions in the Xact happen, or none happen. v C v C onsistency: If each Xact is consistent, and the DB starts consistent, it ends up consistent. v I v I solation: Execution of one Xact is isolated from that of other Xacts. v D v D urability: If a Xact commits, its effects persist.

5 Passing the ACID Test v Concurrency Control –Guarantees Consistency and Isolation, given Atomicity. v Logging and Recovery –Guarantees Atomicity and Durability. v We’ll do C. C. first: –What problems could arise? –What is acceptable behavior? –How do we guarantee acceptable behavior?

6 Schedules v Schedule: An interleaving of actions from a set of Xacts, where the actions of any 1 Xact are in the original order. –Represents some actual sequence of database actions. –Example: R 1 (A), W 1 (A), R 2 (B), W 2 (B), R 1 (C), W 1 (C) –In a complete schedule, each Xact ends in commit or abort.  Initial State + Schedule  Final State

7 Acceptable Schedules v One sensible “isolated, consistent” schedule: –Run Xacts one at a time, in a series. –This is called a serial schedule. –NOTE: Different serial schedules can have different final states; all are “OK” -- DBMS makes no guarantees about the order in which concurrently submitted Xacts are executed. v Serializable schedules: –Final state is what some serial schedule would have produced. –Aborted Xacts are not part of schedule; ignore them for now (they are made to `disappear’ by using logging).

8 Serializability Violations v Two actions conflict when 2 xacts access the same item: –W-R conflict: T2 reads something T1 wrote; T1 still active –R-W and W-W conflicts: Similar. v WR conflict (dirty read): –Result is not equal to any serial execution! –T2 reads what T1 wrote, but it shouldn’t have!! transfer $100 from A to B add 6% interest to A & B Database is inconsistent!

9 More Conflicts v RW Conflicts (Unrepeatable Read) –T2 overwrites what T1 read. –Again, not equivalent to a serial execution. v WW Conflicts (Lost Update) –T2 overwrites what T1 wrote. –Usually occurs with RW or WR anomalies. u Unless you have “blind writes” (as here). T1:R(A), R(A), C T2:R(A), W(A), C T1:W(A), W(B), C T2:W(A), W(B), C

10 Now, Aborted Transactions v Serializable schedule: Equivalent to a serial schedule of committed Xacts. –as if aborted Xacts never happened. v Two Issues: –How does one undo the effects of an xact? u We’ll cover this in logging/recovery –What if another Xact sees these effects?? u Must undo that Xact as well!

11 Cascading Aborts v Abort of T1 requires abort of T2! –Cascading Abort v What about WW conflicts & aborts? –T2 overwrites a value that T1 writes. –T1 aborts: its “remembered” values are restored. –Lose T2’s write! We will see how to solve this, too. v An ACA (avoids cascading abort) schedule is one in which cascading abort cannot arise. –A Xact only reads/writes data from committed Xacts.

12 Recoverable Schedules v Abort of T1 requires abort of T2! –But T2 has already committed! v A recoverable schedule is one in which this cannot happen. –i.e. a Xact commits only after all the Xacts it “depends on” (i.e. it reads from or overwrites) commit. –Recoverable implies ACA (but not vice-versa!). v Real systems typically ensure that only recoverable schedules arise (through locking).

13 Locking: A Technique for C. C. v Concurrency control usually done via locking. v Lock info maintained by a “lock manager”: –Stores (XID, RID, Mode) triples. u This is a simplistic view; suffices for now. –Mode  {S,X} –Lock compatibility table: v If a Xact can’t get a lock, it is suspended on a wait queue. -- SX S X      LOCK REQUESTED LOCKHELDLOCKHELD

14 Two-Phase Locking (2PL) v 2PL: –If T wants to read an object, first obtains an S lock. –If T wants to modify an object, first obtains X lock. –If T releases any lock, it can acquire no new locks! v Locks are automatically obtained by DBMS. v Guarantees serializability! –Why? Time # of locks lock point growing phase shrinking phase

15 Strict 2PL v Strict 2PL: –If T wants to read an object, first obtains an S lock. –If T wants to modify an object, first obtains X lock. –Hold all locks until end of transaction. v Guarantees serializability, and recoverable schedule, too! –Thus ensures ACA! Time # of locks

16 Precedence Graph v A Precedence (or Serializability) graph: –Node for each committed Xact. –Arc from Ti to Tj if an action of Ti precedes and conflicts with an action of Tj. v T1 transfers $100 from A to B, T2 adds 6% –R 1 (A), W 1 (A), R 2 (A), W 2 (A), R 2 (B), W 2 (B), R 1 (B), W 1 (B) T1 T2

17 Conflict Serializability v 2 schedules are conflict equivalent if: –they have the same sets of actions, and –each pair of conflicting actions is ordered in the same way. v A schedule is conflict serializable if it is conflict equivalent to a serial schedule. –Note: Some serializable schedules are not conflict serializable!

18 Conflict Serializability & Graphs v Theorem: A schedule is conflict serializable iff its precedence graph is acyclic. v Theorem: 2PL ensures that the precedence graph will be acyclic! v Strict 2PL improves on this by avoiding cascading aborts, problems with undoing WW conflicts; i.e., ensuring recoverable schedules.

19 Lock Manager Implementation v Question 1: What are we locking? –Tuples, pages, or tables? –Finer granularity increases concurrency, but also increases locking overhead. v Question 2: How do you “lock” something?? v Lock Table: A hash table of Lock Entries. – Lock Entry: u OID u Mode u List: Xacts holding lock (or a count) u List: Wait Queue

20 Dynamic Databases v If we relax the assumption that the DB is a fixed collection of objects, even Strict 2PL will not assure serializability: –T1 locks all pages containing sailor records with rating = 1, and finds oldest sailor (say, age = 71). –Next, T2 inserts a new sailor; rating = 1, age = 96. –T2 also deletes oldest sailor with rating = 2 (and, say, age = 80), and commits. –T1 now locks all pages containing sailor records with rating = 2, and finds oldest (say, age = 63). v No consistent DB state where T1 is “correct”!

21 The Problem v T1 implicitly assumes that it has locked the set of all sailor records with rating = 1. –Assumption only holds if no sailor records are added while T1 is executing! –Need some mechanism to enforce this assumption. (Index locking, predicate locking, or table locking.) v Example shows that conflict serializability guarantees serializability only if the set of objects is fixed!

22 Summary of Concurrency Control v Concurrency control key to a DBMS. –More than just mutexes! v Transactions and the ACID properties: –C & I are handled by concurrency control. –A & D coming soon with logging & recovery. v Conflicts arise when two Xacts access the same object, and one of the Xacts is modifying it. v Serial execution is our model of correctness.

23 Summary, cont. v Serializability allows us to “simulate” serial execution with better performance. v 2PL: A simple mechanism to get serializability. –Strict 2PL also gives us recoverability, ACA v Lock manager module automates 2PL so that only the access methods worry about it. –Lock table is a big main-mem hash table v Deadlocks are possible, and typically a deadlock detector is used to solve the problem.

24 Summary, cont.: SQL-92 support

25 State of the Art (concurrency) v CC in broadcast data environments v Update propagation for replication v CC in search trees (R trees, etc.) v Distributed optimistic CC v CC in real-time DBMS v CC for “long” transactions v Version management