Wolfgang Miller / 02.07.2009 / 1 Concurrency Controll Algorithms Concurrency Control Algorithms Chapter 4.

Slides:



Advertisements
Similar presentations
Concurrency Control III. General Overview Relational model - SQL Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Advertisements

Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
Database Systems (資料庫系統)
Unit 9 Concurrency Control. 9-2 Wei-Pang Yang, Information Management, NDHU Content  9.1 Introduction  9.2 Locking Technique  9.3 Optimistic Concurrency.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
Concurrency Control II
Concurrency Control Enforcing Serializability by Locks
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Concurrency Control Part 2 R&G - Chapter 17 The sequel was far better than the original! -- Nobody.
Universität Karlsruhe (TH) © 2006 Univ,Karlsruhe, IPD, Prof. Lockemann/Prof. BöhmTAV 4 Chapter 4 Isolation: Correctness in the read/write model.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
1 Supplemental Notes: Practical Aspects of Transactions THIS MATERIAL IS OPTIONAL.
Tree Locking Protocol Silberchatz and Kedem, JACM, January1980.
Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.
CONCURRENCY CONTROL SECTION 18.7 THE TREE PROTOCOL By : Saloni Tamotia (215)
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
Session - 13 CONCURRENCY CONTROL CONCURRENCY TECHNIQUE Matakuliah: M0184 / Pengolahan Data Distribusi Tahun: 2005 Versi:
Concurrency. Busy, busy, busy... In production environments, it is unlikely that we can limit our system to just one user at a time. – Consequently, it.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
Transactions or Concurrency Control. Introduction A program which operates on a DB performs 2 kinds of operations: –Access to the Database (Read/Write)
Concurrency. Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
Concurrency Control John Ortiz.
© 1997 UW CSE 11/13/97N-1 Concurrency Control Chapter 18.1, 18.2, 18.5, 18.7.
Concurrency Control In Dynamic Database Systems Laurel Jones.
Academic Year 2014 Spring Academic Year 2014 Spring.
CIS 720 Concurrency Control. Locking Atomic statement –Can be used to perform two or more updates atomically Th1: …. ;……. Th2:…………. ;…….
08_Transactions_LECTURE2 DBMSs should guarantee ACID properties (Atomicity, Consistency, Isolation, Durability). This is typically done by guaranteeing.
Concurrency Control Lectured by, Jesmin Akhter, Assistant professor, IIT, JU.
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
Concurrency Server accesses data on behalf of client – series of operations is a transaction – transactions are atomic Several clients may invoke transactions.
Assignment 3 -- Solution 1. Problem 1 H 1 : r 1 [y] r 1 [x] r 2 [x] w 1 [y] c 1 w 2 [y] c 2 H 1 is normally-strict two-phase locked: rl 1 [y] r 1 [y]
Concurrency Control in Database Operating Systems.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
Concurrency Chapter 6.2 V3.1 Napier University Dr Gordon Russell.
Page 1 Concurrency Control Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
CSE544: Transactions Concurrency Control Wednesday, 4/26/2006.
Timestamp-based Concurrency Control
Multidatabase Transaction Management COP5711. Multidatabase Transaction Management Outline Review - Transaction Processing Multidatabase Transaction Management.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
Jinze Liu. Tree-based concurrency control Validation concurrency control.
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li.
1 Controlled concurrency Now we start looking at what kind of concurrency we should allow We first look at uncontrolled concurrency and see what happens.
Database Isolation Levels. Reading Database Isolation Levels, lecture notes by Dr. A. Fekete, resentation/AustralianComputer.
CS411 Database Systems Kazuhiro Minami 16: Final Review Session.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Assignment 6 - Solution Problem 1 Suppose a transaction sets an intention-write lock on a file and later sets a write lock on a record of the file. Is.
6/18/2016Transactional Information Systems3-1 Part II: Concurrency Control 3 Concurrency Control: Notions of Correctness for the Page Model 4 Concurrency.
Concurrency Control Techniques
Concurrency Control Algorithms (4.4~4.6)
Concurrency Control via Validation
Outline Introduction Background Distributed DBMS Architecture
4. Concurrency control techniques
CIS 720 Concurrency Control.
Concurrency Control II (OCC, MVCC)
Chapter 10 Transaction Management and Concurrency Control
Concurrency Control Chapter 17
Transactional Information Systems:
Distributed Database Management Systems
Concurrency Control Chapter 17
Presentation transcript:

