Defn. A schedule is called Serial if the operations of each individual Tx are performed sequentially.

Similar documents
More on Transactions and Concurrency. Serializability. Checking for Serializability

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

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

BCA204T: DATA BASE MANAGEMENT SYSTEMS


Database Management Systems 2010/11

DB2 Lecture 10 Concurrency Control

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


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

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

Introduction to Data Management CSE 344

Concurrency Control Algorithms

DATABASE DESIGN I - 1DL300

Transaction Processing: Basics - Transactions

5/17/17. Announcements. Review: Transactions. Outline. Review: TXNs in SQL. Review: ACID. Database Systems CSE 414.

CSE 444: Database Internals. Lectures Transactions

Database System Concepts

Database Systems CSE 414

Concurrency Control. Concurrency Control Ensures interleaving of operations amongst concurrent transactions result in serializable schedules

CSIT5300: Advanced Database Systems

Introduction to Data Management CSE 344

TRANSACTION PROCESSING CONCEPTS

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences. Dr. Anis Koubaa. Spring 2014

Introduction to Data Management CSE 344

Lecture 7: Transactions Concurrency Control

Introduction to Data Management CSE 344

Synchronization Part II. CS403/534 Distributed Systems Erkay Savas Sabanci University

Transaction Concept. Chapter 15: Transactions. Example of Fund Transfer. ACID Properties. Example of Fund Transfer (Cont.)

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

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Transactions. Lecture 8. Transactions. ACID Properties. Transaction Concept. Example of Fund Transfer. Example of Fund Transfer (Cont.

Concurrency Control in Distributed Systems. ECE 677 University of Arizona

Desirable properties of transactions ACID test

UNIT-IV TRANSACTION PROCESSING CONCEPTS

Operating Systems. Operating Systems Sina Meraji U of T

CSE 444: Database Internals. Lectures 13 Transaction Schedules

Transaction Management & Concurrency Control. CS 377: Database Systems

CS122 Lecture 15 Winter Term,

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

Midterm 1, CSE 451, Winter 2001 (Prof. Steve Gribble)

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

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

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

Transaction Management. Chapter 14

Chapter 15: Transactions

Transactions. Prepared By: Neeraj Mangla

Last Lecture. More Concurrency. Concurrency So Far. In This Lecture. Serialisability. Schedules. Database Systems Lecture 15

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

T ransaction Management 4/23/2018 1

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.

CSE 344 MARCH 5 TH TRANSACTIONS

Chapter 13: Transactions

BİL 354 Veritabanı Sistemleri. Transaction (Hareket)

Page 1. Goals of Today s Lecture" Two Key Questions" Goals of Transaction Scheduling"

Transactions These slides are a modified version of the slides of the book Database System Concepts (Chapter 15), 5th Ed

Database System Concepts

ICOM 5016 Database Systems. Chapter 15: Transactions. Transaction Concept. Chapter 15: Transactions. Transactions

Transaction Management

In This Lecture. Transactions and Recovery. Transactions. Transactions. Isolation and Durability. Atomicity and Consistency. Transactions Recovery

CS352 Lecture - Concurrency

Roadmap of This Lecture

Chapter 22. Transaction Management

CS322: Database Systems Transactions

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

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

Concurrency Control Techniques

Page 1. Goals of Todayʼs Lecture" Two Key Questions" Goals of Transaction Scheduling"

Database System Concepts

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

Chapter 15: Transactions

Transaction Concept. Two main issues to deal with:

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

CS352 Lecture - Concurrency

Transactions. Silberschatz, Korth and Sudarshan

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

Concurrent & Distributed Systems Supervision Exercises

Introduction to Data Management CSE 344

Database Technology. Topic 9: Concurrency Control

Transactions and Concurrency Control

CHAPTER: TRANSACTIONS

Database Management Systems Concurrency Control

Transactions and Concurrency Control

CSE 344 MARCH 21 ST TRANSACTIONS

UNIT 4 TRANSACTIONS. Objective

Recovery from failures

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

Chapter 9 Concurrency Control

Transactions: Definition. Concurrent transactions: Problems

CSE 344 MARCH 9 TH TRANSACTIONS

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

Implementing Isolation

Distributed Databases Systems

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

The transaction. Defining properties of transactions. Failures in complex systems propagate. Concurrency Control, Locking, and Recovery

Lecture 5: Transactions in SQL. Tuesday, February 6, 2007

Database Management System

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

CS 153 Design of Operating Systems Winter 2016

Intro to Transactions

Transcription:

C. Shadow Paging. (Doesn t require a log file) The database is made up of some number of disk pages. A "page table" is constructed with one entry per data page (The page address). When a Tx begins, the page table is copied to disk. This copy is called the "Shadow Page Table". When a data page is written upon, a completely new copy of the page is made containing the new/changed data. The address of the new page is entered on the current page table (in main memory) If an error occurs, roll back consists entirely of replacing the current page table by the shadow page table. Commit just means disposing of the shadow page table. Advantages: VERY FAST, no log required. Disadvantages: Page table can be large enough that maintaining it is costly Data pages move! Sequential processing is affected. Concurrency Control Defn. Given a set of transactions {T1,T2,...Tn}, a schedule S of that set is an ordering of the various operations in the Tx's, such that for any individual Tx, the operations are performed in the correct sequence. Defn. A schedule is called Serial if the operations of each individual Tx are performed sequentially. Defn. A schedule is called "serializable" if it is equivalent to some serial schedule... What does "equivalent" mean? 1 st try: Result equivalence. S1 is equivalent to a serial schedule S, if, after S1 has occurred the database is in the same state as it would be if S had executed. There is no way to check result equivalence without actually checking all possible serial schedules, and even if we could do that it might allow two schedules to be equivalent that really shouldn t be...complicated example T0: 5% raise rounded up to the nearest $10,000 T1: 1,000 raise Assume that the current salary is $100,000 T0 followed by T1: 100000->105000->110000->111000 T1 followed by T0: 100000->101,000->106050->110000

Consider the following schedule S1 <Read, T0, Salary, 100,000> s:=1.05*s <Read, T1, Salary, 100,000> S := S + 1000 <Write, T1, Salary, 100,000, 101,000> Round(s) <Write, T0, Salary, 100,000, 110,000> The net value of salary will be 110,000 so it satisfies the definition of Result Serializability, but it is an accident...do this for salary being 10000 and T0 rounded up to 1000. 2 nd try: State equivalence. S1 is equivalent to a serial schedule S, if, after S1 has occurred the database is in the same state as it would be if S had executed, for any possible original database state. This is very difficult to check. So there is a sufficient condition for a schedule to be serializable (the one used in most commercial databases), and it is called conflictserializability. In this sense we supply the next definition. The real definition (Conflict-serializability) Schedules S1 and S2 are equivalent if they can be turned one into the other by a sequence of nonconflicting swaps of adjacent actions Conflicts: Given two different transactions T i and T j 1) Read (T i, X) and Read (T j, Y) never conflict, even if X = Y. 2) Read (T i, X) and Write (T j, Y) conflict if X = Y. So do Read (T j, Y) and Write (T i, X), when X = Y. 3) Write (T i, X) and Write (T j, Y) conflict if X = Y. So do Write (T j, Y) and Write (T i, X) when X = Y. Investigate the previous example to see which kind of equivalence we are dealing with. Defn A schedule is serializable if it equivalent to some serial schedule. This second definition of serializability is strictly structural and can be checked merely by investigating the text of the two schedules.

