©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.

Slides:



Advertisements
Similar presentations
1 Integrity Ioan Despi Transactions: transaction concept, transaction state implementation of atomicity and durability concurrent executions serializability,
Advertisements

Chapter 15: Transactions Transaction Concept Transaction Concept Concurrent Executions Concurrent Executions Serializability Serializability Testing for.
Chapter 16: Transaction Management
©Silberschatz, Korth and Sudarshan15.1Database System ConceptsTransactions Transaction Concept Transaction State Implementation of Atomicity and Durability.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Database Management Systems I Alex Coman, Winter 2006
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
Transactions Amol Deshpande CMSC424. Today Project stuff… Summer Internships 
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Transactions.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 14: Transactions.
Transactions Sylvia Huang CS 157B. Transaction A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction.
TRANSACTIONS. Objectives Transaction Concept Transaction State Concurrent Executions Serializability Recoverability Implementation of Isolation Transaction.
Transactions Chapter 14 Transaction Concept A Simple Transaction Model Storage Structure Transaction Atomicity & Durability Transaction Isolation Serializability.
International Computer Institute, Izmir, Turkey Transactions Asst. Prof. Dr. İlker Kocabaş UBİ502 at
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Transactions. Chapter 14: Transactions Transaction Concept Transaction State Concurrent Executions Serializability Recoverability Implementation of Isolation.
Lecture 7- Transactions Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 15: Transactions.
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.
1 Transactions. 2 Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data items. E.g. transaction.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Chapter 15: Transactions
©Silberschatz, Korth and Sudarshan1 Transactions Transaction Concept ACID Properties Transaction State Concurrent Executions Serializability Recoverability.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Database Techniek Lecture 4: Transactions (Chapter 13/15)
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 15: Transactions.
Computing & Information Sciences Kansas State University Wednesday, 05 Nov 2008CIS 560: Database System Concepts Lecture 28 of 42 Wednesday, 05 November.
Chapter 14 Transactions Yonsei University 1 st Semester, 2015 Sanghyun Park.
Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity and Durability Concurrent Executions Serializability Recoverability.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 14: Transactions.
15.1 Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data items. E.g. transaction to transfer.
©Silberschatz, Korth and Sudarshan14.1Database System Concepts - 6 th Edition Chapter 14: Transactions Transaction Concept Transaction State Concurrent.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 15: Transactions.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 14: Transactions.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 14: Transactions.
Chapter 14: Transactions
Chapter 15: Transactions
Chapter 15: Transactions
Chapter 14: Transactions
Chapter 13: Transactions
Database Management System
Chapter 15: Transactions
Transactions.
Transactions.
Chapter 15: Transactions
Transactions.
Transactions Sylvia Huang CS 157B.
Chapter 14: Transactions
Chapter 15: Transactions
Chapter 14: Transactions
Module 17: Transactions.
Module 15: Transactions.
Chapter 15: Transactions
Chapter 14: Transactions
Chapter 15: Transactions
Chapter 15: Transactions
Chapter 14: Transactions
UNIT -IV Transaction.
Module 17: Transactions.
Module 17: Transactions.
Presentation transcript:

©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity and Durability Concurrent Executions Serializability Recoverability Implementation of Isolation Transaction Definition in SQL Testing for Serializability.

©Silberschatz, Korth and Sudarshan15.2Database System Concepts Transaction Concept Transaction  a collection of read/write operations to perform a logcial unit of work E.g., transaction to transfer $50 from account A to B: 1.read(A) 2.A := A – 50 3.write(A) 4.read(B) 5.B := B write(B) Consistency requirement – the sum of A and B shoule not change due to the execution of the transaction Atomicity requirement — if the transaction fails after step 3, the system should ensure that its updates are not reflected in the database.

©Silberschatz, Korth and Sudarshan15.3Database System Concepts ACID Properties Atomicity: Either all operations of the transaction are properly reflected in the database or none are. Consistency: Execution of a transaction in isolation preserves the consistency of the database. Isolation: Each transaction must be unaware of other concurrently executing transactions. Intermediate transaction results must be hidden from other concurrently executed transactions.  For every pair of transactions T i and T j, it appears to T i that either T j, finished execution before T i started, or T j started execution after T i finished. Durability: After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. To preserve integrity of data, the database system must ensure:

