Introduction to Data Management. Lecture #24 (Transactions)

Similar documents
Introduction to Data Management. Lecture #18 (Transactions)

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

Transaction Management Overview

Transaction Management and Concurrency Control. Chapter 16, 17

Concurrency Control & Recovery

Database Management System

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

COURSE 1. Database Management Systems

Concurrency Control & Recovery

Introduction TRANSACTIONS & CONCURRENCY CONTROL. Transactions. Concurrency

Intro to Transaction Management

Overview of Transaction Management

Introduction to Data Management. Lecture #25 (Transactions II)

Overview. Introduction to Transaction Management ACID. Transactions

Intro to Transactions

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

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

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)

Database Systems. Announcement

Transactions Processing (i)

Transaction Management: Concurrency Control

Introduction to Transaction Management

Introduction to Transaction Management

Transactions & Update Correctness. April 11, 2018

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

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

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

Database Management System

Transaction Management & Concurrency Control. CS 377: Database Systems

Lecture 21. Lecture 21: Concurrency & Locking

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

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

CSE 344 MARCH 5 TH TRANSACTIONS

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

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

Integrity Constraints, Triggers, Transactions and Procedures

Lectures 8 & 9. Lectures 7 & 8: Transactions

Database Applications (15-415)

TRANSACTION MANAGEMENT

CSE 344 MARCH 25 TH ISOLATION

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

CSC 261/461 Database Systems Lecture 24

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

CSE 444: Database Internals. Lectures Transactions

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

CSE 344 MARCH 21 ST TRANSACTIONS

CSE 344 MARCH 9 TH TRANSACTIONS

Introduction to Data Management CSE 344

Introduction to Database Management Systems

CSE 444: Database Internals. Lectures 13 Transaction Schedules

CSE 190D Database System Implementation

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

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

Chapter 22. Transaction Management

Introduction to Data Management. Lecture #1 (Course Trailer )

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

Concurrency Control - Formal Foundations

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

Database Management Systems CSEP 544. Lecture 9: Transactions and Recovery

Introduction to Data Management. Lecture #1 (Course Trailer )

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

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

Distributed Transaction Management. Distributed Database System

Databases - Transactions

Transaction Overview and Concurrency Control

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 10: Transaction processing. November 14, Lecturer: Rasmus Pagh

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

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

Database Systems CSE 414

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

Database Systems CSE 414

Concurrency Control 1

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

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

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

Introduction and Overview

L i (A) = transaction T i acquires lock for element A. U i (A) = transaction T i releases lock for element A

Announcements. Motivating Example. Transaction ROLLBACK. Motivating Example. CSE 444: Database Internals. Lab 2 extended until Monday

Announcements. Transaction. Motivating Example. Motivating Example. Transactions. CSE 444: Database Internals

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

Last time: Saw how to implement atomicity in the presence of crashes, but only one transaction running at a time

Introduction and Overview

Introduction to Data Management CSE 414

Information Systems (Informationssysteme)

Introduction to Data Management CSE 344

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

Chapter 20 Introduction to Transaction Processing Concepts and Theory

Introduction to Data Management CSE 344

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

Concurrency control 12/1/17

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

Concurrency Control. Conflict Serializable Schedules. Example. Chapter 17

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

Database Systems CSE 414

Database Management Systems. Chapter 1

Introduction to Database Systems CS432. CS432/433: Introduction to Database Systems. CS432/433: Introduction to Database Systems

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD

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

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

Transcription:

Introduction to Data Management Lecture #24 (Transactions) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v HW and exam info: HW#8 now in flight! (Due Friday; 5pts/day if late) Endterm Exam: Wed, Mar 22, 11-11:50 AM v This week s lecture plan: Today: Transactions Wednesday: JSON mini-course (online self-study) Friday: Wrap up + Endterm review! (Bring Q s...!) v Other notable news: Sample exams are (still J) available on wiki page Discussions can include AsterixDB Q&A... Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 2