Precedence Graphs and a Test for Conflict-Serializability. Because the conflicting actions put some constraints on the order of transactions, we can claim that if the constraints are not contradictory we can find a conflict-equivalent serial schedule. Defn. Given a schedule S involving transactions T 1 and T 2 (among others), we say that T 1 takes precedence over T 2 if there are actions A 1 of T 1 and A 2 of T 2 such that: 1. A 1 is ahead of A 2 in S, 2. Both A 1 and A 2 involve the same database element, and 3. At least one of A 1 and A 2 is a write action. Note that these are the conditions that keep us from swapping the order of A 1 and A 2. Precedence graph: The nodes of the precedence graph are the transactions of a schedule S, labeled according to the name of the transactions. There is an arc from node T i to node T j if Ti takes precedence over T j. Test for Conflict-Serializability: Construct the precedence graph for the schedule S. If there are any cycles, the schedule S is not conflict-serializable. Example: Consider the schedule S 1 T 1 T 2 T 3 Read(A,t) t := t + 100 Read(B,s) s := s + 25 Write(A,t) Read(A,v) v := v*1 Write(B,s) Write(A,v) Read(B,t) t := t*1.06 Write(B,t) Looking at the actions on the value B, we can easily justify that T 1 takes precedence over T 2. The actions on the value A, determine that T 2 takes precedence over T 3.

