Dr Alwyn Barry Dr Joanna Bryson

Slides:



Advertisements
Similar presentations
CM20145 Transactions & Serializability
Advertisements

Chapter 14: Transactions
1 Integrity Ioan Despi Transactions: transaction concept, transaction state implementation of atomicity and durability concurrent executions serializability,
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.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Transactions.
Transaction Management WXES 2103 Database. Content What is transaction Transaction properties Transaction management with SQL Transaction log DBMS Transaction.
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
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.
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
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.
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.
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.
Software System Lab. Transactions Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various.
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 14: Transactions
Chapter 13: Transactions
Database Management System
Part- A Transaction Management
Transactions.
Transactions.
Chapter 15: Transactions
Transactions.
Transactions Sylvia Huang CS 157B.
Chapter 14: Transactions
Chapter 15: Transactions
Chapter 14: Transactions
Module 15: Transactions.
Chapter 15: Transactions
Chapter 14: Transactions
Chapter 15: Transactions
Chapter 15: Transactions
Chapter 14: Transactions
UNIT -IV Transaction.
Presentation transcript:

Dr Alwyn Barry Dr Joanna Bryson CM20145 Transactions

Lecture Plan Basic Concepts Data, Information & Knowledge Data Models (The E-R Model) The Relational Algebra Introduction to SQL Further SQL (Joins, RA Equivalences) Database Design Further DB Design – Normalisation Architectures and Implementations Integrity and Security

Lecture Plan Ethics and Professional Conduct Legal Issues Transactions Recovery Concurrency Control Storage and File Structure Indexing and Hashing Query Processing & Optimisation January… Review, Object Relational Bridges?

A While Ago… Now: Transactions, Concurrency & Recovery Architectures and Implementations Introductions to Transactions & Storage Architecture concerns: Speed, Cost, Reliability, Maintainability. Architectural Types: Centralized, Client/Server, Parallel, Distributed Integrity and Security Domain Constraints Referential Integrity Foreign Keys, Cascading Actions Assertions Triggers Authorization Grant, Revoke, Roles, Audit Trails Now: Transactions, Concurrency & Recovery

Overview Transaction Concepts Schedules Serializability ACID Possible States Schedules Serializability Conflict View Others Testing for Serializability Precedence Graphs Concurrency & Recovery

Introduction to Transactions A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction starts with a consistent database. During transaction execution the database may be inconsistent. When the transaction is committed, the database must be consistent. Two main issues to deal with: Failures, e.g. hardware failures and system crashes. Concurrency, for simultaneous execution of multiple transactions. ©Silberschatz, Korth and Sudarshan Modifications & additions by S Bird, J Bryson

To preserve integrity of data, the database system must ensure: The ACID Test To preserve integrity of data, the database system must ensure: 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: Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions; intermediate transaction results must be hidden from other concurrently executed transactions. Durability: After a transaction completes successfully, the changes it has made to the database persist, even if the system fails.

Example: A Fund Transfer 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) Durability: once the user notified that the transaction complete, the updates to the database by the transaction must persist despite failures. Isolation: between steps 3-6, no other transaction should access the partially updated database, or it would see an inconsistent state (A + B will be less than it should be). Consistency: the sum of A and B is unchanged by the execution of the transaction. Atomicity: if the transaction fails after step 3 and before step 6, the system must ensure that no updates are reflected in the database, else an inconsistency will result.

Transaction States Active, the initial state; the transaction stays in this state while it is executing Partially committed, after the final statement has been executed. Committed, after successful completion. Failed, after the discovery that normal execution can no longer proceed. Aborted, after the transaction has been rolled back and the database restored to its state prior to the start of the transaction.

Transaction Definition in SQL Data manipulation languages must include a construct for specifying the set of actions that comprise a transaction. In SQL, a transaction begins implicitly. A transaction can be explicitly ended by: Commit work: commits current transaction and begins a new one. Rollback work: causes current transaction to abort.

Overview Transaction Concepts Schedules Serializability ACID Possible States Schedules Serializability Conflict View Others Testing for Serializability Precedence Graphs Concurrency & Recovery

Schedules & Concurrency Advantages to Concurrent execution (executing transactions simultaneously): Increased processor and disk utilization; better throughput. One transaction uses CPU while another uses disk. Reduced average response time: short transactions need not wait behind long ones. Concurrency control schemes: Mechanisms to achieve isolation. Control concurrent transactions’ interaction in order to prevent them from destroying database consistency. Schedules: Sequences that indicate the chronological order in which instructions of concurrent transactions are executed. A schedule for a set of transactions must consist of all instructions of those transactions. Must preserve the order in which the instructions appear in each individual transaction.

Example: Serial Schedule Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. This is a serial schedule, in which T1 is followed by T2.

Example: Concurrent Schedule Let T1 and T2 be the transactions defined previously. This schedule is not a serial schedule, but it is equivalent to the previous schedule. In both this and the sequential schedule, the sum A + B is preserved.

Concurrency Gone Bad This concurrent schedule does not preserve the value of A + B.

