1 Concurrency Control Chapter 17. 2 Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.

Slides:



Advertisements
Similar presentations
Concurrency Control III. General Overview Relational model - SQL Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Advertisements

Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme.
Database Systems (資料庫系統)
Unit 9 Concurrency Control. 9-2 Wei-Pang Yang, Information Management, NDHU Content  9.1 Introduction  9.2 Locking Technique  9.3 Optimistic Concurrency.
Transaction Management and Concurrency Control
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
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.
4/16/20151 PSU’s CS Concurrency Control and Recovery (only for DBs with updates…..!)- Review  Concurrency Control  Transaction  ACID  Isolation.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
CSIS 7102 Spring 2004 Lecture 5 : Non-locking based concurrency control (and some more lock-based ones, too) Dr. King-Ip Lin.
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 19.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Quick Review of Apr 29 material
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Concurrency Control R &G - Chapter 19 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book.
©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.
1 Concurrency Control. 2 Locking: A Technique for C. C. Concurrency control usually done via locking. Lock info maintained by a “lock manager”: –Stores.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
Concurrency Control III R &G - Chapter 17 Lecture 24 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue.
Concurrency Control John Ortiz.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
Alternative Concurrency Control Methods R&G - Chapter 17.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Modified by Donghui Zhang.
CPSC 461. Outline I. Transactions II. Concurrency control Conflict Serializable Schedules Two – Phase protocol Lock Management Deadlocks detection and.
Concurrency Control Techniques Chapter 18
1 Concurrency Control II: Locking and Isolation Levels.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Instructor: Xintao Wu.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
Concurrency Control Introduction Lock-Based Protocols
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
Database Systems (資料庫系統)
Concurrency Control Techniques
CS422 Principles of Database Systems Concurrency Control
Concurrency Control More !
Concurrency Control.
Part- A Transaction Management
Concurrency Control Chapter 17 Modified by Donghui Zhang
Transaction Management Overview
Transaction Management
Concurrency Control Chapter 17
MULTIUSER DATABASES : Concurrency and Transaction Management
Database Applications (15-415) DBMS Internals- Part XII Lecture 24, April 11, 2018 Mohammad Hammoud.
Chapter 16: Concurrency Control
4. Concurrency control techniques
Transaction Management
Concurrency Control Chapter 17
CS162 Operating Systems and Systems Programming Review (II)
Chapter 15 : Concurrency Control
Concurrency Control Chapter 17
Concurrency Control Chapter 17
Concurrency Control R&G - Chapter 17
Transaction Management
Concurrency Control Techniques
Concurrency Control Chapter 17
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Presentation transcript:

1 Concurrency Control Chapter 17

2 Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong to different transactions, and  one of them is a write action.  Examples: R1(X),W2(X); W1(Y),W2(Y), …  Two schedules are conflict equivalent if:  Involve the same actions of the same transactions  Every pair of conflicting actions is ordered the same way  Schedule S is conflict serializable if S is conflict equivalent to some serial schedule

3 Example  A schedule that is not conflict serializable:  The cycle in the graph reveals the problem. The output of T1 depends on T2, and vice- versa. T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1T2 A B Dependency graph

4 Dependency Graph  A dependency graph (also called serializability graph, precedence graph ) contains  a node per committed Xact,  an edge from Ti to Tj if an action of Ti precedes and conflicts with one of Tj ’sactions.  Theorem: A schedule is conflict serializable if and only if its dependency graph is acyclic

5 Review: Strict 2PL  Strict Two-phase Locking (Strict 2PL) Protocol :  Each Xact must obtain a S ( shared ) lock on object before reading, and an X ( exclusive ) lock on object before writing.  All locks held by a transaction are released when the transaction completes  If a Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object.  Strict 2PL allows only schedules whose precedence graph is acyclic

6 Two-Phase Locking (2PL)  Two-Phase Locking Protocol  Each Xact must obtain a S ( shared ) lock on object before reading, and an X ( exclusive ) lock on object before writing.  A transaction can not request additional locks once it releases any locks.  If an Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object.

7 Lock Management  Lock and unlock requests are handled by the lock manager.  The lock manager maintains a lock table, i.e. a hash table with the data object id as the key.  Lock table entry:  Number of transactions currently holding a lock  Type of lock held (shared or exclusive)  Pointer to queue of lock requests  Locking and unlocking have to be atomic operations.  Lock upgrade: transaction that holds a shared lock can be upgraded to hold an exclusive lock.  Lock downgrade: transaction that holds an exclusive lock can be downgraded to hold a shared lock. This is the approach used in current commercial systems.

