Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Similar documents
Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

TRANSACTION MANAGEMENT [CH 16]

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

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

Review: The ACID properties

Chapter 10 : Concurrency Control

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

Deadlocks Detection and Avoidance. Prof. Sirer CS 4410 Cornell University

Chapter 18 Concurrency Control Techniques

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

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

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

BCA204T: DATA BASE MANAGEMENT SYSTEMS

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Data diverse software fault tolerance techniques

Transaction Processing: Basics - Transactions

BAAN IVc/BaanERP. Conversion Guide Oracle7 to Oracle8

Database Management Systems

% Sun Logo for. X3T10/95-229, Revision 0. April 18, 1998

Implementing Consistency -- Paxos. Some slides from Michael Freedman

Lecture 21 Concurrency Control Part 1

Federated Transaction Management with Snapshot Isolation

Chapter 15 : Concurrency Control

Concurrency Control Techniques

Traditional queuing behaviour in routers. Scheduling and queue management. Questions. Scheduling mechanisms. Scheduling [1] Scheduling [2]

Lecture 22 Concurrency Control Part 2

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

Chapter 13 : Concurrency Control


Threads and Concurrency in Java: Part 2

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

Transaction Management

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1

CMSC Computer Architecture Lecture 15: Multi-Core. Prof. Yanjing Li University of Chicago

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Foundation of Database Transaction Processing. Copyright 2012 Pearson Education, Inc.

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

Lecture 13 Concurrency Control

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

The Magma Database file formats

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Part A Datapath Design

Reliable Transmission. Spring 2018 CS 438 Staff - University of Illinois 1

Course Site: Copyright 2012, Elsevier Inc. All rights reserved.

% Sun Logo for Frame. X3T10/95-229, Revision 2. September 28, 1995

6.854J / J Advanced Algorithms Fall 2008

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

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

BST Sequence of Operations

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor Advanced Issues

Module Instantiation. Finite State Machines. Two Types of FSMs. Finite State Machines. Given submodule mux32two: Instantiation of mux32two

2 nd Semester 2009/2010

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago

Multiversion schemes keep old versions of data item to increase concurrency. Multiversion Timestamp Ordering Multiversion Two-Phase Locking Each

Energy-Efficient Transaction Management for Mobile Adhoc Network Databases

Introduction to Wireless & Mobile Systems. Chapter 6. Multiple Radio Access Cengage Learning Engineering. All Rights Reserved.

Term Project Report. This component works to detect gesture from the patient as a sign of emergency message and send it to the emergency manager.

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.

Symbolic Execution with Abstraction

Master Informatics Eng. 2017/18. A.J.Proença. Memory Hierarchy. (most slides are borrowed) AJProença, Advanced Architectures, MiEI, UMinho, 2017/18 1

Chapter 12 : Concurrency Control

Security of Bluetooth: An overview of Bluetooth Security

Lazy Type Changes in Object-oriented Database. Shan Ming Woo and Barbara Liskov MIT Lab. for Computer Science December 1999

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

Concurrency control CS 417. Distributed Systems CS 417

Design and Implementation of a Concurrency Control Mechanism in an Object-Oriented Database System

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software

Python Programming: An Introduction to Computer Science

why study sorting? Sorting is a classic subject in computer science. There are three reasons for studying sorting algorithms.

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

DATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Data structures. Appetizer. Appetizer

Analysis of Algorithms

Using VTR Emulation on Avid Systems

Elementary Educational Computer

Chapter 4 Threads. Operating Systems: Internals and Design Principles. Ninth Edition By William Stallings

EE260: Digital Design, Spring /16/18. n Example: m 0 (=x 1 x 2 ) is adjacent to m 1 (=x 1 x 2 ) and m 2 (=x 1 x 2 ) but NOT m 3 (=x 1 x 2 )

Announcements. Reading. Project #4 is on the web. Homework #1. Midterm #2. Chapter 4 ( ) Note policy about project #3 missing components

L6: FSMs and Synchronization

Programming with Shared Memory PART II. HPC Spring 2017 Prof. Robert van Engelen

Operating System Concepts. Operating System Concepts

CIS 121. Introduction to Trees

Fast Fourier Transform (FFT) Algorithms

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

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Priority Queues. Binary Heaps

A Reservation-Based Extended Transaction Protocol

transaction - (another def) - the execution of a program that accesses or changes the contents of the database

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

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

. Written in factored form it is easy to see that the roots are 2, 2, i,

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

The University of Adelaide, School of Computer Science 22 November Computer Architecture. A Quantitative Approach, Sixth Edition.

Automatic Generation of Minimal and Safe Transactions in Conceptual Database Design

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

WYSE Academic Challenge Sectional Computer Science 2005 SOLUTION SET

Heaps. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Transcription:

Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe

CHAPTER 21 Cocurrecy Cotrol Techiques Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe

Itroductio Cocurrecy cotrol protocols Set of rules to guaratee serializability Two-phase lockig protocols Lock data items to prevet cocurret access Timestamp Uique idetifier for each trasactio Multiversio currecy cotrol protocols Use multiple versios of a data item Validatio or certificatio of a trasactio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-3

