1 Controlled concurrency Now we start looking at what kind of concurrency we should allow We first look at uncontrolled concurrency and see what happens.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Advertisements

Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Introduction to Database Systems1 Concurrency Control CC.Lecture 1.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Transactions (Chapter ). What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions.
CS4432: Database Systems II Lecture #26 Concurrency Control and Recovery Professor Elke A. Rundensteiner.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
ACS-4902 R McFadyen 1 Chapter 17 Introduction to Transaction Processing Concepts and Theory 17.1, 17.2, 17.3, 17.5, 17.6.
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 and Recovery Module 6, Lecture 1.
1 Transaction Management Overview Yanlei Diao UMass Amherst March 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
©Silberschatz, Korth and Sudarshan15.1Database System ConceptsTransactions Transaction Concept Transaction State Implementation of Atomicity and Durability.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
Transactions or Concurrency Control. Introduction A program which operates on a DB performs 2 kinds of operations: –Access to the Database (Read/Write)
Transactions. Definitions Transaction (program): A series of Read/Write operations on items in a Database. Example: Transaction 1 Read(C) Read(A) Write(A)
Concurrency. Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
1 Introduction to Transaction Processing (1)
Transactions Amol Deshpande CMSC424. Today Project stuff… Summer Internships 
Transaction Processing
1 Concurrency Control. 2 Transactions A transaction is a list of actions. The actions are reads (written R T (O)) and writes (written W T (O)) of database.
1 Concurrency Control. 2 Transactions A transaction is a list of actions. The actions are reads (written R T (O)) and writes (written W T (O)) of database.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Transaction. A transaction is an event which occurs on the database. Generally a transaction reads a value from the database or writes a value to the.
Copyright © 2004 Pearson Education, Inc.. Chapter 17 Introduction to Transaction Processing Concepts and Theory.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Transaction Processing Concepts
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Transactions Sylvia Huang CS 157B. Transaction A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
CS 162 Discussion Section Week 9 11/11 – 11/15. Today’s Section ●Project discussion (5 min) ●Quiz (10 min) ●Lecture Review (20 min) ●Worksheet and Discussion.
Quick revision on Transaction Processing Concepts By: Dr. Yousry Taha Copyright 2010.
Transaction Lectured by, Jesmin Akhter, Assistant professor, IIT, JU.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
Transactions. What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions developed.
CSCI Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
Transactions and Concurrency Control Fall 2007 Himanshu Bajpai
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.
1 CSE 480: Database Systems Lecture 24: Concurrency Control.
Concurrency (cont.) Schedule. In multiprogramming environment, Several transaction run concurrently Database consistency can be destroy Schedules to ensure.
Transaction Management and Recovery, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Multidatabase Transaction Management COP5711. Multidatabase Transaction Management Outline Review - Transaction Processing Multidatabase Transaction Management.
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
MULTIUSER DATABASES : Concurrency and Transaction Management.
Database System Implementation CSE 507
Database System Implementation CSE 507
Chapter 14: Transactions
1 Introduction to Transaction Processing (1)
CS216: Data-Intensive Computing Systems
Transaction Management Overview
Distributed Transactions
Concurrency.
Lecture 21: Concurrency & Locking
Transaction management
Lec 9: Introduction to Transaction Processing Concepts and Theory
Transaction Management
Transaction Management Overview
Presentation transcript:

1 Controlled concurrency Now we start looking at what kind of concurrency we should allow We first look at uncontrolled concurrency and see what happens –We look at 3 bad examples –We then look at how we can understand whether concurrency is OK or not. Then we look at how to control concurrency

2 FIGURE 21.3 (a) : The lost update problem. This occurs when two transactions that access the same database items have their operations interleaved in a way that makes the value of some database item incorrect. Eg: X = 20, Y = 15, M = 2, N = 3

3 FIGURE 21.3 (b) The temporary update (dirty read) problem. When one transaction updates a database item and then the transaction fails : the updated item is accessed by another transaction before it is changed back to its original value Here issues of concurrency and recovery Eg: X = 20 Y = 15 M = 2 N = 3

4 FIGURE 21.3 (c) The incorrect summary problem. If one T is calculating an aggregate summary function on a number of records while another T id updating some of these records, the aggregate function may calculate some values before they are updated and others after they are updated. Eg: A = 2, N = 3, X = 10, Y = 8

5 Serial Schedules Serial schedule: A schedule S is serial if, for every transaction T in the schedule, all operations of T are executed consecutively in S –i.e. all of one T has to finish before another T starts –Eg: T 2 T 1 T 3 is serial Otherwise, the schedule is called nonserial or interleaved schedule S 1 = r 1 (x), w 1 (x), r 2 (x), r 2 (y) : serial: T 1 T 2 S 2 = r 1 (x), r 2 (x), w 1 (x), r 2 (y) : interleaved

