Chapter 8 Concurrency Control 8.1 Lock-Based Protocols 8.2 Multiple Granularity 8.3 Deadlock Handling 8.4 Insert and Delete Operations.

Slides:



Advertisements
Similar presentations
Concurrency Control II
Advertisements

Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
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.
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
©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.
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)
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.
©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.
Concurrency Control. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Transaction Processing.
© 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.
Concurrency Control.
©Silberschatz, Korth and Sudarshan14.1Database System Concepts - 6 th Edition UNIT 5 :Transactions Transaction concepts, properties of transactions, serializability.
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 (CHAPTER 16) CONCURRENCY CONTROL INTRODUCTION Motivation: A dbms is multiprogrammed to increase the utilization.
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.
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
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.
Concurrency Control Introduction Lock-Based Protocols
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
1 Chapter 17: Concurrency Control. 2 Lock-Based Protocols Timestamp-Based Protocols Validation-Based Protocols Multiple Granularity Multiversion Schemes.
Timestamp-based Concurrency Control
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
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
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
Chapter 7: Concurrency Control
Chapter 16: Concurrency Control
Chapter 16: Concurrency Control
Chapter 16: Concurrency Control
CONCURRENCY CONTROL (CHAPTER 16)
Database System Implementation CSE 507
Chapter 16: Concurrency Control
Database System Implementation CSE 507
CS162 Operating Systems and Systems Programming Review (II)
Concurrency Control.
Chapter 16: Concurrency Control
Chapter 15 : Concurrency Control
Module 16 : Concurrency Control
Chapter 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.
Chapter 16 : Concurrency Control
Presentation transcript:

Chapter 8 Concurrency Control 8.1 Lock-Based Protocols 8.2 Multiple Granularity 8.3 Deadlock Handling 8.4 Insert and Delete Operations

8.1 Lock-Based Protocols One way to ensure serializability is to require that data items be accessed in a mutually exclusive manner.(lock) 1. Shared: if a transaction Ti has obtained a shared-mode lock on item Q, then Ti can read, but cannot write Q. 2. Exculsive: if a transaction T i has obtained an exclusive-mode lock on item Q, then T i can both read and write Q. SX Struefalse X Compatibility function:

8.1 Lock-Based Protocols T 1 lock-X(B) read(B) B:=B-50 write(B) unlock(B) lock-X(A) read(A) A:=A+50 write(A) unlock(A) T 2 lock-S(A) read(A) unlock(A) lock-S(B) read(B) unlock(B) display(A+B) concurrency-control manager grant-X(B,T 1 ) grant-S(A,T 2 ) grant-S(B,T 2 ) grant-X(A,T 1 ) lock-X(B) read(B) B:=B-50 write(B) unlock(B) lock-X(A) read(A) A:=A+50 write(A) unlock(A) T1:T1: lock-S(A) read(A) unlock(A) lock-S(B) read(B) unlock(B) display(A+B) T2:T2:

8.1 Lock-Based Protocols lock-X(B) read(B) B:=B-50 write(B) lock-X(A) read(A) A:=A+50 write(A) unlock(B) unlock(A) T3:T3: lock-S(A) read(A) lock-S(B) read(B) unlock(A) unlock(B) display(A+B) T4:T4: T 3 lock-X(B) read(B) B:=B-50 write(B) lock-X(A) T 4 lock-S(A) read(A) lock-S(B) deadlock

8.1 Lock-Based Protocols When a transaction requests a lock on a data item in a particular node, and no other transaction has a lock on the same data item in a conflicting mode, the lock can be granted. T 1 lock-X(A) wait …. T 2 lock-S(A) A:=A+50 unlock(A) T 3 lock-S(A) A:=A+10 unlock(A) T 4 lock-S(A) A:=A-20 unlock(A) T i lock-S(A) …… … starvation

One protocol that ensures serializability is the two- phase locking protocol. This protocol requires that each transaction issue lock and unlock requests in two phases: ① Growing phase. A transaction may obtain locks, but may not release any lock. ② Shrinking phase. A transaction may release locks, but may not obtain any new locks The Two-Phase Locking Protocol

T 1 lock-S(B) read(B) lock-X(A) A:=B+1 write(A) unlock(B) unlock(A) T 2 lock-S(A) wait lock-S(A) read(A) lock-X(B) B:=A+1 write(B) unlock(B) unlock(A) T 3 lock-S(B) read(B) unlock(B) lock-X(A) A:=B+1 write(A) unlock(A) T 4 lock-S(A) wait lock-S(A) read(A) unlock(A) lock-X(B) B:=A+1 write(B) unlock(B) growing phase shrinking phase lock point T 3 、 T 4 Serializable Not two phase T 1 、 T 2 Serializable two phase  The two- phase locking protocol ensures conflict serializabilit y

