Transaction Processing: Concurrency and Serializability 10/4/05.

Slides:



Advertisements
Similar presentations
CM20145 Concurrency Control
Advertisements

Database Systems (資料庫系統)
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.
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.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Concurrency Control II
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control: Locking-based Protocols Professor Elke A. Rundensteiner.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Lecture 12 Transactions: Isolation. Transactions What’s hard? – ACID – Concurrency control – Recovery.
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.
Quick Review of Apr 29 material
Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.
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.
Concurrency. Busy, busy, busy... In production environments, it is unlikely that we can limit our system to just one user at a time. – Consequently, it.
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,
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control John Ortiz.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
Transaction Processing Concepts
08_Transactions_LECTURE2 DBMSs should guarantee ACID properties (Atomicity, Consistency, Isolation, Durability). This is typically done by guaranteeing.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#21: Concurrency Control (R&G ch. 17)
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.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Concurrency Control II: Locking and Isolation Levels.
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
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.
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.
1 CSE 480: Database Systems Lecture 24: Concurrency Control.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
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.
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:
DBMS Deadlock.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
Transaction Management
Concurrency Control Techniques
CS216: Data-Intensive Computing Systems
Concurrency Control.
Part- A Transaction Management
Transaction Management
Transactions.
Transaction Management
Lecture 21: Concurrency & Locking
CS162 Operating Systems and Systems Programming Review (II)
6.830 Lecture 12 Transactions: Isolation
Chapter 15 : Concurrency Control
Lecture 22: Intro to Transactions & Logging IV
Transaction management
Transaction Management
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
UNIT -IV Transaction.
Database Systems (資料庫系統)
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Presentation transcript:

Transaction Processing: Concurrency and Serializability 10/4/05

 Interleave transactions to improve concurrency; increasing concurrency can increase throughput (performance).  Some interleaved transactions will never violate isolation because they act on different data.  Some interleaved transactions MAY violate isolation.  Interleave transactions to improve concurrency; increasing concurrency can increase throughput (performance).  Some interleaved transactions will never violate isolation because they act on different data.  Some interleaved transactions MAY violate isolation.

 Concurrency control: An algorithm to (hopefully) permit good interleaving and refuse bad interleaving.  NB, Executing a concurrency control algorithm will increase overhead of the transaction manager.  This will increase response time,  and reduce throughput.  Concurrency control: An algorithm to (hopefully) permit good interleaving and refuse bad interleaving.  NB, Executing a concurrency control algorithm will increase overhead of the transaction manager.  This will increase response time,  and reduce throughput.

Concurrency control  Input to the algorithm are the arriving requests for database reads/writes.  The input is obtained from the various transactions.  Output is a sequence of database read/write requests.  The output is provided to the portion of the data manager actually accessing the disk.  Input to the algorithm are the arriving requests for database reads/writes.  The input is obtained from the various transactions.  Output is a sequence of database read/write requests.  The output is provided to the portion of the data manager actually accessing the disk.

 A serial schedule has no interleaving between transactions (a transaction completes before another begins).  A schedule is correct if it is equivalent to a serial schedule.  A serial schedule has no interleaving between transactions (a transaction completes before another begins).  A schedule is correct if it is equivalent to a serial schedule.

Isolation levels  By relaxing the isolation requirement, more interleaving is possible -- at a greater risk to data integrity.  Isolation levels characterize the amount of isolation imposed.  By relaxing the isolation requirement, more interleaving is possible -- at a greater risk to data integrity.  Isolation levels characterize the amount of isolation imposed.

Commuting operations Two operations, p1 and p2, commute if, for all possible initial database states,  p1 returns the same value when executed in order or  p2 returns the same value when executed in order or  The database state produced by both sequences is the same.  Note, commutativity is symmetric.  NOTE! Two operations on different data items always commute.  Note, Two operations on the same data item MAY commute. Two operations, p1 and p2, commute if, for all possible initial database states,  p1 returns the same value when executed in order or  p2 returns the same value when executed in order or  The database state produced by both sequences is the same.  Note, commutativity is symmetric.  NOTE! Two operations on different data items always commute.  Note, Two operations on the same data item MAY commute.

