Concurrency Control 1

Similar documents
COURSE 1. Database Management Systems

Concurrency Control - Formal Foundations

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

Transaction Management Overview

Transaction Management and Concurrency Control. Chapter 16, 17

Lecture 21. Lecture 21: Concurrency & Locking

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

Database Systems. Announcement

Overview of Transaction Management

Intro to Transaction Management

Introduction TRANSACTIONS & CONCURRENCY CONTROL. Transactions. Concurrency

Concurrency Control - Two-Phase Locking

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

Concurrency Control & Recovery

Concurrency Control & Recovery

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

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

Transaction Management & Concurrency Control. CS 377: Database Systems

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

Overview. Introduction to Transaction Management ACID. Transactions

CSC 261/461 Database Systems Lecture 24

CSE 444: Database Internals. Lectures 13 Transaction Schedules

TRANSACTION MANAGEMENT

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

Transactions & Update Correctness. April 11, 2018

Lectures 8 & 9. Lectures 7 & 8: Transactions

CSE 444: Database Internals. Lectures Transactions

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

Introduction to Data Management. Lecture #24 (Transactions)

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

Transaction Management: Introduction (Chap. 16)

Transaction Management: Concurrency Control

Database Management System

Databases - Transactions

Introduction to Data Management CSE 344

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

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

Intro to Transactions

Database Management System

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

CSE 344 MARCH 5 TH TRANSACTIONS

Transactions. ACID Properties of Transactions. Atomicity - all or nothing property - Fully performed or not at all

Introduction to Data Management. Lecture #18 (Transactions)

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

CSE 190D Database System Implementation

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

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

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

Implementing Isolation

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

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

Roadmap of This Lecture

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

CSE 344 MARCH 9 TH TRANSACTIONS

Database transactions

Transactions and Concurrency Control

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

Transactions. Silberschatz, Korth and Sudarshan

Lecture 7: Transactions Concurrency Control

Introduction to Data Management CSE 344

Database Applications (15-415)

6.830 Lecture Transactions October 23, 2017

Transaction Processing Concepts and Theory. Truong Tuan Anh CSE-HCMUT

Introduction to Data Management CSE 344

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

Transaction Management

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

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

Introduction to Data Management CSE 344

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

Lecture 5: Transactions Concurrency Control. Wednesday October 26 th, 2011

Lock-based Concurrency Control

Database Management Systems 2010/11

Transaction Concept. Chapter 15: Transactions. Example of Fund Transfer. ACID Properties. Example of Fund Transfer (Cont.)

DBMS Architecture. Transaction Management. Chapters 16 and 17. Concurrency control and Recovery. Relationship with the mutual exclusion problem

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

CSE 344 MARCH 25 TH ISOLATION

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

Transaction Processing: Concurrency Control ACID. Transaction in SQL. CPS 216 Advanced Database Systems. (Implicit beginning of transaction)

