CS216: Data-Intensive Computing Systems

Slides:



Advertisements
Similar presentations
Cs4432concurrency control1 CS4432: Database Systems II Lecture #21 Concurrency Control : Theory Professor Elke A. Rundensteiner.
Advertisements

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.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Chapter 15: Transactions Transaction Concept Transaction Concept Concurrent Executions Concurrent Executions Serializability Serializability Testing for.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control Professor Elke A. Rundensteiner.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control: Locking-based Protocols Professor Elke A. Rundensteiner.
Lecture 12 Transactions: Isolation. Transactions What’s hard? – ACID – Concurrency control – Recovery.
Kyoung-Hwan Yun (#110). Conflicts Precedence Graphs and a Test for Conflict- Serializability.
1 CS216 Advanced Database Systems Shivnath Babu Notes 11: Concurrency Control.
Quick Review of Apr 29 material
Conflict-Serializability Bharath Kumar Manur Venkataramana Class ID No:- 110.
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Concurrency Control R&G - Chapter 17 Smile, it is the key that fits the lock of everybody's heart. Anthony J. D'Angelo, The College Blue Book.
1 Concurrency Control and Recovery Module 6, Lecture 1.
Transaction Processing: Concurrency and Serializability 10/4/05.
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 18.1 – 18.2 Chiu Luk CS257 Database Systems Principles Spring 2009.
CS4432: Database Systems II Transaction Management Motivation 1.
Transaction Processing Concepts
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
CS 162 Discussion Section Week 9 11/11 – 11/15. Today’s Section ●Project discussion (5 min) ●Quiz (10 min) ●Lecture Review (20 min) ●Worksheet and Discussion.
Introduction to Data Management CSE 344 Lecture 23: Transactions CSE Winter
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
Transactions. What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions developed.
Degrees of Isolation – A Theoretical Formulation Presented by Balaji Sethuraman.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
Concurrency (cont.) Schedule. In multiprogramming environment, Several transaction run concurrently Database consistency can be destroy Schedules to ensure.
Transaction Management and Recovery, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
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.
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
MULTIUSER DATABASES : Concurrency and Transaction Management.
Concurrency Control.
Chapter 14: Transactions
Transaction Management Overview
1 Introduction to Transaction Processing (1)
Database Management System
Transaction Management
Transactions.
Transaction Management Overview
March 21st – Transactions
Temple University – CIS Dept. CIS661 – Principles of Data Management
Transaction Management
Transaction Management Overview
Transactions Sylvia Huang CS 157B.
Lecture 21: Concurrency & Locking
CS162 Operating Systems and Systems Programming Review (II)
Conflict-Serializability (section 18.2 of Concurrency Control)
6.830 Lecture 12 Transactions: Isolation
Conflicts.
Transaction Management Overview
Lecture 22: Intro to Transactions & Logging IV
Transaction management
Transaction Management
CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule
Transaction Management Overview
C. Faloutsos Transactions
Temple University – CIS Dept. CIS616– Principles of Data Management
Locks.
UNIT -IV Transaction.
Lecture 18: Concurrency Control
Transaction Management Overview
Presentation transcript:

CS216: Data-Intensive Computing Systems Concurrency Control Shivnath Babu

Transaction Programming abstraction Implement real-world transactions Banking transaction Airline reservation

Transaction: Programmer’s Role Consistent State Transaction Consistent State

Transaction: System’s Role Atomicity All changes of the transaction recorded or none at all Durability All future transactions see the changes made by this transaction if it completes Isolation Net effect as if the transaction executed in isolation

Transaction: States Abort Begin Run Commit

Transaction Concept: Virtues and Limitations by Jim Gray Transactions Historical note: Turing Award for Transaction concept Jim Gray (1998) Interesting reading: Transaction Concept: Virtues and Limitations by Jim Gray http://www.hpl.hp.com/techreports/tandem/TR-81.3.pdf

Transaction: Programmer’s View See Section 8.6 of the textbook

Context We have seen: Next: Ensure atomicity in presence of failures Ensure Isolation during concurrency

Issues with Concurrency: Example Bank database: 3 Accounts A = 500 Account Balances B = 500 C = 500 Property: A + B + C = 1500 Money does not leave the system

Issues with Concurrency: Example Transaction T1: Transfer 100 from A to B A = 500, B = 500, C = 500 Read (A, t) t = t - 100 Write (A, t) Read (B, t) t = t + 100 Write (B, t) A = 400, B = 600, C = 500

Issues with Concurrency: Example Transaction T2: Transfer 100 from A to C Read (A, s) s = s - 100 Write (A, s) Read (C, s) s = s + 100 Write (C, s)

Transaction T1 Transaction T2 A B C 500 500 500 Read (A, t) t = t - 100 Read (A, s) s = s - 100 Write (A, s) 400 500 500 Write (A, t) 400 500 500 Read (B, t) t = t + 100 400 600 500 Write (B, t) Read (C, s) s = s + 100 Write (C, s) 400 600 600 400 + 600 + 600 = 1600

Transaction T1 Transaction T2 A B C 500 500 500 Read (A, t) t = t - 100 400 500 500 Write (A, t) Read (A, s) s = s - 100 Write (A, s) 300 500 500 Read (B, t) t = t + 100 300 600 500 Write (B, t) Read (C, s) s = s + 100 Write (C, s) 300 600 600 300 + 600 + 600 = 1500

Terminology Schedule: The exact sequence of (relevant) actions of one or more transactions

Problems Which schedules are “correct”? Mathematical characterization How to build a system that allows only “correct” schedules? Efficient procedure to enforce correctness

Correct Schedules: Serializability Initial database state is consistent Transaction: consistent state  consistent state Serial execution of transactions: Initial state  consistent state Serializable schedule: A schedule equivalent to a serial schedule Always “correct”

Serial Schedule A B C 500 500 500 Read (A, t) t = t - 100 T1 Write (A, t) Read (B, t) t = t + 100 Write (B, t) 400 600 500 Read (A, s) s = s - 100 Write (A, s) Read (C, s) T2 s = s + 100 Write (C, s) 300 600 600 300 + 600 + 600 = 1500

Serial Schedule A B C Read (A, s) 500 500 500 s = s - 100 Write (A, s) Read (C, s) s = s + 100 Write (C, s) 400 500 600 Read (A, t) t = t - 100 Write (A, t) T1 Read (B, t) t = t + 100 Write (B, t) 300 600 600 300 + 600 + 600 = 1500

Serial Schedule T1 Tn T2 Sn S0 S1 S2 Consistent States

Is this Serializable? Read (A, t) t = t - 100 Write (A, t) Read (A, s) Write (A, s) Read (B, t) t = t + 100 Write (B, t) Read (C, s) s = s + 100 Write (C, s) Transaction T1 Transaction T2

Equivalent Serial Schedule Read (A, t) t = t - 100 Write (A, t) Read (B, t) t = t + 100 Write (B, t) Read (A, s) s = s - 100 Write (A, s) Read (C, s) s = s + 100 Write (C, s) Transaction T1 Transaction T2

Is this Serializable? Read (A, t) t = t - 100 Read (A, s) s = s - 100 Write (A, s) Write (A, t) Read (B, t) No. In fact, it leads to inconsistent state t = t + 100 Write (B, t) Read (C, s) s = s + 100 Write (C, s) Transaction T1 Transaction T2

Is this Serializable? Read (A, t) t = t - 100 Read (A, s) s = s - 100 Write (A, s) Write (A, t) Read (B, t) t = t + 100 Write (B, t) Read (C, s) s = s + 100 Write (C, s) Transaction T1 Transaction T2

Is this Serializable? Read (A, t) t = t - 100 Read (A, s) s = s - 0 Write (A, s) Write (A, t) Yes, T2 is no-op Read (B, t) t = t + 100 Write (B, t) Read (C, s) s = s + 0 Write (C, s) Transaction T1 Transaction T2

Serializable Schedule Read (A, t) t = t - 100 Read (A, s) s = s - 0 Write (A, s) Write (A, t) Serializability depends on code details Read (B, t) t = t + 100 Write (B, t) Read (C, s) s = s + 0 Write (C, s) Transaction T1 Transaction T2

Serializable Schedule Read (A, t) t = t - 100 Write (A, t) Read (A, s) s = s - 100 Write (A, s) Read (B, t) Still Serializable! t = t + 100 Write (B, t) Read (C, s) s = s + 100 Write (C, s) Transaction T1 Transaction T2

Serializability General Serializability: Goal: weaker serializability Hard to determine Goal: weaker serializability Determined from database operations alone Database Operations: Reads, Writes, Inserts, …

Simpler Notation r (X) w (X) Transaction T reads X Transaction T writes X T

What is X in r (X)? X could be any component of a database: Attribute of a tuple Tuple Block in which a tuple resides A relation …

New Notation: Example Schedule r1(A) w1(A) r2(A) w2(A) r1(B) w1(B) r2(B) w2(B) time

Conflict Serializability Weaker notion of serializability Depends only on reads and writes

Conflict Serializability Serializable Schedules Conflict Serializable Schedules

Conflict Serializable Schedule Transformations: swap non-conflicting actions S S1 S2 Sn Conflict Serializable Schedule Serial Schedule

Transformation: Example r1(A) w1(A) r2(A) w2(A) r1(B) w1(B) r2(B) w2(B) r1(A) w1(A) r2(A) r1(B) w2(A) w1(B) r2(B) w2(B)

Non-Conflicting Actions Two actions are non-conflicting if whenever they occur consecutively in a schedule, swapping them does not affect the final state produced by the schedule. Otherwise, they are conflicting.

Conflicting or Non-Conflicting? (Work on paper: Example 1)

Conflicting Actions: General Rules Two actions of the same transaction conflict: r1(A) w1(B) r1(A) r1(B) Two actions over the same database element conflict, if one of them is a write r1(A) w2(A) w1(A) w2(A)

Conflict Serializability Examples (Work on paper: Example 2 and 3)

Testing Conflict Serializability Construct precedence graph G for given schedule S S is conflict-serializable iff G is acyclic

Graph Theory 101 Directed Graph: Nodes

Graph Theory 101 Directed Graph: Edges

Graph Theory 101 Directed Graph: Cycle

Graph Theory 101 Directed Graph: Not a cycle

Graph Theory 101 Acyclic Graph: A graph with no cycles

Graph Theory 101 Acyclic Graph:

Testing Conflict Serializability Construct precedence graph G for given schedule S S is conflict-serializable iff G is acyclic

Precedence Graph Precedence graph for schedule S: Nodes: Transactions in S Edges: Ti → Tj whenever S: … ri (X) … wj (X) … S: … wi (X) … rj (X) … S: … wi(X) … wj (X) … Note: not necessarily consecutive

Precedence Graph Ti → Tj whenever: There is an action of Ti that occurs before a conflicting action of Tj.

Precedence Graph Example (Work on paper: Example 4)

Testing Conflict Serializability Construct precedence graph G for given schedule S S is conflict-serializable iff G is acyclic

Correctness of precedence graph method (Work on paper)

Serializability vs. Conflict Serializability (Work on paper: Example 5)

View Serializability A schedule S is view serializable if there exists a serial schedule S’, such that the source of all reads in S and S’ are the same.

View Serializability Example View Serializable Schedule r2(B) w2(A) r1(A) r3(A) w1(B) w2(B) w3(B) Serial Schedule r2(B) w2(A) w2(B) r1(A) w1(B) r3(A) w3(B)

View Serializability Example View Serializable Schedule r2(B) w2(A) r1(A) r3(A) w1(B) w2(B) w3(B) Serial Schedule r2(B) w2(A) w2(B) r1(A) w1(B) r3(A) w3(B)

View Serializability Example View Serializable Schedule r2(B) w2(A) r1(A) r3(A) w1(B) w2(B) w3(B) Serial Schedule r2(B) w2(A) w2(B) r1(A) w1(B) r3(A) w3(B)

View Serializability Example View Serializable Schedule r2(B) w2(A) r1(A) r3(A) w1(B) w2(B) w3(B) Serial Schedule r2(B) w2(A) w2(B) r1(A) w1(B) r3(A) w3(B)

View Serializability Serializable Schedules Conflict Serializable Schedules View Serializable Schedules

Problems Which schedules are “correct”? Serializability theory How to build a system that allows only “correct” schedules? Efficient procedure to enforce correctness serializable schedules

Enforcing Serializability Tn reads/writes Strategy: Prevent precedence graph cycles? Scheduler DB

Next Enforcing serializability Locking-based techniques Timestamp-based techniques Validation-based techniques