8 Deadlocks  Deadlock: Cycle of transactions waiting for locks to be released by each other.  Two ways of dealing with deadlocks:  Deadlock prevention  Deadlock detection

9 Deadlock Prevention  Assign priorities based on timestamps; the lower the timestamp, the higher the priority: old Xacts have high priority.  Assume Ti wants a lock that Tj holds. Two policies are possible:  Wait-Die: It Ti has higher priority, Ti waits for Tj; otherwise Ti aborts (and restarts)  Wound-wait: If Ti has higher priority, Tj aborts (and restarts); otherwise Ti waits  If a transaction re-starts, make sure it has its original timestamp.  Prevention is also possible by using conservative 2PL: each Xact obtains all the locks that it ever will need.

10 Deadlock Detection  Create a waits-for graph:  Nodes are transactions  There is an edge from Ti to Tj if Ti is waiting for Tj to release a lock  Periodically check for cycles in the waits-for graph.

11 Deadlock Detection (Continued) Example: T1: S(A), R(A), S(B) T2: X(B),W(B) X(C) T3: S(C), R(C) X(A) T4: X(B) T1T2 T4T3 T1T2 T3

12 Optimistic CC (Kung-Robinson)  Locking is a conservative (pessimistic) approach in which conflicts are prevented. Disadvantages:  Lock management overhead.  Deadlock detection/resolution.  Lock contention for heavily used objects.  If conflicts are rare, we might be able to gain concurrency by not locking, and instead checking for conflicts before Xacts commit.

13 Kung-Robinson Model  In an optimistic protocol, Xacts have three phases:  READ: Xacts read from the database, but make changes to private copies of objects.  VALIDATE: Check for conflicts.  WRITE: Make local copies of changes public. ROOT

14 Timestamp CC  Idea: Give each object a read-timestamp (RTS) and a write-timestamp (WTS), give each Xact a timestamp (TS) when it begins:  If action ai of Xact Ti conflicts with action aj of Xact Tj, and TS(Ti) < TS(Tj), then ai must occur before aj. Otherwise, restart any Xact that violates this ordering.

15 When Xact T wants to read Object O  If TS(T) < WTS(O), this violates timestamp order of T w.r.t. writer of O.  So, abort T and restart it with a new, larger TS. (If restarted with same TS, T will fail again!)  If TS(T) > WTS(O):  Allow T to read O.  Reset RTS(O) to max(RTS(O), TS(T))  Change to RTS(O) on reads must be written to disk! This and restarts represent overheads.

16 When Xact T wants to Write Object O  If TS(T) < RTS(O), this violates timestamp order of T w.r.t. writer of O; abort and restart T.  If TS(T) < WTS(O), violates timestamp order of T w.r.t. writer of O; abort and restart T (naïve approach).  Thomas Write Rule: We can safely ignore such outdated writes; need not restart T! (T’s write is effectively followed by another write, with no intervening reads.) Allows some serializable but non conflict serializable schedules:  Else, allow T to write O and WST(O) is set to TS(T). T1 T2 R(A) W(A) Commit W(A) Commit

17 Timestamp CC and Recoverability  Timestamp CC can be modified to allow only recoverable schedules:  Buffer all writes until writer commits (but update WTS(O) when the write is allowed.)  Block readers T (where TS(T) > WTS(O)) until writer of O commits.  Similar to writers holding X locks until commit, but still not quite 2PL. T1 T2 W(A) R(A) W(B) Commit v Unfortunately, unrecoverable schedules are allowed:

18 Summary  There are several lock-based concurrency control schemes (Strict 2PL, 2PL). Conflicts between transactions can be detected in the dependency graph.  The lock manager keeps track of the locks issued. Deadlocks can either be prevented or detected.  Naïve locking strategies may have the phantom problem.

19 Summary (Contd.)  Optimistic CC aims to minimize CC overheads in an ``optimistic’’ environment where reads are common and writes are rare.  Optimistic CC has its own overheads however; most real systems use locking. Timestamp CC is another alternative to 2PL; allows some serializable schedules that 2PL does not (although converse is also true).  Ensuring recoverability with Timestamp CC requires ability to block Xacts (similar to locking).