We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byPatrick Rivera
Modified over 2 years ago
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
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
CM20145 Recovery + Intro. to Concurrency Dr Alwyn Barry Dr Joanna Bryson.
CM20145 Concurrency Control Dr Alwyn Barry Dr Joanna Bryson.
CM20145 Transactions Dr Alwyn Barry Dr Joanna Bryson.
CM20145 Transactions & Serializability Chris Middup.
Concurrency control 1. 2 Introduction concurrency more than one transaction have access to data simultaneously part of transaction processing.
G.Vadivu & P.Subha, Assistant Professor, SRM University, Kattankulathur 8/22/2011School of Computing, Department of IT.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 26: Advanced.
Universität Karlsruhe (TH) TAV 10© 2007 Univ,Karlsruhe, IPD, Prof. Lockemann/Prof. Böhm Chapter 10 Distributed Transactions: Synchronization.
1 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transactions 3.
Transaction Indra Budi Fakultas Ilmu Komputer UI 2 Exercise A series of actions to be taken on the database such that either all actions.
CSL 771: Database Implementation Transaction Processing Maya Ramanath All material (including figures) from: Concurrency Control and Recovery in Database.
Concurrency Control Alexandra Cristea and Steve Russ 1.
Transaction Management Reading: CB, Ch. 22. Dept of Computing Science, University of Aberdeen2 In this lecture you will learn the problems of concurrency.
Chapter 17: Recovery System Failure Classification Storage Structure Recovery and Atomicity Log-Based Recovery Shadow Paging Recovery With Concurrent Transactions.
1 Database Concurrency Control and Recovery Pessimistic concurrency control Two-phase locking (2PL) and Strict 2PL Timestamp ordering (TSO) and Strict.
Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
1 Concurrency: Deadlock and Starvation Chapter 6.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 20: Database System.
MSc IT UFCE8K-15-M Data Management Prakash Chatterjee Room 2Q18
Managing Multi-User Databases (1) IS 240 – Database Management Lecture #18 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 17: Database.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Query Processing.
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Copyright © George Coulouris, Jean Dollimore, Tim Kindberg This material is made available for private study and for direct.
1 Consistency in Distributed Systems Recall the fundamental DS properties – DS may be large in scale and widely distributed 1.concurrent execution of components.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide Types of Distributed Database Systems Homogeneous All sites of the database system have.
© 2016 SlidePlayer.com Inc. All rights reserved.