Concurrency Control R&G - Chapter 17

Slides:



Advertisements
Similar presentations
Database Systems (資料庫系統)
Advertisements

1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 6: Cascading Rollbacks, Deadlocks, and Long Transactions Professor Chen Li.
Transaction Overview and Concurrency Control Chapters 16 & 17.
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
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.
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 Control II R &G - Chapter 17 Lecture 20 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17.
Transaction Processing: Concurrency and Serializability 10/4/05.
CS194-3/CS16x Introduction to Systems Lecture 8 Database concurrency control, Serializability, conflict serializability, 2PL and strict 2PL September.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
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.
Concurrency Control. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Transaction Processing.
Transactions Introduction and Concurrency Control Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#21: Concurrency Control (R&G ch. 17)
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Concurrency Control, II (R&G ch. 17)
Concurrency Control R &G - Chapter 19. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#21: Concurrency Control (R&G ch. 17)
Chapter 11 Concurrency Control. Lock-Based Protocols  A lock is a mechanism to control concurrent access to a data item  Data items can be locked in.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Concurrency Control II: Locking and Isolation Levels.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
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 ( 朱浩華 )
CS 440 Database Management Systems
Diskusi-08 Jelaskan dan berikan contoh penggunaan theta join, equijoin, natural join, outer join, dan semijoin The slides for this text are organized into.
Transactions Intro & Concurrency Control
Database Systems (資料庫系統)
Diskusi-5 Sebutkan perangkat (tools) yang berpotensi mendukung kebutuhan tugas-tugas manajerial (management work) Jelaskan enam karakteristik informasi.
Diskusi-1 Bacalah materi chapter-01, lalu buatlah ringkasan yang berisi tentang : Definisi EUIS Siapa end user Dampak euis pada lingkungan kerja Perencanaan.
Latihan Answer the following questions using the relational schema from the Exercises at the end of Chapter 3: Create the Hotel table using the integrity.
Transaction Management Overview
Diskusi-16 Buatlah ringkasan tentang pertimbangan dalam desain yang ergonomis pada tiga perangkat utama komputer yaitu monitor, keyboard dan mouse (lihat.
Concurrency Control More !
Concurrency Control.
Transaction Management Overview
April 9, 2014 Anthony D. Joseph CS162 Operating Systems and Systems Programming Lecture 19 Transactions, Two Phase.
Latihan Create a separate table with the same structure as the Booking table to hold archive records. Using the INSERT statement, copy the records from.
Tugas-05 a. Sebutkan primary key masing-masing tabel
Transaction Management
Transaction Management Overview
Anthony D. Joseph and John Canny
April 4, 2011 Ion Stoica CS162 Operating Systems and Systems Programming Lecture 18 Transactions April 4, 2011 Ion.
Transaction Overview and Concurrency Control
Anthony D. Joseph and Ion Stoica
Transaction Management
Transaction Management Overview
March 9th – Transactions
Lecture#21: Concurrency Control – Part 1
Concurrency Control Chapter 17
Lecture 21: Concurrency & Locking
CS162 Operating Systems and Systems Programming Review (II)
Chapter 15 : Concurrency Control
Concurrency Control Chapter 17
Lecture 22: Intro to Transactions & Logging IV
Transaction Management
Temple University – CIS Dept. CIS661 – Principles of Data Management
Transaction Management Overview
Database Systems (資料庫系統)
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Transaction Management Overview
Presentation transcript:

Concurrency Control R&G - Chapter 17 The slides for this text are organized into chapters. This lecture covers Chapter 19. The slides present the material suitable at the level of a graduate course; concurrency control in B+ Trees, optimistic concurrency control, and multiversion concurrency control are explained in detail. For an introductory undergraduate course, we usually cover only the material in slides 1 to 20. Chapter 1: Introduction to Database Systems Chapter 2: The Entity-Relationship Model Chapter 3: The Relational Model Chapter 4 (Part A): Relational Algebra Chapter 4 (Part B): Relational Calculus Chapter 5: SQL: Queries, Programming, Triggers Chapter 6: Query-by-Example (QBE) Chapter 7: Storing Data: Disks and Files Chapter 8: File Organizations and Indexing Chapter 9: Tree-Structured Indexing Chapter 10: Hash-Based Indexing Chapter 11: External Sorting Chapter 12 (Part A): Evaluation of Relational Operators Chapter 12 (Part B): Evaluation of Relational Operators: Other Techniques Chapter 13: Introduction to Query Optimization Chapter 14: A Typical Relational Optimizer Chapter 15: Schema Refinement and Normal Forms Chapter 16 (Part A): Physical Database Design Chapter 16 (Part B): Database Tuning Chapter 17: Security Chapter 18: Transaction Management Overview Chapter 19: Concurrency Control Chapter 20: Crash Recovery Chapter 21: Parallel and Distributed Databases Chapter 22: Internet Databases Chapter 23: Decision Support Chapter 24: Data Mining Chapter 25: Object-Database Systems Chapter 26: Spatial Data Management Chapter 27: Deductive Databases Chapter 28: Additional Topics Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book

Review ACID transaction semantics. Today: focus on Isolation property Serial schedules safe but slow Try to find schedules equivalent to serial …

Conflicting Operations Need a tool to decide if 2 schedules are equivalent Use notion of “conflicting” operations Definition: Two operations conflict if: They are by different transactions, they are on the same object, and at least one of them is a write.

Conflict Serializable Schedules Definition: Two schedules are conflict equivalent iff: They involve the same actions of the same transactions, and every pair of conflicting actions is ordered the same way Definition: Schedule S is conflict serializable if: S is conflict equivalent to some serial schedule. Note, some “serializable” schedules are NOT conflict serializable A price we pay to achieve efficient enforcement.

Conflict Serializability – Intuition A schedule S is conflict serializable if: You are able to transform S into a serial schedule by swapping consecutive non-conflicting operations of different transactions. Example: R(A) R(B) W(A) W(B) R(A) W(A) R(B) R(A) W(A) R(B) R(B) W(B) R(A) W(B) W(B) W(A) R(A) W(A) R(B) W(B)

Conflict Serializability (Continued) Here’s another example: Serializable or not???? R(A) W(A) R(A) W(A) NOT!

Dependency Graph Dependency graph: Ti Tj Dependency graph: One node per Xact Edge from Ti to Tj if: An operation Oi of Ti conflicts with an operation Oj of Tj and Oi appears earlier in the schedule than Oj. Theorem: Schedule is conflict serializable if and only if its dependency graph is acyclic.

Example A schedule that is not conflict serializable: The cycle in the graph reveals the problem. The output of T1 depends on T2, and vice-versa. T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1: R(A), W(A), R(B), W(B) T2: T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) A T1 T2 Dependency graph B

