1 CS216 Advanced Database Systems Shivnath Babu Notes 11: Concurrency Control.

Slides:



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

Database Systems (資料庫系統)
Conflict Serializability Example Murat Kantarcioglu.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Introduction to Database Systems1 Concurrency Control CC.Lecture 1.
1 Integrity Ioan Despi Transactions: transaction concept, transaction state implementation of atomicity and durability concurrent executions serializability,
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Lecture 12 Transactions: Isolation. Transactions What’s hard? – ACID – Concurrency control – Recovery.
Transactions (Chapter ). What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions.
Kyoung-Hwan Yun (#110). Conflicts Precedence Graphs and a Test for Conflict- Serializability.
Quick Review of Apr 29 material
Conflict-Serializability Bharath Kumar Manur Venkataramana Class ID No:- 110.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Concurrency control using transactions 1Transactions.
1 Concurrency Control and Recovery Module 6, Lecture 1.
Transaction Processing General Overview Where we ‘ve been... DBA skills for relational DB’s: Logical Schema Design  E/R diagrams  Decomposition.
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.
Transactions Amol Deshpande CMSC424. Today Project stuff… Summer Internships 
CS4432: Database Systems II Transaction Management Motivation 1.
Transaction Processing Concepts
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
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Concurrency Control II: Locking and Isolation Levels.
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
Transactions. What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions developed.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
Chapter 14 Transactions Yonsei University 1 st Semester, 2015 Sanghyun Park.
Degrees of Isolation – A Theoretical Formulation Presented by Balaji Sethuraman.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
CM Name : p.rajesh Year/Semester : VI Semester Subject : Advanced database system Subject Code : CM-603 Topic : Advanced database concepts Duration.
Concurrency (cont.) Schedule. In multiprogramming environment, Several transaction run concurrently Database consistency can be destroy Schedules to ensure.
1 Advanced Database Concepts Transaction Management and Concurrency Control.
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:
CS 440 Database Management Systems
Chapter 8: Concurrency Control on Relational Databases
Concurrency Control.
Chapter 14: Transactions
1 Introduction to Transaction Processing (1)
CS216: Data-Intensive Computing Systems
Database Management System
Transaction Management
Transactions.
March 21st – Transactions
ACID PROPERTIES.
Temple University – CIS Dept. CIS661 – Principles of Data Management
Transaction Management
Transactions Sylvia Huang CS 157B.
Lecture 21: Concurrency & Locking
CS162 Operating Systems and Systems Programming Review (II)
6.830 Lecture 12 Transactions: Isolation
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Lecture 22: Intro to Transactions & Logging IV
Transaction management
Transaction Management
CPSC-608 Database Systems
C. Faloutsos Transactions
Temple University – CIS Dept. CIS616– Principles of Data Management
UNIT -IV Transaction.
Presentation transcript:

1 CS216 Advanced Database Systems Shivnath Babu Notes 11: Concurrency Control

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

3 Transaction: Programmer’s Role Consistent State Transaction

4 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

5 Transaction: States BeginRun Abort Commit

6 Transactions Historical note: –Turing Award for Transaction concept –Jim Gray (1998) Interesting reading: Transaction Concept: Virtues and Limitations by Jim Gray

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

8 Context Last class: –Ensure atomicity in presence of failures Next few classes: –Ensure Isolation during concurrency

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

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

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

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) Transaction T1Transaction T2ABC = 1600

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) Transaction T1Transaction T2ABC = 1500

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

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

16 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”

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) ABC = 1500 Serial Schedule T1 T2

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) ABC = 1500 Serial Schedule T2 T1

19 Serial Schedule SnS0S1S2 T1 T2 Tn Consistent States

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) Transaction T2Transaction T1 Is this Serializable?

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) Equivalent Serial Schedule Transaction T2Transaction T1

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

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) Is this Serializable? Transaction T2Transaction T1 0 0

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

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

Read (A, t) t = t Write (A, t) Read (B, t) t = t Write (B, t) Read (A, s) s = s Write (A, s) Read (C, s) s = s Write (C, s) Transaction T2Transaction T1 Serializable Schedule Still Serializable!

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

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

29 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 –…

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

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

32 Conflict Serializability Serializable Schedules Conflict Serializable Schedules

33 Conflict Serializable Schedule SS1S2 Sn Serial Schedule Conflict Serializable Schedule Transformations: swap non-conflicting actions

34 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)

35 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.

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

37 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)

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

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

40 Graph Theory 101 Directed Graph: Nodes

41 Graph Theory 101 Directed Graph:Edges

42 Graph Theory 101 Directed Graph: Cycle

43 Graph Theory 101 Directed Graph: Not a cycle

44 Graph Theory 101 Acyclic Graph: A graph with no cycles

45 Graph Theory 101 Acyclic Graph:

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

47 Precedence Graph Precedence graph for schedule S: –Nodes: Transactions in S –Edges: Ti → Tj whenever S: … r i (X) … w j (X) … S: … w i (X) … r j (X) … S: … w i (X) … w j (X) … Note: not necessarily consecutive

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

49 Precedence Graph Example (Work on paper: Example 4)

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

51 Correctness of precedence graph method (Work on paper) Also read: Section

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

53 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.

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

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

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

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

58 View Serializability Serializable Schedules Conflict Serializable Schedules View Serializable Schedules

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

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

61 Next class Enforcing serializability –Locking-based techniques –Timestamp-based techniques –Validation-based techniques