Revision exercises. CS-460 Fall 2018

Similar documents
Conflict serializability

Concurrency Control. Himanshu Gupta CSE 532 CC 1

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

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

Transactions and Locking. April 16, 2018

Concurrency Control. R &G - Chapter 19

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

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

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

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

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

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

Outline. Database Management and Tuning. Index Tuning Examples. Exercise 1 Query for Student by Name. Concurrency Tuning. Johann Gamper.

Transaction Management and Concurrency Control. Chapter 16, 17

Concurrency Control CHAPTER 17 SINA MERAJI

CSE232: Database System Principles

CS 245: Database System Principles

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

Concurrency Control. Conflict Serializable Schedules. Example. Chapter 17

Database Management System

CS 5614: Transaction Processing 121. Transaction = Unit of Work Recall ACID Properties (from Module 1)

Transaction Management. Concurrency Control (4)

Lecture 22 Concurrency Control Part 2

Transactions and Concurrency Control

Unit 10.5 Transaction Processing: Concurrency Zvi M. Kedem 1

CS 245: Database System Principles

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

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

Database Systems. Announcement

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

Chapter 18 Concurrency Control Techniques

Transaction Management: Concurrency Control

Transaction Management. Concurrency Control (2)

Outline. Database Tuning. Undesirable Phenomena of Concurrent Transactions. Isolation Guarantees (SQL Standard) Concurrency Tuning.

Outline. Database Tuning. Undesirable Phenomena of Concurrent Transactions. Isolation Guarantees (SQL Standard) Concurrency Tuning.

Concurrency Control - Formal Foundations

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

Lecture 21 Concurrency Control Part 1

Concurrency Control. Data Base Management Systems. Inherently Concurrent Systems: The requirements

Intro to Transaction Management

Chapter 13 : Concurrency Control

Outline. Database Management and Tuning. Isolation Guarantees (SQL Standard) Undesirable Phenomena of Concurrent Transactions. Concurrency Tuning

CS377: Database Systems Concurrency Control. Li Xiong Department of Mathematics and Computer Science Emory University

CSE 344 MARCH 9 TH TRANSACTIONS

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

Transaction Management Exercises KEY

15-415/615 Homework 8, Page 2 of 11 Thu, 4/24/2014, 1:30pm

Outline. Database Tuning. What is a Transaction? 1. ACID Properties. Concurrency Tuning. Nikolaus Augsten. Introduction to Transactions

CSE 344 MARCH 25 TH ISOLATION

Introduction to Data Management CSE 344

MASSACHUSETTS INSTITUTE OF TECHNOLOGY

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

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

CS 245: Database System Principles

Chapter 9 Concurrency Control

Transaction Management Overview

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

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

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

Concurrency Control & Recovery

Lock-based Concurrency Control

DB2 Lecture 10 Concurrency Control


IMPORTANT: Circle the last two letters of your class account:

Chapter 7: Isolation

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

CSE 444: Database Internals. Lectures Transactions

Concurrency Control - Two-Phase Locking

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

Lecture 13 Concurrency Control

mywbut.com Concurrency Control

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

Overview of Transaction Management

TRANSACTION MANAGEMENT

MASSACHUSETTS INSTITUTE OF TECHNOLOGY

CS 245 Final Exam Winter 2016

DATABASE TRANSACTIONS. CS121: Relational Databases Fall 2017 Lecture 25

Database Systems CSE 414

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

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

Lock!= Serializability. REVISÃO: Controle de Concorrência. Two-Phase Locking Techniques

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

Introduction to Data Management CSE 344

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

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

0: BEGIN TRANSACTION 1: W = 1 2: X = W + 1 3: Y = X * 2 4: COMMIT TRANSACTION

2 nd Semester 2009/2010

Chapter 15 : Concurrency Control

Seminar 3. Transactions. Concurrency Management in MS SQL Server

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

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

Multi-User-Synchronization

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.