Wolfgang Miller / / 1 Concurrency Controll Algorithms Concurrency Control Algorithms Chapter 4

Wolfgang Miller / / 2 Concurrency Controll Algorithms Overview I.Introduction o Basics II.Locking schedulers o Two-Phase Locking Non-Two-Phase Locking Protocols o Write-Only Tree Locking o Read/Write Tree Locking III. Non-locking schedulers o Timestamp Ordering IV.Optimistic schedulers o BOCC

Wolfgang Miller / / 3 Concurrency Controll Algorithms Overview I.Introduction  Basics II.Locking schedulers o Two-Phase Locking Non-Two-Phase Locking Protocols o Write-Only Tree Locking o Read/Write Tree Locking III. Non-locking schedulers o Timestamp Ordering IV.Optimistic schedulers o BOCC

Wolfgang Miller / / 4 Concurrency Controll Algorithms CSR – Class of conflict-serializable schedules Definition: Conflict Equivalence Schedules s and s‘ are conflict equivalent (denoted s  c s‘), if: op(s) = op(s‘) and conf(s) = conf(s‘). Definition: Conflicts and Conflict Relations Let s be a schedule, t, t‘  trans(s), t  t‘. (i)Two data operations p  t and q  t‘ are in conflict in s if they access the same data item and at least one of them is a write. i.e., (p = r(x) ˄ q = w(x)) ˅ (p = w(x) ˄ q = r(x)) ˅ (p = w(x) ˄ q = w(x)) (ii){(p, q)} | p, q are in conflict and p occurs before q in s} is the conflict relation of s.

Wolfgang Miller / / 5 Concurrency Controll Algorithms CSR – Class of conflict-serializable schedules Definition: Conflict Serializability: Schedule s is conflict serializable if there is a serial schedule s‘ such that s  c s‘. CSR denotes the class of all conflict serializable schedules. Example: s 1 = r 1 (x) r 2 (x) r 1 (z) w 1 (x) w 2 (y) r 3 (z) w 3 (y) c 1 c 2 w 3 (z) c 3  CSR s 2 = r 2 (x) w 2 (x) r 1 (x) r 1 (y) r 2 (y) w 2 (y) c 1 c 2  CSR t 2 writes on x before t 1 read x

Wolfgang Miller / / 6 Concurrency Controll Algorithms Scheduler Actions and Transaction States Definition: CSR Safety For a scheduler S, Gen(S) denotes the set of all schedules that S can generate. A scheduler is called CSR safe if Gen(S)  CSR All of the following algorithms are CSR safe

Wolfgang Miller / / 7 Concurrency Controll Algorithms Scheduler Classification Schedulers can be classified as pessimistic or optimistic:  optimistic Schedulers:  also called „aggressiv“, because they mostly let steps pass and rarely block. This bears the danger of „getting stuck“ eventually when the serializability of the output can no longer be guaranteed  pessimistic Schedulers:  also called „conservative“, because they mostly block, in extreme, albeit unlikely case, the output could become a serial schedule, if all transactions but one were blocked.

Wolfgang Miller / / 8 Concurrency Controll Algorithms Scheduler Classification – Algorithms Overview

Wolfgang Miller / / 9 Concurrency Controll Algorithms Overview I.Introduction basics II.Locking schedulers  Two-Phase Locking Non-Two-Phase Locking Protocols o Write-Only Tree Locking o Read/Write Tree Locking III. Non-locking schedulers o Timestamp Ordering IV.Optimistic schedulers o BOCC

