MULTIUSER DATABASES : Concurrency and Transaction Management.

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.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
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 Overview and Concurrency Control Chapters 16 & 17.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
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.
CS194-3/CS16x Introduction to Systems Lecture 8 Database concurrency control, Serializability, conflict serializability, 2PL and strict 2PL September.
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
1 IT420: Database Management and Organization Transactions 31 March 2006 Adina Crăiniceanu
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 Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
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.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
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.
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.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
H.Lu/HKUST L06: Concurrency Control & Locking. L06: Concurrency Control & Locking - 2 H.Lu/HKUST Transactions  Concurrent execution of user programs.
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.
Transaction Management Overview
Database Systems (資料庫系統)
Transaction Management Overview
Transaction Management
MULTIUSER DATABASES : Concurrency and 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
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:

MULTIUSER DATABASES : Concurrency and Transaction Management

Banking Application Entities in a banking application: Customers Employees Accounts In an operational bank database, customers use the ATMs, internet, and phones to interact with their accounts This is a multiuser database since many customers may be connected to the bank database and doing money transfers, checking their balance etc.

Banking Application Consider that Alice is transferring 100 TL from his account to Bob’s account. The following operations take place: Read the amount of money in the account of Alice(a) a := a – 100 Read the amount of money in Bob’s account (r) r = r At the same time, the bank calculates the total amount of money stored in the accounts Read amount of money in the accounts one by one Add the amounts to the sum.

Banking Application 400 TL100 TL Alice Bob

Banking Application 300 TL100 TL Alice Bob 100 YTL

Banking Application 300 TL 200 TL Alice Bob

Banking Application 300 TL 200 TL Alice Bob 0 Sum

Banking Application 300 TL 200 TL Alice Bob 300 Sum := sum + 300

Banking Application 300 TL 200 TL Alice Bob 500 Sum := sum + 200

Banking Application 300 TL 200 TL Alice Bob Things are fine if I finish the money transfer and then calculate the sum. But consider the following case

Banking Application 300 TL 100 TL Alice Bob 0 sum 100 TL

Banking Application 300 TL 100 TL Alice Bob 300 Sum := sum + 300

Banking Application 300 TL 100 TL Alice Bob 400 Sum := sum + 100

Banking Application 300 TL 200 TL Alice Bob 400 sum 100TL

Concurrency Interleaving the execution of the operations such as the money transfer and account sum. Concurrency is needed for performance reasons (ex: using the CPU when somebody else is accessing the disk) Database user4user1user3user2

Concurrency A users program may be doing many different operations but from a database point of view, only R/W operations are of interest. A transaction is the DBMS’s abstract view of a user program: a sequence of reads and writes. Ex: Transaction1: Read(Account1), Read(Account2), Write(Account1)

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. DB Transaction1 DB ’

Concurrency in a DBMS 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). Main Issues: Effect of interleaving transactions, and crashes.

ACID Properties of transactions Atomicity Consistency Isolation Durability

Atomicity requires that each transaction be "all or nothing": if one part of the transaction fails, the entire transaction fails, and the database state is left unchanged. Atomicity The consistency property ensures that any transaction will bring the database from one valid state to another. Obey constraints.consistency The isolation property ensures that the concurrent execution of transactions results in a system state that would be obtained if transactions were executed seriallyisolation The durability property ensures that once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors.durability

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. Transaction Begin Transaction Commit Transaction Abort Transaction Begin

Atomicity of Transactions A very important property guaranteed by the DBMS for all transactions is that they are atomic. That is, a user can think of a transaction 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. Transaction Abort Transaction Begin rollback LOG head

Example Consider two transactions T1:BEGIN A=A+100, B=B-100 END T2:BEGIN A=1.06*A, B=1.06*B END v 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. v 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.

Example (Contd.) Consider a possible interleaving (schedule): T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B v This is OK. But what about: T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B v 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)

Scheduling Transactions Serial schedule: Schedule that does not interleave the actions of different transactions. T1 T2 T1: A=A+100, B=B-100 T2: A=1.06*A,B=1.06*B

Scheduling Transactions Equivalent schedules: Schedules involving the same set of operations on the same data objects T1: R(A), W(A), R(B), W(B) T2: R(A), W(A) Schedule 1 T1: R(A), W(A), R(B), W(B) T2: R(A), W(A) Schedule 2

Scheduling Transactions Equivalent schedules: Schedules with the same set of operations on the same data objects And, 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. DB Schedule 1 Schedule 2 DB’ DB’’ DB’ = DB’’

Scheduling Transactions Serializable schedule: A schedule that is equivalent to some serial execution of the transactions. T1: R(A), W(A), R(B), W(B) T2: R(A), W(A) Schedule 1 T1: R(A), W(A), R(B), W(B) T2: R(A), W(A) T1: R(A), W(A), R(B), W(B) T2: R(A), W(A) Serial Schedule A Serial Schedule B Question: Is schedule 1 Equivalent to serial schedule A or B?

Scheduling Transactions If each transaction preserves consistency, every serializable schedule preserves consistency!

Anomalies with Interleaved Execution Reading Uncommitted Data (WR Conflicts, “dirty reads”): What happens when T1 aborts? T1: R(A), W(A), R(B), W(B), Abort T2:R(A), W(A), C

Anomalies with Interleaved Execution Unrepeatable Reads (RW Conflicts): T1:R(A), R(A), W(A), C T2:R(A), W(A), C

Anomalies (Continued) Overwriting Uncommitted Data (WW Conflicts): T1:W(A), W(B), C T2:W(A), W(B), C

Role of a concurrency control in a database system. Databases and Transaction Processing (Lewis, Bernstein, Kifer)

Lock-Based Concurrency Control Each transaction must obtain a S (shared) lock on object before reading, and an X (exclusive) lock on object before writing. An S or X lock is released when the corresponding object is no longer needed. Ex: T1: S(A), R(A), Release_S(A), X(B), W(B), Release_X(B) …

Lock-Based Concurrency Control X conflicts with X and S No transaction can obtain an X lock on an object if some other transaction has an X or S lock on that object. No transaction can obtain an S lock on an object if some other transaction has an X lock on that object S locks do not conflict with each other Multiple transactions may obtain an S lock on the same object

Lock-Based Concurrency Control Strict Two-phase Locking (Strict 2PL) Protocol: Each transaction 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 a transaction holds an X lock on an object, no other transaction can get a lock (S or X) on that object. Strict 2PL allows only serializable schedules.

Aborting a Transaction If a transaction Ti is aborted, all its actions have to be undone. if Tj reads an object last written by Ti, Tj must be aborted as well! (called cascading aborts ) T1: R(A), W(A), R(B), Abort T2:R(A),Abort

Aborting a Transaction Most systems avoid cascading aborts 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. Log is also used to recover from system crashes: all active transactions at the time of the crash are aborted when the system comes back up.

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 transaction id, so it’s easy to undo a specific transaction. Log is 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.