Overview Transaction Concepts Schedules Serializability ACID Possible States Schedules Serializability Conflict View Others Testing for Serializability Precedence Graphs Concurrency & Recovery

Serializability Basic Assumption: Each transaction, on its own, preserves database consistency. That is, serial execution of transactions preserves database consistency. A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule. Different forms of equivalence lead to different kinds of serializability: conflict and view. Serialization makes recovery easier, but can slow down throughput.

Conflict Serializability Instructions li and lj of transactions Ti and Tj respectively, conflict iff there exists some item Q accessed by both li and lj, and at least one of these instructions wrote Q. 1. li = read(Q), lj = read(Q). li and lj don’t conflict. 2. li = read(Q), lj = write(Q). They conflict. 3. li = write(Q), lj = read(Q). They conflict 4. li = write(Q), lj = write(Q). They conflict Intuitively, a conflict between li and lj forces a (logical) temporal order between them. If li and lj are consecutive in a schedule and they do not conflict, their results would remain the same even if they had been interchanged in the ordering.

Conflict Serializability (2) If a schedule S can be transformed into a schedule S´ by a series of swaps of non-conflicting instructions, we say that S and S´ are conflict equivalent. We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule. Example of a schedule that is not conflict serializable: T3 T4 read(Q) write(Q) write(Q) We are unable to swap instructions in the above schedule to obtain either the serial schedule < T3, T4 >, or the serial schedule < T4, T3 >.

Conflict Serializability (3) The first example concurrent schedule can be transformed into the serial one (where T2 followed T1) by a series of swaps of non-conflicting instructions. Therefore our concurrent schedule is conflict serializable.

View Serializability Let S and S´ be two schedules with the same set of transactions. S and S´ are view equivalent if the following three conditions are met, where Q is a data item and Ti is a transaction: If Ti reads the initial value of Q in schedule S, then Ti in schedule S´ must also read the initial value of Q. If Ti executes read(Q) in schedule S, and that value was produced by transaction Tj (if any), then transaction Ti must in schedule S´ also read the value of Q that was produced by transaction Tj The transaction (if any) that performs the final write(Q) operation in schedule S (for any data item Q) must perform the final write(Q) operation in schedule S´ NB. View equivalence is also based purely on reads and writes

View Serializability (2) A schedule S is view serializable if it is view equivalent to a serial schedule. Every conflict serializable schedule is also view serializable. Some schedules are view-serializable but not conflict serializable (see below). Every view serializable schedule that is not conflict serializable has blind writes.

Other Notions of Serializability This schedule produces the same outcome as the serial schedule < T1, T5 > However it is not conflict equivalent or view equivalent to it. Determining such equivalence requires analysis of operations other than read and write. This is hard (computationally).

Overview Transaction Concepts Schedules Serializability ACID Possible States Schedules Serializability Conflict View Others Testing for Serializability Precedence Graphs Concurrency & Recovery

Testing for Serializability Consider some schedule of a set of transactions T1, T2, ..., Tn Precedence graph: a directed graph where the vertices are transaction names. We draw an arc from Ti to Tj if the two transactions conflict, and Ti accessed the data item before Tj We may label the arc by the item that was accessed. Example: x y

Schedule & Precedence Graph T1 T2 T3 T4 T5 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) T3 T4 T1 T2

Testing Conflict Serializability A schedule is conflict serializable if and only if its precedence graph is acyclic. Cycle-detection algorithms exist which take order n2 time, 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. This is a linear order consistent with the partial order of the graph. For example, a serializability order for this graph is: T1  T2  T4  T3  T5 Example of an acyclic precedence graph

Testing 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 is NP-complete. Thus existence of an efficient algorithm is unlikely. However practical algorithms that just check some sufficient conditions for view serializability can still be used.

Overview Transaction Concepts Schedules Serializability ACID Possible States Schedules Serializability Conflict View Others Testing for Serializability Precedence Graphs Concurrency & Recovery

Concurrency & Serializability Goal – to develop concurrency control protocols that will ensure serializability. These protocols will impose a discipline that avoids nonseralizable schedules. A common concurrency control protocol uses locks. While one transaction is accessing a data item, no other transaction can modify it. Require a transaction to lock the item before accessing it. Topic of Lecture 15!

Recoverability How do we address failures when we are running concurrent transactions? Recoverable schedule: if a transaction Tj reads a data item previously written by a transaction Ti , the commit operation of Ti appears before the commit operation of Tj This schedule is not recoverable if T9 commits immediately after the read. If T8 should abort, T9 would have read (and possibly shown to the user) an inconsistent database state. A Database must ensure that schedules are recoverable!

Summary Next: Recovery Transaction Concepts Schedules Serializability ACID Possible States Schedules Serializability Conflict View Others Testing for Serializability Precedence Graphs Concurrency & Recovery Next: Recovery

Reading & Exercises Reading Exercises: Silberschatz Ch: 15. Connolly & Begg 20.1 – 20.2.2 (very clear!) Exercises: Silberschatz 15.1, 15.5-9. Connolly & Begg 20.1-3, 20.18-19