©Silberschatz, Korth and Sudarshan15.4Database System Concepts Example of Fund Transfer (Cont.) Durability requirement  Once the user has been notified that the transaction has completed (i.e., the transfer of the $50 has taken place), the updates to the database by the transaction must persist despite failures Isolation requirement  If another transaction is allowed to access the partially updated database between steps 3 and 6, it will see an inconsistent database  The sum A + B will be less than it should be  Trivial solution: Run transactions serially  Performance degradation

©Silberschatz, Korth and Sudarshan15.5Database System Concepts Transaction State

©Silberschatz, Korth and Sudarshan15.6Database System Concepts Implementation of Atomicity and Durability Assumes disks do not fail Extremely inefficient for large databases: executing a single transaction requires copying the entire database.  Logging & recovery (Chapter 17) Shadow-database scheme:

©Silberschatz, Korth and Sudarshan15.7Database System Concepts Concurrent Executions Advantages of concurrent executions  Higher throughput  One transaction does I/O, another uses CPU  Reduced average response time  Short transactions do not have to wait long ones Concurrency control schemes  Achieve isolation  Control the interaction among the concurrent transactions in order to prevent them from destroying the consistency of the database  Serializability: concurrent execution is equal to some serial execution

©Silberschatz, Korth and Sudarshan15.8Database System Concepts Example (Serial) Schedules Let T 1 transfer $50 from A to B, and T 2 transfer 10% of the balance from A to B.

©Silberschatz, Korth and Sudarshan15.9Database System Concepts Example Schedule (Cont.) Not a serial schedule, but equivalent to the serial schedule In both Schedule 1 and 3, the sum A + B is preserved.

©Silberschatz, Korth and Sudarshan15.10Database System Concepts Example Schedules (Cont.) The following concurrent schedule does not preserve the value of the the sum A + B.

©Silberschatz, Korth and Sudarshan15.11Database System ConceptsSerializability Basic Assumption  Each transaction preserves database consistency.  Serial execution preserves consistency A schedule is serializable if it is equivalent to a serial schedule. 1.conflict serializability 2.view serializability Consider read write operations only

©Silberschatz, Korth and Sudarshan15.12Database System Concepts Conflict Serializability Instructions l i and l j of transactions T i and T j respectively, conflict if and only if both l i and l j access some data item Q, and at least one of them is write(Q). 1. l i = read(Q), l j = read(Q): No conflict. 2. l i = read(Q), l j = write(Q): Conflict. 3. l i = write(Q), l j = read(Q): Conflict 4. l i = write(Q), l j = write(Q): Conflict If a schedule S can be transformed into a schedule S´ by swapping of non-conflicting instructions, S and S´ are conflict equivalent. A schedule S is conflict serializable if it is conflict equivalent to a serial schedule.

©Silberschatz, Korth and Sudarshan15.13Database System Concepts Conflict Serializability (Cont.) Not conflict serializable T 3 T 4 read(Q) write(Q) write(Q) Can not swap instructions to obtain either the serial schedule, or the serial schedule.

©Silberschatz, Korth and Sudarshan15.14Database System Concepts Conflict Serializability (Cont.) Conflict serializable to a serial schedule  Swap non-conflicting instructions

©Silberschatz, Korth and Sudarshan15.15Database System Concepts View Serializability Let S and S´ be two schedules with the same set of transactions. S and S´ are view equivalent if: 1.For each data item Q, if transaction T i reads the initial value of Q in schedule S, then transaction T i must, in schedule S´, also read the initial value of Q. 2.For each data item Q if transaction T i executes read(Q) in schedule S, and that value was produced by transaction T j (if any), then transaction T i must in schedule S´ also read the value of Q that was produced by transaction T j. 3.For each data item Q, the transaction (if any) that performs the final write(Q) operation in schedule S must perform the final write(Q) operation in schedule S´.