Conflicting operations  Two operations that do not commute are conflicting operations.  E.g., S1 : S1’ : If they are run on the same starting state, and end up in different states, then s11 and s12 conflict. Look at the following from the aspect of two different transactions, A read and read on the same item always commute. A read and a write on the same item conflict because (though the final state is the same), value returned depends on order of ops. A write and a write on the same item conflict.  Two operations that do not commute are conflicting operations.  E.g., S1 : S1’ : If they are run on the same starting state, and end up in different states, then s11 and s12 conflict. Look at the following from the aspect of two different transactions, A read and read on the same item always commute. A read and a write on the same item conflict because (though the final state is the same), value returned depends on order of ops. A write and a write on the same item conflict.

 If S2 can be obtained from S1 by “swapping” commuting operations, then S1 and S2 are equivalent.  Equivalence of schedules is transitive!  If S2 can be obtained from S1 by “swapping” commuting operations, then S1 and S2 are equivalent.  Equivalence of schedules is transitive!

Example schedules  Two interleaved transactions T1 (t11, t12), T2 (t21, t22): S1: s11, s12, s13, s14 Suppose s12 and s13 commute, then S2 : s11, s13, s12, s14 Same start state Same end state  Two interleaved transactions T1 (t11, t12), T2 (t21, t22): S1: s11, s12, s13, s14 Suppose s12 and s13 commute, then S2 : s11, s13, s12, s14 Same start state Same end state

 Schedule equivalence (not the same as E&N’s ‘complete schedule’ definition):  Two schedules of the same set of ops are equivalent iff conflicting operations are ordered in the same way in both schedules.  ==> A schedule S2 can be derived from a schedule S1 by interchanging commuting operations iff conflicting operations are ordered in the same way in both schedules.  Schedule equivalence (not the same as E&N’s ‘complete schedule’ definition):  Two schedules of the same set of ops are equivalent iff conflicting operations are ordered in the same way in both schedules.  ==> A schedule S2 can be derived from a schedule S1 by interchanging commuting operations iff conflicting operations are ordered in the same way in both schedules.

Restatement of Serializable Schedule  A schedule is serializable if it is equivalent to a serial schedule  Equivalent construction:  Commute commuting operators and use transitivity of equivalence, or  Conflicting operations are in the same order in both schedules.  A schedule is serializable if it is equivalent to a serial schedule  Equivalent construction:  Commute commuting operators and use transitivity of equivalence, or  Conflicting operations are in the same order in both schedules.

Try this: is S1 serializable (what commutations?), S2? S3?  T1:  T2:  S1:  S2:  S3:  T1:  T2:  S1:  S2:  S3:

Try this: is S4 serializable?  S4:

More on schedule equivalence  The preceding definition of equivalence (by commuting, AKA by maintaining order of conflicting ops) is called conflict equivalence.  A different kind of equivalence is view equivalence, two schedules of the same set of ops are view equivalent if both the following are true:  Corresponding read ops in each schedule return the same values,  Both schedules yield the same final state.  The preceding definition of equivalence (by commuting, AKA by maintaining order of conflicting ops) is called conflict equivalence.  A different kind of equivalence is view equivalence, two schedules of the same set of ops are view equivalent if both the following are true:  Corresponding read ops in each schedule return the same values,  Both schedules yield the same final state.

View equivalence  If corresponding read ops in both schedules return the same values, then the transactions perform the same calculations and write the same results!  I.e., transactions in both schedules have the same view of the database.  Conflict equivalence implies view equivalence  View equivalence does not imply conflict equivalence.  I.e., Conflict equivalence is the stronger; but it turns out that conflict equivalence is easier to use for concurrency control.  If corresponding read ops in both schedules return the same values, then the transactions perform the same calculations and write the same results!  I.e., transactions in both schedules have the same view of the database.  Conflict equivalence implies view equivalence  View equivalence does not imply conflict equivalence.  I.e., Conflict equivalence is the stronger; but it turns out that conflict equivalence is easier to use for concurrency control.

Serialization graphs  A schedule, S, is represented as a directed graph.  Nodes are (committed) transactions.  Edge between Ti and Tj (Ti -> Tj) if:  Some op in Ti, pi, conflicts with some op, pj, in Tj, and  pi appears before pj in S.  A schedule, S, is represented as a directed graph.  Nodes are (committed) transactions.  Edge between Ti and Tj (Ti -> Tj) if:  Some op in Ti, pi, conflicts with some op, pj, in Tj, and  pi appears before pj in S.

Example  S1: T2 writes a after T1 reads a. The ops do not commute: r1(a), w2(a) Graph of S1: T1 T2  S1: T2 writes a after T1 reads a. The ops do not commute: r1(a), w2(a) Graph of S1: T1 T2

A schedule is conflict serializable iff its serialization graph is acyclic. T2T4 T1 T3T5 T6T7 Topological sorts give conflict equivalent serial schedules, e.g.: T1, T3, T5, T2, T6, T7, T4. Others? T2T4 T1 T3T5 T6T7 Topological sorts give conflict equivalent serial schedules, e.g.: T1, T3, T5, T2, T6, T7, T4. Others?