Wolfgang Miller / / 10 Concurrency Controll Algorithms Locking Schedulers In a nuthsell this means that if a transaction holds a lock on a specific data item, this item is not available to other, concurrent transactions The Idea behind locking schedules is to synchronize access to shared data by using locks. lock notation: rl(x)  read lock x wl(x)  write lock x ru(x)  write unlock x wu(x)  write unlock x compatibility of locks:

Wolfgang Miller / / 11 Concurrency Controll Algorithms Rules for well-formed locking LR1: If t i contains a step of the form r i (x)[w i (x)], then the schedule s also contains a step of the form rl i (x)[wl i (x)] before the data operation. Moreover s contains a step of the form ru i (x)[wu i (x)] somewhere after the operation. LR2: For each x accessed by t i, schedule s has at most one rl i (x) and at most one wl i (x) step.  locks of the same type are set at most once per transaction and per data item. LR3: No step of the form ru i (.) or wu i (.) is redundant (i.e., executed per transaction more than once) LR4: If x is held locked by both t i and t j for t i, t j  trans(s), i ≠ j, then these locks are not in conflict (i.e., they are compatible)

Wolfgang Miller / / 12 Concurrency Controll Algorithms Two-Phase Locking (2PL) - Definition Definition: Two-Phase Locking A locking protocol is two-phase if for every output s and every transaction t i  trans(s) is true that no ql i step follows the first ou i step (o,q  {r, w}). A locking protocol is two-phase if for every transaction a phase during which locks are set is distinguished from and strictly followed by a phase during which locks are released.

Wolfgang Miller / / 13 Concurrency Controll Algorithms Two-Phase Locking (2PL) - Example 2PL Example : s = w 1 (x) r 2 (x) w 1 (y) w 1 (z) r 3 (z) c 1 w 2 (y) w 3 (y) c 2 w 3 (z) c 3 wl 1 (x) w 1 (x) wl 1 (y) w 1 (y) wl 1 (z) w 1 (z) wu 1 (x) rl 2 (x) r 2 (x) wu 1 (y) wu 1 (z) c 1 rl 3 (z) r 3 (z) wl 2 (y) w 2 (y) wu 2 (y) ru 2 (x) c 2 wl 3 (y) w 3 (y) wl 3 (z) w 3 (z) wu 3 (z) wu 3 (y) c 3 A 2PL output could be:

Wolfgang Miller / / 14 Concurrency Controll Algorithms Overview I.Introduction basics II.Locking schedulers Two-Phase Locking Non-Two-Phase Locking Protocols  Write-Only Tree Locking  Read/Write Tree Locking III. Non-locking schedulers o Timestamp Ordering IV.Optimistic schedulers o BOCC V.Hybrid Schedulers

Wolfgang Miller / / 15 Concurrency Controll Algorithms Non-Two-Phase Locking Protocols The following two tree-based protocols are geared for transactions that exhibit treelike access patterns. In other cases they are susceptible to degradation. The data items are viewed as nodes of a tree and accesses have to follow a path down the tree. On the next slides we will have a look at those two tree-based locking schedulers: Write-Only Tree LockingRead/Write Tree Locking

Wolfgang Miller / / 16 Concurrency Controll Algorithms Write-Only Tree Locking (WTL) Note: the tree is a virtual data organization only, the relationship between the data items can be quite different Under the write-only tree locking protocol, lock requests and releases must obey the locking rules LR1-LR4 and the following two rules on the next slide: The Write-Only Tree Locking protocol uses a tree to organize the data items. In its model read operations are missing, they would cause problems we will see later. Thus a transaction can only write data (or read and write are applied to the same item as collapsed into one operation).

