Concurrency Control Techniques Chapter 18

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.
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
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
IDA / ADIT Databasteknik Databaser och bioinformatik Transaction Fang Wei-Kleiner.
Concurrency Control.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
CS 728 Advanced Database Systems Chapter 21 Introduction to Protocols for Concurrency Control in Databases.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Quick Review of Apr 29 material
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Jan. 2014ACS Concurrency control techniques (Ch. 20, 3 rd ed. – Ch. 18, 4 th ed., Ch. 18, 5 th ed. – Ch. 22, 6 th ed.)
Transaction Management
ICS (072)Concurrency Control1 Transaction Processing and Concurrency Control Dr. Muhammad Shafique Chapter March 2008.
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
ACS-4902 R. McFadyen 1 Chapter 18 Database Concurrency Control Locking 18.1 Shared/Exclusive (aka Read/Write) Locks Lock Operations Read_lock(X) Write_lock(X)
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control John Ortiz.
CS346: Advanced Databases Graham Cormode Concurrency Control.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
© 1997 UW CSE 11/13/97N-1 Concurrency Control Chapter 18.1, 18.2, 18.5, 18.7.
Concurrency Control In Dynamic Database Systems Laurel Jones.
Concurrency Control.
Databases Illuminated
IDA / ADIT Lecture 9: Transactions and concurrency control Jose M. Peña
Transaction Management, Concurrency Control and Recovery Chapter 20 1.
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
ICS (072)Concurrency Control Techniques1 Concurrency Control Techniques Chapter 18 Dr. Muhammad Shafique.
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.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
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.
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
Page 1 Concurrency Control Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Lec 9 Concurrency Control Techniques.
Transactions and Concurrency Control Fall 2007 Himanshu Bajpai
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
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 ( 朱浩華 )
1 Lecture 4: Transaction Serialization and Concurrency Control Advanced Databases CG096 Nick Rossiter [Emma-Jane Phillips-Tait]
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
Concurrency Control The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4th edition,
10 1 Chapter 10_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li.
Chap 21 – Concurrency Control. Database Concurrency Control 1 Purpose of Concurrency Control To enforce Isolation (through mutual exclusion) among conflicting.
Enterprise Database Systems Transaction Processing Dr. Georgia Garani Dr. Theodoros Mitakos Technological Educational Institution of Larissa.
Enterprise Database Systems Transaction Processing
Lec 10: Concurrency Control Techniques
Lecture 3 Concurrency control techniques
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
Database Concurrency Control
4. Concurrency control techniques
Concurrency Control Techniques Module 9
Concurrency Control.
Concurrency Control Techniques
Ch 22: Databases Concurrency Control
Chapter 15 : Concurrency Control
Concurrency Control Techniques
Presentation transcript:

Concurrency Control Techniques Chapter 18

Outline Granularity of data items Concurrency control techniques Locking techniques Timestamp ordering techniques Concurrency Control Techniques

Concurrency Control Techniques Categories of concurrency techniques Locking techniques Timestamp ordering techniques Multi-version concurrency control techniques Optimistic concurrency control techniques Advanced concurrency control techniques Concurrency Control Techniques

Granularity of Data Items Data item granularity Size or granule of data for concurrency control. It could be An attribute value A database record A disk block A whole file The whole database Data item granularity and degree of concurrency Fine granularity --- refers to small item sizes Coarse granularity --- refers to large item sizes Larger the data item size, lower the degree of concurrency Data item size depends on the types of transactions Concurrency Control Techniques

Concurrency Control Using Locks A variable associated with a data item Describes status of the data item with respect to operations that can be performed on it Types of locks Binary locks Locked/unlocked Enforces mutual exclusion Multiple-mode locks: Each data item can be in one of three lock states Read lock or shared lock Write lock or exclusive lock Unlock Lock table managed by lock manager subsystem of DBMS Lock table – records have 3 fields <data item name, LOCK, locking transaction> Concurrency Control Techniques

Lock and Unlock Operations for Binary Locks Concurrency Control Techniques

Binary Locking Rules Every transaction must obey the following rules: A transaction T must issue the operation lock_item(X) before any read_item(X) or write_item(X) operations are performed in T. A transaction T must issue the operation unlock_item(X) after all read_item(X) and write_item(X) operations are completed in T. A transaction T will not issue a 1ock_i tem(X) operation if it already holds the lock on item X. A transaction T will not issue an unlock_item(X) operation unless it already holds the lock on item X. Concurrency Control Techniques

Shared/exclusive Locking Rules T must issue read_lock(X) or write_lock(X) before any read_item(X) operation is performed in T T must issue write_lock(X) before any write_item(X) operation is performed in T T must issue unlock(X) after all read_item(X) and write_item(X) operations are completed in T T will not issue a read_lock(X) if it already holds a read lock or write lock on X (may be relaxed) T will not issue a write_lock(X) if it already holds a read lock or write lock on X (may be relaxed) T will not issue unlock (X) request unless it holds a read lock or write lock on X Concurrency Control Techniques

