Announcements. Review of Schedules. Scheduler. Notation. Pessimistic Scheduler. CSE 444: Database Internals. Serializability.

Similar documents
CSE 444: Database Internals. Lectures Transactions

Introduction to Data Management CSE 414

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

Database Systems CSE 414

Database Systems CSE 414

Introduction to Data Management CSE 344

CSE 344 MARCH 25 TH ISOLATION

CSE 344 MARCH 9 TH TRANSACTIONS

Lecture 7: Transactions Concurrency Control

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

Introduction to Data Management CSE 344

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

CSE544 Transac-ons: Concurrency Control. Lectures #5-6 Thursday, January 20, 2011 Tuesday, January 25, 2011

Outline. Review questions. Carnegie Mellon Univ. Dept. of Computer Science Database Applications

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

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)

Transaction Processing: Concurrency Control. Announcements (April 26) Transactions. CPS 216 Advanced Database Systems

CMSC 424 Database design Lecture 22 Concurrency/recovery. Mihai Pop

Lock-based Concurrency Control

Database Management Systems Concurrency Control

CSEP 544: Lecture 07. Transactions Part 2: Concurrency Control. CSEP544 - Fall

Lecture 21 Concurrency Control Part 1

Distributed Systems (ICE 601) Transactions & Concurrency Control - Part1

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

Introduction to Data Management CSE 344

Multi-User-Synchronization

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

CSE 344 MARCH 5 TH TRANSACTIONS

Introduction to Database Systems CSE 444

Chapter 22. Transaction Management

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

Intro to Transactions

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

Introduction to Database Systems CSE 444

Concurrency Control. Transaction Management. Lost Update Problem. Need for Concurrency Control. Concurrency control

Lecture 22 Concurrency Control Part 2

Graph-based protocols are an alternative to two-phase locking Impose a partial ordering on the set D = {d 1, d 2,..., d h } of all data items.

Chapter 13 : Concurrency Control

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


Pessimistic v.s. Optimistic. Outline. Timestamps. Timestamps. Timestamps. CSE 444: Database Internals. Main invariant:

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

CSE 190D Database System Implementation

Lecture 13 Concurrency Control

Database Systems. Announcement

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

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

Implementing Isolation

Advanced Databases. Lecture 9- Concurrency Control (continued) Masood Niazi Torshiz Islamic Azad University- Mashhad Branch

Chapter 15 : Concurrency Control

Concurrency Control Overview. COSC 404 Database System Implementation. Concurrency Control. Lock-Based Protocols. Lock-Based Protocols (2)

TRANSACTION MANAGEMENT

6.830 Lecture Transactions October 23, 2017

Some Examples of Conflicts. Transactional Concurrency Control. Serializable Schedules. Transactions: ACID Properties. Isolation and Serializability

Concurrency Control. R &G - Chapter 19

Concurrency Control - Two-Phase Locking

DATABASE DESIGN I - 1DL300

Practice and Applications of Data Management CMPSCI 345. Lecture 13: Transactions

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

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

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

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

! A lock is a mechanism to control concurrent access to a data item! Data items can be locked in two modes :

Chapter 5. Concurrency Control Techniques. Adapted from the slides of Fundamentals of Database Systems (Elmasri et al., 2006)

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

3. Concurrency Control for Transactions Part One

References. Concurrency Control. Administração e Optimização de Bases de Dados 2012/2013. Helena Galhardas e

Overview. Introduction to Transaction Management ACID. Transactions

Introduction to Data Management CSE 344

Chapter 12 : Concurrency Control

Distributed Systems. 12. Concurrency Control. Paul Krzyzanowski. Rutgers University. Fall 2017

Chapter 18 Concurrency Control Techniques

Introduction to Data Management CSE 344

Isolation levels. Introduction to Database Design 2012, Lecture 14. Rasmus Ejlers Møgelberg. Questions class about one week before exam

Database Management Systems

Seminar 3. Transactions. Concurrency Management in MS SQL Server

DB2 Lecture 10 Concurrency Control

Transaction Management. Pearson Education Limited 1995, 2005

Concurrency control CS 417. Distributed Systems CS 417

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

Datenbanksysteme II: Implementation of Database Systems Synchronization of Concurrent Transactions

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 18-1

Concurrency Control CHAPTER 17 SINA MERAJI

Introduction to Data Management CSE 344

A lock is a mechanism to control concurrent access to a data item Data items can be locked in two modes:

Chapter 10 : Concurrency Control

Transactions and Isolation

2 nd Semester 2009/2010

Database Applications (15-415)

Conflict serializability

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

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

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

Concurrency Control. Conflict Serializable Schedules. Example. Chapter 17

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

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 Management: Concurrency Control

