Concurrency Control. Example Schedules Constraint: The sum of A+B must be the same Before: 100+50 After: 45+105 T1 read(A) A = A -50 write(A) read(B)

Slides:



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

Concurrency Control II
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Lecture 12 Transactions: Isolation. Transactions What’s hard? – ACID – Concurrency control – Recovery.
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Transaction Overview and Concurrency Control Chapters 16 & 17.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
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.
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 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.
Concurrency Control II
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
1 Transaction Management Database recovery Concurrency control.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
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.
Chapter 181 Chapter 18: Concurrency Control (Slides by Hector Garcia-Molina,
15.1Database System Concepts - 6 th Edition Chapter 15: Concurrency Control Lock-Based Protocols The Two-Phase Locking Protocol Graph-Based Protocols #Deadlock.
Concurrency Control.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Concurrency Control, II (R&G ch. 17)
General Overview Where we’ve been... DBA skills for relational DB’s: Logical Schema Design  E/R diagrams  Decomposition and Normalization.
©Silberschatz, Korth and Sudarshan14.1Database System Concepts - 6 th Edition UNIT 5 :Transactions Transaction concepts, properties of transactions, serializability.
Concurrency Control Lectured by, Jesmin Akhter, Assistant professor, IIT, JU.
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.
CONCURRENCY CONTROL (CHAPTER 16) CONCURRENCY CONTROL INTRODUCTION Motivation: A dbms is multiprogrammed to increase the utilization.
Concurrency control. Lock-based protocols One way to ensure serializability is to require the data items be accessed in a mutually exclusive manner One.
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
Concurrency Control Concurrency Control By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
Database Techniek Lecture 5: Concurrency Control (Chapter 14/16)
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Lecture 8- Concurrency Control Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Chapter 8 Concurrency Control 8.1 Lock-Based Protocols 8.2 Multiple Granularity 8.3 Deadlock Handling 8.4 Insert and Delete Operations.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15 : Concurrency.
CS 440 Database Management Systems Concurrency Control 1.
CS 540 Database Management Systems Concurrency Control 1.
CS 440 Database Management Systems
Concurrency Control.
Part- A Transaction Management
Transaction Processing
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
Chapter 16: Concurrency Control
בקרת בו זמניות (concurrency control)
Concurrency Control 11/22/2018.
Anthony D. Joseph and Ion Stoica
Lock Granularity and Consistency Levels (Lecture 7, cs262a)
CONCURRENCY CONTROL (CHAPTER 16)
Database System Implementation CSE 507
March 9th – Transactions
Database System Implementation CSE 507
Yan Huang - CSCI5330 Database Implementation – Concurrency Control
CS162 Operating Systems and Systems Programming Review (II)
Chapter 16: Concurrency Control
Chapter 15 : Concurrency Control
Concurrency Control R&G - Chapter 17
Temple University – CIS Dept. CIS661 – Principles of Data Management
CPSC-608 Database Systems
Database Management System
Lecture 18: Concurrency Control
Lecture 8 Transactions.
Presentation transcript:

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) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) Transactions: T1: transfers $50 from A to B T2: transfers 10% of A to B =150, consistent Example 1: a “serial” schedule

Example Schedule Another “serial” schedule: T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) Before: After: Consistent but not the same as previous schedule.. Either is OK! =150, consistent

Example Schedule (Cont.) Another “good” schedule: T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) Effect: Before After A B Same as one of the serial schedules Serializable

Example Schedules (Cont.) A “bad” schedule Before: = 150 After: = 110 !! Not consistent T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) Non Serializable

Equivalence by Swapping T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B)

Equivalence by Swapping T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B)

Equivalence by Swapping T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B)

Example Schedules (Cont.) A “bad” schedule T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) X Y Can’t move Y below X read(B) and write(B) conflict

Example Schedules (Cont.) A “bad” schedule T1 read(A) A = A -50 write(A) read(B) B=B+50 write(B) T2 read(A) tmp = A*0.1 A = A – tmp write(A) read(B) B = B+ tmp write(B) X Y Can’t move Y below X read(B) and write(B) conflict Other options don’t work either So: Not Conflict Serializable

Lock instructions New instructions - lock-S: shared lock request - lock-X: exclusive lock request - unlock: release previously held lock Example: lock-X(B) read(B) B  B-50 write(B) unlock(B) lock-X(A) read(A) A  A + 50 write(A) unlock(A) lock-S(A) read(A) unlock(A) lock-S(B) read(B) unlock(B) display(A+B) T1 T2

Locking Issues No xction proceeds: Deadlock - T1 waits for T2 to unlock A - T2 waits for T1 to unlock B T1T2 lock-X(B) read(B) B  B-50 write(B) lock-X(A) lock-S(A) read(A) lock-S(B) Rollback transactions Can be costly...

Locking Issues Does not ensure serializability by itself: lock-X(B) read(B) B  B-50 write(B) unlock(B) lock-X(A) read(A) A  A + 50 write(A) unlock(A) lock-S(A) read(A) unlock(A) lock-S(B) read(B) unlock(B) display(A+B) T1 T2 T2 displays 50 less!!

2PhaseLocking Example: T1 in 2PL T1 lock-X(B) read(B) B  B - 50 write(B) lock-X(A) read(A) A  A - 50 write(A) unlock(B) unlock(A) Growing phase Shrinking phase

2PL Issues 2PL does not prevent deadlock > 2 xctions involved? - Rollbacks expensive T1T2 lock-X(B) read(B) B  B-50 write(B) lock-X(A) lock-S(A) read(A) lock-S(B)

Strict 2PL T1T2T3 lock-X(A) read(A) lock-S(B) read(B) write(A) unlock(A) lock-X(A) read(A) write(A) unlock(A) lock-S(A) read(A) Strict 2PL will not allow that

Dealing with Deadlocks How do you detect a deadlock?  Wait-for graph  Directed edge from Ti to Tj  Ti waiting for Tj T1T2T3T4 S(V) X(V) S(W) X(Z) S(V) X(W) T1 T2 T4 T3 Suppose T4 requests lock-S(Z)....

Example of Granularity Hierarchy The highest level in the example hierarchy is the entire database. The levels below are of type area, file or relation and record in that order.

Compatibility Matrix with Intention Lock Modes The compatibility matrix for all lock modes is: IS IX S S IX X IS IX S S IX X          holder requestor

ParentChild can belocked in IS IX S SIX X P C IS, S IS, S, IX, X, SIX [S, IS] not necessary X, IX, [SIX] none

Example R1 t1t1 t2t2 t3t3 t4t4 T 1 (IS) T 1 (S), T 2 (IX) T 2 (X)

Examples R t1 t3 t4 t2 f2.1 f2.2 f4.2 T1(IX) T1(X) R t1 t3 t4 t2 f2.1 f2.2 f4.2 T1(IS) T1(S) R t1 t3 t4 t2 f2.1 f2.2 f4.2 T1(SIX) T1(IX) T1(X) Can T2 access object f2.2 in X mode? What locks will T2 get?

Examples T1 scans R, and updates a few tuples:  T1 gets an SIX lock on R, then repeatedly gets an S lock on tuples of R, and occasionally upgrades to X on the tuples. 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. -- ISIX -- IS IX      SX   S X      