An Aside: View Serializability Alternative (weaker) notion of serializability. Schedules S1 and S2 are view equivalent if: If Ti reads initial value of A in S1, then Ti also reads initial value of A in S2 If Ti reads value of A written by Tj in S1, then Ti also reads value of A written by Tj in S2 If Ti writes final value of A in S1, then Ti also writes final value of A in S2 Basically, allows all conflict serializable schedules + “blind writes” T1: R(A) W(A) T2: W(A) T3: W(A) T1: R(A),W(A) T2: W(A) T3: W(A) view

Notes on Serializability Definitions View Serializability allows (slightly) more schedules than Conflict Serializability does. Problem is that it is difficult to enforce efficiently. Neither definition allows all schedules that you would consider “serializable”. This is because they don’t understand the meanings of the operations or the data. In practice, Conflict Serializability is what gets used, because it can be enforced efficiently. To allow more concurrency, some special cases do get handled separately, such as for travel reservations, etc.

Two-Phase Locking (2PL) X  – Lock Compatibility Matrix rules: Xact must obtain a S (shared) lock before reading, and an X (exclusive) lock before writing. Xact cannot get new locks after releasing any locks.

Two-Phase Locking (2PL), cont. acquisition phase release phase # locks held time But, does not prevent Cascading Aborts. 2PL guarantees conflict serializability

Strict 2PL Problem: Cascading Aborts Example: rollback of T1 requires rollback of T2! Strict Two-phase Locking (Strict 2PL) protocol: Same as 2PL, except: Locks released only when transaction completes i.e., either: (a) transaction has committed (commit record on disk), or (b) transaction has aborted and rollback is complete. T1: R(A), W(A), R(B), W(B), Abort T2: R(A), W(A)

Strict 2PL (continued) acquisition phase # locks held release all locks at end of xact time

Next ... A few examples

Non-2PL, A= 1000, B=2000, Output =? Lock_X(A) Read(A) Lock_S(A) A: = A-50 Write(A) Unlock(A) Lock_S(B) Lock_X(B) Read(B) Unlock(B) PRINT(A+B) B := B +50 Write(B)

2PL, A= 1000, B=2000, Output =? Lock_X(A) Read(A) Lock_S(A) A: = A-50 Write(A) Lock_X(B) Unlock(A) Lock_S(B) Read(B) B := B +50 Write(B) Unlock(B) PRINT(A+B)

Strict 2PL, A= 1000, B=2000, Output =? Lock_X(A) Read(A) Lock_S(A) A: = A-50 Write(A) Lock_X(B) Read(B) B := B +50 Write(B) Unlock(A) Unlock(B) Lock_S(B) PRINT(A+B)

Venn Diagram for Schedules All Schedules View Serializable Conflict Serializable Avoid Cascading Abort Serial

Which schedules does Strict 2PL allow? All Schedules View Serializable Conflict Serializable Avoid Cascading Abort Serial

Lock Management Lock and unlock requests handled by Lock Manager LM keeps an entry for each currently held lock. Entry contains: List of xacts currently holding lock Type of lock held (shared or exclusive) Queue of lock requests

Lock Management, cont. When lock request arrives: Lock upgrade: Does any other xact hold a conflicting lock? If no, grant the lock. If yes, put requestor into wait queue. Lock upgrade: xact with shared lock can request to upgrade to exclusive

Example Lock_X(A) Lock_S(B) Read(B) Lock_S(A) Read(A) A: = A-50 Write(A) Lock_X(B)

Deadlocks Deadlock: Cycle of transactions waiting for locks to be released by each other. Two ways of dealing with deadlocks: prevention detection Many systems just punt and use Timeouts What are the dangers with this approach?

Deadlock Detection Create and maintain a “waits-for” graph Periodically check for cycles in graph

Deadlock Detection (Continued) Example: T1: S(A), S(D), S(B) T2: X(B) X(C) T3: S(D), S(C), X(A) T4: X(B) T1 T2 T4 T3

Deadlock Prevention Assign priorities based on timestamps. Say Ti wants a lock that Tj holds Two policies are possible: Wait-Die: If Ti has higher priority, Ti waits for Tj; otherwise Ti aborts Wound-wait: If Ti has higher priority, Tj aborts; otherwise Ti waits Why do these schemes guarantee no deadlocks? Important detail: If a transaction re-starts, make sure it gets its original timestamp. -- Why?

Summary Correctness criterion for isolation is “serializability”. In practice, we use “conflict serializability,” which is somewhat more restrictive but easy to enforce. Two Phase Locking and Strict 2PL: Locks implement the notions of conflict directly. The lock manager keeps track of the locks issued. Deadlocks may arise; can either be prevented or detected.