Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity."— Presentation transcript:

1 ©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.

2 ©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 + 50 6.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.

3 ©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:

4 ©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

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

6 ©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:

7 ©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

8 ©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.

9 ©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.

10 ©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.

11 ©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

12 ©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.

13 ©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.

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

15 ©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´.

16 ©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

17 ©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.

18 ©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.

19 ©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

20 ©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

21 ©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

22 ©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

23 ©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)

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

25 ©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.

26 ©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.

27 ©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.

28 End of Chapter


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

Similar presentations


Ads by Google