This graph does not have cycles, so it is possible to convert S 1 into the schedule in which all the actions of each of the three transactions occur in a serial order: T 1 T 2 T 3 Read(B,s) s := s + 25 Write(B,s) Read(A,t) t := t + 100 Write(A,t) Read(B,t) t := t*1.06 Write(B,t) Read(A,v) v := v*1 Write(A,v) On the other hand, if we consider the schedule S 2 with the same set of actions as before, but in different order: T 1 T 2 T 3 Read(A,t) t := t + 100 Read(B,s) s := s + 25 Write(A,t) Read(B,t) t := t*1.06 Read(A,v) v := v*1 Write(B,s) Write(A,v) Write(B,t) Here again examining the actions on A we see that T 2 takes precedence over T 3. But when we examine B, we see that T 1 takes precedence over T 2 [because Read( T 1, B) and

Write(T 1,B) appear before Write(T 2, B) ] but also T 2 takes precedence over T 1 [ because Read(T 2, B) appears before Write(T 1,B) ]. So the precedence graph for schedule S 2 would be NOTE: Finding cycles has a very nice theoretical touch, but it does not work in real situations. You need to have the complete schedule to inspect before you can decide. Unfortunately the interleaving of operations is done in real time, and you don t want to stop the process and start it all over again. This means that in realistic situations it is not feasible to prepare a schedule and then test it for serializability... What we have to do is to find a set of rules that we can impose on the way schedules are created so that we simply forbid non-serializable schedules. Unfortunately...we will be forced to exclude some otherwise serializable schedules and therefore compromise efficiency. Defn. A Lock is a variable associated to a data item that describes the availability of that item for access by a Tx's 1 st try Binary Locks. A lock may assume only the values 1 ( locked) and 0 ( unlocked). If the lock for a particular data item is 1, the item cannot be accessed by a Tx. The OS must support 2 new operations Lock(X){ if lock(x) == 0 lock(x) = 1 else while ( lock(x) == 1 ) continue; } Whatever Tx that successfully executes Lock(X) is said to hold a lock on X. Unlock(X){ lock(x) = 0; } The Binary Locking Protocol...Tx's must adhere to the following rules: 1.A Tx must successfully execute Lock(X) before it executes either Read(X) or Write(X). 2. A TX must execute Unlock(X) after all reads and writes are finished 3. If a Tx already holds a lock on X, it cannot execute Lock(X).

4. If a TX does not hold a lock on X, it may not execute Unlock(X). Example T0 Lock(S) Read(S) Update S TIMEOUT Write(S) Unlock(S) Commit T1 Lock(S) //refused TIMEOUT Lock(S) NOTE on implementation. The usual implementation of a locking scheme is via a separate "lock manager". Instead of a separate variable for every data item, the lock manager will maintain some kind of lock table which shows which Tx's hold locks on which data items. If several processes may request a particular data item, the OS may maintain a "locking queue" Lock(X) becomes if queue(x) is empty, place Tx at the head of the queue else place the Tx at the back of the queue. Unlock(X) consists of deleting the head of the queue. Multimode locking... a lock can have three values.. Read locked (a.k.a. Shared lock or S-Lock) Write locked (a.k.a. Exclusive lock or X-Lock). Unlocked, The locking scheme is a shown in the box: Request \ Value U S X S Granted Granted Refused X Granted Refused Refused The OS must support three primitive operations: read_lock(x) write_lock(x) unlock(x)