8.1.3 The Two-Phase Locking Protocol T 3 lock-X(B) read(B) B:=B-50 write(B) lock-X(A) T 4 lock-S(A) read(A) lock-S(B) deadlock T 3 、 T 4 two phase  Two-phase locking does not ensure freedom from deadlock. T 5 lock-X(A) read(A) lock-S(B) read(B) write(A) unlock(A) T 6 lock-S(A) read(A) write(A) unlock(A) T 7 lock-S(A) read(A) T 5 、 T 6 、 T 7 two phase  Cascadi ng rollback may occur under two- phase locking.

Strict two-phase locking protocol: This protocol requires not only that locking be two phase, but also that all exclusive-mode locks taken by a transaction be held until that transaction commits. Rigorous two-phase locking protocol: This protocol requires that all locks be held until the transaction commits The Two-Phase Locking Protocol

read(a 1 ); read(a 2 ); … read(a n ); write(a 1 ); T8:T8: read(a1); read(a2); display(A+B) T9:T9: T 8 lock-S(a 1 ) lock-S(a 2 ) lock-S(a 3 ) lock-S(a 4 ) lock-S(a n ) upgrade(a 1 ) T 9 lock-S(a 1 ) lock-S(a 2 ) unlock(a 1 ) unlock(a 2 ) lock conversion The Two-Phase Locking Protocol  Upgrade: share to exclusive mode Upgrading can take place in only the growing phase  Downgrade: exclusive to share mode downgrading can take place in only the shrinking phase

 When a transaction Ti issues a read(Q) operation, the system issues a lock-S(Q) instruction followed by the read(Q) instruction.  When Ti issues a write (Q) operation, the system checks to see whether Ti already holds a shared lock on Q. if it does, then the system issues an up-grade (Q) instruction, followed by the write (Q) instruction. Otherwise, the system issues a lock-X (Q) instruction, followed by the write (Q) instruction.  All locks obtained by a transaction are unlocked after that transaction commits or aborts The Two-Phase Locking Protocol

Tree protocol: the only lock instruction allowed is lock-X. each transaction T i can lock a data item at most once, and must observe the following rules: ① The first lock by Ti may be on any data item. ② Subsequently, a data item Q can be locked by T i only if the parent of Q is currently locked by T i. ③ Data items may be unlocked at any time. ④ A data item that has been locked and unlocked by Ti cannot subsequently be relocked by T i Graph-Based Protocols

Lock and unlock instructions: T 10 : lock-X(B); lock-X(E); lock-X(D); unlock(B); unlock(E); lock-X(G); unlock(D); unlock(G); T 11 : lock-X(D); lock-X(H); unlock(D); unlock(H); T 12 : lock-X(B); lock-X(E); unlock(E); unlock(B); T 13 : lock-X(D); lock-X(H); unlock(D); unlock(H); Graph-Based Protocols A BC F E I D GH J

T 10 lock-X(B) lock-X(E) lock-X(D) unlock(B) unlock(E) lock-X(G) unlock(D) unlock(G) T 11 lock-X(D) lock-X(H) unlock(D) unlock(H) T 12 lock-X(B) lock-X(E) unlock(E) unlock(B) T 13 lock-X(D) lock-X(H) unlock(D) unlock(H) A BC F E I D GH J  Tree protocol ensures conflict serializability and freedom from deadlock  Tree protocol does not ensure recoverability and cascadelessness.

 Advantages: ① unlike two-phase locking, it is deadlock-free, so no rollbacks are required.unlocking may occur earlier. ② Earlier unlocking may lead to shorter waiting times, and to an increase in concurrency.  Disadvantages: ① in some cases, a transaction may have to lock data items that it does not access. ② Without prior knowledge of what data items will need to be locked, transactions will have to lock the root of the tree, and that can reduce concurrency greatly Graph-Based Protocols

 A method for determining the serializability order is to select an ordering among transactions in advance.(timestamp-ordering scheme)  Timestamps: with each transaction T i in the system, we associate a unique fixed timestamp, denoted by TS(T i ). This timestamp is assigned by the database system before the transaction T i starts execution. If a transaction T i has been assigned timestamp TS(T i ), and a new transaction T j enters the system, then TS(T i )< TS(T j ). There are two simple methods for implementing this scheme: ① Use the value of the system clock as the timestamp; that is, a transaction’s timestamp is equal to the value of the clock when the transaction enters the system. ② Use a logical counter that is incremented after a new timestamp has been assigned; that is, a transaction’s timestamp is equal to the value of the counter when the transaction enters the system. 8.2 Timestamp-Based Protocols

Timestamp-ordering protocol: 1.Suppose that transaction Ti issues read(Q). a. If TS(T i )<W-timestamp(Q), then Ti needs to read a value of Q that was already overwritten. Hence, the read operation is rejected, and T i is rolled back. b. If TS(T i )>=W-timestamp(Q) then the read operation is executed, and R-timestamp(Q) is set to the maximum of R- timestamp(Q) and TS(T i ). 8.2 Timestamp-Based Protocols

