Database Systems Lecture 16 Natasha Alechina

Slides:



Advertisements
Similar presentations
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
Advertisements

1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme.
Database Systems (資料庫系統)
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Unit 9 Concurrency Control. 9-2 Wei-Pang Yang, Information Management, NDHU Content  9.1 Introduction  9.2 Locking Technique  9.3 Optimistic Concurrency.
Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Concurrency Control II
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Lock-Based Concurrency Control
Concurrency Control.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 6: Cascading Rollbacks, Deadlocks, and Long Transactions Professor Chen Li.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
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.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
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.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Concurrency Control John Ortiz.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
DBMS2001Notes 9: Transaction Processing1 Principles of Database Management Systems 9: More on Transaction Processing Pekka Kilpeläinen (Partially based.
© 1997 UW CSE 11/13/97N-1 Concurrency Control Chapter 18.1, 18.2, 18.5, 18.7.
Transactions and Recovery
Deadlocks in Distributed Systems Deadlocks in distributed systems are similar to deadlocks in single processor systems, only worse. –They are harder to.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Concurrency Control Techniques Chapter 18
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Concurrency Chapter 6.2 V3.1 Napier University Dr Gordon Russell.
7c.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Module 7c: Atomicity Atomic Transactions Log-based Recovery Checkpoints Concurrent.
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 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
Timestamp-based Concurrency Control
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
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.
Transaction Management
CS 245: Database System Principles Notes 10: More TP
Lecture 3 Concurrency control techniques
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
Concurrency Control Chapter 17
Concurrency Control WXES 2103 Database.
Database Transactions
Basic Two Phase Locking Protocol
Distributed Database Management Systems
Concurrency Control Chapter 17
Transaction management
Database Management System
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
CSE 542: Operating Systems
Database Systems (資料庫系統)
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Presentation transcript:

Database Systems Lecture 16 Natasha Alechina More Concurrency Database Systems Lecture 16 Natasha Alechina

In This Lecture Deadlock detection Deadlock prevention Timestamping For more information Connolly and Begg chapter 20

Deadlocks A deadlock is an impasse that may result when two or more transactions are waiting for locks to be released which are held by each other. For example: T1 has a lock on X and is waiting for a lock on Y, and T2 has a lock on Y and is waiting for a lock on X. Given a schedule, we can detect deadlocks which will happen in this schedule using a wait-for graph (WFG).

Precedence/Wait-For Graphs Precedence graph Each transaction is a vertex Arcs from T1 to T2 if T1 reads X before T2 writes X T1 writes X before T2 reads X T1 writes X before T2 writes X Wait-for Graph Each transaction is a vertex Arcs from T2 to T1 if T1 read-locks X then T2 tries to write-lock it T1 write-locks X then T2 tries to read-lock it T1 write-locks X then T2 tries to write-lock it

Example T1 T2 T3 T1 T2 T3 T1 Read(X) T2 Read(Y) T1 Write(X) T2 Read(X) T3 Read(Z) T3 Write(Z) T1 Read(Y) T3 Read(X) T1 Write(Y) T2 T3 Wait for graph T1 T2 T3 Precedence graph

Example T1 T2 T3 T1 T2 T3 T1 Read(X) T2 Read(Y) T1 Write(X) T2 Read(X) T3 Read(Z) T3 Write(Z) T1 Read(Y) T3 Read(X) T1 Write(Y) T2 T3 Wait for graph T1 T2 T3 Precedence graph

Example T1 T2 T3 T1 T2 T3 T1 Read(X) T2 Read(Y) T1 Write(X) T2 Read(X) T3 Read(Z) T3 Write(Z) T1 Read(Y) T3 Read(X) T1 Write(Y) T2 T3 Wait for graph T1 T2 T3 Precedence graph

Example T1 T2 T3 T1 T2 T3 T1 Read(X) T2 Read(Y) T1 Write(X) T2 Read(X) T3 Read(Z) T3 Write(Z) T1 Read(Y) T3 Read(X) T1 Write(Y) T2 T3 Wait for graph T1 T2 T3 Precedence graph

Example T1 T2 T3 T1 T2 T3 T1 Read(X) read-locks(X) T2 Read(Y) read-locks(Y) T1 Write(X) write-lock(X) T2 Read(X) tries read-lock(X) T3 Read(Z) T3 Write(Z) T1 Read(Y) T3 Read(X) T1 Write(Y) T2 T3 Wait for graph T1 T2 T3 Precedence graph

Example T1 T2 T3 T1 T2 T3 T1 Read(X) read-locks(X) T2 Read(Y) read-locks(Y) T1 Write(X) write-lock(X) T2 Read(X) tries read-lock(X) T3 Read(Z) read-lock(Z) T3 Write(Z) write-lock(Z) T1 Read(Y) read-lock(Y) T3 Read(X) tries read-lock(X) T1 Write(Y) T2 T3 Wait for graph T1 T2 T3 Precedence graph

Example T1 T2 T3 T1 T2 T3 T1 Read(X) read-locks(X) T2 Read(Y) read-locks(Y) T1 Write(X) write-lock(X) T2 Read(X) tries read-lock(X) T3 Read(Z) read-lock(Z) T3 Write(Z) write-lock(Z) T1 Read(Y) read-lock(Y) T3 Read(X) tries read-lock(X) T1 Write(Y) tries write-lock(Y) T2 T3 Wait for graph T1 T2 T3 Precedence graph

Deadlock Prevention Deadlocks can arise with 2PL Conservative 2PL Deadlock is less of a problem than an inconsistent DB We can detect and recover from deadlock It would be nice to avoid it altogether Conservative 2PL All locks must be acquired before the transaction starts Hard to predict what locks are needed Low ‘lock utilisation’ - transactions can hold on to locks for a long time, but not use them much

Deadlock Prevention We impose an ordering on the resources Transactions must acquire locks in this order Transactions can be ordered on the last resource they locked This prevents deadlock If T1 is waiting for a resource from T2 then that resource must come after all of T1’s current locks All the arcs in the wait-for graph point ‘forwards’ - no cycles

Example of resource ordering Suppose resource order is: X < Y This means, if you need locks on X and Y, you first acquire a lock on X and only after that a lock on Y (even if you want to write to Y before doing anything to X) It is impossible to end up in a situation when T1 is waiting for a lock on X held by T2, and T2 is waiting for a lock on Y held by T1.

Timestamping Transactions can be run concurrently using a variety of techniques We looked at using locks to prevent interference An alternative is timestamping Requires less overhead in terms of tracking locks or detecting deadlock Determines the order of transactions before they are executed

Timestamping Each transaction has a timestamp, TS, and if T1 starts before T2 then TS(T1) < TS(T2) Can use the system clock or an incrementing counter to generate timestamps Each resource has two timestamps R(X), the largest timestamp of any transaction that has read X W(X), the largest timestamp of any transaction that has written X

Timestamp Protocol If T tries to read X T tries to write X If TS(T) < W(X) T is rolled back and restarted with a later timestamp If TS(T)  W(X) then the read succeeds and we set R(X) to be max(R(X), TS(T)) T tries to write X If TS(T) < W(X) or TS(T) < R(X) then T is rolled back and restarted with a later timestamp Otherwise the write succeeds and we set W(X) to TS(T)

Timestamping Example Given T1 and T2 we will assume T1 T2 The transactions make alternate operations Timestamps are allocated from a counter starting at 1 T1 goes first T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z)

