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

Slides:



Advertisements
Similar presentations
Concurrency control 1. 2 Introduction concurrency more than one transaction have access to data simultaneously part of transaction processing.
Advertisements

1 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transactions 3.
CM20145 Concurrency Control
CM20145 Recovery + Intro. to Concurrency
Concurrency Control Techniques
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Lecture plan Transaction processing Concurrency control
Chapters 15-17: Transaction Management
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15 : Concurrency.
Chapter 16: Recovery System
Database Systems (資料庫系統)
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Concurrency Control Enforcing Serializability by Locks
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
CSC271 Database Systems Lecture # 32.
Lock-Based 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.
Quick Review of Apr 29 material
Prepared by: Mudra Patel (113) Locking Scheduler & Managing Hierarchies of Database Elements.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Transaction Management and Concurrency Control
Concurrency Control By Donavon Norwood Ankit Patel Aniket Mulye 1.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Transaction Management
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
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. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Transaction Processing.
Academic Year 2014 Spring Academic Year 2014 Spring.
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.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Databases Illuminated
PMIT-6102 Advanced Database Systems
V. Megalooikonomou Concurrency control (based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and Sudarshan) Temple University – CIS.
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. 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.
Concurrency Control in Database Operating Systems.
1 Concurrency Control II: Locking and Isolation Levels.
7c.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Module 7c: Atomicity Atomic Transactions Log-based Recovery Checkpoints Concurrent.
Page 1 Concurrency Control Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
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
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.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15 : Concurrency.
1 Concurrency Control By Ankit Patel. 2 INTRODUCTION Enforcing serializability by locks Locks Locking scheduler Two phase locking Locking systems with.
Lecture 3 Concurrency control techniques
Concurrency Control.
Part- A Transaction Management
Chapter 7: Concurrency Control
Chapter 16: Concurrency Control
Chapter 16: Concurrency Control
Chapter 16: Concurrency Control
By Donavon Norwood Ankit Patel 112 Aniket Mulye 111
Concurrency Control.
Concurrency Control WXES 2103 Database.
Chapter 15 : Concurrency Control
ENFORCING SERIALIZABILITY BY LOCKS
Temple University – CIS Dept. CIS661 – Principles of Data Management
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:

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

©Silberschatz, Korth and Sudarshan16.2Database System Concepts - 5 th Edition, Sep 12, 2005 Chapter 16: Concurrency Control Lock-Based Protocols

©Silberschatz, Korth and Sudarshan16.3Database System Concepts - 5 th Edition, Sep 12, 2005 Lock-Based Protocols A lock is a mechanism to control concurrent access to a data item Data items can be locked in two modes : 1. exclusive (X) mode. Data item can be both read as well as written. X-lock is requested using lock-X instruction. 2. shared (S) mode. Data item can only be read. S-lock is requested using lock-S instruction. Lock requests are made to concurrency-control manager. Transaction can proceed only after request is granted. A locking protocol is a set of rules followed by all transactions while requesting and releasing locks. Locking protocols restrict the set of possible schedules.

©Silberschatz, Korth and Sudarshan16.4Database System Concepts - 5 th Edition, Sep 12, 2005 Lock-Based Protocols (Cont.) Lock-compatibility matrix A transaction may be granted a lock on an item if the requested lock is compatible with locks already held on the item by other transactions Any number of transactions can hold shared locks on an item, but if any transaction holds an exclusive on the item no other transaction may hold any lock on the item. If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held by other transactions have been released. The lock is then granted.

©Silberschatz, Korth and Sudarshan16.5Database System Concepts - 5 th Edition, Sep 12, 2005 Lock-Based Protocols (Cont.) Consider that T 1 transfers $50 from account B to account A, and T 2 displays the total amount in A and B. Suppose that the values of A and B are $100 and $200, respectively. T 1 : lock-X(B); T 2 : lock-S(A); read(B); read(A); B := B - 50; unlock(A); write(B); lock-S(B); unlock(B); read(B); lock-X(A); unlock(B); read(A); display(A + B); A := A + 50; write(A); unlock(A); Executed serially, then T 2 displays $300. But executed concurrently(see Schedule 1), then T 2 display $250, which is incorrect. The reason is that T 1 unlocked data item B too early.