Wolfgang Miller / / 17 Concurrency Controll Algorithms Write-Only Tree Locking (WTL) WTL1: If x is any node in the tree other than the root, wl i (x) can be set only if t i currently holds a write lock on y, where y is parent of x WTL2: After a wu i (x), no further wl i (x) is allowed (on the same data item x) Example: if a transaction t = w(c)w(e) wants to acquire wl(c) or wl(e) it has to hold wl(b)

Wolfgang Miller / / 18 Concurrency Controll Algorithms Write-Only Tree Locking (WTL) Sample Transaction under the WTL protocol: transaction t = w(d)w(i)w(k) wl(a)wl(b)wu(a)wl(d)wl(e)wu(b)w(d)wu(d)wl(i)wu(e)w(i) wl(k)wu(i)w(k)wu(k)

Wolfgang Miller / / 19 Concurrency Controll Algorithms Read/Write Tree Locking (RWTL) The Read/Write Tree Locking is a generalization of the Write- Only Tree Locking protocol. Unlike the the Write-Only Tree Locking protocol it supports seperate read operations, too.

Wolfgang Miller / / 20 Concurrency Controll Algorithms Read/Write Tree Locking (RWTL) Problem: t i locks root before t j does, but t j passes t i within a “read zone” Example: rl 1 (a) rl 1 (b) r 1 (a) r 1 (b) wl 1 (a) w 1 (a) wl 1 (b) ul 1 (a) rl 2 (a) r 2 (a) w 1 (b) rl 1 (e) ul 1 (b) rl 2 (b) r 2 (b) ul 2 (a) rl 2 (e) rl 2 (i) ul 2 (b) r 2 (e) r 1 (e) r 2 (i) wl 2 (i) w 2 (i) wl 2 (k) ul 2 (e) ul 2 (i) rl 1 (i) ul 1 (e) r 1 (i)... Solution: formalize “read zone” and enforce two-phase property on “read zones”. This zones are called pitfall. appears to follow TL rules but  CSR

Wolfgang Miller / / 21 Concurrency Controll Algorithms Read/Write Tree Locking (RWTL) Definition: Read-Write Tree Locking Under the RWTL lock requests and releases must obey LR1 - LR4, WTL1, WTL2, and the two-phase property within each pitfall. Definition: pitfall For transaction t with read set RS(t) and write set WS(t) let C 1,..., C m be the connected components of RS(t). A pitfall of t is a set of the form C i  {x  WS(t) | x is a child or parent of some y  C i }.

Wolfgang Miller / / 22 Concurrency Controll Algorithms Read/Write Tree Locking (RWTL) Example: transaction t with RS(t) = {f, i, g} and WS(t) = {c, l, j, k, o} has pitfalls pf 1 ={c, f, i, l, j} and pf 2 ={g, c, k}.

Wolfgang Miller / / 23 Concurrency Controll Algorithms Overview I.Introduction basics II.Locking schedulers Two-Phase Locking Non-Two-Phase Locking Protocols Write-Only Tree Locking Read/Write Tree Locking III. Non-locking schedulers  Timestamp Ordering IV.Optimistic schedulers o BOCC V.Hybrid Schedulers

Wolfgang Miller / / 24 Concurrency Controll Algorithms Nonlocking Schedulers The next two protocols are alternatives to locking schedulers. They guarantee safety of their output without using locks. The first one is the Basic Time Stamp Ordering, which counts to the pessimistic protocols and with the BOCC protocol we will also see an optimistic scheduler

Wolfgang Miller / / 25 Concurrency Controll Algorithms Timestamp Ordering (TO) Timestamp Ordering Rule (TO rule): Each transaction t i is assigned a unique timestamp ts(t i ) (e.g., the time of t i ‘s beginning). If p i (x) and q j (x) are in conflict, then the following must hold: p i (x) is executed before q j (x) iff ts(t i ) < ts(t j ). Timestamp Ordering protocols get rid of locks and use timestamps instead.