Unit 10.5 Transaction Processing: Concurrency Zvi M. Kedem 1

Transaction Management: Introduction (Chap. 16)

Intro to Transaction Management

Transcription:

nnouncements SE 444: Database Internals Lab 2 is due tonight Lab 2 quiz is on Wednesday in class Same format as lab 1 quiz Lectures 14 Transactions: Locking Lab 3 is available Fastest way to do lab 3 is to do it very slowly Hw5 is due on Friday 1 2 Serializability Review of Schedules Serial Serializable onflict serializable View serializable Recoverability Recoverable voids cascading aborts Scheduler The scheduler: Module that schedules the transaction s actions, ensuring serializability Two main approaches Pessimistic: locks Optimistic: timestamps, multi-version, validation 3 4 Pessimistic Scheduler Notation Simple idea: Each element has a unique lock Each transaction must first acquire the lock before reading/writing that element If the lock is taken by another transaction, then wait The transaction must release the lock(s) l i () = transaction T i acquires lock for element u i () = transaction T i releases lock for element 5 6 1

Non-Serializable Schedule RED(, t) WRITE(, t) RED(, t) WRITE(,t) RED(,s) WRITE(,s) RED(,s) WRITE(,s) 7 L 1 (); RED(, t) WRITE(, t); U 1 (); L 1 () RED(, t) WRITE(,t); U 1 (); Example L 2 (); RED(,s) WRITE(,s); U 2 (); L 2 (); DENIED GRNTED; RED(,s) WRITE(,s); U 2 (); Scheduler has ensured a conflict-serializable schedule 8 L 1 (); RED(, t) WRITE(, t); U 1 (); L 1 (); RED(, t) WRITE(,t); U 1 (); ut L 2 (); RED(,s) WRITE(,s); U 2 (); L 2 (); RED(,s) WRITE(,s); U 2 (); Locks did not enforce conflict-serializability!!! What s wrong 9? The 2PL rule: In every transaction, all lock requests must precede all unlock requests This ensures conflict serializability! (will prove this shortly) 10 Example: 2PL transactions L 1 (); L 1 (); RED(, t) WRITE(, t); U 1 () RED(, t) WRITE(,t); U 1 (); Now it is conflict-serializable L 2 (); RED(,s) WRITE(,s); L 2 (); DENIED GRNTED; RED(,s) WRITE(,s); U 2 (); U 2 (); 11 Growing phase Shrinking phase Example with Multiple Transactions T4 Unlocks second so perhaps was waiting for Unlocks first Was not waiting for anyone Equivalent to each transaction executing entirely the moment it enters shrinking phase 12 2

13 14 Then there is the following temporal cycle in the schedule: Then there is the following temporal cycle in the schedule: U 1 ()àl 2 () why? 15 16 Then there is the following temporal cycle in the schedule: U 1 ()àl 2 () L 2 ()àu 2 () why? 17 Then there is the following temporal cycle in the schedule: U 1 ()àl 2 () L 2 ()àu 2 () U 2 ()àl 3 () L 3 ()àu 3 () U 3 ()àl 1 () 18 L 1 ()àu 1 () ontradiction 3

New Problem: Non-recoverable Schedule L 1 (); L 1 (); RED(, t) WRITE(, t); U 1 () RED(, t) WRITE(,t); U 1 (); bort L 2 (); RED(,s) WRITE(,s); L 2 (); DENIED GRNTED; RED(,s) WRITE(,s); U 2 (); U 2 (); ommit 19 Strict 2PL Strict 2PL: ll locks held by a transaction are released when the transaction is completed; release happens at the time of OMMIT or ROLLK Schedule is recoverable Schedule avoids cascading aborts Schedule is strict: read book 20 L1(); RED() :=+100 WRITE(); L1(); RED() :=+100 WRITE(); U1(),U1(); Rollback Strict 2PL L2(); DENIED GRNTED; RED() := *2 WRITE(); L2(); RED() := *2 WRITE(); U2(); U2(); ommit 21 Summary of Strict 2PL Ensures serializability, recoverability, and avoids cascading aborts Issues: implementation, lock modes, granularity, deadlocks, performance 22 The Locking Scheduler Task 1: -- act on behalf of the transaction dd lock/unlock requests to transactions Examine all RED() or WRITE() actions dd appropriate lock requests On OMMIT/ROLLK release all locks Ensures Strict 2PL! The Locking Scheduler Task 2: -- act on behalf of the system Execute the locks accordingly Lock table: a big, critical data structure in a DMS! When a lock is requested, check the lock table Grant, or add the transaction to the element s wait list When a lock is released, re-activate a transaction from its wait list When a transaction aborts, release all its locks heck for deadlocks occasionally 23 24 4

