Locking to ensure serializability

Σχετικά έγγραφα
Αρχεία και Βάσεις Δεδομένων

2 Composition. Invertible Mappings

The challenges of non-stable predicates

Transaction Processing (Διαχείριση Δοσοληψιών)

The Simply Typed Lambda Calculus

Αρχεία και Βάσεις Δεδομένων

C.S. 430 Assignment 6, Sample Solutions

Συστήματα Διαχείρισης Βάσεων Δεδομένων

Finite Field Problems: Solutions

Nowhere-zero flows Let be a digraph, Abelian group. A Γ-circulation in is a mapping : such that, where, and : tail in X, head in

Every set of first-order formulas is equivalent to an independent set

Example Sheet 3 Solutions

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

Section 8.3 Trigonometric Equations

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

EE512: Error Control Coding

Instruction Execution Times

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

6.1. Dirac Equation. Hamiltonian. Dirac Eq.

derivation of the Laplacian from rectangular to spherical coordinates

Συστήματα Διαχείρισης Βάσεων Δεδομένων

Lecture 2. Soundness and completeness of propositional logic

Homework 3 Solutions

Bounding Nonsplitting Enumeration Degrees

Econ 2110: Fall 2008 Suggested Solutions to Problem Set 8 questions or comments to Dan Fetter 1

Inverse trigonometric functions & General Solution of Trigonometric Equations

Στο εστιατόριο «ToDokimasesPrinToBgaleisStonKosmo?» έξω από τους δακτυλίους του Κρόνου, οι παραγγελίες γίνονται ηλεκτρονικά.

Fractional Colorings and Zykov Products of graphs

TMA4115 Matematikk 3

Other Test Constructions: Likelihood Ratio & Bayes Tests

Section 9.2 Polar Equations and Graphs

4.6 Autoregressive Moving Average Model ARMA(1,1)

PARTIAL NOTES for 6.1 Trigonometric Identities

Lecture 2: Dirac notation and a review of linear algebra Read Sakurai chapter 1, Baym chatper 3

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Matrices and Determinants

Overview. Transition Semantics. Configurations and the transition relation. Executions and computation

Math221: HW# 1 solutions

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

Approximation of distance between locations on earth given by latitude and longitude

ANSWERSHEET (TOPIC = DIFFERENTIAL CALCULUS) COLLECTION #2. h 0 h h 0 h h 0 ( ) g k = g 0 + g 1 + g g 2009 =?

ST5224: Advanced Statistical Theory II

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

Concrete Mathematics Exercises from 30 September 2016

Jesse Maassen and Mark Lundstrom Purdue University November 25, 2013

Second Order RLC Filters

Partial Differential Equations in Biology The boundary element method. March 26, 2013