Transactions v Concurrent execution of user programs is essential for good DBMS performance. Because disk accesses are frequent, and relatively slow, it s important to keep the CPU cores humming by working on several user programs concurrently. v A user s program may carry out many operations on the data pulled 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 (record) reads and writes. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 3 The ACID Properties v Atomicity: Each transaction is all or nothing. No worries about partial effects (if failures) and cleanup. v Consistency: Each transaction moves the database from one consistent state to another one. This is largely the application builder s responsibility. v Isolation: Each transaction can be written as if it s the only transaction in existence. No concurrency worries while building applications. v Durability: Once a transaction has committed, its effects will not be lost. Application code doesn t have to worry about data loss. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 4

Concurrency in a DBMS v Users submit transactions, and they can think of each one as executing all 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 may enforce some ICs, depending on the ICs declared in CREATE TABLE statements. (CHECK, PK/FK,...) Beyond this, the DBMS does not understand the semantics of the data. (E.g., it doesn t know how the interest on a bank account is computed.) v Issues: Effect of interleaving transactions, and crashes. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 5 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. Could violate some constraint, encounter some other error, be caught in a crash, or be picked to resolve a deadlock. 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. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 6

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 bank account A to bank account B. The second is crediting both accounts with a 6% interest payment. v No guarantee that T1 will execute before T2 or viceversa, if both are submitted together. However, the net effect must be equivalent to these transactions running serially in some (but either!) order. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 7 A Quick Aside on A & B v What are these two transactions, really? T1: BEGIN UPDATE Acct SET bal = bal + 100 WHERE acct_no = 101; UPDATE Acct SET bal = bal 100 WHERE acct_no = 201; END T2: BEGIN UPDATE Acct SET bal = bal * 1.06 WHERE acct_type = SV ; END v Again, the first transaction is transferring $100 from account B (201) to account A (101). The second one is giving all savings accounts their 6% interest payment. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 8

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 happens if: T1: A=A+100, B=B-100 T2: A=1.06*A, B=1.06*B ßToo much interest!) v The DBMSs view of the second schedule: T1: R(A), W(A), R(B), W(B) T2: R(A), W(A), R(B), W(B) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 9 Scheduling Transactions (Defn s.) v Serial schedule: Any 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 (any!) serial execution of the transactions. (Note: If each transaction preserves consistency, then every serializable schedule preserves consistency!) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 10

Anomalies with Interleaved Execution v Reading Uncommitted Data (WR Conflicts, a.k.a. dirty reads ): T3: R(A), W(A), R(B), W(B), Abort T4: R(A), W(A), C v Unrepeatable Reads (RW Conflicts): T5: R(A), R(A), W(A), C T6: R(A), W(A), C Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 11 Anomalies (Continued) v Overwriting Uncommitted Data (WW Conflicts): T7: W(A), W(B), C T8: W(A), W(B), C (Note how results are a must have been concurrent! intermingling of transactions T1 & T2 writes ) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 12

Lock-Based Concurrency Control v Strict Two-phase Locking (Strict 2PL) Protocol: Each Xact must get an S (shared) lock on an object before reading, and an X (exclusive) lock on it before writing. All locks held by a transaction are released only when the transaction completes. (Non-strict) 2PL Variant: Release locks anytime, but do not acquire any new locks after releasing any lock. Note: If a Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object they must wait. v Strict 2PL allows only serializable schedules. And additionally, it simplifies transaction aborts! (Non-strict) 2PL also allows only serializable schedules, but needs more complex abort processing (as you ll see). Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 13 2PL Prevents the Anomalies v Reading Uncommitted Data (WR Conflicts, a.k.a. dirty reads ): T3: R(A), W(A), R(B), W(B), Abort T4: R(A), W(A), C v Unrepeatable Reads (RW Conflicts): T5: R(A), R(A), W(A), C T6: R(A), W(A), C Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 14

2PL & Anomalies (Continued) v Overwriting Uncommitted Data (WW Conflicts): T7: W(A), W(B), C T8: W(A), W(B), C (Now results will no longer be a must have been concurrent! intermingling of T1 s & T2 s writes ) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 15 Aborting a Transaction v If transaction Ti aborts, all its actions must be undone. And, if some Tj already read a value last written by Ti, Tj must also be aborted! ( If I tell you, I ll have to kill you... J) 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 it only after Ti commits. v In order to undo the actions of an aborted transaction, the DBMS keeps a log where every write is recorded. Also used to recover from system crashes: active Xacts at crash time are aborted when the DBMS comes back up. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 16

Tune in Friday...! Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 17