Concurrency Control John Ortiz.

Slides:



Advertisements
Similar presentations
CM20145 Concurrency Control
Advertisements

Database Systems (資料庫系統)
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.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
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.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Quick Review of Apr 29 material
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.
©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.
Transaction Management and Concurrency Control
What is a Transaction? Logical unit of work
Transaction Management
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
©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.
1 Concurrency Control. 2 Transactions A transaction is a list of actions. The actions are reads (written R T (O)) and writes (written W T (O)) of database.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Distributed DBMSSlide 1Lectured by, Jesmin Akhter, Assistant Professor, IIT, JU PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor,
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
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.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Concurrency Control Techniques Chapter 18
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.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
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.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Chapter 16 Concurrency. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.16-2 Topics in this Chapter Three Concurrency Problems Locking Deadlock.
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.
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
6.830 Lecture 14 Two-phase Locking Recap Optimistic Concurrency Control 10/28/2015.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
Lecture 3 Concurrency control techniques
Concurrency Control.
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
Part- A Transaction Management
Transaction Management
Transaction Management
Concurrency.
Ch 22: Databases Concurrency Control
Basic Two Phase Locking Protocol
6.830 Lecture 14 Two-phase Locking Recap Optimistic Concurrency Control 10/28/2015.
Chapter 15 : Concurrency Control
Distributed Database Management Systems
Concurrency Control Chapter 17
Transaction management
Transaction Management
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Database Systems (資料庫系統)
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Transactions, Properties of Transactions
Presentation transcript:

Concurrency Control John Ortiz

Introduction Concurrency control subsystem coordinates database operations of concurrent transactions to prevent interference How to represent concurrent transactions? What is a “correct” concurrent execution of transactions? How to arrange operations of concurrent transactions so they do not interfere with each other? Lecture 21 Concurrency control

Schedule Schedule: a sequence of operations from a set of transactions, where operations from any one transaction are in their original order Notation: Ri(X): read X by Ti Wi(X): write X by Ti R1(A), W1(A), R2(B), W2(B), R1(C), W1(C) Lecture 21 Concurrency control

Serializable Schedules Serial schedule : one transaction runs entirely before the next transaction starts. Serializable schedule: Equivalent to a serial schedule of committed transactions. Non-serial (allow concurrent execution) Acceptable (final state is what some serial schedule would have produced) Lecture 21 Concurrency control

Conflict Operations Two operations in a schedule are in conflict if from different transactions access same data item one is a write operation Types of conflict operations: W-R conflict (dirty read): W1(X), R2(X) R-W conflict (unrepeatable read): R1(X), W2(X) W-W conflict (lost update): W1(X), W2(X) Lecture 21 Concurrency control

Lock-based CC Protocols It is not practical to test for serializability during transaction execution One way for DBMS to generate serializable schedule is to maintain locks on data items. Transactions must request DBMS to set a lock on a data item before accessing the data, and tell DBMS to release the lock when the data is no longer needed DBMS decides how to maintain locks based on locking protocols Lecture 21 Concurrency control

Types of Locks Different types of locks are for different data accesses: Read (shared) lock: for read only access Write (exclusive) lock: for read and write Notation: RLi(X): Ti requests read lock on X WLi(X): Ti requests write lock on X ULi(X): Ti release lock on X Lecture 21 Concurrency control

Lock Compatibility Multiple transactions may request locks on same data item DBMS determines what to do based on the compatibility between locks held and locks requested Lock Requested Lock Held Lecture 21 Concurrency control

Two-Phase Locking (2PL) Protocol A data can be accessed only if appropriate locks are requested and granted Shared lock for reads Exclusive lock for writes A lock request can be granted only if it is compatible with locks held on the data A transaction can not request more locks after it released any lock (until all are released) Locks can be released at any time Lecture 21 Concurrency control

Two-Phase Locking (2PL) Protocol Acquire ALL locks (R and W) prior to execution of transaction Several levels of 2PL protocol – some are more flexible Expanding Phase – acquiring new locks May upgrade locks (from R to W) Shrinking Phase – releasing locks May downgrade locks (from W to R) Why would upgrading/downgrading be helpful? Lecture 21 Concurrency control

Example: 2PL Not 2PL: T1: rl(X), R(X), ul(X), wl(Y), R(Y), W(Y), ul(Y), C 2PL: T2: rl(X), R(X), wl(Y), R(Y), ul(X), W(Y), ul(Y), C Lecture 21 Concurrency control