Transactions. Lecture 8. Transactions. ACID Properties. Transaction Concept. Example of Fund Transfer. Example of Fund Transfer (Cont.

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

Chapter 22. Transaction Management

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

6.830 Lecture Recovery 10/30/2017

Introduction to Data Management CSE 414

Database Tuning and Physical Design: Execution of Transactions

Serializability of global history

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

Introduction to Transaction Management

Introduction. Storage Failure Recovery Logging Undo Logging Redo Logging ARIES

Transaction Overview and Concurrency Control

Chapter 15: Transactions

Database System Concepts

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

Introduction to Transaction Processing Concepts and Theory

Concurrency control 12/1/17

Integrity Constraints, Triggers, Transactions and Procedures

Chapter 13: Transactions

6.830 Lecture Recovery 10/30/2017

Optimistic Concurrency Control. April 18, 2018

Transcription:

Concurrency Control 1

Last time Isolation anomalies Dirty read, unrepeatable read, lost update Towards defining "correct" execution Transaction schedules e.g. R1(A) W2(B) R2(C) "Good" schedules have some equivalence to a serial schedule with same transaction 2

Big Picture (all inclusions are proper) All schedules Final State Serializable View Serializable Serial 3

Another notion of serializability View-serializability is nice but difficult to check/enforce in practice A third notion: conflict-serializability This can be enforced efficiently 4

Big Picture (all inclusions are proper) All schedules Final State Serializable View Serializable Conflict Serializable Serial 5

Conflicting Operations Based on identifying conflicting pairs of operations between transactions Observation: read-only transactions cannot interfere with each other in any bad way! The only problems are due to writes All three of our anomalies involve a write somewhere 6

Conflicting Operations Two operations by different transactions on the same object conflict if at least one is a write WW WR RW Example: if T1 and T2 both write Alice's bank account balance, they conflict But if T1 only writes Alice's balance and T2 only writes Bob's, no conflict! Also, two writes by the same transaction never conflict with each other 7

Conflicting Operations Conflicting operations do not commute W1(A) W2(A) R1(A) W2(A) W1(A) R2(A) So, they induce some notion of precedence or ordering 8

Conflict Graphs Given a schedule, can identify all conflicting pairs of operations and represent them as a graph Nodes are transactions Edge from i to j if transaction i contains an operation that conflicts with and precedes (in the schedule) an operation by transaction j Example: R1(A) W2(A) R1(A) 9

Conflict Graphs R1(A) W2(A) R1(A) 1 2 10

A conflict graph exercise R1(A) R2(A) R1(C) W1(A) R3(C) W2(B) W3(B) W3(C) 11

A conflict graph exercise R1(A) R2(A) R1(C) W1(A) R3(C) W2(B) W3(B) W3(C) 2 1 3 12

Conflict Serializability A schedule is conflict serializable if its conflict graph contains no cycle Alternative (equivalent) statement: it is conflict serializable if it has the same conflict graph as some serial schedule Why are these equivalent? Topological sort on the conflict graph gives us equivalent serial execution 13

A conflict graph exercise R1(A) R2(A) R1(C) W1(A) R3(C) W2(B) W3(B) W3(C) 2 1 3 14

An equivalent serial schedule R1(A) R2(A) R1(C) W1(A) R3(C) W2(B) W3(B) W3(C) Executing the transactions in the order 2, 1, 3 produces the same DB Let's see if we believe it R2(A) W2(B) R1(A) R1(C) W1(A) R3(C) W3(B) W3(C) 15

A slightly different schedule R1(A) R2(A) R1(C) W1(A) R3(C) W3(B) W2(B) W3(C) Compare with previous: R1(A) R2(A) R1(C) W1(A) R3(C) W2(B) W3(B) W3(C) 16

A conflict graph exercise R1(A) R2(A) R1(C) W1(A) R3(C) W3(B) W2(B) W3(C) 2 1 3 17

Big Picture (all inclusions are proper) All schedules Final State Serializable View Serializable Conflict Serializable Serial 18

What about aborts? Convention: if a schedule contains transactions that abort, we ignore the operations (R/W) of these transactions when determining if a schedule is serializable Rationale: aborted transactions' operations should not have happened and will be cleaned up Although, the "cleanup" can be nontrivial! 19

Dealing with aborts Cleanup issues W1(A) R2(A) W2(B) C2 A1... <= not good! 2 has read a value of A that "should not have been there" 2 has already committed, so extremely unclear how to clean up in a sensible way 20

Recoverability A schedule is recoverable if a transaction commits only after the commit of all transactions whose changes it has read Never have to undo an already committed transaction due to someone else's abort W1(A) R2(A) W2(B) C2... <= not recoverable 21

Recoverability Enforcing this will be a problem - need to keep track of who has read from whom So, more (stronger) criteria 22

ACA schedules A schedule avoids cascading aborts if a transaction never reads uncommitted writes Now that is easier to enforce W1(A) R2(A) W2(B) C1 C2 is recoverable but does not avoid cascading aborts But there could still be problems even if we enforce ACA 23

Strict schedules Consider schedule W1(A) W2(A) C2 A1 Recoverable and avoids cascading aborts because no-one never read anything But "cleanup" could be a pain Need to retain write by T2 while erasing write by T1 Depending on what the objects are and what records you keep of changes, could be a lot of work May need to roll back to initial state and redo T2 24

Strict schedule If we don't want this problem, can place an even stronger restriction A schedule is strict if whenever a transaction writes to a data item, no other transaction can read or write to that item until T has committed or aborted Avoids our problem W1(A) W2(A) C2 A1 25

Summary All schedules Recoverable Avoid Cascading Aborts Strict Serial 26

Summary Restrictions on schedules for serializability: Final-state serializable View-serializable Conflict-serializable Restrictions on schedules for handling aborts: Recoverable Avoids Cascading Aborts Strict 27

What was all this for? We now know how to tell good interleavings from bad ones Want either view-serializability or conflictserializability And possibly something like ACA or strictness too The system needs to allow only good interleavings Let's see this in action in MySQL 28

Transaction 1 START TRANSACTION; UPDATE accounts SET amount= amount-100 WHERE name = 'Alice'; UPDATE accounts SET amount= amount+100 WHERE name = 'Bob'; COMMIT; 29

Transaction 2 START TRANSACTION; UPDATE accounts SET amount= amount*1.1 WHERE name = 'Alice'; UPDATE accounts SET amount= amount*1.1 WHERE name = 'Bob'; COMMIT; 30

Bad interleaving Transaction 1 Transaction 2 UPDATE accounts SET amount= amount- 100 WHERE name = 'Alice'; UPDATE accounts SET amount= amount+ 100 WHERE name = 'Bob'; UPDATE accounts SET amount= amount*1.1 WHERE name = 'Alice'; UPDATE accounts SET amount= amount*1.1 WHERE name = 'Bob'; 31

Enforcing conflict serializability Goal: system must only allow interleavings (schedules) that are (conflict) serializable. Still don't know how to do it Specification vs implementation There may be (and are!) different ways to do it 32

Protocols for enforcing a Property General systems discussion Common problem: need to enforce a property All interleavings of transactions are conflict-serializable No customer receives a product without having paid for it If someone modifies your 4320 grade, that person is one of the 4320 course staff To enforce it, system uses an algorithm or protocol E.g. require me to log in before I modify your grade 33

Protocols and properties There can be many different protocols for enforcing a property Some protocols can be stricter than necessary, but still correct I.e. forbid all "bad" behavior But forbid some "good" behavior too Ok as long as never allow "bad" behavior This often happens in practice 34

Back to transactions Property: conflict-serializability A variety of protocols Most of which are conservative (disallow some conflict serializable schedules) 35

Big Picture All schedules Want this as big as possible Conflict Serializable Schedules allowed by a correct protocol Serial 36

Concurrency control protocols A very simple protocol: force all transactions to execute serially No operations by different transactions may interleave If another transaction is not done reading/writing to DB, you must wait Does this permit only conflict-serializable schedules? Does this permit all conflict-serializable schedules? 37

Reasonable protocols Should allow as many conflict-serializable schedules as possible Should be simple and not impose too much overhead of their own Otherwise the performance boost from allowing interleavings is lost Several (families of) solutions 38