Concurrency Control Part 2 R&G - Chapter 17 The sequel was far better than the original! -- Nobody.

Slides:



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

Transaction Management and Concurrency Control
Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
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.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 4: More on Locks Professor Chen Li.
1 CS216 Advanced Database Systems Shivnath Babu Notes 12: Concurrency Control (II)
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
4/16/20151 PSU’s CS Concurrency Control and Recovery (only for DBs with updates…..!)- Review  Concurrency Control  Transaction  ACID  Isolation.
Managing Hierarchies of Database Elements (18.6) 1 Presented by Sarat Dasika (114) February 16, 2012.
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
1 Supplemental Notes: Practical Aspects of Transactions THIS MATERIAL IS OPTIONAL.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 19.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#22: Concurrency Control – Part 2 (R&G.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. –Because disk accesses are.
1 Concurrency Control Yanlei Diao UMass Amherst March 27 and 29, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
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.
Managing Hierarchies of Database Elements (18.6) -Neha Saxena Class Id: 214.
1 Concurrency Control. 2 Locking: A Technique for C. C. Concurrency control usually done via locking. Lock info maintained by a “lock manager”: –Stores.
Concurrency Control Managing Hierarchies of Database Elements (18.6) 1 Presented by Ronak Shah (214) March 9, 2009.
Dynamic Granular Locking Approach to Phantom Protection in R-trees Kaushik Chakrabarti Sharad Mehrotra Department of Computer Science University of Illinois.
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.
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.
Concurrency Control II R &G - Chapter 19 Lecture 22 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue.
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.
Presentation Topic 18.7 of Book Tree Protocol Submitted to: Prof. Dr. T.Y.LIN Submitted By :Saurabh Vishal.
18.7 The Tree Protocol Andy Yang. Outline Introduction Motivation Rules for Access to Tree-Structured Data Why the Tree Protocol Works.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#22: Concurrency Control – Part 2 (R&G.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Modified by Donghui Zhang.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Concurrency Control, II (R&G ch. 17)
CPSC 461. Outline I. Transactions II. Concurrency control Conflict Serializable Schedules Two – Phase protocol Lock Management Deadlocks detection and.
Concurrency Control R &G - Chapter 19. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses.
V. Megalooikonomou Concurrency control (based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and Sudarshan) Temple University – CIS.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Concurrency control.
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.
 Concurrent execution of user programs is essential for good DBMS performance. Disk accesses are frequent, and relatively slow. Want to keep the CPU working.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
1 Concurrency Control II: Locking and Isolation Levels.
Transaction Management: Concurrency Control CS634 Class 18, Apr 9, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Introduction to Database Management Systems, Jarek Gryz1 Transaction Management Overview Chapter 16.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#21: Concurrency Control (R&G ch. 17)
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 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
CS 440 Database Management Systems Concurrency Control 1.
Database Applications (15-415) DBMS Internals- Part XII Lecture 23, April 12, 2016 Mohammad Hammoud.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
CS 440 Database Management Systems
Concurrency Control Managing Hierarchies of Database Elements (18.6)
Concurrency Control Techniques
Extra slide #3.
Concurrency Control More !
Concurrency Control Chapter 17 Modified by Donghui Zhang
Concurrency Control Part 2
Concurrency Control Chapter 17
J.N GRAY R.A LORIE IBM RESEARCH LAB, SAN JOSE, CALIFORNIA
Database Applications (15-415) DBMS Internals- Part XII Lecture 24, April 11, 2018 Mohammad Hammoud.
Anthony D. Joseph and Ion Stoica
Concurrency Control Chapter 17
Transactions and Concurrency
Concurrency Control E0 261 Prasad Deshpande, Jayant Haritsa
Temple University – CIS Dept. CIS661 – Principles of Data Management
Concurrency Control Chapter 17
Database Management System
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Presentation transcript:

Concurrency Control Part 2 R&G - Chapter 17 The sequel was far better than the original! -- Nobody

Outline Last time: –Theory: conflict serializability, view serializability –Two-phase locking (2PL) –Strict 2PL –Dealing with deadlocks (prevention, detection) Today: “advanced” locking issues… –Locking granularity –Tree locking protocols –Phantoms & predicate locking

Locking Granularity Hard to decide what granularity to lock (tuples vs. pages vs. tables). why?

Multiple-Granularity Locks Shouldn’t have to make same decision for all transactions! Data “containers” are nested: Tuples Tables Pages Database contains

Solution: New Lock Modes, Protocol Allow Xacts to lock at each level, but with a special protocol using new “intention” locks: Still need S and X locks, but before locking an item, Xact must have proper intension locks on all its ancestors in the granularity hierarchy. v IS – Intent to get S lock(s) at finer granularity. v IX – Intent to get X lock(s) at finer granularity. v SIX mode: Like S & IX at the same time. Why useful? Tuples Tables Pages Database

Multiple Granularity Lock Protocol Each Xact starts from the root of the hierarchy. To get S or IS lock on a node, must hold IS or IX on parent node. –What if Xact holds S on parent? SIX on parent? To get X or IX or SIX on a node, must hold IX or SIX on parent node. Must release locks in bottom-up order. Protocol is correct in that it is equivalent to directly setting locks at the leaf levels of the hierarchy. Tuples Tables Pages Database

Lock Compatibility Matrix v IS – Intent to get S lock(s) at finer granularity. v IX – Intent to get X lock(s) at finer granularity. v SIX mode: Like S & IX at the same time. IS IX SIX IS IX SIX SX S X   -     Tuples Tables Pages Database

