1 Transaction Management Overview Chapter 16. 2 Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
1 Part V: Transactions, Concurrency control, Scheduling, and Recovery.
Topic 6.3: Transactions and Concurrency Control Hari Uday.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. –Because disk accesses are.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
1 Concurrency Control and Recovery Module 6, Lecture 1.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
1 Transaction Management Overview Yanlei Diao UMass Amherst March 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Transaction Management
1 Lecture 08: Transaction management overview
Transaction Management and Concurre cy Overview R & G Chapter There are three side effects of acid. Enhanced long term memory, decreased short term.
Transaction Processing
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
MULTIUSER DATABASES : Concurrency and Transaction Management.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Transaction Management Overview Chapter Transactions  A transaction is the DBMS’s abstract view of a user program: a sequence of reads and writes.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
CS 162 Discussion Section Week 9 11/11 – 11/15. Today’s Section ●Project discussion (5 min) ●Quiz (10 min) ●Lecture Review (20 min) ●Worksheet and Discussion.
Concurrency Control R &G - Chapter 19. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Transaction Processing Chapter Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Instructor: Xintao Wu.
Introduction to Database Systems1. 2 Basic Definitions Mini-world Some part of the real world about which data is stored in a database. Data Known facts.
ICS 321 Fall 2011 The Database Language SQL (iv) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 10/26/20111Lipyeow.
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Overview of Transaction Management
Transaction Management and Recovery, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
1 Database Systems ( 資料庫系統 ) December 27/28, 2006 Lecture 13 Merry Christmas & New Year.
H.Lu/HKUST L06: Concurrency Control & Locking. L06: Concurrency Control & Locking - 2 H.Lu/HKUST Transactions  Concurrent execution of user programs.
Database Applications (15-415) DBMS Internals- Part XI Lecture 22, April 10, 2016 Mohammad Hammoud.
MULTIUSER DATABASES : Concurrency and Transaction Management.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Database Systems ( 資料庫系統 ) December 20, 2004 Chapter 16 By Hao-hua Chu ( 朱浩華 )
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
Part V: Transactions, Concurrency control, Scheduling, and Recovery
Database Systems (資料庫系統)
Transaction Management Overview
Database Systems (資料庫系統)
Transaction Management Overview
Transaction Management
Transaction Management Overview
CS122B: Projects in Databases and Web Applications Winter 2018
Transaction Management Overview
Transaction Management Overview
Transaction Management Overview
Transaction Management
Transaction Management Overview
Chapter 10 Transaction Management and Concurrency Control
Lecture 21: Concurrency & Locking
Lecture 21: Intro to Transactions & Logging III
Transaction Management
Database Management systems Subject Code: 10CS54 Prepared By:
Transaction Management Overview
Transaction Management Overview
CS122B: Projects in Databases and Web Applications Winter 2019
CS122B: Projects in Databases and Web Applications Spring 2018
Transaction Management Overview
Presentation transcript:

1 Transaction Management Overview Chapter 16

2 Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because disk accesses are frequent, and relatively slow, it is important to keep the cpu humming by working on several user programs concurrently.  A user’s program may carry out many operations on the data retrieved from the database, but the DBMS is only concerned about what data is read/written from/to the database.  A transaction is the DBMS’s abstract view of a user program: a sequence of reads and writes.

3 Concurrency in a DBMS  Users submit transactions, and can think of each transaction as executing by itself.  Concurrency is achieved by the DBMS, which interleaves actions (reads/writes of DB objects) of various transactions.  Each transaction must leave the database in a consistent state if the DB is consistent when the transaction begins. DBMS will enforce some ICs, depending on the ICs declared in CREATE TABLE statements. Beyond this, the DBMS does not really understand the semantics of the data. (e.g., it does not understand how the interest on a bank account is computed).  Issues: Effect of interleaving transactions, and crashes.

4 Atomicity of Transactions  A transaction might commit after completing all its actions, or it could abort (or be aborted by the DBMS) after executing some actions.  A very important property guaranteed by the DBMS for all transactions is that they are atomic. That is, a user can think of a Xact as always executing all its actions in one step, or not executing any actions at all.  DBMS logs all actions so that it can undo the actions of aborted transactions.

5 Example  Consider two transactions ( Xacts ): T1:BEGIN A=A+100, B=B-100 END T2:BEGIN A=1.06*A, B=1.06*B END  Intuitively, the first transaction is transferring $100 from B’s account to A’s account. The second is crediting both accounts with a 6% interest payment.  There is no guarantee that T1 will execute before T2 or vice-versa, if both are submitted together. However, the net effect must be equivalent to these two transactions running serially in some order.

6 Example (Contd.)  Consider a possible interleaving ( schedule ): T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B  This is OK. But what about: T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B  The DBMS’s view of the second schedule: T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B)

7 Transactions: ACID Properties  Atomicity. Transactions can never “partly commit”; their updates are applied “all or nothing”.  Logging, undo the actions of incomplete transactions  Consistency. Each transaction T transitions the dataset from one semantically consistent state to another.  Responsibility of user, w.r.t application’s consistency criterion  Isolation. All updates by T1 are either entirely visible to T2, or are not visible at all. Ch 17  no see/access to intermediate data of other transactions  locking or timestamp-based concurrency control  May interleave, net effect is identical to a series of transactions  Durability. Updates made by T persist once T commits.  Logging, writing updates to stable storage  Atomicity and Durability: recovery manager, Ch 18