Timestamp Example X Y Z R T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS

Timestamp Example X Y Z R 1 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 1

Timestamp Example X Y Z R 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 1 2

Timestamp Example X Y Z R 2 1 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 1 2

Timestamp Example X Y Z R 2 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 1 2

Timestamp Example X Y Z R 2 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 1 2

Timestamp Example X Y Z R 2 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 1 2

Timestamp Example X Y Z R 2 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 1 2

Timestamp Example X Y Z R 2 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W T1 T2 TS 3 2

Timestamp Example X Y Z R 2 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W 2 T1 T2 TS 3 2

Timestamp Example X Y Z R 3 2 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W 2 T1 T2 TS 3 2

Timestamp Example X Y Z R 3 3 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W 2 T1 T2 TS 3 2

Timestamp Example X Y Z R 3 3 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W 2 T1 T2 TS 3 2

Timestamp Example X Y Z R 3 3 T1 T2 Read(X) Read(X) Read(Y) Read(Y) Y = Y + X Z = Y - X Write(Y) Write(Z) W 3 2 T1 T2 TS 3 2

Timestamping The protocol means that transactions with higher times take precedence Equivalent to running transactions in order of their final time values Transactions don’t wait - no deadlock Problems Long transactions might keep getting restarted by new transactions - starvation Rolls back old transactions, which may have done a lot of work

Next Lecture Database Security Database Integrity For more information Aspects of security Access to databases Privileges and views Database Integrity View updating, Integrity constraints For more information Connolly and Begg chapters 6 and 19