21.1 Two-Phase Lockig Techiques for Cocurrecy Cotrol Lock Variable associated with a data item describig status for operatios that ca be applied Oe lock for each item i the database Biary locks Two states (values) Locked (1) Item caot be accessed Ulocked (0) Item ca be accessed whe requested Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-4

Two-Phase Lockig Techiques for Cocurrecy Cotrol (cot d.) Trasactio requests access by issuig a lock_item(x) operatio Figure 21.1 Lock ad ulock operatios for biary locks Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-5

Two-Phase Lockig Techiques for Cocurrecy Cotrol (cot d.) Lock table specifies items that have locks Lock maager subsystem Keeps track of ad cotrols access to locks Rules eforced by lock maager module At most oe trasactio ca hold the lock o a item at a give time Biary lockig too restrictive for database items Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-6

Two-Phase Lockig Techiques for Cocurrecy Cotrol (cot d.) Shared/exclusive or read/write locks Read operatios o the same item are ot coflictig Must have exclusive lock to write Three lockig operatios read_lock(x) write_lock(x) ulock(x) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-7

Figure 21.2 Lockig ad ulockig operatios for two-mode (read/write, or shared/exclusive) locks Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-8

Two-Phase Lockig Techiques for Cocurrecy Cotrol (cot d.) Lock coversio Trasactio that already holds a lock allowed to covert the lock from oe state to aother Upgradig Issue a read_lock operatio the a write_lock operatio Dowgradig Issue a read_lock operatio after a write_lock operatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-9

Guarateeig Serializability by Two- Phase Lockig Two-phase lockig protocol All lockig operatios precede the first ulock operatio i the trasactio Phases Expadig (growig) phase New locks ca be acquired but oe ca be released Lock coversio upgrades must be doe durig this phase Shrikig phase Existig locks ca be released but oe ca be acquired Dowgrades must be doe durig this phase Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-10

Figure 21.3 Trasactios that do ot obey two-phase lockig (a) Two trasactios T1 ad T2 (b) Results of possible serial schedules of T1 ad T2 (c) A oserializable schedule S that uses locks Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-11

Guarateeig Serializability by Two- Phase Lockig If every trasactio i a schedule follows the twophase lockig protocol, schedule guarateed to be serializable Two-phase lockig may limit the amout of cocurrecy that ca occur i a schedule Some serializable schedules will be prohibited by two-phase lockig protocol Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-12

Variatios of Two-Phase Lockig Basic 2PL Techique described o previous slides Coservative (static) 2PL Requires a trasactio to lock all the items it accesses before the trasactio begis Predeclare read-set ad write-set Deadlock-free protocol Strict 2PL Trasactio does ot release exclusive locks util after it commits or aborts Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-13

Variatios of Two-Phase Lockig (cot d.) Rigorous 2PL Trasactio does ot release ay locks util after it commits or aborts Cocurrecy cotrol subsystem resposible for geeratig read_lock ad write_lock requests Lockig geerally cosidered to have high overhead Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-14

Dealig with Deadlock ad Starvatio Deadlock Occurs whe each trasactio T i a set is waitig for some item locked by some other trasactio T Both trasactios stuck i a waitig queue Figure 21.5 Illustratig the deadlock problem (a) A partial schedule of T1 ad T2 that is i a state of deadlock (b) A wait-for graph for the partial schedule i (a) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-15

Dealig with Deadlock ad Starvatio (cot d.) Deadlock prevetio protocols Every trasactio locks all items it eeds i advace Orderig all items i the database Trasactio that eeds several items will lock them i that order Both approaches impractical Protocols based o a timestamp Wait-die Woud-wait Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-16

Dealig with Deadlock ad Starvatio (cot d.) No waitig algorithm If trasactio uable to obtai a lock, immediately aborted ad restarted later Cautious waitig algorithm Deadlock-free Deadlock detectio System checks to see if a state of deadlock exists Wait-for graph Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-17

Dealig with Deadlock ad Starvatio (cot d.) Victim selectio Decidig which trasactio to abort i case of deadlock Timeouts If system waits loger tha a predefied time, it aborts the trasactio Starvatio Occurs if a trasactio caot proceed for a idefiite period of time while other trasactios cotiue ormally Solutio: first-come-first-served queue Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-18

21.2 Cocurrecy Cotrol Based o Timestamp Orderig Timestamp Uique idetifier assiged by the DBMS to idetify a trasactio Assiged i the order submitted Trasactio start time Cocurrecy cotrol techiques based o timestamps do ot use locks Deadlocks caot occur Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-19

Cocurrecy Cotrol Based o Timestamp Orderig (cot d.) Geeratig timestamps Couter icremeted each time its value is assiged to a trasactio Curret date/time value of the system clock Esure o two timestamps are geerated durig the same tick of the clock Geeral approach Eforce equivalet serial order o the trasactios based o their timestamps Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-20

Cocurrecy Cotrol Based o Timestamp Orderig (cot d.) Timestamp orderig (TO) Allows iterleavig of trasactio operatios Must esure timestamp order is followed for each pair of coflictig operatios Each database item assiged two timestamp values read_ts(x) write_ts(x) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-21