Examples – 2 level hierarchy T1 scans R, and updates a few tuples: –T1 gets an SIX lock on R, then get X lock on tuples that are updated. T2 uses an index to read only part of R: –T2 gets an IS lock on R, and repeatedly gets an S lock on tuples of R. T3 reads all of R: –T3 gets an S lock on R. –OR, T3 could behave like T2; can use lock escalation to decide which. –Lock escalation dynamically asks for coarser-grained locks when too many low level locks acquired IS IX SIX IS IX SIX      SX  S X   Tuples Tables

Outline Today: “advanced” locking issues… –Locking granularity –Tree locking protocols –Phantoms & predicate locking

Locking in B+ Trees What about locking indexes --- why is it needed? Tree-based indexes present a potential concurrency bottleneck: If you ignore the tree structure & just lock pages while traversing the tree, following 2PL. –Root node (and many higher level nodes) become bottlenecks because every tree access begins at the root. Special protocol for tree locking? –BTW, don’t confuse this with multiple granularity locking!

Two Useful Observations 1) In a B+Tree, higher levels of the tree only direct searches for leaf pages. 2) For inserts, a node on a path from root to modified leaf must be locked (in X mode, of course), only if a split can propagate up to it from the modified leaf. (Similar point holds w.r.t. deletes.) We can exploit these observations to design efficient locking protocols that guarantee serializability even though they violate 2PL.

A Simple Tree Locking Algorithm: “crabbing” Search: Start at root and go down; repeatedly, S lock child then unlock parent. Insert/Delete: Start at root and go down, obtaining X locks as needed. Once child is locked, check if it is safe: –If child is safe, release all locks on ancestors. Safe node: Node such that changes will not propagate up beyond this node. –Insertions: Node is not full. –Deletions: Node is not half-empty.

Example ROOT A B C DE F G H I * *23*24*35*36*38*41*44* Do: 1) Search 38* 2) Delete 38* 3) Insert 45* 4) Insert 25* 23

A Better Tree Locking Algorithm (From Bayer-Schkolnick paper) Search: As before. Insert/Delete: –Set locks as if for search, get to leaf, and set X lock on leaf. –If leaf is not safe, release all locks, and restart Xact using previous Insert/Delete protocol. Gambles that only leaf node will be modified; if not, S locks set on the first pass to leaf are wasteful. In practice, usually better than previous alg.

Example ROOT A B C DE F G H I * *23*24*35*36*38*41*44* Do: 1) Delete 38* 2) Insert 25* 23

Outline Today: “advanced” locking issues… –Locking granularity –Tree locking protocols –Phantoms & predicate locking

Dynamic Databases – The “Phantom” Problem Relax assumption that DB = fixed collection of objects Even Strict 2PL (on individual items) will not ensure serializability: Consider T1 – “Find oldest sailor” –T1 locks all records, and finds oldest sailor (say, age = 71). –Next, T2 inserts a new sailor; age = 96 and commits. –T1 (within the same transaction) checks for the oldest sailor again and finds sailor aged 96!! The sailor with age 96 is a “phantom tuple” from T1’s point of view --- first it’s not there then it is. No serial execution where T1’s result could happen!

The “Phantom” Problem – example 2 Consider T3 – “Find oldest sailor for each rating” –T3 locks all pages containing sailor records with rating = 1, and finds oldest sailor (say, age = 71). –Next, T4 inserts a new sailor; rating = 1, age = 96. –T4 also deletes oldest sailor with rating = 2 (and, say, age = 80), and commits. –T3 now locks all pages containing sailor records with rating = 2, and finds oldest (say, age = 63). T3 saw only part of T4’s effects! No serial execution where T3’s result could happen!

The Problem T1 and T3 implicitly assumed that they had locked the set of all sailor records satisfying a predicate. –Assumption only holds if no sailor records are added while they are executing! –Need some mechanism to enforce this assumption. (Index locking and predicate locking.) Examples show that conflict serializability on reads and writes of individual items guarantees serializability only if the set of objects is fixed!

Predicate Locking Grant lock on all records that satisfy some logical predicate, e.g. age > 2*salary. In general, predicate locking has a lot of locking overhead. Index locking is a special case of predicate locking for which an index supports efficient implementation of the predicate lock. –What is the predicate in the sailor example?

Index Locking If there is a dense index on the rating field using Alternative (2), T3 should lock the index page containing the data entries with rating = 1. –If there are no records with rating = 1, T3 must lock the index page where such a data entry would be, if it existed! If there is no suitable index, T3 must obtain: 1.A lock on every page in the table file To prevent a record’s rating from being changed to 1 AND 2.The lock for the file itself To prevent records with rating = 1 from being added or deleted r=1 Data Index

Transaction Support in SQL-92 SERIALIZABLE – No phantoms, all reads repeatable, no “dirty” (uncommited) reads. REPEATABLE READS – phantoms may happen. READ COMMITTED – phantoms and unrepeatable reads may happen READ UNCOMMITTED – all of them may happen.

Summary Multiple granularity locking – flexibility for each xact to choose locking granularity independently Tree-structured indexes: –Straightforward use of 2PL very inefficient. –Instead, design specialized locking protocols for trees Other work in this (important) area, e.g., Lehman-Yao If database objects can be added/removed, need to guard against Phantom Problem –Must lock logical sets of records. –Efficient solution: index locking.