2.Suppose that transaction T i issues write(Q). a. If TS(T i )<R-timestamp(Q), then the value of that T i is producing was needed previously, and the system assumed that value would never be produced. Hence, the system rejects the write operation and rolls T i back. b. If TS(T i )<W-timestamp(Q) then T i is attempting to write an obsolete value of Q. hence, the system rejects this write operation and rolls T i back. c. Otherwise, the system executes the write operation and sets W -timestamp(Q) to TS(T i ) 8.2 Timestamp-Based Protocols

read(B); read(A); display(A+B); T 14 : read(B); B:=B-50; write(B); read(A); A:=A+50; write(A); display(A+B); T 15 : T 14 read(B) read(A) display(A+B) T 15 read(B) B:=B-50 write(B) read(A) A:=A+50 write(A) display(A+B) R-timestamp(B)= TS(T 15 ) W-timestamp(B)= TS(T 15 ) TS(T 14 )< TS(T 15 ) R-timestamp(A)= TS(T 15 )

8.4 Multiple Granularity ISIXSSIXX IStrue false IXtrue false Struefalsetruefalse SIXtruefalse X

 A system is in a deadlock state if there exists a set of transactions such that every transaction in the set is waiting for another transaction in the set.  There two principal methods for dealing with the deadlock problem: ① deadlock prevention ② deadlock detection&deadlock recovery 8.4 Deadlock Handling

There are two approaches to deadlock prevention: ① one approach ensures that no cyclic waits can occur by ordering the requests for locks, or requiring all locks to be acquired together. Disadvantages: a. It is often hard to predict, before the transaction begins,what data items need to be locked. b. Data-item utilization may be very low. ② the other approach is closer to deadlock recovery, an performs transaction rollback instead of waiting for a lock, whenever the wait could potentially result in a deadlock Deadlock Prevention

1.The wait-die scheme is a nonpreemptive technique. When transaction T i requests a data item currently held by T j, T i is allowed to wait only if it has a timestamp smaller than that of T j (that is, T i is older than T j ). Otherwise, T i is rolled back(dies) Deadlock Prevention timestamp T 22 T 23 T T 22 lock-S(A) wait T 23 lock-X(A) T 24 lock-X(A) rollback T 3 lock-X(B) read(B) write(B) lock-X(A) T 4 lock-S(A) read(A) lock-S(B) Timestamp: T 3 <T 4 T 4 rollback

2. The wound-wait scheme is a primitive technique. It is a counterpart to the wait-die scheme. When transaction T i requests a data item currently held by T j, T i is allowed to wait only if it has a timestamp larger than that of T j (that is, T i is younger than T j ). Otherwise, T j is rolled back(T j is wounded by T i ) Deadlock Prevention timestamp T 22 T 23 T T 22 lock-S(A) T 23 lock-X(A) rollback T 24 lock-X(A) wait T 3 lock-X(B) read(B) write(B) lock-X(A) T 4 lock-S(A) read(A) lock-S(B) Timestamp: T 3 <T 4 T 4 rollback

Similarity: both the wound-wait and the wait-die schemes avoid starvation. Difference: operation ① In the wait-die scheme, the older the transaction gets, the more it tends to wait. By contrast, in the wound-wait scheme, an older transaction never waits for a younger transaction. ② In the wait-die scheme, if a transaction T i dies and is rolled back because it requested a data item held by transaction T j, the T i may reissue the same sequence of requests when it is restarted. If the data item is still held by T j, then T i will die again. Thus, T i may die several times before acquiring the needed data item.contrast this series of events with what happens in the wound-wait scheme. There may be fewer rollbacks in the wound-wait scheme Deadlock Prevention

Lock timeouts: a transaction that has requested a lock waits for at most a specified amount of time. If the lock has not been granted within that time, the transaction is said to timeout,and it rolls itself back and restarts. If there was in fact a deadlock, one or more transactions involved in the deadlock will time out and roll back, allowing the others to proceed Timeout-Based Scheme

Deadlock Detection: wait-for graph:G=(V,E) V:is a set of vertices E:is a set of edges T i →T j : transaction T i is waiting for transaction T j to release a data item that it needs Deadlock Detection and Recovery T 25 T 27 T 28 T 26 T 28 T 25 T 27 T 26 Transaction T 28 is requesting an item held by T 27. Deadlock: contains a cycle

Recovery from Deadlock: roll back ① selection of a victim: Given a set of deadlocked transactions, we must determine which transaction to rollback to break the deadlock.(minimum cost) ② Rollback: Once we have decided that a particular transaction must be rolled back, we must determine how far this transaction should be rolled back.(total rollback, partial rollback) ③ Starvation: We must ensure that transaction can be picked as a victim only a finite number of times.(include the number of rollbacks in the cost factor) Deadlock Detection and Recovery