Transaction Management & Concurrency Control. CS 377: Database Systems

Data Management for Data Science

CS352 Lecture - Concurrency

Concurrency Control & Recovery

Introduction to Data Management. Lecture #24 (Transactions)

CS Transactions

CS352 Lecture - Concurrency

Transcription:

Revision exercises Exer 1: Consider the following two schedules of concurrent execution: S 1 = r 1 (A); w 4 (B); w 1 (C); w 3 (D); r 2 (C); w 3 (A); w 1 (A); r 3 (B); w 3 (B); r 2 (D); w 2 (A) S 2 = r 1 (A); w 4 (B); w 1 (C); w 3 (D); r 2 (C); w 1 (A); w 3 (A); r 3 (B); w 3 (B); r 2 (D); w 2 (A) α) Draw the precedence graph for each one of them β) Is these two schedules conflict serializable? If yes, give an equivalent serial schedule Exer 2: Consider the following pairs of transactions. Use 2-phase locking and insert the appropriate locks for each transaction, assuming that the scheduler performs only exclusive locking. In case of concurrent execution, are there deadlocks? α) Τ 1 = r 1 (A); r 1 (B); w 1 (C); w 1 (B) Τ 2 = r 2 (D); r 2 (B); w 2 (B); w 2 (D) β) Τ 1 = r 1 (C); r 1 (B); w 1 (C); w 1 (B) Τ 2 = r 2 (B); r 2 (C); w 2 (B); w 2 (C) 116

Upgrading locks (Αναβάθμιση φραγμών) A transaction that wants to read and write an element, may first obtain a shared lock on the item for reading (being friendly toward other transactions) and then upgrade it to an exclusive lock for writing. Example: T1: SL1(A); R1(A); SL1(B); R1(B); XL1(B); W1(B); U1(A); U1(B) T2: SL2(A); R2(A); SL2(B); R2(B); U2(A); U2(B) If it asked for a XL1(Β) from the beginning, then it would have to wait and not even be able to read Β. T1 SL1(A); R1(A); SL1(B); R1(B); XL1(B); wait XL1(B); W1(B); U1(A); U1(B); T2 SL2(A); R2(A); SL2(B); R2(B); U2(A); U2(B); 117

Upgrading locks (Αναβάθμιση φραγμών) Unfortunately, the use of upgrading introduces a new and potentially serious source of deadlocks. Example: T1 SL1(A); R1(A); XL1(A); wait Both T1 and T2 try to upgrade to x-lock, but the scheduler forces each to wait because the other has a s- lock on A. T2 SL2(A); R2(A); XL2(A); wait 118

Update locks (Ενημερώσιμοι φραγμοί) We can avoid the deadlock problems caused by lock upgrade by using update locks: An update lock ULi(X) allows transaction Ti to read X but not to write X Only an update lock can be upgraded to a write lock (a read lock can not be upgraded) An update lock can be granted on X when there are already shared locks on X Once there is an update lock on X, no additional locks are allowed on X (otherwise such a lock would never be upgraded to exclusive because there are always other locks) 119

Update locks (Ενημερώσιμοι φραγμοί) Example: T1: UL1(A); R1(A); XL1(A); W1(A); U1(A); T2: UL2(A); R2(A); XL2(A); W2(A); U2(A); T1 T2 UL1(A); R1(A); XL1(A); W1(A); U1(A); UL2(A); wait UL2(A); R2(A); XL2(A); W2(A); U2(A); 120

Update locks (Ενημερώσιμοι φραγμοί) Compatibility matrix Lock requested Lock held S X U S True False True X False False False U False False False 121

Increment locks (Φραγμοί αύξησης) Many transactions operate on the DB only by incrementing or decrementing stored values. e.g. consider a transaction that transfers money from one bank account to another, ticket booking etc. The useful property of increment actions is that they can be interchanged with each other and their relative order doesn t matter However, they don t interchange with transactions that read or write Transactions may include operations of the form INC(A,c), meaning that constant c is to be added to DB element A INC(A,c) stands for: Read(A,t); t:=t+c; Write(A,t); Increment actions need increment locks: ILi(X) 122

