<<

CSL 451 Introduction to Systems

partially commied commied

active

failed aborted Transactions

Department of Science and Engineering Indian Institute of Technology Ropar

Narayanan (CK) Chatapuram Krishnan! Summary • Transaction • Testing for Serializability – Atomicity – Consistency – Precedence graph – Isolation • acyclic – Durability – topological sorting • Transaction states – active, partially committed, failed, committed, aborted • Concurrent executions – why? • Schedules – serial – serializable • Serializability – conflict • conflict equivalent • conflict serializable Department of Computer Science and Engineering ! 17/04/15! 2! Indian Institute of Technology Ropar! Testing for Serializability

■ Consider some schedule of a set of transactions T1, T2, ..., Tn ■ Precedence graph — a directed graph where the vertices are the transactions (names).

■ We draw an arc from Ti to Tj if the two transaction conflict, and Ti accessed the data item on which the conflict arose earlier. ■ We may label the arc by the item that was accessed. ■ Example 1

T1 T2

Database System Concepts - 6th Edition 14.3 ©Silberschatz, Korth and Sudarshan Test for Conflict Serializability

■ A schedule is conflict serializable if and only Ti if its precedence graph is acyclic.

■ Cycle-detection algorithms exist which take Tj Tk order n2 time, where n is the number of vertices in the graph. Tm ● (Better algorithms take order n + e where e is the number of edges.) (a) ■ If precedence graph is acyclic, the serializability order can be obtained by a Ti Ti topological sorting of the graph.

T ● This is a linear order consistent with the j Tk partial order of the graph. ● For example, a serializability order for Tk Tj Schedule A would be

T5 → T1 → T3 → T2 → T4 Tm Tm

(b) (c)

Database System Concepts - 6th Edition 14.4 ©Silberschatz, Korth and Sudarshan Summary

• Transaction • Testing for Serializability – Atomicity – Precedence graph • acyclic – Consistency – topological sorting – Isolation • Transaction Isolation and – Durability Atomicity • Transaction states – Partial schedule – active, partially committed, failed, – Recoverable Schedules committed, aborted – Cascadeless Schedules • cascading rollback • Concurrent executions • Transaction Isolation levels – why? – Serializable • Schedules – Repeatable read – serial – Read committed – Read uncommitted – serializable • policies • Serializability – locking – conflict – • conflict equivalent • conflict serializable Department of Computer Science and Engineering ! 17/04/15! 5! Indian Institute of Technology Ropar! 14.1 Suppose that there is a database system that never fails. Is a recovery manager required for this system?

Department of Computer Science and Engineering ! 17/04/15! 6! Indian Institute of Technology Ropar! 14.4 Justify the following statement: Concurrent execution of transactions is more important when data must be fetched from (slow) disk or when transactions are long, and is less important when data are in memory and transactions are very short.

Department of Computer Science and Engineering ! 17/04/15! 7! Indian Institute of Technology Ropar! 14.14 Explain the distinction between the terms serial schedule and serializable schedule.

Department of Computer Science and Engineering ! 17/04/15! 8! Indian Institute of Technology Ropar! 14.15 Consider the following two transactions:

T13: read(A); read(B); if A=0 then B:=B+1; write(B);

T14: read(B); read(A); if B:=0 then A:=A+1; write(A); Let the consistency requirement be A=0 V B=0, with A=B=0 the initial values a. Show that every serial execution involving these two transactions preserves the consistency of the database.

Department of Computer Science and Engineering ! 17/04/15! 9! Indian Institute of Technology Ropar! 14.15 Consider the following two transactions:

T13: read(A); read(B); if A=0 then B:=B+1; write(B);

T14: read(B); read(A); if B:=0 then A:=A+1; write(A); Let the consistency requirement be A=0 V B=0, with A=B=0 the initial values b. Show a concurrent execution of the transactions that produces a nonserializable schedule.

Department of Computer Science and Engineering ! 17/04/15! 10! Indian Institute of Technology Ropar! 14.15 Consider the following two transactions:

T13: read(A); read(B); if A=0 then B:=B+1; write(B);

T14: read(B); read(A); if B:=0 then A:=A+1; write(A); Let the consistency requirement be A=0 V B=0, with A=B=0 the initial values c. Is there a concurrent execution of the transactions that produces a serializable schedule?

Department of Computer Science and Engineering ! 17/04/15! 11! Indian Institute of Technology Ropar! 14.16 Give an example of a serializable schedule with two transactions such that the order in which the transactions commit is different from the serialization order.

Department of Computer Science and Engineering ! 17/04/15! 12! Indian Institute of Technology Ropar! 14.6 Consider the precedence graph. Is the corresponding schedule conflict serializable?

Department of Computer Science and Engineering ! 17/04/15! 13! Indian Institute of Technology Ropar! 14.20 Give an example of a schedule that respects the specified level of isolation, but is not serializable. a. Read uncommitted

Department of Computer Science and Engineering ! 17/04/15! 14! Indian Institute of Technology Ropar! 14.17 What is a recoverable schedule? Why is recoverability of schedules desirable? Are there any circumstances under which it would be desirable to allow nonrecoverable schedules?

Department of Computer Science and Engineering ! 17/04/15! 15! Indian Institute of Technology Ropar! 14.8 The lost update anomaly is said to occur if a transaction Tj reads a data item, then another transaction Tk writes the data item. The update performed by Tk had been lost, since the update done by Tj ignored the value written by Tk. a. Give an example of a schedule showing the lost update anomaly.

Department of Computer Science and Engineering ! 17/04/15! 16! Indian Institute of Technology Ropar! 14.8 The lost update anomaly is said to occur if a transaction Tj reads a data item, then another transactions Tk writes the data item. The update performed by Tk had been lost, since the update done by Tj ignored the value written by Tk. c. Explain why the lost update anomaly is not possible with the repeatable read isolation level.

Department of Computer Science and Engineering ! 17/04/15! 17! Indian Institute of Technology Ropar! 14.9 Consider a database for a bank where the database system uses snapshot isolation. Describe a particular scenario in which a nonserializable execution occurs that would present a problem for the bank.

Department of Computer Science and Engineering ! 17/04/15! 18! Indian Institute of Technology Ropar!