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

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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15 : Concurrency.
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Lock-Based Concurrency Control
Fall 2006R McFadyen ACS Deadlock Prevention Strategies wait-die wound-wait schemes use transaction timestamps for the sake of deadlock prevention.
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.
Chapter 7 Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks 7.1 System Model.
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.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
Chapter 16 : Concurrency Control Chapter 16: Concurrency Control agreement, accordance of opinion; cooperation, shared effort; simultaneous occurrence.
ACS-4902 R. McFadyen 1 Database Concurrency Control Deadlock Deadlock occurs when each transaction in a set is waiting for another transaction in the set.
©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.
What is a Transaction? Logical unit of work
Transaction Management
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control John Ortiz.
Concurrency Control. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Transaction Processing.
DBMS2001Notes 9: Transaction Processing1 Principles of Database Management Systems 9: More on Transaction Processing Pekka Kilpeläinen (Partially based.
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.
PMIT-6102 Advanced Database Systems
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.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
Concurrency Control in Database Operating Systems.
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Database Techniek Lecture 5: Concurrency Control (Chapter 14/16)
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
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.
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Chapter 16 : Concurrency.
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Chapter 16 : Concurrency.
Lecture 8- Concurrency Control Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15 : Concurrency.
Chapter 8 Concurrency Control 8.1 Lock-Based Protocols 8.2 Multiple Granularity 8.3 Deadlock Handling 8.4 Insert and Delete Operations.
1 Chapter 17: Concurrency Control. 2 Lock-Based Protocols Timestamp-Based Protocols Validation-Based Protocols Multiple Granularity Multiversion Schemes.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li.
Academic Year 2014 Spring Academic Year 2014 Spring.
DBMS Deadlock.
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
Database System Implementation CSE 507
Chapter 16: Concurrency Control
Concurrency Control WXES 2103 Database.
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.
Presentation transcript:

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

©Silberschatz, Korth and Sudarshan15.2Database System Concepts - 6 th Edition Chapter 15: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols Validation-Based Protocols Multiple Granularity Multiversion Schemes Insert and Delete Operations Concurrency in Index Structures

©Silberschatz, Korth and Sudarshan15.3Database System Concepts - 6 th Edition 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.

©Silberschatz, Korth and Sudarshan15.4Database System Concepts - 6 th Edition 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 Sudarshan15.5Database System Concepts - 6 th Edition Lock-Based Protocols (Cont.) Example of a transaction performing locking: T 1 : lock-X(A); read (A); A:=A-50; write (A); lock-X(B); read (B); B:=B+50; write (B); Commit; 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 Sudarshan15.6Database System Concepts - 6 th Edition 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 Sudarshan15.7Database System Concepts - 6 th Edition Pitfalls of Lock-Based Protocols (Cont.) The potential for deadlock exists in most locking protocols. Deadlocks are a necessary evil. 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. Concurrency control manager can be designed to prevent starvation.

©Silberschatz, Korth and Sudarshan15.8Database System Concepts - 6 th Edition Automatic Acquisition of Locks A transaction T i issues the standard read/write instruction, without explicit locking calls. The operation read(D) is processed as: if T i has a lock on D then read(D) else begin if necessary wait until no other transaction has a lock-X on D grant T i a lock-S on D; read(D) end

©Silberschatz, Korth and Sudarshan15.9Database System Concepts - 6 th Edition Automatic Acquisition of Locks (Cont.) write(D) is processed as: if T i has a lock-X on D then write(D) else begin if necessary wait until no other trans. has any lock on D, if T i has a lock-S on D then upgrade lock on D to lock-X else grant T i a lock-X on D write(D) end; All locks are released after commit or abort

©Silberschatz, Korth and Sudarshan15.10Database System Concepts - 6 th Edition Deadlock Handling Consider the following two transactions: T 1 : write (X) T 2 : write(Y) write(Y) write(X) Schedule with deadlock

©Silberschatz, Korth and Sudarshan15.11Database System Concepts - 6 th Edition Deadlock Handling System is deadlocked if there is a set of transactions such that every transaction in the set is waiting for another transaction in the set. Deadlock prevention protocols ensure that the system will never enter into a deadlock state. Some prevention strategies: Require that each transaction locks all its data items before it begins execution (predeclaration). Impose partial ordering of all data items and require that a transaction can lock data items only in the order specified by the partial order (graph-based protocol).

©Silberschatz, Korth and Sudarshan15.12Database System Concepts - 6 th Edition More Deadlock Prevention Strategies Following schemes use transaction timestamps for the sake of deadlock prevention alone. wait-die scheme — non-preemptive 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

©Silberschatz, Korth and Sudarshan15.13Database System Concepts - 6 th Edition Deadlock Detection Deadlocks can be described as a wait-for graph, which consists of a pair G = (V,E), V is a set of vertices (all the transactions in the system) E is a set of edges; each element is an ordered pair T i  T j. If T i  T j is in E, then there is a directed edge from T i to T j, implying that T i is waiting for T j to release a data item. When T i requests a data item currently being held by T j, then the edge T i T j is inserted in the wait-for graph. This edge is removed only when T j is no longer holding a data item needed by T i. The system is in a deadlock state if and only if the wait-for graph has a cycle. Must invoke a deadlock-detection algorithm periodically to look for cycles.

©Silberschatz, Korth and Sudarshan15.14Database System Concepts - 6 th Edition Deadlock Detection (Cont.) Wait-for graph without a cycle Wait-for graph with a cycle

©Silberschatz, Korth and Sudarshan15.15Database System Concepts - 6 th Edition 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. Include the number of rollbacks in the cost factor to avoid starvation

Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com End of Chapter Thanks to Alan Fekete and Sudhir Jorwekar for Snapshot Isolation examples

©Silberschatz, Korth and Sudarshan15.17Database System Concepts - 6 th Edition Figure 15.01

©Silberschatz, Korth and Sudarshan15.18Database System Concepts - 6 th Edition Figure 15.07

©Silberschatz, Korth and Sudarshan15.19Database System Concepts - 6 th Edition Figure 15.08

©Silberschatz, Korth and Sudarshan15.20Database System Concepts - 6 th Edition Figure 15.09

©Silberschatz, Korth and Sudarshan15.21Database System Concepts - 6 th Edition Figure 15.13

©Silberschatz, Korth and Sudarshan15.22Database System Concepts - 6 th Edition Figure 15.14

©Silberschatz, Korth and Sudarshan15.23Database System Concepts - 6 th Edition Figure 15.17

©Silberschatz, Korth and Sudarshan15.24Database System Concepts - 6 th Edition Figure 15.18

©Silberschatz, Korth and Sudarshan15.25Database System Concepts - 6 th Edition Figure 15.19

©Silberschatz, Korth and Sudarshan15.26Database System Concepts - 6 th Edition Figure 15.20

©Silberschatz, Korth and Sudarshan15.27Database System Concepts - 6 th Edition Figure in-15.1