Transaction Management and Concurrency Control. Chapter 16, 17

Similar documents
Transaction Management Overview. Transactions. Concurrency in a DBMS. Chapter 16

Transaction Management Overview

Concurrency Control & Recovery

Goal of Concurrency Control. Concurrency Control. Example. Solution 1. Solution 2. Solution 3

Database Management System

Intro to Transactions

Introduction to Data Management. Lecture #24 (Transactions)

Concurrency Control & Recovery

Overview of Transaction Management

Intro to Transaction Management

COURSE 1. Database Management Systems

Introduction to Data Management. Lecture #18 (Transactions)

Introduction TRANSACTIONS & CONCURRENCY CONTROL. Transactions. Concurrency

Overview. Introduction to Transaction Management ACID. Transactions

Transaction Management: Concurrency Control

Transaction Management: Introduction (Chap. 16)

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636)

Page 1. CS194-3/CS16x Introduction to Systems. Lecture 8. Database concurrency control, Serializability, conflict serializability, 2PL and strict 2PL

Slides Courtesy of R. Ramakrishnan and J. Gehrke 2. v Concurrent execution of queries for improved performance.

Concurrency Control. Chapter 17. Comp 521 Files and Databases Fall

Concurrency Control. Chapter 17. Comp 521 Files and Databases Spring

Concurrency Control CHAPTER 17 SINA MERAJI

Concurrency Control. R &G - Chapter 19

Concurrency Control. [R&G] Chapter 17 CS432 1

Database Systems. Announcement

Concurrency Control. Conflict Serializable Schedules. Example. Chapter 17

Transactions Processing (i)

Review. Review. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Lecture #21: Concurrency Control (R&G ch.

Concurrency Control. Chapter 17. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Phantom Problem. Phantom Problem. Phantom Problem. Phantom Problem R1(X1),R1(X2),W2(X3),R1(X1),R1(X2),R1(X3) R1(X1),R1(X2),W2(X3),R1(X1),R1(X2),R1(X3)

Conflict Equivalent. Conflict Serializability. Example 1. Precedence Graph Test Every conflict serializable schedule is serializable

Concurrency Control. Chapter 17. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke

CAS CS 460/660 Introduction to Database Systems. Transactions and Concurrency Control 1.1

Distributed Transaction Management. Distributed Database System

Concurrency Control! Snapshot isolation" q How to ensure serializability and recoverability? " q Lock-Based Protocols" q Other Protocols"

Lecture 21. Lecture 21: Concurrency & Locking

Transactions. Transaction. Execution of a user program in a DBMS.

TRANSACTION MANAGEMENT

Introduction to Transaction Management

Implementing Isolation

Including Aborts in Serializability. Conflict Serializable Schedules. Recall Conflicts. Conflict Equivalent

Transaction Management & Concurrency Control. CS 377: Database Systems

Transactions & Update Correctness. April 11, 2018

CSC 261/461 Database Systems Lecture 21 and 22. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

Transaction Overview and Concurrency Control

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #17: Transac0ons 2: 2PL and Deadlocks

CSC 261/461 Database Systems Lecture 24

Page 1. Goals of Todayʼs Lecture" Two Key Questions" Goals of Transaction Scheduling"

Page 1. Goals of Today s Lecture" Two Key Questions" Goals of Transaction Scheduling"

Lectures 8 & 9. Lectures 7 & 8: Transactions

Database Management System

Introduction to Data Management. Lecture #26 (Transactions, cont.)

Introduction to Transaction Management

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #17: Transac0ons 1: Intro. to ACID

Why Transac'ons? Database systems are normally being accessed by many users or processes at the same 'me.

Database Applications (15-415)

Deadlock Prevention (cont d) Deadlock Prevention. Example: Wait-Die. Wait-Die

CS 5614: (Big) Data Management Systems. B. Aditya Prakash Lecture #6: Transac/ons 1: Intro. to ACID

Page 1. Goals of Today s Lecture. The ACID properties of Transactions. Transactions

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class. Last Class. Faloutsos/Pavlo CMU /615

Concurrency Control Serializable Schedules and Locking Protocols

h p:// Authors: Tomáš Skopal, Irena Holubová Lecturer: Mar n Svoboda, mar

Integrity Constraints, Triggers, Transactions and Procedures

Page 1. Goals for Today" What is a Database " Key Concept: Structured Data" CS162 Operating Systems and Systems Programming Lecture 13.

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

doc. RNDr. Tomáš Skopal, Ph.D.

Transactions and Locking. April 16, 2018

Database transactions

Databases - Transactions II. (GF Royle, N Spadaccini ) Databases - Transactions II 1 / 22

Homework 5 (by Joy Arulraj) Due: Monday Nov 13, 11:59pm

CSE 444: Database Internals. Lectures Transactions

Transactions. 1. Transactions. Goals for this lecture. Today s Lecture

Transactions. Concurrency. Consistency ACID. Modeling transactions. Transactions and Concurrency Control

Lock Granularity and Consistency Levels (Lecture 7, cs262a) Ali Ghodsi and Ion Stoica, UC Berkeley February 7, 2018

Database design and implementation CMPSCI 645. Lectures 18: Transactions and Concurrency

Concurrency. Consider two ATMs running in parallel. We need a concurrency manager. r1[x] x:=x-250 r2[x] x:=x-250 w[x] commit w[x] commit

CSE 444: Database Internals. Lectures 13 Transaction Schedules

CSE 190D Database System Implementation

Final Review. CS634 May 11, Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke

Databases - Transactions

CMPT 354: Database System I. Lecture 11. Transaction Management