Cocurrecy Cotrol Based o Timestamp Orderig (cot d.) Basic TO algorithm If coflictig operatios detected, later operatio rejected by abortig trasactio that issued it Schedules produced guarateed to be coflict serializable Starvatio may occur Strict TO algorithm Esures schedules are both strict ad coflict serializable Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-22

Cocurrecy Cotrol Based o Timestamp Orderig (cot d.) Thomas s write rule Modificatio of basic TO algorithm Does ot eforce coflict serializability Rejects fewer write operatios by modifyig checks for write_item(x) operatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-23

21.3 Multiversio Cocurrecy Cotrol Techiques Several versios of a item are kept by a system Some read operatios that would be rejected i other techiques ca be accepted by readig a older versio of the item Maitais serializability More storage is eeded Multiversio currecy cotrol scheme types Based o timestamp orderig Based o two-phase lockig Validatio ad sapshot isolatio techiques Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-24

Multiversio Cocurrecy Cotrol Techiques (cot d.) Multiversio techique based o timestamp orderig Two timestamps associated with each versio are kept read_ts(x i ) write_ts(x i ) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-25

Multiversio Cocurrecy Cotrol Techiques (cot d.) Multiversio two-phase lockig usig certify locks Three lockig modes: read, write, ad certify Figure 21.6 Lock compatibility tables (a) Lock compatibility table for read/write lockig scheme (b) Lock compatibility table for read/write/certify lockig scheme Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-26

21.4 Validatio (Optimistic) Techiques ad Sapshot Isolatio Cocurrecy Cotrol Optimistic techiques Also called validatio or certificatio techiques No checkig is doe while the trasactio is executig Updates ot applied directly to the database util fiished trasactio is validated All updates applied to local copies of data items Validatio phase checks whether ay of trasactio s updates violate serializability Trasactio committed or aborted based o result Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-27

Cocurrecy Cotrol Based o Sapshot Isolatio Trasactio sees data items based o committed values of the items i the database sapshot Does ot see updates that occur after trasactio starts Read operatios do ot require read locks Write operatios require write locks Temporary versio store keeps track of older versios of updated items Variatio: serializable sapshot isolatio (SSI) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-28

21.5 Graularity of Data Items ad Multiple Graularity Lockig Size of data items kow as graularity Fie (small) Coarse (large) Larger the data item size, lower the degree of cocurrecy permitted Example: etire disk block locked Smaller the data item size, more locks required Higher overhead Best item size depeds o trasactio type Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-29

Multiple Graularity Level Lockig Lock ca be requested at ay level Figure 21.7 A graularity hierarchy for illustratig multiple graularity level lockig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-30

Multiple Graularity Level Lockig (cot d.) Itetio locks are eeded Trasactio idicates alog the path from the root to the desired ode, what type of lock (shared or exclusive) it will require from oe of the ode s descedats Itetio lock types Itetio-shared (IS) Shared locks will be requested o a descedat ode Itetio-exclusive (IX) Exclusive locks will be requested Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-31

Multiple Graularity Level Lockig (cot d.) Itetio lock types (cot d.) Shared-itesio-exclusive (SIX) Curret ode is locked i shared mode but oe or more exclusive locks will be requested o a descedat ode Figure 21.8 Lock compatibility matrix for multiple graularity lockig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-32

Multiple Graularity Level Lockig (cot d.) Multiple graularity lockig (MGL) protocol rules Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-33

21.6 Usig Locks for Cocurrecy Cotrol i Idexes Two-phase lockig ca be applied to B-tree ad B+ -tree idexes Nodes of a idex correspod to disk pages Holdig locks o idex pages could cause trasactio blockig Other approaches must be used Coservative approach Lock the root ode i exclusive mode ad the access the appropriate child ode of the root Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-34

Usig Locks for Cocurrecy Cotrol i Idexes (cot d.) Optimistic approach Request ad hold shared locks o odes leadig to the leaf ode, with exclusive lock o the leaf B-lik tree approach Siblig odes o the same level are liked at every level Allows shared locks whe requestig a page Requires lock be released before accessig the child ode Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-35

21.7 Other Cocurrecy Cotrol Issues Isertio Whe ew data item is iserted, it caot be accessed util after operatio is completed Deletio operatio o the existig data item Write lock must be obtaied before deletio Phatom problem Ca occur whe a ew record beig iserted satisfies a coditio that a set of records accessed by aother trasactio must satisfy Record causig coflict ot recogized by cocurrecy cotrol protocol Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-36

Other Cocurrecy Cotrol Issues (cot d.) Iteractive trasactios User ca iput a value of a data item to a trasactio T based o some value writte to the scree by trasactio T, which may ot have committed Solutio approach: postpoe output of trasactios to the scree util committed Latches Locks held for a short duratio Do ot follow usual cocurrecy cotrol protocol Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-37

21.8 Summary Cocurrecy cotrol techiques Two-phase lockig Timestamp-based orderig Multiversio protocols Sapshot isolatio Data item graularity Lockig protocols for idexes Phatom problem ad iteractive trasactio issues Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 21-38