Increment locks (Φραγμοί αύξησης) Increment actions and locks requires us to make several modifications to the definitions of consistent transactions, conflicts, and legal schedules: A consistent transaction can only have an increment action INCi(X) if it holds an increment lock on X at the time. An increment lock does not enable either read or write actions, however. In a legal schedule, any number of transactions can hold an increment lock on item X at a time. If a transaction has an increment lock on X, no other transaction can have a shared or exclusive lock on X at the same time. INCi(X) conflicts with Rj(X) and Wj(X) for j i INCi(X) does not conflict with INCj(X) 123

Increment locks (Φραγμοί αύξησης) Example: T1: SL1(A); R1(A); IL1(B); INC1(B); U1(A); U1(B); T2: SL2(A); R2(A); IL2(B); INC2(B); U2(A); U2(B); T1 T2 SL1(A); R1(A); IL1(B); INC1(B); U1(A); U1(B); SL2(A); R2(A); IL2(B); INC2(B); U2(A); U2(B); 124

Increment locks (Φραγμοί αύξησης) Compatibility matrix Lock requested Lock held S X I S True False False X False False False I False False True 125

Lock table (Πίνακας φραγμών) The scheduler maintains a lock table A...... Object: A Group mode: U Waiting: yes List: T1 S no T2 U no hash table T3 X yes Handling Lock Requests: First-come-first-served or Priority to S locks or Priority to U locks to other Τ3 records 126

Locks With Multiple Granularity What kind of objects do we lock? Locking works well in any case, but should we lock small or large objects? If large objects are locked (e.g., relations) Need few locks Low concurrency (χαμηλή συγχρονικότητα) If small objects are locked (e.g., tuples, attributes) Need more locks More concurrency We can do both. The bathroom metaphor: Relation A Relation B... Tuple A Tuple B Tuple C... Stall 1 Stall 2 Stall 3 Stall 4 restroom Disk Block A Disk Block B... DB DB DB hall 127

Locking on Hierarchies of DB Elements Assume there is a tree structure to the data Hierarchy of lockable elements (relations, tuples, attributes) Data organized in a tree (e.g. B+-tree) Locking schemes seen so far perform poorly in such cases 3 levels of DB elements: Relations are the largest lockable elements Each relation comprises one or more blocks Each block contains one or more tuples E.g. bank (block- or tuple-level locking, but sometimes accounts relation), document management DB Need a new type of lock, called a warning lock 128

Warning locks (Προειδοποιητικοί φραγμοί) Warning locks denote the intention (πρόθεση) to obtain a lock IS: intention to obtain a shared lock IX: intention to obtain an exclusive lock Rules: To place a S or X lock, start at the root of the hierarchy If we are at the element that we want to lock, request S or X lock If the element is further down the hierarchy, place a warning of the appropriate kind at the current node (IS or IX) Proceed to the appropriate child node and repeat until the desired node is reached 129

Warning locks (Προειδοποιητικοί φραγμοί) In order to decide whether or not one of these locks can be granted, we use the compatibility matrix. Lock requested Lock held IS IX S X IS True True True False IX True True False False S True False True False X False False False False 130

Warning locks (Προειδοποιητικοί φραγμοί) Incompatibilities: An IS on a node N is only incompatible with an X lock on N An IX on a node N is incompatible with S and X on N Potential conflicts that may arise with IS/IS, IS/IX, IX/IS and IX/IX will be resolved at a lower level An S on N is compatible with IS and S An X on N is incompatible with every other type of lock Can only lock existing items, but not items that might later be inserted. To handle insertions / deletions: Get exclusive lock on A before deleting A At insert A operation, the transaction is given exclusive lock on A 131