Conversion of Locks A transaction T that holds a lock on item X, under certain conditions, is allowed to convert the lock from one state to another Upgrade Convert read_lock to write_lock Downgrade Convert write_lock to read_lock Using locks does not guarantee serializability of schedules on its own Concurrency Control Techniques

Two Transactions Let’s assume serial schedule S1: T1,T2 read_lock(Y); read_item(Y); unlock(Y); write_lock(X); read_item(X); X:=X+Y; write_item(X); unlock(X); T2 read_lock(X); read_item(X); unlock(X); write_lock(Y); read_item(Y); Y:=X+Y; write_item(Y); unlock(Y); Let’s assume serial schedule S1: T1,T2 Initial values: X=20, Y=30  Result: X=50, Y=80 Concurrency Control Techniques

Locks Alone Don’t Insure Serializability Let’s run T1 and T2 in interleaved fashion Schedule S T1 read_lock(Y); read_item(Y); unlock(Y); write_lock(X); read_item(X); X:=X+Y; write_item(X); unlock(X); T2 read_lock(X); read_item(X); unlock(X); write_lock(Y); read_item(Y); Y:=X+Y; write_item(Y); unlock(Y); unlocked too early! Non-serializable! Result: X=50, Y=50 Concurrency Control Techniques

Two-Phase Locking (2PL) Protocol Transaction is said to follow the two-phase-locking protocol if all locking operations precede the first unlock operation Expanding (growing) phase New locks can be acquired but none can be released. Upgrading is ok Downgrading is not Shrinking phase Existing locks can be released but no new locks can be acquired Downgrading ok Upgrading is not Concurrency Control Techniques

2PL Example T2’ T1’ read_lock(X); read_lock(Y); read_item(X); write_lock(Y); unlock(X); read_item(Y); Y:=X+Y; write_item(Y); unlock(Y); T1’ read_lock(Y); read_item(Y); write_lock(X); unlock(Y); read_item(X); X:=X+Y; write_item(X); unlock(X); Both T1’ and T2’ follow the 2PL protocol Any schedule including T1’ and T2’ is guaranteed to be serializable Limits the amount of concurrency Can produce a deadlock Concurrency Control Techniques

Locking Techniques for Concurrency Control Quick review of ideas discussed so far Locks and system lock tables Lock table and lock manager Binary locks --- lock & unlock operations (critical sections) Shared/exclusive locks --- read-lock, write-lock, and unlock Conversion of locks Upgrade the lock Downgrade the lock Concurrency control subsystem generates read-lock and write- lock requests on behalf of the transactions Using locks in transactions does not guarantee serializability of schedules on its own Concurrency Control Techniques

Locking Techniques for Concurrency Control (Cont.) Two-phase locking protocol (2PL) All lock operations precede the first unlock operation Expanding phase and shrinking phase Upgrading of locks must be done in expanding phase and downgrading of locks must be done in shrinking phase If every transaction in a schedule follows 2PL protocol then the schedules is guaranteed to be serializable. Variants of 2PL Basic, conservative, strict, and rigorous Concurrency Control Techniques

Locking Techniques for Concurrency Control (Cont.) Basic 2PL All lock operations before the first unlock operation Conservative 2PL or static 2PL Lock all the items it accesses before the transaction begins execution. Deadlock free protocol Read-set and write-set of the transaction should be known Strict 2PL No exclusive lock will be unlocked until the transaction commits or aborts Rigorous 2PL No lock will be unlocked until the transaction commits or aborts Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL 2PL can cause two problems: Deadlocks Starvation Deadlock in 2PL Deadlock occurs when each transaction T in a set of two or more transactions is waiting for some item that is locked by some other transaction T’ in the set. Example (next slide) Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL Deadlock prevention protocols Conservative 2PL, lock all needed items in advance Ordering all items in the database Possible actions if a transaction is involved in a possible deadlock situation Block and wait Abort and restart Preempt and abort another transaction Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL Two schemes that prevent deadlock (Timestamp based) Wait-die An older transaction is allowed to wait on a younger transaction whereas a younger transaction requesting an item held by an older transaction is aborted and restarted later with the same timestamp. Wound-wait A younger transaction is allowed to wait on an older transaction whereas an older transaction requesting an item held by a younger transaction preempts the younger transaction by aborting it. Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL Two schemes that prevent deadlock and do not require timestamps No waiting Abort immediately and restart after a certain time delay Cautious waiting If a transaction holding the lock is not waiting for another item to be locked then allow T to wait otherwise abort and restart T Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL Deadlock detection and timeouts The system checks if a state of deadlock actually exist Good: if there will be little interference among transactions If transactions are short and each locks few data items If the transaction load is light Bad: otherwise Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL Deadlock detection and timeouts Construct and maintain a wait-for graph A directed edge from Ti to Tj is created when Ti is waiting to lock an item X that is currently locked by by Tj If the system detects a deadlock (cycle in the graph), some of the transactions causing the deadlock must be aborted (Victim selection) Problem: when the system should check for a deadlock? Timeouts If a transaction waits for a period longer than a system-defined timeout period, the system assumes that the transaction maybe deadlocked and aborts it—regardless of whether a deadlock actually exists or not. Practical ( low overhead + simplicity ) Concurrency Control Techniques