6 Concurrency How to deal with problems of inconsistency of data because of concurrency? –Like in the 3 examples we saw earlier Only allow serial execution. Problem? Wasteful:T 1 is doing I/O, T 2 is forced to wait Solution: Allow controlled concurrency –Allow when no conflict –Don’t allow when conflict Now we see how to do “controlled concurrency”

7 Concurrency Eg– Figure 21.5 Which of C, D should be allowed? Eg: –X= 50 –M = 10 –N = 5

8 Different serial schedules Will 2 diff. serial schedules always give same results ? No – diff. serial schedules can give diff. results. Eg: –T 1 = r(x), r(y), x = x + y, w(x) –T 2 = r(x), r(y), y = x + y, w(y) –x = 20, y = 30 –Serial schedule T 1 T 2 : final values of X, Y? –Serial schedule T 2 T 1 : final values of X, Y? Any serial execution is OK: why? o/w we should not allow concurrency at all. Eg: Suppose T 1 T 2 OK, but T 2 T 1 not OK: –All of T 1 has to happen before all of T 2 –Makes no sense to talk about T 1 and T 2 executing concurrently

9 Serializability Implication for concurrent execution? Want concurrent schedule equivalent to some serial schedule Serializable: A schedule S is serializable if it is equivalent to some serial schedule. Intuition behind serializability: since any serial execution OK –allow interleaved execution as long as result will be same as some serial execution. Eg: Fig D OK (equivalent to A), C not OK

10 Serializability: Result Equivalency We said schedule S is serializable if it is equivalent to some serial schedule. –What does “equivalent” mean ? Check if concurrent schedule produces the same result as a serial schedule. How ? First approach: pick some data values, try. Result equivalent: Two schedules are result equivalent if they produce same final state on some data –Is this idea OK? –Saw it with Fig 17.5 Eg

11 Serializability: Result Equivalency Problem: could have happened by accident i.e. on the data we happened to look at, get the same result but not generally true Eg: Look at Fig 17.5 again –Any values of X, M, N which will make C produce same result as A (or B) ? When M = 0 –But C should not be allowed Want stronger guarantee. How ? Important ops should be in same order as serial

12 Conflicting Operations Order of some pairs of ops are important to consider for concurrency/recovery, others not. Two operations are in conflict: When ? 1. Belong to different transactions. Why? Within T 1 can’t switch: Eg: w 1 (y), r 1 (x) 2. Access the same data item. Why? If diff. data, then doesn’t matter: –w 1 (x), w 2 (y) same as w 2 (y), w 1 (x) 3. One of them is a write op.. Why? r 1 (x),r 2 (x) same as r 2 (x),r 1 (x): data unchanged

13 Complete Schedules Complete Schedule : S of T 1, T 2, … T n 1.Exactly same ops in S and T 1, T 2, … T n 2.Includes abort/commit for each T i 3.If op 1 before op 2 in T i then same order in S 4.For any pair of conflicting operations, one must occur before other in S –We can leave out internal operations

14 Serializability: Conflict Equivalent Eg: S: r 1 (x), r 2 (y), w 1 (y), w 1 (x), w 2 (x) What are the conflict pairs ? (r 1 (x), w 2 (x)) (w 1 (x), w 2 (x)) (r 2 (y), w 1 (y)) Conflict Equivalent: Two schedules are conflict equivalent if the order of any two conflicting operations is the same –i.e. have the same conflict pairs

15 Serializability: Conflict Equivalent Eg: T1 = r 1 (x), w 1 (y), T2 = r 2 (y), w 2 (x) –S1 = r 1 (x), r 2 (y), w 2 (x), w 1 (y) –S2 = r 2 (y), w 2 (x), r 1 (x), w 1 (y) –Are S1, S2 conflict equivalent ? – are conflict pairs the same ? What are the conflict pairs of S1 ( r 1 (x), w 2 (x)), (r 2 (y), w 1 (y)) What are the conflict pairs of S2 ( w 2 (x)), r 1 (x)), (r 2 (y), w 1 (y)) Different pairs: not conflict equivalent

16 Serializability: Conflict Equivalent Eg: S3 = r 1 (x), r 2 (y), w 1 (y), w 2 (x) S4 = r 2 (y), r 1 (x), w 1 (y), w 2 (x ) Are S3, S4 conflict equivalent ? – are conflict pairs the same ? What are the conflict pairs of S3 ( r 1 (x), w 2 (x)), (r 2 (y), w 1 (y)) What are the conflict pairs of S4 ( r 1 (x), w 2 (x)), (r 2 (y), w 1 (y)) Same pairs : are conflict equivalent

17 Serializability Eg– Figure 21.5 Which of C, D should be allowed?

