Concurrency Control Introduction Lock-Based Protocols

Slides:



Advertisements
Similar presentations
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Chapter 16 : Concurrency.
Advertisements

CM20145 Concurrency Control
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme.
Database Systems (資料庫系統)
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
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.
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.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 6: Cascading Rollbacks, Deadlocks, and Long Transactions Professor Chen Li.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Chapter 6 Process Synchronization: Part 2. Problems with Semaphores Correct use of semaphore operations may not be easy: –Suppose semaphore variable called.
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.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Chapter 16 : Concurrency Control Chapter 16: Concurrency Control agreement, accordance of opinion; cooperation, shared effort; simultaneous occurrence.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Concurrency Control.
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.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control John Ortiz.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
DBMS2001Notes 9: Transaction Processing1 Principles of Database Management Systems 9: More on Transaction Processing Pekka Kilpeläinen (Partially based.
© 1997 UW CSE 11/13/97N-1 Concurrency Control Chapter 18.1, 18.2, 18.5, 18.7.
Transactions Transaction Concept Transaction State
15.1Database System Concepts - 6 th Edition Chapter 15: Concurrency Control Lock-Based Protocols The Two-Phase Locking Protocol Graph-Based Protocols #Deadlock.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15 : Concurrency.
Concurrency Control.
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)
Concurrency Control Techniques Chapter 18
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..
Concurrency Control in Database Operating Systems.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Database Techniek Lecture 5: Concurrency Control (Chapter 14/16)
7c.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Module 7c: Atomicity Atomic Transactions Log-based Recovery Checkpoints Concurrent.
Computing & Information Sciences Kansas State University Wednesday, 14 Nov 2007CIS 560: Database System Concepts Lecture 34 of 42 Wednesday, 14 November.
CSIS 7102 Spring 2004 Lecture 3 : Two-phase locking Dr. King-Ip Lin.
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
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 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
Timestamp-based Concurrency Control
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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15 : Concurrency.
DBMS Deadlock.
Transaction Management
Concurrency Control.
Part- A Transaction Management
Chapter 7: Concurrency Control
Chapter 16: Concurrency Control
Chapter 16: Concurrency Control
Database System Implementation CSE 507
Chapter 16: Concurrency Control
Chapter 15 : Concurrency Control
Module 16 : Concurrency Control
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 Introduction Lock-Based Protocols Timestamp-Based Protocols

The Two-Phase Locking Protocol This is a protocol which ensures conflict-serializable schedules. Phase 1: Growing Phase transaction may obtain locks transaction may not release locks Phase 2: Shrinking Phase transaction may release locks transaction may not obtain locks The protocol assures serializability. It can be proved that the transactions can be serialized in the order of their lock points (i.e. the point where a transaction acquired its final lock).

Two-Phase Locking (2PL) Rule (1) Ti locks tuple A before read/write Rule (2) If Ti holds the lock on A, no other transaction is granted the lock on A Rule (3): Growing stage: Ti may obtain locks, but may not release any lock Shrinking stage: Ti my release locks, but may not obtain any new locks 3 3

Two-Phase Locking # locks held by Ti Time Growing Shrinking Phase Phase 4 4

Pitfalls of 2PL and many locking protocols Deadlocks is possible with basic 2PL. Starvation is also possible if concurrency control manager is badly designed. For example: A transaction may be waiting for an X-lock on an item, while a sequence of other transactions request and are granted an S-lock on the same item. The same transaction is repeatedly rolled back due to deadlocks. Example T1 needs A, T2 needs B, but T3 needs both A and B. Concurrency control manager can be designed to prevent starvation. Non-recoverable schedules can occur while using basic 2PL Restrictive forms of 2PL can be used to avoid these problems.

Non-recoverable Schedule T2’s dirty read can not be undone since the transaction has committed

Recoverable Schedule S1 S2 Which schedule is recoverable? A schedule is recoverable, if every transaction that performs dirty reads commits after the transaction that wrote the dirty data. S1 S2 Which schedule is recoverable? What is the cost of recovery? Cascading of dirty data and of rollbacks. How to ensure recoverability? How to ensure recoverability without having to cascade?

Rigorous Two-Phase Locking (R2PL) # locks held by Ti Time Commit Strict 2PL unlock x-locks only at the end of transaction Rigorous 2PL releases X-locks & S-locks only at the end of transaction As such they exclude dirty reads and produce recoverable cascadeless schedules. 8 8

Checkpoint Rigorous 2PL guarantees recoverable cascadeless serializable schedule But deadlocks can still occur: Handling deadlocks Detection and recovery: using the Deadlock prevention in 2PL: can be made deadlock-free by using Conservative 2PL wait-die scheme wound-wait scheme Lock-free Protocols such as timestamp-based scheduling do not have the deadlock problem.

Conservative Two-Phase Locking # locks held by Ti Time Commit Our transaction requests all the locks at the beginning, If it does not get them it does not start. If it gets the resources and starts it will complete. 10 10