Dealing with Deadlocks and Starvation in 2PL Starvation A transaction cannot proceed for an infinite period of time while other transactions in the system continue normally Unfair waiting scheme giving priority to some transactions over others. Sol: FCFS , increase priority as the longer wait Victim selection Sol: increase priority as aborted multiple times No starvation in wait-die and wound-wait schemes. Concurrency Control Techniques

Concurrency Control Based on Timestamp Ordering a unique identifier created by the DBMS to identify a transaction Timestamp values are assigned in the order in which the transactions are submitted to the system (can be thought of as the transaction start time) Can be implemented using: a counter incremented each time its value is assigned to a transaction the current date/time value of the system clock and ensure that no two timestamp values are generated during the same tick of the clock. Concurrency Control Techniques

Concurrency Control Based on Timestamp Ordering Timestamp Ordering Algorithm (TO) does not use locks, hence, deadlocks cannot occur. orders the transactions based on their timestamps. A schedule in which the transactions participate is then serializable, and the equivalent serial schedule has the transactions in order of their timestamp values. In 2PL, a schedule is serializable by being equivalent to some serial schedule allowed by the locking protocols. In timestamp ordering, however, the schedule is equivalent to the particular serial order corresponding to the order of the transaction timestamps. The algorithm must ensure that, for each item accessed by conflicting operations in the schedule, the order in which the item is accessed does not violate the serializability order. Concurrency Control Techniques

Concurrency Control Based on Timestamp Ordering Timestamp Ordering Algorithm (TO) Read-TS(X) The largest timestamp among all the timestamps of transactions that have successfully read item X Read-TS(X) = TS(T), where T is the youngest transaction that has read X successfully. Write-TS(X) The largest timestamp among all the timestamps of transactions that have successfully written item X Write_TS(X)= TS(T), where T is the youngest transaction that has written X successfully. TO algorithm variations: Basic timestamp ordering Strict timestamp ordering Thomas’s write rule Concurrency Control Techniques

Concurrency Control Based on Timestamp Ordering (Cont.) Basic timestamp ordering algorithm T issues a write(X) If read-TS(X) > TS(T) or if write-TS(X) > TS(T) then abort and rollback T and reject the operation. If condition above does not occur then execute the operation and set write-TS(X) = TS(T) T issues a read(X) If write-TS(X) > TS(T) then abort and rollback T and reject the operation. If write-TS(X)  TS(T) then execute the operation and set read-TS(X) = max ( read-TS(X), TS(T) ) The schedules produced by basic TO are guaranteed to be conflict serializable No deadlocks but cyclic restart are possible (hence starvation) Concurrency Control Techniques

Concurrency Control Based on Timestamp Ordering (Cont.) Strict Timestamp Ordering (strict TO) A transaction T that issues a read-item(X) or write- item(X) such that TS(T) > write-TS(X) has its read or write operation delayed until the transaction T’ that wrote the value of X (hence TS(T’ ) = write-TS(X)) has committed or aborted. No deadlocks, since T waits for T’ only if TS(T) > TS(T’) Strict TO ensures that the schedules are (conflict) serializable Concurrency Control Techniques

Concurrency Control Based on Timestamp Ordering (Cont.) Thomas’s write rule It rejects fewer write operations, by modifying the basic TO checks for the write-item(X) operation as follows: If read-TS(X) > TS(T), then abort and roll back T and reject the operation. If write-TS(X) > TS(T), then do not execute the write operation but continue processing. [This is because some transaction with timestamp greater than TS(T)—and hence after T in the timestamp ordering—has already written the value of X. Hence, we must ignore the write_item(X) operation of T because it is already outdated and obsolete.] If neither the condition in part (1) nor the condition in part (2) occurs, then execute the write-item(X) operation of T and set write-TS(X) to TS(T). Thomas’ write rule does not enforce conflict serializability Concurrency Control Techniques

Summary Granularity of data items Concurrency control techniques Locking techniques Timestamp ordering techniques Thank you Concurrency Control Techniques