In class  Using concurrent transactions, deposit to a, withdraw from a, make a (non-serial) schedule:  Give the serialization graph  Is it acyclic? If so, give a conflict equivalent serial schedule.  Identify commuting operations.  Identify conflicting operations.  Using the concurrent deposit, transfer and withdraw transactions (deposit to a, withdraw from b, transfer takes from b and puts in a), make a (non-serial) schedule:  Give the serialization graph  Is it acyclic? Is there a serial schedule?  How many total pairs of operations are there?  Identify, at least some, commuting operations.  Identify, at least some, conflicting operations.  Using concurrent transactions, deposit to a, withdraw from a, make a (non-serial) schedule:  Give the serialization graph  Is it acyclic? If so, give a conflict equivalent serial schedule.  Identify commuting operations.  Identify conflicting operations.  Using the concurrent deposit, transfer and withdraw transactions (deposit to a, withdraw from b, transfer takes from b and puts in a), make a (non-serial) schedule:  Give the serialization graph  Is it acyclic? Is there a serial schedule?  How many total pairs of operations are there?  Identify, at least some, commuting operations.  Identify, at least some, conflicting operations.

A strict concurrency control  A transaction is not allowed to read or write data that has been written by another still active transaction. (Recoverability topic later).  Conflict avoidance:  If operation requests by T1 and T2 do not conflict, they are granted.  Requests don’t conflict if either:  Requests are to different data items, OR  Requests are both reads.  A transaction is not allowed to read or write data that has been written by another still active transaction. (Recoverability topic later).  Conflict avoidance:  If operation requests by T1 and T2 do not conflict, they are granted.  Requests don’t conflict if either:  Requests are to different data items, OR  Requests are both reads.

In class  Make the conflict table for the previous algorithm: (put X for conflicting requests) Granted op: Requested op:readwrite read write  Make the conflict table for the previous algorithm: (put X for conflicting requests) Granted op: Requested op:readwrite read write

But if you make a transaction wait … DEADLOCK (a cycle of k transactions waiting for each other) DEADLOCK (a cycle of k transactions waiting for each other)

Dealing with deadlock  Prevention: maintain a data structure that checks whether deadlock may result. If so, some transaction involved in the deadlock must be aborted.  Timeout: if time to execute exceeds a threshold, force an abort.  Timestamp:Timestamp start of each transaction. Use timestamp to implement a conflict resolution policy:  Older transaction never waits for younger (e.g., by aborting younger, even though younger has been waiting a long time),  Younger transaction can only wait for an older (place younger on wait-list)  Prevention: maintain a data structure that checks whether deadlock may result. If so, some transaction involved in the deadlock must be aborted.  Timeout: if time to execute exceeds a threshold, force an abort.  Timestamp:Timestamp start of each transaction. Use timestamp to implement a conflict resolution policy:  Older transaction never waits for younger (e.g., by aborting younger, even though younger has been waiting a long time),  Younger transaction can only wait for an older (place younger on wait-list)

Manual locking: an alternative to AUTOMATIC locking  A transaction explicitly requests concurrency control to grant a lock on a data item, then makes the read/write request.  Concurrency control grants (or refuses) locks.  A transaction explicitly requests concurrency control to grant a lock on a data item, then makes the read/write request.  Concurrency control grants (or refuses) locks.

UNLOCKING  Can be automatic -- when a transaction terminates, all locks held by it are released.  Can be manual -- transaction explicitly releases a lock.  Can be automatic -- when a transaction terminates, all locks held by it are released.  Can be manual -- transaction explicitly releases a lock.

Two phase locking: 2PL  A transaction maintains 2PL protocol if it obtains all of its locks before making any unlocks …  lock phase, followed by unlock phase  Automatic locking is 2PL.  Automatic unlocking is 2PL.  2PL protocol produces serializable schedules.  A transaction maintains 2PL protocol if it obtains all of its locks before making any unlocks …  lock phase, followed by unlock phase  Automatic locking is 2PL.  Automatic unlocking is 2PL.  2PL protocol produces serializable schedules.

 For next time, we’ll discuss the paper in the RedBook: “Granularity of Locks …”  How are the different lock modes used?  What are the degrees of consistency?  How does the locking protocol relate to degrees of consistency.  What are the overhead costs of the different locking protocols?  For next time, we’ll discuss the paper in the RedBook: “Granularity of Locks …”  How are the different lock modes used?  What are the degrees of consistency?  How does the locking protocol relate to degrees of consistency.  What are the overhead costs of the different locking protocols?