Lock Modes S = shared lock (for RED) X = exclusive lock (for WRITE) Lock Granularity Fine granularity locking (e.g., tuples) High concurrency High overhead in managing locks Lock compatibility matrix: None S X None OK OK OK S OK OK onflict X OK onflict onflict 25 oarse grain locking (e.g., tables, predicate locks) Many false conflicts Less overhead in managing locks lternative techniques Hierarchical locking (and intentional locks) [commercial DMSs] Lock escalation 26 Hierarchical Locking Hierarchical Locking To enable both coarse- and fine-grained locking onsider database as a hierarchy Relations are largest lockable elements Relations consist of blocks locks contain tuples To place a lock on an element, start at the top If at element to lock, get an S or X lock on it If want to lock an element deeper in the hierarchy Leave an intentional lock: IS or IX 27 From Franklin97. See readings SE 444 - Spring posted 2016 on course website28 Deadlocks Lock Performance ycle in the wait-for graph: waits for waits for waits for Deadlock detection Timeouts Wait-for graph Deadlock avoidance cquire locks in pre-defined order cquire all locks at once before starting Throughput # ctive Transactions thrashing Why? 29 30 5

The Tree Protocol n alternative to 2PL, for tree structures E.g. -trees (the indexes of choice in databases) ecause Indexes are hot spots! 2PL would lead to great lock contention Rules: The Tree Protocol The first lock may be any node of the tree Subsequently, a lock on a node may only be acquired if the transaction holds a lock on its parent Nodes can be unlocked in any order (no 2PL necessary) rabbing First lock parent then lock child Keep parent locked only if may need to update it Release lock on parent if child is not full The tree protocol is NOT 2PL, yet ensures conflict-serializ ability! 31 32 So far we have assumed the database to be a static collection of elements (=tuples) If tuples are inserted/deleted then the phantom problem appears INSERT INTO Product(name, color) VLUES ( gizmo, blue ) Is this schedule serializable? 33 34 INSERT INTO Product(name, color) VLUES ( gizmo, blue ) Suppose there are two blue products, X1, X2: R1(X1),R1(X2),W2(X3),R1(X1),R1(X2),R1(X3) INSERT INTO Product(name, color) VLUES ( gizmo, blue ) Suppose there are two blue products, X1, X2: R1(X1),R1(X2),W2(X3),R1(X1),R1(X2),R1(X3) 35 This is conflict serializable SE 444 - Spring! What s 2016 wrong?? 36 6

INSERT INTO Product(name, color) VLUES ( gizmo, blue ) Suppose there are two blue products, X1, X2: R1(X1),R1(X2),W2(X3),R1(X1),R1(X2),R1(X3) phantom is a tuple that is invisible during part of a transaction execution but not invisible during the entire execution In our example: : reads list of products : inserts a new product : re-reads: a new product appears! Not serializable SE 444 due - Spring to 2016 phantoms 37 38 In a static database: onflict serializability implies serializability In a dynamic database, this may fail due to phantoms Dealing With Phantoms Lock the entire table, or Lock the index entry for blue If index is available Or use predicate locks lock on an arbitrary predicate Strict 2PL guarantees conflict serializability, but not serializability Dealing with phantoms is expensive! 39 40 Isolation Levels in SQL 1. Isolation Level: Dirty Reads 1. Dirty reads SET TRNSTION ISOLTION LEVEL RED UNOMMITTED 2. ommitted reads SET TRNSTION ISOLTION LEVEL RED OMMITTED 3. Repeatable reads SET TRNSTION ISOLTION LEVEL REPETLE RED 4. Serializable transactions ID SET TRNSTION ISOLTION LEVEL SERILIZLE 41 Long duration WRITE locks No RED locks Read-only transactions are never delayed Possible pbs: dirty and inconsistent reads 42 7

2. Isolation Level: Read ommitted Long duration WRITE locks Short duration RED locks Only acquire lock while reading (not 2PL) 3. Isolation Level: Repeatable Read Long duration WRITE locks Long duration RED locks Unrepeatable reads When reading same element twice, may get two different values This is not serializable yet!!! Why? 43 44 4. Isolation Level Serializable RED-ONLY Transactions Long duration WRITE locks Long duration RED locks Deals with phantoms too lient 1: STRT TRNSTION INSERT INTO SmallProduct(name, price) SELET pname, price WHERE price <= 0.99 DELETE WHERE price <=0.99 OMMIT lient 2: SET TRNSTION RED ONLY STRT TRNSTION SELET count(*) May improve performance 45 SELET count(*) FROM SmallProduct OMMIT 46 8