©Silberschatz, Korth and Sudarshan15.16Database System Concepts View Serializability (Cont.) A schedule S is view serializable if it is view equivalent to a serial schedule. Every conflict serializable schedule is also view serializable A schedule which is view-serializable but not conflict serializable:  Every view serializable schedule, which is not conflict serializable, has blind writes More concurrency than conflict serializability, howerver, NP- complete

©Silberschatz, Korth and Sudarshan15.17Database System Concepts Other Notions of Serializability Schedule 8 (from text) given below produces same outcome as the serial schedule, yet is not conflict equivalent or view equivalent to it. Determining such equivalence requires analysis of operations other than read and write.

©Silberschatz, Korth and Sudarshan15.18Database System ConceptsRecoverability Recoverable schedule: if T k reads a data item previously written by T j,T j should commit before T k commits. The following schedule is not recoverable if T 9 commits immediately after the read If T 8 should abort, T 9 would have read (and possibly shown to the user) an inconsistent database state. Hence database must ensure that schedules are recoverable. Need to address the effect of transaction failures on concurrently running transactions.

©Silberschatz, Korth and Sudarshan15.19Database System Concepts Recoverability (Cont.) Cascading rollback  A single transaction failure leads to a series of transaction rollbacks  Assume no transaction has committed (so the schedule is recoverable)  If T 10 fails, T 11 and T 12 must also be rolled back. Possibly undo a significant amount of work

©Silberschatz, Korth and Sudarshan15.20Database System Concepts Recoverability (Cont.) Cascadeless schedules  Cascading rollbacks cannot occur; for each pair of transactions T j and T k such that T k reads a data item previously written by T j, the commit operation of T j appears before the read operation of T k. Every cascadeless schedule is also recoverable  Stricter than recoverable schedules  Avoid cascading aborts

©Silberschatz, Korth and Sudarshan15.21Database System Concepts Implementation of Isolation Objective:  Schedules must be conflict or view serializable, and recoverable for consistency  Preferably cascadeless Supported by concurrency control

©Silberschatz, Korth and Sudarshan15.22Database System Concepts Testing for Serializability Consider some schedule of a set of transactions T 1, T 2,..., T n Precedence graph  Draw an arc from T i to T j if the two transaction conflict, and T i accessed the data item on which the conflict arose earlier. Example 1

©Silberschatz, Korth and Sudarshan15.23Database System Concepts Example Schedule (Schedule A) T 1 T 2 T 3 T 4 T 5 read(X) read(Y) read(Z) read(V) read(W) read(W) read(Y) write(Y) write(Z) read(U) read(Y) write(Y) read(Z) write(Z) read(U) write(U)

©Silberschatz, Korth and Sudarshan15.24Database System Concepts Precedence Graph for Schedule A T3T3 T4T4 T1T1 T2T2

©Silberschatz, Korth and Sudarshan15.25Database System Concepts Test for Conflict Serializability A schedule is conflict serializable iff its precedence graph is acyclic. Cycle-detection algorithms O(n 2 ) where n is the number of vertices in the graph. If precedence graph is acyclic, the serializability order can be obtained by a topological sorting of the graph. For example, a serializability order for Schedule A would be T 5  T 1  T 3  T 2  T 4.

©Silberschatz, Korth and Sudarshan15.26Database System Concepts Test for View Serializability The precedence graph test for conflict serializability must be modified to apply to a test for view serializability. The problem of checking if a schedule is view serializable falls in the class of NP-complete problems. Thus existence of an efficient algorithm is unlikely. However practical algorithms that just check some sufficient conditions for view serializability can still be used.

©Silberschatz, Korth and Sudarshan15.27Database System Concepts Concurrency Control vs. Serializability Tests Too late to test the serializability after a schedule has been executed Develop concurrency control protocols that will assure serializability  Do not examine the precedence graph; instead  Impose disciplines that avoids nonseralizable schedules  Serializability test help understand why a concurrency control protocol is correct.

End of Chapter