Wolfgang Miller / / 26 Concurrency Controll Algorithms Basic Timestamp Odering (BTO) Basic timestamp ordering protocol (BTO): For each data item x maintain max-r-scheduled(x): the value of the largest timestamp of a read operation on x already sent to the scheduler max-w-scheduled(x): the value of the largest timestamp of a write operation on x already sent to the scheduler Operation p i (x) is compared to max-q (x) for each conflicting q: if ts(t i ) < max-q (x) for some q then abort t i else schedule p i (x) for execution and set max-p (x) to ts(t i )

Wolfgang Miller / / 27 Concurrency Controll Algorithms Basic Timestamp Ordering (BTO) BTO Example: s = r 1 (x) w 2 (x) r 3 (y) w 2 (y) c 2 w 3 (z) c 3 r 1 (z) c 1 r 1 (x) w 2 (x) r 3 (y) a 2 w 3 (z) c 3 a 1

Wolfgang Miller / / 28 Concurrency Controll Algorithms Scheduler Classification – Algorithms Overview

Wolfgang Miller / / 29 Concurrency Controll Algorithms Overview I.Introduction basics II.Locking schedulers Two-Phase Locking Non-Two-Phase Locking Protocols Write-Only Tree Locking Read/Write Tree Locking III. Non-locking schedulers Timestamp Ordering IV.Optimistic schedulers  BOCC V.Hybrid Schedulers

Wolfgang Miller / / 30 Concurrency Controll Algorithms Optimistic Protocols In some scenarios optmistic protocols can do a better job then pessimistic. A product catalog application where 99% of the transactions are just read price information and descriptions of products. From time to time prices are updated or new products are added, but this occurs with a very low frequency compared to the read events.  A 2PL protocol for example would waste a considerable amount of time for managing locks, instead of reading data items. optimistic schedulers do a good job in cases were conflicts aren‘t frequent

Wolfgang Miller / / 31 Concurrency Controll Algorithms The three phases of a optimistic scheduler 1. Read phase: The transaction is executed, but all writes applied to a workspace private to the transaction only (not the database) 2. Validation phase: The scheduler tests if its execution has been „correct“ in the sense of conflict serializability and whether the result can be copied to database – if not the transaction is aborted, otherwise the next phase is entered 3. Write phase: The workspace contents are transferred into the database to conclude the transaction

Wolfgang Miller / / 32 Concurrency Controll Algorithms BOCC BOCC validation of t j : compare t j to all previously committed t i accept t j if one of the following holds t i has ended before t j has started, or RS(t j )  WS(t i ) =  and t i has validated before t j Under backward-oriented optimistic concurrency control (BOCC), a transaction under validation executes a conflict test against all those transactions that are already committed.

Wolfgang Miller / / 33 Concurrency Controll Algorithms BOCC Example: Execution of BOCC

Wolfgang Miller / / 34 Concurrency Controll Algorithms Overview I.Introduction Basics II.Locking schedulers Two-Phase Locking Non-Two-Phase Locking Protocols Write-Only Tree Locking Read/Write Tree Locking III. Non-locking schedulers Timestamp Ordering IV.Optimistic schedulers BOCC

Wolfgang Miller / / 35 Concurrency Controll Algorithms Thank you for your attention. Any questions?

Wolfgang Miller / / 36 Concurrency Controll Algorithms Database System Layers 1.Language & Interface Layer 2.Query Decomposition & Optimization Layer 3.Query Execution Layer 4.Access Layer 5.Storage Layer

Wolfgang Miller / / 37 Concurrency Controll Algorithms A transaction scheduler

Wolfgang Miller / / 38 Concurrency Controll Algorithms A Transaction Scheduler  Transaction Manager (TM)  Data Manager (DM)

Wolfgang Miller / / 39 Concurrency Controll Algorithms Write-Only Tree Locking (WTL) Lemma: If transaction t i locks x before t j, then each successor v of x in the data tree is locked by both t i and t j is also locked by t i before it is locked by t j