Deadlock Detection and Recovery: the wait-for graph Deadlocks can be described as a wait-for graph, which consists of a pair G = (V,E), V is a set of Transactions E is a set of arcs between transactions: A B A B if A is waiting for B to release a lock on some data item. Theorem: The system is in a deadlock state if and only if the wait-for graph has a cycle.

Deadlock Detection & Recovery (cont.) Keep the wait-for graph and periodically check it to see if there is a cycle. When a deadlock is detected, select a transaction from each deadlock cycle and abort it. Timeout Approach: If some transaction has failed to make any progress for a significant time, assume that this is because it is in a deadlock cycle and abort it. Both these approaches are prone to starvation. E.g. a transaction with lots of conflicts might be delayed for a long time under both scheme A and B.

Deadlock Recovery When deadlock is detected : Some transaction will have to rolled back (made a victim) to break deadlock. Select that transaction as victim that will incur minimum cost. Rollback -- determine how far to roll back transaction Total rollback: Abort the transaction and then restart it. More effective to roll back transaction only as far as necessary to break deadlock. Starvation happens if same transaction is always chosen as victim factor to avoid starvation. Consider age or the number of previous rollbacks before rolling back a given transaction.

Deadlock Prevention 2PL can also be made deadlock-free by adding additional constraints: Conservative 2PL wait-die scheme wound-wait Note: Protocols that do not use locks, e.g. timestamp-based scheduling do not have the deadlock problem

Timestamp Based Deadlock Prevention Using transaction timestamps for the sake of deadlock prevention alone. wait-die scheme older transaction may wait for younger one to release data item. Younger transactions never wait for older ones; they are rolled back instead. a transaction may die several times before acquiring needed data item wound-wait scheme — preemptive older transaction wounds (forces rollback) of younger transaction instead of waiting for it. Younger transactions may wait for older ones. may be fewer rollbacks than wait-die scheme. Rolled back transactions must keep their initial timestamps.

Deadlock prevention (Cont.) Both in wait-die and in wound-wait schemes, a rolled back transactions is restarted with its original timestamp. Older transactions thus have precedence over newer ones, and starvation is hence avoided. Timeout-Based Schemes: a transaction waits for a lock only for a specified amount of time. After that, the wait times out and the transaction is rolled back. thus deadlocks are not possible simple to implement; but starvation is possible. Also difficult to determine good value of the timeout interval.

2PL: many complications But even conservative + rigorous deliver good concurren Lock-Based Protocols Timestamp-Based Protocols

2PL—many refinements needed But even conservative + rigorous Start Commit Often deliver good performance. Why? 18 18

Concurrency Control Introduction Lock-Based Protocols Timestamp-Based Protocols

Timestamp-Based Protocols Each transaction is issued a timestamp when it enters the system. If an old transaction Ti has time-stamp TS(Ti), a new transaction Tj is assigned time-stamp TS(Tj) such that TS(Ti) <TS(Tj). The protocol manages concurrent execution such that the time-stamps determine the serializability order. In order to assure such behavior, the protocol maintains for each data Q two timestamp values: W-timestamp(Q) is the largest time-stamp of any transaction that executed write(Q) successfully. R-timestamp(Q) is the largest time-stamp of any transaction that executed read(Q) successfully.

Timestamp-Based Protocols (Cont.) The timestamp ordering protocol ensures that any conflicting read and write operations are executed in timestamp order. Suppose a transaction Ti issues a read(Q) If TS(Ti)  W-timestamp(Q), then Ti needs to read a value of Q that was already overwritten. Hence, the read operation is rejected, and Ti is rolled back. If TS(Ti) W-timestamp(Q), then the read operation is executed, and R-timestamp(Q) is set to max(R-timestamp(Q), TS(Ti)).

Timestamp-Based Protocols (Cont.) Suppose that transaction Ti issues write(Q). If TS(Ti) < R-timestamp(Q), then the value of Q that Ti is producing was needed previously, and the system assumed that that value would never be produced. Hence, the write operation is rejected, and Ti is rolled back. If TS(Ti) < W-timestamp(Q), then Ti is attempting to write an obsolete value of Q. Hence, this write operation is rejected, and Ti is rolled back. Otherwise, the write operation is executed, and W-timestamp(Q) is set to TS(Ti).

Example Use of the Protocol A partial schedule for several data items for transactions with timestamps 1, 2, 3, 4, 5

Correctness of Timestamp-Ordering Protocol The timestamp-ordering protocol guarantees serializability since all the arcs in the precedence graph are of the form: Thus, there will be no cycles in the precedence graph Timestamp protocol ensures freedom from deadlock as no transaction ever waits. But the schedule may not be cascade-free, and may not even be recoverable.

Thomas’ Write Rule Modified version of the timestamp-ordering protocol in which obsolete write operations may be ignored under certain circumstances. When Ti attempts to write data item Q, if TS(Ti) < W-timestamp(Q), then Ti is attempting to write an obsolete value of {Q}. Rather than rolling back Ti as the timestamp ordering protocol would have done, this {write} operation can be ignored. Otherwise this protocol is the same as the timestamp ordering protocol. Thomas' Write Rule allows greater potential concurrency. Allows some view-serializable schedules that are not conflict-serializable.