Assalamu `alaikum wr. wb.

Statistical Inference I Locally most powerful tests

Homework 8 Model Solution Section

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

CRASH COURSE IN PRECALCULUS

ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ Ι. Κεφάλαιο 6ο: Αδιέξοδα

Practice Exam 2. Conceptual Questions. 1. State a Basic identity and then verify it. (a) Identity: Solution: One identity is csc(θ) = 1

forms This gives Remark 1. How to remember the above formulas: Substituting these into the equation we obtain with

Numerical Analysis FMN011

Μηχανική Μάθηση Hypothesis Testing

Απόκριση σε Μοναδιαία Ωστική Δύναμη (Unit Impulse) Απόκριση σε Δυνάμεις Αυθαίρετα Μεταβαλλόμενες με το Χρόνο. Απόστολος Σ.

Fourier Series. MATH 211, Calculus II. J. Robert Buchanan. Spring Department of Mathematics

b. Use the parametrization from (a) to compute the area of S a as S a ds. Be sure to substitute for ds!

Mean bond enthalpy Standard enthalpy of formation Bond N H N N N N H O O O

DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.

Συστήματα Διαχείρισης Βάσεων Δεδομένων

k A = [k, k]( )[a 1, a 2 ] = [ka 1,ka 2 ] 4For the division of two intervals of confidence in R +

Χρονοδιάγραμμα/Χρονοπρόγραμμα

On a four-dimensional hyperbolic manifold with finite volume

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

Section 7.6 Double and Half Angle Formulas

department listing department name αχχουντσ ϕανε βαλικτ δδσϕηασδδη σδηφγ ασκϕηλκ τεχηνιχαλ αλαν ϕουν διξ τεχηνιχαλ ϕοην µαριανι

2. Let H 1 and H 2 be Hilbert spaces and let T : H 1 H 2 be a bounded linear operator. Prove that [T (H 1 )] = N (T ). (6p)

Exercises 10. Find a fundamental matrix of the given system of equations. Also find the fundamental matrix Φ(t) satisfying Φ(0) = I. 1.

6.3 Forecasting ARMA processes

( y) Partial Differential Equations

Reminders: linear functions

Math 6 SL Probability Distributions Practice Test Mark Scheme

ω ω ω ω ω ω+2 ω ω+2 + ω ω ω ω+2 + ω ω+1 ω ω+2 2 ω ω ω ω ω ω ω ω+1 ω ω2 ω ω2 + ω ω ω2 + ω ω ω ω2 + ω ω+1 ω ω2 + ω ω+1 + ω ω ω ω2 + ω

Srednicki Chapter 55

Right Rear Door. Let's now finish the door hinge saga with the right rear door

Areas and Lengths in Polar Coordinates

Solutions to Exercise Sheet 5

Block Ciphers Modes. Ramki Thurimella

Areas and Lengths in Polar Coordinates

Partial Trace and Partial Transpose

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 10η: Basics of Game Theory part 2 Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

Solution Series 9. i=1 x i and i=1 x i.

Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο

Solutions to the Schrodinger equation atomic orbitals. Ψ 1 s Ψ 2 s Ψ 2 px Ψ 2 py Ψ 2 pz

Démographie spatiale/spatial Demography

A Hierarchy of Theta Bodies for Polynomial Systems

1) Formulation of the Problem as a Linear Programming Model

Advanced Subsidiary Unit 1: Understanding and Written Response

Galatia SIL Keyboard Information

Φραγή σε πολλαπλά επίπεδα λεπτομέρειας Τι αντικείμενα κλειδώνουμε?

9.09. # 1. Area inside the oval limaçon r = cos θ. To graph, start with θ = 0 so r = 6. Compute dr

ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ. ΕΠΛ342: Βάσεις Δεδομένων. Χειμερινό Εξάμηνο Φροντιστήριο 10 ΛΥΣΕΙΣ. Επερωτήσεις SQL

Strain gauge and rosettes

Second Order Partial Differential Equations

Transcript:

Locking to ensure serializability Concurrent access to database items is controlled by strategies based on locking, timestamping or certification A lock is an access privilege to a single database item Lock Manager: manages the locks requested by transactions. Locks are obtained by transactions stored in a lock table Lock is an entry of the form (item, lock-type, transactionid) item is the item that the transaction locks lock-type can be shared or exclusive transactionid is the transaction identifier 1

Locking to Ensure Serializability Locking can prevent the lost update problem T 1 = Lock(A) R 1 (A) W 1 (A) Unlock(A) C 1 T 2 = Lock(A) R 2 (A) W 2 (A) Unlock(A) C 2 Under the locking policy, only serial execution of the transactions is permitted 2

Locking When a transaction holds an exclusive lock on a database item, no other transaction can read or write the item used for writing When a transaction holds a shared lock, other transactions can obtain a shared lock on the same item used for reading Assumptions (for now) there is a single type of lock and every transaction must obtain a lock on an item before accessing it. all items locked by a transaction must be unlocked, otherwise no other transaction may gain access to them. a transaction must wait until the lock it requests is released by the transaction that holds it. 3

Transaction Management 1. Locking can prevent the lost update problem: T 1 = Lock 1 (A) R 1 (A) W 1 (A) Unlock 1 (A) C 1 T 2 = Lock 2 (A) R 2 (A) W 2 (A) Unlock 2 (A) C 2 2. Locking enforces a serial execution of the transactions 3. Locking can also prevent the blind write problem: T 1 = Lock 1 (A) W 1 (A) Lock 1 (B) W 1 (B) Unlock 1 (A) Unlock 1 (B) C 1 T 2 = Lock 2 (A) W 2 (A) Lock 2 (B) W 2 (B) Unlock 2 (A) Unlock 2 (B) C 1 Then the following schedule is valid: Lock 1 (A) W 1 (A) Lock 1 (B) W 1 (B) Unlock 1 (A) Lock 2 (A) W 2 (A) Unlock 1 (B) Lock 2 (B) W 2 (B) Unlock 2 (A) Unlock 2 (B) C 1 C 2 4

LiveLock Undesirable phenomena if locks are granted in an arbitrary manner Example: while T2 is waiting for T1 to release the lock on A, another transaction T3 that has also requested a lock on A is granted the lock instead of T2. When T3 releases the lock on A the lock is granted to T4 etc. Livelock: The situation where a transaction may wait for ever while other transactions obtain a lock on a database item Can be avoided by using a first-come-first-served lock granting strategy but, even then a deadlock might occur 5

Deadlock Occurs when a transaction is waiting to lock an item that is currently locked by some other transaction Example: Consider the transactions: T 1 = Lock 1 (A) Lock 1 (B). Unlock 1 (A) Unlock 1 (B) C 1 T 2 = Lock 2 (B) Lock 2 (A). Unlock 2 (B) Unlock 1 (A) C 2 Assume T 1 is granted a lock on A and T 2 is granted a lock on B Then T 1 requests a lock on B but is forced to wait because T 2 has the lock on B. Similarly, T 2 requests a lock on A but is forced to wait because T 1 has the lock on A. Neither transaction can proceed because each is waiting for the other to release a lock: both processes wait for ever 6

Different solutions for Deadlocks Solution 1: Require each transaction to request all locks at once. Either all locks are granted or none. Solution 2: Assign an arbitrary linear order to the items and require all transactions to request their locks in that order. Solution 3: Do nothing to prevent deadlocks: abort one or more of the deadlocked transactions if a deadlock arises. 7

Deadlock Discovery Deadlocks can be discovered using wait-for graphs: Given a set of transactions S, a wait-for graph is a directed graph: vertices correspond to transactions in the set there exists an edge from T i to T j if T i is waiting to lock an item on which T j is holding a lock. Theorem: A set of transactions is deadlocked if and only if there exists a cycle in the wait-for graph. Example: The wait-for graph for the transactions contains a cycle T 1 = Lock 1 (A) Lock 1 (B). Unlock 1 (A) Unlock 1 (B) C 1 T 2 = Lock 2 (B) Lock 2 (A). Unlock 2 (B) Unlock 2 (A) C 2 T 1 T 2 8

2-Phase Locking (2PL) 2-Phase Locking (2PL): a protocol ensuring serializability of schedules Definition: A schedule is said to obey the 2-phase locking protocol if the following rules are obeyed by each transaction in the schedule 1. When a transaction attempts to read (write) a data item, a read lock (write lock) must be acquired first 2. If a transaction T 1 holds a lock on data item A for operation op 1 and some other transaction T 2 requests the lock to perform a conflicting operation op 2 on the same item, the transaction requesting the lock (T 2 ) is forced to wait until no conflicting lock on the item exists (only read locks are non-conflicting) 3 A transaction cannot request additional locks once it releases any lock! 9

2-Phase Locking (2PL): Conflicts two locks by the same transaction never conflict a transaction with a read lock on a data item can acquire a write lock on the item as long as no other transaction has a lock on the data item; a transaction with a write lock on a data item need not acquire a read lock on the same item. 2PL permits the early release of locks Notation: RL i : transaction T i obtains a read lock WL i : transaction T i obtains a write lock RU i : transaction T i releases a read lock WU i : transaction T i releases a write lock 10

2-Phase Locking (2PL): Example Does the following schedule obey the 2PL protocol? S = R 1 (A) R 2 (B) W 2 (B) R 2 (A) W 2 (A) R 1 (B) C 1 C 2 Lock/unlock operations must be added first. The schedule becomes: S = RL 1 (A) R 1 (A) RU 1 (A) RL 2 (B) R 2 (B) WL 2 (B) W 2 (B) WU 2 (B) RL 2 (A) R 2 (A) WL 2 (A) W 2 (A) RL 1 (B) R 1 (B) C 1 C 2 Rule 1 : no item is accessed without a lock being granted to the requested transaction obeyed 11

2-Phase Locking (2PL): Example Does the following schedule obey the 2PL protocol? S = R 1 (A) R 2 (B) W 2 (B) R 2 (A) W 2 (A) R 1 (B) C 1 C 2 Lock/unlock operations must be added first. The schedule becomes: S = RL 1 (A) R 1 (A) RU 1 (A) RL 2 (B) R 2 (B) WL 2 (B) W 2 (B) WU 2 (B) RL 2 (A) R 2 (A) WL 2 (A) W 2 (A) RL 1 (B) R 1 (B) C 1 C 2 Rule 2 : no two conflicting operations have a lock on the same item at the same time obeyed 12

2-Phase Locking (2PL): Example Does the following schedule obey the 2PL protocol? S = R 1 (A) R 2 (B) W 2 (B) R 2 (A) W 2 (A) R 1 (B) C 1 C 2 Lock/unlock operations must be added first. The schedule becomes: S = RL 1 (A) R 1 (A) RU 1 (A) RL 2 (B) R 2 (B) WL 2 (B) W 2 (B) WU 2 (B) RL 2 (A) R 2 (A) WL 2 (A) W 2 (A) RL 1 (B) R 1 (B) C 1 C 2 Rule 3: A transaction cannot request additional locks once it releases any lock! Violated! 13

2-Phase Locking (2PL): Example Applying the 2PL discipline to the schedule S = R 1 (A) R 2 (B) W 2 (B) R 2 (A) W 2 (A) R 1 (B) C 1 C 2 yields the following interleaved execution (all locks released at commit) T 1 RL 1 (A) R 1 (A) T 2 RL 2 (B) R 2 (B) WL 2 (B) W 2 (B) RL 2 (A) R 2 (A) WL 2 (A) T 1 RL 1 (B) wait abort restart C 1 T 2 wait W 2 (A) C 2 The deadlock had to be resolved by aborting and restarting one of the transactions. Under 2PL S is equivalent to the serial schedule T 2 T 1 14

2-Phase Locking (2PL): Example Theorem: A schedule that follows 2PL is always serializable. Example: The schedule S = R 1 (A) R 2 (A) W 1 (A) W 2 (A) C 1 C 2 is forced to execute as follows by a transaction scheduler that uses 2PL: T1 RL 1 (A) R 1 (A) WL 1 (A) wait abort T2 RL 2 (A) R 2 (A) WL 2 (A) wait T1 restart C 1 T2 W 2 (A) C2 If no locking was imposed S would be non-serializable 15

Transaction Management Example: Consider the following transactions T 1 : W 1 (U) R 1 (Y) W 1 (U) C 1 T 2 : R 2 (X) W 2 (U) W 2 (Y) W 2 (W) C 2 T 3 : W 3 (W) R 3 (X) W 3 (U) W 3 (Z) C 3 Is it possible to add lock/unlock steps to these transactions so that every legal schedule is serializable? Answer: yes by adding add lock/unlock steps using 2PL 16

Transaction Management 1. T 1 : W 1 (U) R 1 (Y) W 1 (U) C 1 2. T 2 : R 2 (X) W 2 (U) W 2 (Y) W 2 (W) C 2 3. T 3 : W 3 (W) R 3 (X) W 3 (U) W 3 (Z) C 3 T 1 T 2 RL 2 (X) WL 2 (U) wait T 3 WL 3 (W) RL 3 (X) WL 3 (U) WL 3 (Z) W 3 (W) T 1 WL 1 (U) T 2 wait wait wait wait wait WL 2 (Y) T 3 WU 3 (W) R 3 (X) RU 3 (X) W 3 (U) WU 3 (U) 17

Transaction Management 1. T 1 : W 1 (U) R 1 (Y) W 1 (U) C 1 2. T 2 : R 2 (X) W 2 (U) W 2 (Y) W 2 (W) C 2 3. T 3 : W 3 (W) R 3 (X) W 3 (U) W 3 (Z) C 3 T 1 wait wait wait wait wait RL 1 (Y) wait T 2 WL 2 (W) R 2 (X) W 2 (U) WU 2 (U) W 2 (Y) T 3 W 3 (Z) T 1 WL 1 (U) wait W 1 (U) R 1 (Y) W 1 (U) T 2 W 2 (W) WU 2 (W) C 2 T 3 WU 3 (Z) C 3 T 1 WU 1 (U) RU 1 (Y) WU 1 (Z) C 1 T 2 T 3 18