Database. Università degli Studi di Roma Tor Vergata. ICT and Internet Engineering. Instructor: Andrea Giglio

Today s Class. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Formal Properties of Schedules. Conflicting Operations

Carnegie Mellon University Department of Computer Science /615 - Database Applications C. Faloutsos & A. Pavlo, Fall 2016

Concurrency Control 1

T ransaction Management 4/23/2018 1

Concurrency Control - Two-Phase Locking

CSE 344 MARCH 5 TH TRANSACTIONS

Introduction to Database Management Systems

Chapter 22. Transaction Management

Lecture 12. Lecture 12: The IO Model & External Sorting

CS Transactions

Lock-based Concurrency Control

CSE 344 MARCH 9 TH TRANSACTIONS

References. Transaction Management. Database Administration and Tuning 2012/2013. Chpt 14 Silberchatz Chpt 16 Raghu

Introduction to Data Management CSE 344

Database Tuning and Physical Design: Execution of Transactions

6.830 Lecture Transactions October 23, 2017

Introduction to Database Systems. Chapter 1. Instructor: . Database Management Systems, R. Ramakrishnan and J. Gehrke 1

Concurrency Control. Concurrency Control Ensures interleaving of operations amongst concurrent transactions result in serializable schedules

Transcription:

Transaction Management and Concurrency Control Chapter 16, 17 Instructor: Vladimir Zadorozhny vladimir@sis.pitt.edu Information Science Program School of Information Sciences, University of Pittsburgh 1 Transactions v 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. v 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. v A transaction is the DBMS s abstract view of a user program: a sequence of reads and writes. 2

Concurrency in a DBMS v 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). v Issues: Effect of interleaving transactions, and crashes. 3 Atomicity of Transactions v A transaction might commit after completing all its actions, or it could abort (or be aborted by the DBMS) after executing some actions. v 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. 4

Example v Consider two transactions (Xacts): 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. 5 Example (Contd.) v 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) 6

Scheduling Transactions v Serial schedule: Schedule that does not interleave the actions of different transactions. v 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. v Serializable schedule: A schedule that is equivalent to some serial execution of the transactions. (Note: If each transaction preserves consistency, every serializable schedule preserves consistency. ) 7 Aborting a Transaction v 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! v Most systems avoid such 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. v 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. 8

Anomalies with Interleaved Execution v Reading Uncommitted Data (WR Conflicts, dirty reads ): T1: R(A), W(A), R(B), W(B), Abort T2: R(A), W(A), C v Unrepeatable Reads (RW Conflicts): T1: R(A), R(A), W(A), C T2: R(A), W(A), C 9 Anomalies (Continued) v Overwriting Uncommitted Data (WW Conflicts): T1: W(A), W(B), C T2: W(A), W(B), C 10

Conflict Serializable Schedules v Two schedules are conflict equivalent if: Involve the same actions of the same transactions Every pair of conflicting actions is ordered the same way v Schedule S is conflict serializable if S is conflict equivalent to some serial schedule 11 Example v A schedule that is not conflict serializable: T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) T1 A B v The cycle in the graph reveals the problem. The output of T1 depends on T2, and viceversa. T2 Dependency graph 12

Dependency Graph v Dependency graph: One node per Xact; edge from Ti to Tj is created if one of the operations in Ti appears in the schedule before some conflicting operation in Tj. v Theorem: Schedule is conflict serializable if and only if its dependency graph is acyclic 13 Lock-Based Concurrency Control Each Xact must obtain a S (shared) lock on object before reading, and an X (exclusive) lock on object before writing. If an Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object. 14

Two-Phase Locking (2PL) Each Xact must obtain a S (shared) lock on object before reading, and an X (exclusive) lock on object before writing. A transaction can not request additional locks once it releases any locks. If an Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object. 15 Strict 2PL 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. Strict 2PL allows only serializable schedules 16

Lock Management v Lock and unlock requests are handled by the lock manager v Lock table entry: Number of transactions currently holding a lock Type of lock held (shared or exclusive) Pointer to queue of lock requests v Locking and unlocking have to be atomic operations v Lock upgrade: transaction that holds a shared lock can be upgraded to hold an exclusive lock 17 Deadlocks v Deadlock: Cycle of transactions waiting for locks to be released by each other. v Two ways of dealing with deadlocks: Deadlock prevention Deadlock detection 18

Deadlock Prevention v Assign priorities based on timestamps. Assume Ti wants a lock that Tj holds. Two policies are possible: Wait-Die: It Ti has higher priority, Ti waits for Tj; otherwise Ti aborts Wound-wait: If Ti has higher priority, Tj aborts; otherwise Ti waits v If a transaction re-starts, make sure it has its original timestamp 19 Deadlock Detection v Create a waits-for graph: Nodes are transactions There is an edge from Ti to Tj if Ti is waiting for Tj to release a lock v Periodically check for cycles in the waits-for graph 20

Deadlock Detection (Continued) Example: T1: S(A), R(A), S(B) T2: X(B),W(B) X(C) T3: S(C), R(C) X(A) T4: X(B) T1 T2 T1 T2 T4 T3 T3 T3 21 Multiple-Granularity Locks v Hard to decide what granularity to lock (tuples vs. pages vs. tables). v Shouldn t have to decide! v Data containers are nested: Database contains Tables Pages Tuples 22

Summary v There are several lock-based concurrency control schemes (Strict 2PL, 2PL). Conflicts between transactions can be detected in the dependency graph v The lock manager keeps track of the locks issued. Deadlocks can either be prevented or detected. 23