Concurrency Control Techniques

Slides:



Advertisements
Similar presentations
Concurrency Control Techniques
Advertisements

1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme.
Database Systems (資料庫系統)
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
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.
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.
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.
Transaction Management
ICS (072)Concurrency Control1 Transaction Processing and Concurrency Control Dr. Muhammad Shafique Chapter March 2008.
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.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
System Catalogue v Stores data that describes each database v meta-data: – conceptual, logical, physical schema – mapping between schemata – info for query.
© 1997 UW CSE 11/13/97N-1 Concurrency Control Chapter 18.1, 18.2, 18.5, 18.7.
Data Concurrency Control And Data Recovery
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
The Concept of Transaction Processing A Transaction: logical unit of database processing that includes one or more access operations (read - retrieval,
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.
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.
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Lec 9 Concurrency Control Techniques.
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 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
Timestamp-based Concurrency Control
Concurrency Control The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4th edition,
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.
Concurrency control.
Enterprise Database Systems Transaction Processing
Transaction Management
Lec 10: Concurrency Control Techniques
Lecture 3 Concurrency control techniques
Concurrency Control Techniques
Transaction Management and Concurrency Control
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
Chapter 16: Concurrency Control
Database Concurrency Control
4. Concurrency control techniques
Database System Implementation CSE 507
Chapter 10 Transaction Management and Concurrency Control
Concurrency Control Techniques Module 9
Concurrency Control.
Concurrency Control Techniques
Ch 22: Databases Concurrency Control
Database Transactions
Chapter 15 : Concurrency Control
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Transaction Management
Database Management System
Submitted to Dr. Badie Sartawi Submitted by Nizar Handal Course
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 (資料庫系統)
Database Systems (資料庫系統)
Transactions, Properties of Transactions
Presentation transcript:

Concurrency Control Techniques Chapter 18 April 17, 2019 ADBS: Concurrency control

ADBS: Concurrency control Chapter Objectives Discusses a number of concurrency control techniques that are used to insure the noninterference or isolation property (one of the ACID properties) of concurrently executing transactions. SID Name Major YOB GPA 221234 Ali ICS 1984 3.2 221543 Ahmed COE 1983 3.3 221965 Emad SE 1985 3.4 222785 Fahd SWE 3.5 223542 Lutfi 3.6 229851 Basam 3.7 A B April 17, 2019 ADBS: Concurrency control

ADBS: Concurrency control - Chapter Outline Purpose of Concurrency Control Two-Phase Locking Based Concurrency Control Timestamp Based Concurrency Control Multiversion Concurrency Control Technique April 17, 2019 ADBS: Concurrency control

- Purpose of Concurrency Control To enforce Isolation or noninterference among conflicting transactions. To preserve database consistency through consistency preserving execution of transactions. To resolve read-write and write-write conflicts Example: In concurrent execution environment if T1 conflicts with T2 over a data item A, then the existing concurrency control decides if T1 or T2 should get the A and if the other transaction is rolled-back or waits. April 17, 2019 ADBS: Concurrency control

… - Two-Phase Locking (2PL) … A lock is a variable associated with a data item that describes the status of the item with respect to possible operations that can be applied to it. Locking is an operation which secures a permission to Read or a permission to Write a data item for a transaction. Example: Lock (X): Data item X is locked in behalf of the requesting transaction Unlocking is an operation which removes these permissions from the data item. Example: Unlock (X): Data item X is made available to all other transactions. Lock and Unlock are Atomic operations. April 17, 2019 ADBS: Concurrency control

-- 2PL: Essential components … Two locks modes: Shared mode: shared lock (X). More than one transaction can apply share lock on X for reading its value but no write lock can be applied on X by any other transaction. Exclusive mode: Write lock (X). Only one write lock on X can exist at any time and no shared lock can be applied by any other transaction on X. Lock Yes No Conflict matrix April 17, 2019 ADBS: Concurrency control

-- 2PL: Essential components … SID Name Major YOB GPA 221234 Ali ICS 1984 3.2 221543 Ahmed COE 1983 3.3 221965 Emad SE 1985 3.4 222785 Fahd SWE 3.5 223542 Lutfi 3.6 229851 Basam 3.7 T1 T3 T2 April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … Lock Manager: Managing locks on data items. Lock table: Lock manager uses it to store the identify of transaction locking a data item, the data item, lock mode and pointer to the next data item locked. One simple way to implement a lock table is through linked list April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … Database requires that all transactions should be well-formed. A transaction is well-formed if: It must lock the data item before it reads or writes to it. It must unlock the data item after it is done with it. It must not lock an already locked data item. It must not try to unlock a free data item. April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … The following code performs the read-lock operation: B: if LOCK (X) = “unlocked” then begin LOCK (X)  “read-locked”; no_of_reads (X)  1; end else if LOCK (X)  “read-locked” then no_of_reads (X)  no_of_reads (X) +1 else begin wait (until LOCK (X) = “unlocked” and the lock manager wakes up the transaction); go to B end; April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … The following code performs the write-lock operation: B: if LOCK (X) = “unlocked” then begin LOCK (X)  “write-locked”; else begin wait (until LOCK (X) = “unlocked” and the lock manager wakes up the transaction); go to B end; April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … The following code performs the unlock operation: if LOCK (X) = “write-locked” then begin LOCK (X)  “unlocked”; wakes up one of the transactions, if any end else if LOCK (X)  “read-locked” then begin no_of_reads (X)  no_of_reads (X) -1 if no_of_reads (X) = 0 then LOCK (X) = “unlocked”; wake up one of the transactions, if any end; April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … Lock conversion Lock upgrade: existing read-lock to write-lock if Ti has a read-lock (X) and Tj has no read-lock (X) (i  j) then convert read-lock (X) to write-lock (X) else force Ti to wait until Tj unlocks X Lock downgrade: existing write-lock to read-lock Ti has a write-lock (X) (*no transaction can have any lock on X*) convert write-lock (X) to read-lock (X) April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … A transaction is said to follow 2PL protocol if all its locking operations precede its first unlock operation. 2PL algorithm 2 Phases Locking (Growing) Phase: A transaction applies locks (read or write) on desired data items one at a time Unlocking (Shrinking) Phase: A transaction unlocks its locked data items one at a time. Requirement: For a transaction these two phases must be mutually exclusively, that is, during locking phase unlocking phase must not start and during unlocking phase locking phase must not begin. April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … T1 T2 read_lock (Y); read_lock (X); read_item (Y); read_item (X); unlock (Y); unlock (X); write_lock (X); Write_lock (Y); read_item (X); read_item (Y); X:=X+Y; Y:=X+Y; write_item (X); write_item (Y); unlock (X); unlock (Y); T1 and T2 are NOT following 2PL protocol April 17, 2019 ADBS: Concurrency control

… -- 2PL: Essential components … T3 T4 read_lock (Y); read_lock (X); read_item (Y); read_item (X); write_lock (X); Write_lock (Y); unlock (Y); unlock (X); read_item (X); read_item (Y); X:=X+Y; Y:=X+Y; write_item (X); write_item (Y); unlock (X); unlock (Y); T3 and T4 are following 2PL protocol April 17, 2019 ADBS: Concurrency control

ADBS: Concurrency control -- 2PL Algorithms Two-phase policy generates two locking algorithms: Conservative: Prevents deadlock by locking all desired data items before transaction begins execution. Basic: Transaction locks data items incrementally. This may cause deadlock which is dealt with Strict: A more stricter version of Basic algorithm where unlocking is performed after a transaction terminates (commits or aborts and rolled-back). This is the most commonly used two-phase locking algorithm April 17, 2019 ADBS: Concurrency control

-- Dealing with Deadlock and Starvation … T1 T2 read_lock (Y); read_item (Y); read_lock (X); write_lock (X); (waits for X) write_lock (Y); (waits for Y) T1 and T2 did follow two-phase policy but they are deadlock April 17, 2019 ADBS: Concurrency control

… -- Dealing with Deadlock and Starvation … SID Name Major YOB GPA 221234 Ali ICS 1984 3.2 221543 Ahmed COE 1983 3.3 221965 Emad SE 1985 3.4 222785 Fahd SWE 3.5 223542 Lutfi 3.6 229851 Basam 3.7 T1 T2 : Holds : Requests April 17, 2019 ADBS: Concurrency control

… -- Dealing with Deadlock and Starvation … Three techniques to solve deadlock problems Deadlock prevention A transaction locks all data items it refers to before it begins execution Deadlock detection and resolution A wait-for-graph is created using the lock table. As soon as a transaction is blocked, it is added to the graph. When a chain like: Ti waits for Tj waits for Tk waits for Ti or Tj occurs, then this creates a cycle. One of the transaction of the cycle is selected and rolled back Deadlock avoidance As soon as the algorithm discovers that blocking a transaction is likely to create a cycle, it rolls back the transaction April 17, 2019 ADBS: Concurrency control

… -- Dealing with Deadlock and Starvation … Starvation occurs when a particular transaction consistently waits or restarted and never gets a chance to proceed further. In a deadlock resolution it is possible that the same transaction may consistently be selected as victim and rolled-back. This limitation is inherent in all priority based scheduling mechanisms. In Wound-Wait scheme a younger transaction may always be wounded (aborted) by a long running older transaction which may create starvation. April 17, 2019 ADBS: Concurrency control

- Timestamp based concurrency control algorithm … A timestamp is a unique identifier created by a DBMS to identify a transaction. A timestamp is a monotonically increasing variable (integer) indicating the age a transaction. A larger timestamp value indicates a younger transaction. Timestamp based algorithm uses timestamp to serialize the execution of concurrent transactions. April 17, 2019 ADBS: Concurrency control

…- Timestamp based concurrency control algorithm … In order to use timestamp values for serializable scheduling of transactions, the transaction manager of a DBMS associates with each database item X two timestamp (TS) values: Read_TS(X): The timestamp (identifier) of the youngest transaction that has read X successfully. Write_TS(X): The timestamp (identifier) of the youngest transaction that has written X successfully. April 17, 2019 ADBS: Concurrency control

… - Timestamp based concurrency control algorithm … Basic Timestamp Ordering Transaction T issues a write_item(X) operation: If read_TS(X) > TS(T) or if write_TS(X) > TS(T), then an younger transaction has already read the data item so abort and roll-back T and reject the operation If the condition in part (a) does not exist, then execute write_item(X) of T and set write_TS(X) to TS(T). Transaction T issues a read_item(X) operation: If write_TS(X) > TS(T), then an younger transaction has already written to the data item so abort and roll-back T and reject the operation. If write_TS(X)  TS(T), then execute read_item(X) of T and set read_TS(X) to the larger of TS(T) and the current read_TS(X). April 17, 2019 ADBS: Concurrency control

… - Timestamp based concurrency control algorithm … Strict Timestamp Ordering (for ease of recoverability) Transaction T issues a write_item(X) operation: If TS(T) > read_TS(X), then delay T until the transaction T’ that wrote or read X has terminated (committed or aborted). Transaction T issues a read_item(X) operation: If TS(T) > write_TS(X), then delay T until the transaction T’ that wrote or read X has terminated (committed or aborted). April 17, 2019 ADBS: Concurrency control

- Multiversion concurrency control technique Concept … This approach maintains a number of versions of a data item and allocates the right version to a read operation of a transaction. Thus unlike other mechanisms a read operation in this mechanism is never rejected. Side effect: Significantly more storage (RAM and disk) is required to maintain multiple versions. To check unlimited growth of versions, a garbage collection is run when some criteria is satisfied April 17, 2019 ADBS: Concurrency control

- Multiversion concurrency control technique Concept … Assume X1, X2, …, Xn are the version of a data item X created by a write operation of transactions. With each Xi a read_TS (read timestamp) and a write_TS (write timestamp) are associated. read_TS(Xi): The read timestamp of Xi is the largest of all the timestamps of transactions that have successfully read version Xi write_TS(Xi): The write timestamp of Xi that wrote the value of version Xi. A new version of Xi is created only by a write operation. April 17, 2019 ADBS: Concurrency control

- Multiversion concurrency control technique Concept … To ensure serializability, the following two rules are used. If transaction T issues write_item (X) and version i of X has the highest write_TS(Xi) of all versions of X that is also less than or equal to TS(T), and read _TS(Xi) > TS(T), then abort and roll-back T; otherwise create a new version Xi and read_TS(X) = write_TS(Xj) = TS(T). If transaction T issues read_item (X), find the version i of X that has the highest write_TS(Xi) of all versions of X that is also less than or equal to TS(T), then return the value of Xi to T, and set the value of read _TS(Xi) to the largest of TS(T) and the current read_TS(Xi). Rule 2 guarantees that a read will never be rejected. April 17, 2019 ADBS: Concurrency control

ADBS: Concurrency control END April 17, 2019 ADBS: Concurrency control