18 Serializability: Conflict Equivalency S is conflict serializable if it is conflict equivalent to some serial schedule S’ Figure 17.5 : A (T 1 T 2 ) is serial, so is B (T 2 T 1 ) Is D conflict serializable –D’s conflict pairs equivalent to those of A or B? Conflict pair of A, B, D ? A: (r 1 (x), w 2 (x)), (w 1 (x), r 2 (x)), (w 1 (x), w 2 (x)) B: (r 2 (x), w 1 (x)), (w 2 (x), r 1 (x)), (w 2 (x),w 1 (x)) D: (r 1 (x), w 2 (x)), (w 1 (x), r 2 (x)), (w 1 (x), w 2 (x)) Is C conflict serializable. Conflict pairs ? C: (r 1 (x), w 2 (x)), (w 1 (x), w 2 (x)), (r 2 (x), w 1 (x)) C not equivalent to A: r 2 (x) before w 1 (x) C not equivalent to B: w 1 (x) before w 2 (x)

19 Serializability Serializable not the same as serial. –What is the difference ? Serial means no interleaving: T1 T2 T3 etc Serializable allows interleaving, but has to be equivalent to a serial schedule Serializable schedule : –Will leave the database in a consistent state. –Interleaving is controlled and will result in the same state as if the transactions were serially executed, –Will achieve efficiency due to concurrent execution.

20 Testing For Conflict Serializability Testing for conflict serializability Algorithm 17.1: 1.Looks at only read_Item (X) and write_Item (X) operations : not the internal ops 2.Constructs a precedence graph (serialization graph) - a graph with directed edges 3.An edge is created from T i to T j if one of the operations in T i appears before a conflicting operation in T j 4.The schedule is serializable if and only if the precedence graph has no cycles.

21 Figure 21.5: draw precedence graphs

22 FIGURE 21.7: precedence graph for Figure 21.5 Constructing precedence graphs for schedules from Figure 17.5 to test for conflict serializability. Precedence graphs for (a) serial schedule A. (b) serial schedule B. (c) schedule C (not serializable). (d) schedule D (serializable, equivalent to schedule A). How do we interpret the cycles ?

23 FIGURE 21.8 (a). Another example of serializability testing. (a) The READ and WRITE operations of three transactions T 1, T 2, and T 3. We will look at schedules in next 2 slides –And draw the precedence graphs

24 FIGURE 21.8 (b). Schedule E. –Precedence graph ? Serializable ?

25 FIGURE 21.8 (c). Schedule F. –Precedence graph ? Serializable ?

26 Serializability Issue: OS controls how ops get interleaved : –Resulting schedule may or may not be serializable –Problem ? If not serializable, then what? Have to rollback. Problem? Expensive – not practical! How to solve? Guarantee serializability. How ? Locks: –Current approach used in most DBMSs: Two phase locking: will study

27 View Serializability We have seen result equivalent and conflict equivalent. View equivalent: another condition. [RG] eg: Schedule S2 is serial Schedule S1: R 1 (A), W 2 (A), W 1 (A), W 3 (A). Is this conflict serializable? No – precedence graph has a cycle. –T1 → T2 → T1 Do you think S1 should be allowed ? Schedule S1: T1: R(A) W(A) T2: W(A) T3: W(A) Schedule S2: T1: R(A),W(A) T2: W(A) T3: W(A)

28 View Serializability S1 is equivalent (in every situation) to serial S2 i.e. T1,T2,T3. Why? Because final value of A written by T3 –This is a blind write so does not matter whether T1, T2 were in serial order or interleaved Stronger than result equivalent, weaker than conflict equivalent View equivalent: we won’t do formal defn. View serializability good enough –but expensive to test (NP-hard) –so use conflict serializability since easier to test

29 Other Notions of Serializability Other Types of Equivalence of Schedules Under special semantic constraints –schedules that are otherwise not conflict serializable may work correctly. –[SKS Eg] in next slide

30 [SKS] Example A is checking account B is savings account T 1 transferring 50$ from A to B T 5 transferring 10$ from B to A Is this schedule conflict serializable? No. Also not view serializable –Though we have not studied definition. Should this schedule be allowed ? Yes : Eg: A = 100, B = 30. In general, OK. Why? D: debit, C: credit. D D C C same as D C D C

31 Recoverability vs Serializability Both affected by concurrent execution of transactions, but the two are quite different Recoverability : How to recover if transaction aborts or system crashes Serializability : Even if no system crashes and all transactions commit –Have to make sure we get correct results Equivalent to serial schedule

32 Serializability Tests DBMS has to provide a mechanism to ensure that schedules are conflict serializable We have seen how to test a schedule to see if it is (was) serializable. –How can this be used? We could run the transactions without attempting to control concurrency. Then what ? Test to see if the schedule which resulted was serializable. If serializable, then what ? Everything OK. If not serializable, then what ? Rollback. Problem ? Expensive. Alternative ?

33 Concurrency Control vs. Serializability Tests Develop concurrency control protocols that only allow concurrent schedules which we want –Serializable –Recoverable, cascadeless. Connection between concurrency control protocols and serializability tests ? Tests for serializability help us understand why a concurrency control protocol is correct –i.e. why protocol guarantees serializability.