Example: 2PL T1: R(X), X=X+1, W(X), R(Y), Y=Y-1, W(Y) WL1(X)R1(X)W1(X)WL1(Y)UL1(X)WL2(X) R2(X)W2(X) R1(Y)W1(Y)UL1(Y)WL2(Y) UL2(X)R2(Y)W2(Y) UL2(Y) S: S satisfies the 2PL protocol. Theorem: Any schedule satisfying the 2PL protocol is conflict serializable. (why?) Lecture 21 Concurrency control

Problems of Basic 2PL Basic 2PL may cause cascading abort S: WL1(X)R1(X)W1(X)WL1(Y)UL1(X)WL2(X) R2(X)W2(X) R1(Y) ABORT1 W1(Y)UL1(Y)WL2(Y) UL2(X)R2(Y)W2(Y) UL2(Y) S: T2 must be aborted, too. Basic 2PL does not prevent deadlock. A deadlock is a situation in which a set of transactions wait for each other to release locks & no one can make any progress Lecture 21 Concurrency control

Example: Deadlock T1: R(X), X=X+1, W(X), R(Y), Y=Y-1, W(Y) T2: R(Y), Y=2*Y, W(Y), R(X), X=2*X, W(X) WL1(X)R1(X)WL2(Y)R2(Y)W1(X)W2(Y)WL1(Y) WL2(X) Deadlock R1(Y)R2(X)W2(X)UL2(Y) W1(Y)UL1(X)UL1(Y)UL2(X) S’: None of T1 & T2 can make any progress Lecture 21 Concurrency control

Deadlock Management How can DBMS tell if there is deadlock? WL1(X)R1(X)WL2(Y)R2(Y)W1(X)W2(Y)WL1(Y) WL2(X) Deadlock R1(Y)R2(X)W2(X)UL2(Y) W1(Y)UL1(X)UL1(Y)UL2(X) S’: T1 T2 Wait-for-graph Has a cycle! Lecture 21 Concurrency control

Wait-For-Graph A wait-for-graph (WFG) is a directed graph G = (V, E) V is a set of transactions {T1, T2, … Tn} E is a set of directed edges. An edge from Ti to Tj means that Ti is waiting for transaction Tj to release a lock. A deadlock occurs if and only if the WFG has a cycle. Lecture 21 Concurrency control

Deadlock Management Options Deadlock prevention Conservative 2PL – several levels, details in the chapter Resource Ordering – not practical Transaction prioritization Deadlock detection and resolution Detect with WFG Victum Selection – must be carefully done to prevent starvation Timeouts Lecture 21 Concurrency control

Transaction prioritization Assign a priority to each transaction and avoid potential deadlocks by aborting transactions with lower priorities. One priority implementation is to use the start time (time stamp) of each transaction, i.e., older transactions have higher priority. Two possible rules for choosing a transaction to abort: wait-die & wound-wait. Lecture 21 Concurrency control

Wait-Die Rule When Ti requests an incompatible lock held by Tj if Ti is older than Tj, then Ti waits; if Ti is younger than Tj, then Ti dies (i.e.,Ti is aborted and restarted with its old time stamp) Wait-Die Rule prevents both deadlock and starvation Starvation : a transaction is repeatedly aborted in favor of other transactions Lecture 21 Concurrency control

Wound-Wait Rule When Ti requests an incompatible lock held by Tj, if Ti is older than Tj, then Ti wounds Tj (i.e., aborting Tj & gets the lock; Tj will restart with the same time stamp.) if Ti is younger than Tj, then Ti waits; Lecture 21 Concurrency control

Example: Transaction prioritization Assume T1 is older then T2 T1: R(X) W(X) R(Y) W(Y) T2: R(Y) W(Y) R(X) W(X) WL1(X) R1(X) W1(X) WL2(Y) R2(Y) W2(Y) WL1(Y) R1(Y) W1(Y) UL1(X) UL1(Y) WL2(X) Deadlock R2(X) W2(X) UL2(Y) UL2(X) S: Wait-Die: T1 waits for T2 on Y, T2 dies on X Wound-Wait: T2 is aborted, T1 gets lock on Y Either way, S is impossible Lecture 21 Concurrency control

Summary of Concurrency Control 2PL is a simple and practical mechanism to get serializability Strict 2PL is also recoverable, and has no cascade abort Lock manager module automates 2PL so that only the access methods worry about it. Lock table is a big main-memory hash table Deadlocks are possible, and can be either avoid or resolved Other CC mechanisms: timestamp, validation, … Lecture 21 Concurrency control

Look Ahead Next topic: Crash Recovery Read textbook: Chapter 21 Lecture 21 Concurrency control