8 Scheduling Transactions  Schedule: a list of actions (read, write, abort, commit) from a set of transactions  Serial schedule: Schedule that does not interleave the actions of different transactions.  Equivalent schedules : For any database state, the effect (on the set of objects in the database) of executing the first schedule is identical to the effect of executing the second schedule.  Serializable schedule : A schedule that is equivalent to some serial execution of the transactions.  If each transaction preserves consistency, every serializable schedule preserves consistency

9 Anomalies with Interleaved Execution  Reading Uncommitted Data (WR Conflicts, “dirty reads”): T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B

10 Anomalies with Interleaved Execution  Unrepeatable Reads (RW Conflicts):  A is number of copies of book, T1 and T2 both want to place an order on the book T1:R(A), R(A), W(A), C T2:R(A), W(A), C

11 Anomalies (Continued)  Overwriting Uncommitted Data (WW Conflicts):  Two employees salaries must be equal, T1 set to 2000, T2 set to 1000 T1:W(A), W(B), C T2:W(A), W(B), C

12 Note on conflicts  WR, RW, WW  Presence of conflicts <> unserializable schedule  CC uses locking and other mechanisms to “sort the conflicts” nicely, so that the net effect is equivalent to same serial schedule

13 Note on serializable schedule  A serializable schedule over a set S of transactions is a schedule whose effect on any consistent database instance is guaranteed to be identical to that of some complete serial schedule over the set of committed transactions in S.  The definition of serializability relies on the actions of aborted transactions being undone completely, which may be impossible in some situations

14 Aborting a Transaction  If a transaction Ti is aborted, all its actions have to be undone. Not only that, if Tj reads an object last written by Ti, Tj must be aborted as well!  In a recoverable schedule, transactions commit only after all transactions whose changes they read commit  The above example, unrecoverable T1: R(A), W(A), Abort T2: R(A), W(A), R(B), W(B), Commit T1: R(A), W(A), Commit T2: R(A), W(A), R(B), W(B), Commit

15 Aborting a Transaction  If transactions read only the changes of committed transactions, not only is the schedule recoverable, but also aborting a transaction can be accomplished without cascading the abort to other transactions. Such a schedule is said to avoid cascading aborts (ACA)  by releasing a transaction’s locks only at commit time.  If Ti writes an object, Tj can read this only after Ti commits.  In order to undo the actions of an aborted transaction, the DBMS maintains a log in which every write is recorded. This mechanism is also used to recover from system crashes: all active Xacts at the time of the crash are aborted when the system comes back up. T1: R(A), W(A) Commit T2: R(A), W(A), R(B), W(B)

16 Lock-Based Concurrency Control  Strict Two-phase Locking (Strict 2PL) Protocol :  Most widely used local protocol  Each Xact must obtain a S ( shared ) lock on object before reading, and an X ( exclusive ) lock on object before writing.  All locks held by a transaction are released when the transaction completes  If an Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object.  If an Xact holds a lock (S or X) on an object, no other Xact can get an X lock on that object.  Strict 2PL allows only serializable schedules.

17 Strict 2PL Example  Not allowed, forced to be executed as follows:  a serial execution of two transactions, in this example T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B T1: X(A)R(A)W(A)X(B)R(B) W(B)Commit T2: X(A)R(A)W(A)X(B)R(B)W(B)

18 Issues in locking  Deadlock  Must prevent or detect (and resolve)  More details in ch 17  Performance

19 The Log  The following actions are recorded in the log:  Ti writes an object : the old value and the new value. Log record must go to disk before the changed page!  Ti commits/aborts : a log record indicating this action.  Log records are chained together by Xact id, so it’s easy to undo a specific Xact.  Log is often duplexed and archived on stable storage.  All log related activities (and in fact, all CC related activities such as lock/unlock, dealing with deadlocks etc.) are handled transparently by the DBMS.

20 Recovering From a Crash  There are 3 phases in the Aries recovery algorithm:  Analysis : Scan the log forward (from the most recent checkpoint ) to identify all Xacts that were active, and all dirty pages in the buffer pool at the time of the crash.  Redo : Redoes all updates to dirty pages in the buffer pool, as needed, to ensure that all logged updates are in fact carried out and written to disk.  Undo : The writes of all Xacts that were active at the crash are undone (by restoring the before value of the update, which is in the log record for the update), working backwards in the log. (Some care must be taken to handle the case of a crash occurring during the recovery process!)

21 Summary  Concurrency control and recovery are among the most important functions provided by a DBMS.  Users need not worry about concurrency.  System automatically inserts lock/unlock requests and schedules actions of different Xacts in such a way as to ensure that the resulting execution is equivalent to executing the Xacts one after the other in some order.  Write-ahead logging (WAL) is used to undo the actions of aborted transactions and to restore the system to a consistent state after a crash.  Consistent state : Only the effects of commited Xacts seen.