whose implementation is similar to the operations for binary locks. The multimode locking protocol...each Tx must follow the following set of rules: 1. A Tx must execute read_lock(x) or write_lock(x) before it executes read(x) 2. A Tx must execute write_lock(x) before it executes write(x) 3. A Tx must execute unlock(x) after all reads and writes have finished. 4. A Tx may not execute read_lock(x) it it already holds a read lock nor write_lock(x) if it holds a write lock. 5.A Tx may not execute unlock(x) unless it holds a lock on X. Multimode locking does not guarantee serializability. Example T0 read_lock(y) read(y, y) unlock(y) <Time out> write_lock(x) read(x,x) x = x+y write (X.x) Unlock(X) T1 read_lock(x) Read(X,x) Unlock(X) Write_lock(Y) Read(Y,y) Y = x+y Write(Y,y) Unlock(Y) Assume the intial values of X and Y are X = 20 and Y=30 then this schedule results in x=50 and y = 50, but the schedule T0T1 yields x=50, y=80, and the schedule T1T0 yields x=70, y=50 Also, using the precedence graph, we see that

Since Read (T0, Y) appears before Write (T1, Y), and similarly, T1 takes precedence over T0, because Read (T1, X) appears before Write (T0, X). Finally!! The two phase locking protocol (for either binary or multimode locking) Each Tx must go through two phases. In the first phase, a Tx may acquire new locks but no locks may be released. In the second phase, locks may be released, but no new locks may be acquired The net effect of TPLP is that once a Tx starts releasing locks, it can't acquire any new locks. Thrm: The TPLP guarantees serializability Pf: There are essentially 4 possible cases in which the test for serializability can be violated: case 1. T0 read(x,x) write(y,y).. T1.. write (X,x) read(y,y).. Its easy to show that this schedule cannot be made to satisify the TPLP other 3 cases...homework. TPLP doesn't solve all the problems: T0 read_lock(y) read(y) write_lock(x) T1 read_lock(x) read(x) write_lock(y) Defn. A situation in which a sequence of Tx's is waiting for another to finish in such a way that none can finish is called "deadlock"

Deadlock can be dealt with by 1. Deadlock avoidance (don t let it happen) 2. Deadlock detection and recovery 1. Deadlock can be avoided by using a more restricted locking protocol. First try: A Tx must request and be granted all locks before it begins any processing...(slows down concurrency a lot! ) Second try. A prioritized locking system. Data items are (partially) ordered. The protocol is A Tx's first lock request can be for any data item. After that a Tx cannot request a lock on a data item unless it already holds a lock on that data item s immediate superior. Example A / \ / \ B H / \ \ / \ \ C D I / \ / \ / \ / \ E F G K (If you need both B & H, you first have to lock A) The ordering can as simple as Tables -> pages-> records This system works but requires a lot of overhead 2. Deadlock detection: a. The "wait-for" graph is a bipartite graph, one of whose node sets corresponds to Tx's the other to a set of resources (data items)...draw a line from Ti to Dj if Ti has attempted to execute lock(dj)

Deadlock occurs if the wait for graph contains a cycle. b. brute force. Keep track of which processes are in a wait state. If more than 2 processes are in wait state for some number of seconds, assume that deadlock has occurred. In either case, Deadlock recovery means killing one or the other of the Tx's (causes a system error) ASIDE... multimode can also cause another problem called "livelock" Livelock can be avoided by T0 T1 T2 read_lock(x) write_lock(x) unlock(x) (Refused) read_lock(x) write_lock(x) 1. "Fair locking". All locking requests are queued. When a write_lock enters the queue, no more read_locks can be granted until the write_lock executes (read_locks must go behind the write lock on the queue). This works but can really screw up throughput 2. Priority queues and aging. All lock requests are given a priority..read_locks are always given higher priority. When unlock is executed, the lock holding the highest priority is then granted. Periodically, all requests in the queue are "aged", ie have their priority increased so eventually every lock is granted.