©Silberschatz, Korth and Sudarshan16.6Database System Concepts - 5 th Edition, Sep 12, 2005 Lock-Based Protocols (Cont.) T1 T2 lock-X(B) read(B) B := B – 50 write(B) unlock(B) lock-S(A) read(A) unlock(A) lock-S(B) read(B) unlock(B) display(A + B) lock-X(A) read(A) A := A + 50 write(A) unlock(A) Schedule 1.

©Silberschatz, Korth and Sudarshan16.7Database System Concepts - 5 th Edition, Sep 12, 2005 Lock-Based Protocols (Cont.) Suppose now that unlocking is delayed to the end of the transaction. T 3 and T 4 correspond to T 1 and T 2 with unlocking delayed, respectively: T3: lock-X(B); T4: lock-S(A); read(B); read(A); B := B - 50; lock-S(B); write(B); read(B); lock-X(A); display(A + B); read(A); unlock(A); A := A + 50; unlock(B); write(A); unlock(B); unlock(A);

©Silberschatz, Korth and Sudarshan16.8Database System Concepts - 5 th Edition, Sep 12, 2005 Pitfalls of Lock-Based Protocols Consider the partial schedule Neither T 3 nor T 4 can make progress executing lock-S(B) causes T 4 to wait for T 3 to release its lock on B, while executing lock-X(A) causes T 3 to wait for T 4 to release its lock on A. Such a situation is called a deadlock. To handle a deadlock one of T 3 or T 4 must be rolled back and its locks released.

©Silberschatz, Korth and Sudarshan16.9Database System Concepts - 5 th Edition, Sep 12, 2005 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.

©Silberschatz, Korth and Sudarshan16.10Database System Concepts - 5 th Edition, Sep 12, 2005 The Two-Phase Locking Protocol (Cont.) Two-phase locking does not ensure freedom from deadlocks Cascading roll-back is possible under two-phase locking. To avoid this, follow a modified protocol called strict two-phase locking. Here a transaction must hold all its exclusive locks till it commits/aborts. Rigorous two-phase locking is even stricter: here all locks are held till commit/abort. In this protocol transactions can be serialized in the order in which they commit.

©Silberschatz, Korth and Sudarshan16.11Database System Concepts - 5 th Edition, Sep 12, 2005 Partial Schedule Under Two-Phase Locking Cascading rollback may occur under two-phase locking: Each transaction observes the two-phase locking protocol, but the failure of T 5 after the read(A) step of T 7 leads to cascading rollback of T 6 and T 7. Partial schedule under two-phase locking

©Silberschatz, Korth and Sudarshan16.12Database System Concepts - 5 th Edition, Sep 12, 2005 Lock Conversions Two-phase locking with lock conversions: – First Phase: can acquire a lock-S on item can acquire a lock-X on item can convert a lock-S to a lock-X (upgrade) – Second Phase: can release a lock-S can release a lock-X can convert a lock-X to a lock-S (downgrade) This protocol assures serializability.

©Silberschatz, Korth and Sudarshan16.13Database System Concepts - 5 th Edition, Sep 12, 2005 Lock Conversions Rigorous two-phase locking protocol: requires all locks to be held until the transaction commits. Consider T 8 : read(a 1 ); T 9 : read(a 1 ); read(a 2 ); read(a 2 );... display(a 1 + a 2 ). read(a n ); write(a 1 ). Two-phase locking protocol ==> serial

©Silberschatz, Korth and Sudarshan16.14Database System Concepts - 5 th Edition, Sep 12, 2005 Lock Conversions If we employ the two-phase locking protocol, then T 8 must lock a 1 in exclusive mode. Therefore, any concurrent execution of both transactions amounts to a serial execution. Notice, however, that T 8 needs an exclusive lock on a 1 only at the end of its execution, when it writes a 1. Thus, if T 8 could initially lock a1 in shared mode, and then could later change the lock to exclusive mode, we could get more concurrency, since T 8 and T 9 could access a 1 and a 2 simultaneously. lock conversion: - upgrade: shared exclusive modes in growing phase. - downgrade: exclusive shared mode in shrinking phase.

©Silberschatz, Korth and Sudarshan16.15Database System Concepts - 5 th Edition, Sep 12, 2005 Incomplete Schedule With a Lock Conversion See the incomplete schedule with a lock conversion. Strict two-phase locking and rigorous two-phase locking (with lock conversions) are used extensively in commercial database systems.

Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com End of Chapter 16