Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.

Slides:



Advertisements
Similar presentations
Lecture plan Transaction processing Concurrency control
Advertisements

Database Systems (資料庫系統)
More About Transaction Management Chapter 10. Contents Transactions that Read Uncommitted Data View Serializability Resolving Deadlocks Distributed Databases.
Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
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.
Concurrency Control II
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
CSC271 Database Systems Lecture # 32.
Transaction Management Transparencies
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 6: Cascading Rollbacks, Deadlocks, and Long Transactions Professor Chen Li.
1 Chapter 20 Transaction Management Transparencies © Pearson Education Limited 1995, 2005.
Quick Review of Apr 29 material
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Transaction Management and Concurrency Control
Chapter 17: Transaction Management
What is a Transaction? Logical unit of work
Transaction Management
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control John Ortiz.
CS4432transaction management1 CS4432: Database Systems II Lecture #23 Transaction Management Professor Elke A. Rundensteiner.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management
Concurrency Control.
1 Chapter 6 : Transaction Management Pearson Education © 2009.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
Databases Illuminated
Lecture 12 Recoverability and failure. 2 Optimistic Techniques Based on assumption that conflict is rare and more efficient to let transactions proceed.
Transaction Management, Concurrency Control and Recovery Chapter 20 1.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
ICS (072)Concurrency Control Techniques1 Concurrency Control Techniques Chapter 18 Dr. Muhammad Shafique.
Chapter 11 Concurrency Control. Lock-Based Protocols  A lock is a mechanism to control concurrent access to a data item  Data items can be locked in.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Concurrency Control II: Locking and Isolation Levels.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Concurrency Control Introduction Lock-Based Protocols
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
10 1 Chapter 10_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Chapter 22 Transaction Management Pearson Education © 2014.
CS 440 Database Management Systems
Lecture 3 Concurrency control techniques
Concurrency Control Techniques
Transaction Management and Concurrency Control
Concurrency Control.
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
Transaction Management Transparencies
Transaction Properties
Chapter 10 Transaction Management and Concurrency Control
Chapter 15 : Concurrency Control
Transaction management
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Transactions, Properties of Transactions
Presentation transcript:

Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.

Lecture 3 2 Dr. Said Mirza Pahlevi, M.Eng.

Sekolah Tinggi Ilmu Statistik (STIS) Today’s Lecture Concurrency Control  Meaning of serializability  Conflict serializability  View serializability Locking Methods 3 Dr. Said Mirza Pahlevi, M.Eng. Last time lecture

Second Subtopic (from previous lecture) 4 Dr. Said Mirza Pahlevi, M.Eng.

Sekolah Tinggi Ilmu Statistik (STIS) View Serializability Conflict equivalent-----View equivalent Conflict serializable-----View serializable 5 Dr. Said Mirza Pahlevi, M.Eng.

Sekolah Tinggi Ilmu Statistik (STIS) Motivating example Schedule Q T 1 T 2 T 3 Read(A) Write(A) 6 Dr. Said Mirza Pahlevi, M.Eng. t1:t1: t2:t2: t3:t3: t4:t4:

Sekolah Tinggi Ilmu Statistik (STIS) Motivating Example Same as Q = r 1 (A) w 2 (A) w 1 (A) w 3 (A) P(Q): T1 T2 T3  Not conflict serializable! 7 Dr. Said Mirza Pahlevi, M.Eng.

Sekolah Tinggi Ilmu Statistik (STIS) Compare Q to Serial Schedule (S) QT 1 T 2 T 3 Read(A) Write(A) Write(A) Write(A) S T 1 T 2 T 3 Read(A) Write(A) Write(A) Write(A) T 1 reads same thing in Q dan S T 2, T 3 read same thing (nothing?) After Q or S, DB is left in same state  So what is wrong with Q? T 1 reads same thing in Q dan S T 2, T 3 read same thing (nothing?) After Q or S, DB is left in same state  So what is wrong with Q? 8 Dr. Said Mirza Pahlevi, M.Eng.

Sekolah Tinggi Ilmu Statistik (STIS) View Equivalent Two schedules S1 and S2 are view equivalent: 1.IF in S1: w j (A)  r i (A), THEN in S2: w j (A)  r i (A) 2.IF in S1: r i (A) reads initial DB value, THEN in S2: r i (A) also reads initial DB value 3.IF in S1: T i does last write on A, THEN in S2: T i also does last write on A Dr. Said Mirza Pahlevi, M.Eng. 9  means “reads value produced by”

Sekolah Tinggi Ilmu Statistik (STIS) View Serializability Schedule is view serializable if it is view equivalent to a serial schedule. Offers less stringent definition of schedule equivalence than conflict serializability. Every conflict serializable schedule is view serializable, although converse is not true. It can be shown that any view serializable schedule that is not conflict serializable contains one or more blind writes. 10 Dr. Said Mirza Pahlevi, M.Eng.

Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng. 11 add 1. Add final transaction T f that reads all DB e.g.: S = …..W 1 (A)…….. W 2 (A)…  R f (A) last A write

Sekolah Tinggi Ilmu Statistik (STIS) add View Serializable Test Dr. Said Mirza Pahlevi, M.Eng Add initial transaction T b that writes all DB e.g.: S = w b (A) ... r 1 (A) … w 2 (A) …

Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng Create labeled precedence (LP) graph of S: (a) If w i (A)  r j (A) in S, add T i  T j  means “reads value produced by”

Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng. 14 p p 0 0 (b) For each w i (A)  r j (A) do consider each w k (A): [T k  T b ] (i) IF T i  T b  T j  T f THEN insert T k  T i some new p T j  T k (ii) IF T i =T b  T j  T f THEN insert T j  T k (iii) IF T i  T b  T j =T f THEN insert T k  T i

Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng Check if LP(S) is acyclic; if so, then S is view serializable - For each pair of “p” arcs (p  0), choose one

Sekolah Tinggi Ilmu Statistik (STIS) Example 1: View Serializable (VS) Dr. Said Mirza Pahlevi, M.Eng. 16 Check if Q is view serializable: Q = r 1 (A) w 2 (A) w 1 (A) w 3 (A) Q’ = w b (A) r 1 (A) w 2 (A) w 1 (A) w 3 (A) r f (A) T3T3 T2T2 T1T1 TfTf TbTb   rule 3a rule 3b (ii) 0 0 rule 3b (iii) Acyclic graph!! Q is VS Acyclic graph!! Q is VS

Sekolah Tinggi Ilmu Statistik (STIS) Z=w b (A) r 1 (A) w 2 (A) r 3 (A) w 1 (A) w 3 (A) r f (A) T3T3 T2T2 T1T1 TfTf TbTb    Acyclic graph, so Z is VS (equivalent to T b T 1 T 2 T 3 T f ) Acyclic graph, so Z is VS (equivalent to T b T 1 T 2 T 3 T f ) do not pick this one of “1” pair do not pick this one of “1” pair 17 Dr. Said Mirza Pahlevi, M.Eng Example 2: View Serializable (VS) rule 3b (i) rule 3b (ii) rule 3b (iii) rule 3a

Sekolah Tinggi Ilmu Statistik (STIS) Recoverability Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine recoverability of transactions within schedule. If transaction fails, atomicity requires effects of transaction to be undone Durability states that once transaction commits, its changes cannot be undone (without running another, compensating, transaction). 18 Dr. Said Mirza Pahlevi, M.Eng.

Sekolah Tinggi Ilmu Statistik (STIS) If T9 Rollback Instead of Commit Dr. Said Mirza Pahlevi, M.Eng. 19 We should undo T10 but T10 has committed the transaction (durability does not allow it). This is a non- recoverable schedule

Sekolah Tinggi Ilmu Statistik (STIS) Recoverable Schedule A schedule where, for each pair of transactions T i and T j, if T j reads a data item previously written by T i, then the commit operation of T i precedes the commit operation of T j. If commit operation of T j precedes the commit operation of T i then it is unrecoverable, because of the durability. 20 Dr. Said Mirza Pahlevi, M.Eng.

Third Topic Dr. Said Mirza Pahlevi, M.Eng. 21

Sekolah Tinggi Ilmu Statistik (STIS) Concurrency Control Techniques Two basic concurrency control techniques:  Locking,  Timestamping. Both are conservative approaches: delay transactions in case they conflict with other transactions. Optimistic methods assume conflict is rare and only check for conflicts at commit. Dr. Said Mirza Pahlevi, M.Eng. 22

Sekolah Tinggi Ilmu Statistik (STIS) Locking Transaction uses locks to deny access to other transactions and so prevent incorrect updates. Most widely used approach to ensure serializability. Generally, a transaction must claim a shared (read) or exclusive (write) lock on a data item before read or write. Lock prevents another transaction from modifying item or even reading it, in the case of a write lock. Dr. Said Mirza Pahlevi, M.Eng. 23

Sekolah Tinggi Ilmu Statistik (STIS) Locking - Basic Rules 1. If transaction has shared lock on item, it can read but not update item. 2. If transaction has exclusive lock on item, it can both read and update item. 3. Reads cannot conflict, so more than one transaction can hold shared locks simultaneously on same item. 4. Exclusive lock gives transaction exclusive access to that item. Dr. Said Mirza Pahlevi, M.Eng. 24

Sekolah Tinggi Ilmu Statistik (STIS) Locking - Basic Rules 5. Some systems allow transaction to upgrade read lock to an exclusive lock, or downgrade exclusive lock to a shared lock. But this basic rules does not guarantee serializability of schedules by themselves Dr. Said Mirza Pahlevi, M.Eng. 25

Sekolah Tinggi Ilmu Statistik (STIS) Incorrect Locking Schedule Dr. Said Mirza Pahlevi, M.Eng. 26 Valid schedule using basic rules: S = {write_lock(T 9, bal x ), read(T 9, bal x ), write(T 9, bal x ), unlock(T 9, bal x ), write_lock(T 10, bal x ), read(T 10, bal x ), write(T 10, bal x ), unlock(T 10, bal x ), write_lock(T 10, bal y ), read(T 10, bal y ), write(T 10, bal y ), unlock(T 10, bal y ), commit(T 10 ), write_lock(T 9, bal y ), read(T 9, bal y ), write(T 9, bal y ), unlock(T 9, bal y ), commit(T 9 ) }

Sekolah Tinggi Ilmu Statistik (STIS) Example - Incorrect Locking Schedule If at start, bal x = 100, bal y = 400, result should be:  bal x = 220, bal y = 330, if T 9 executes before T 10, or  bal x = 210, bal y = 340, if T 10 executes before T 9. However, result gives bal x = 220 and bal y = 340. S is not a serializable schedule.  Problem is that transactions release locks too soon, resulting in loss of total isolation and atomicity.  To guarantee serializability, need an additional protocol concerning the positioning of lock and unlock operations in every transaction. Dr. Said Mirza Pahlevi, M.Eng. 27

Sekolah Tinggi Ilmu Statistik (STIS) Two-Phase Locking (2PL) Transaction follows 2PL protocol if all locking operations precede first unlock operation in the transaction. Two phases for transaction:  Growing phase - acquires all locks but cannot release any locks.  Shrinking phase - releases locks but cannot acquire any new locks. Dr. Said Mirza Pahlevi, M.Eng. 28

Sekolah Tinggi Ilmu Statistik (STIS) Preventing Lost Update Problem using 2PL Dr. Said Mirza Pahlevi, M.Eng. 29

Sekolah Tinggi Ilmu Statistik (STIS) Preventing Uncommitted Dependency Problem using 2PL Dr. Said Mirza Pahlevi, M.Eng. 30

Sekolah Tinggi Ilmu Statistik (STIS) Apply 2PL! Dr. Said Mirza Pahlevi, M.Eng. 31

Sekolah Tinggi Ilmu Statistik (STIS) Preventing Inconsistent Analysis Problem using 2PL Dr. Said Mirza Pahlevi, M.Eng. 32

Sekolah Tinggi Ilmu Statistik (STIS) Apply 2PL! Dr. Said Mirza Pahlevi, M.Eng. 33

Sekolah Tinggi Ilmu Statistik (STIS) Cascading Rollback If every transaction in a schedule follows 2PL, schedule is serializable. However, problems can occur with interpretation of when locks can be released. Dr. Said Mirza Pahlevi, M.Eng. 34

Sekolah Tinggi Ilmu Statistik (STIS) Cascading Rollback Dr. Said Mirza Pahlevi, M.Eng. 35 Transactions conform to 2PL. T14 aborts. Since T15 is dependent on T14, T15 must also be rolled back. Since T16 is dependent on T15, it too must be rolled back. This is called cascading rollback. To prevent this with 2PL, leave release of all locks until end of transaction.

Sekolah Tinggi Ilmu Statistik (STIS) Deadlock An impasse (kebuntuan) that may result when two (or more) transactions are each waiting for locks held by the other to be released. Dr. Said Mirza Pahlevi, M.Eng. 36

Sekolah Tinggi Ilmu Statistik (STIS) Deadlock Only one way to break deadlock: abort one or more of the transactions. Deadlock should be transparent to user, so DBMS should restart transaction(s). Three general techniques for handling deadlock:  Timeouts.  Deadlock prevention.  Deadlock detection and recovery. Dr. Said Mirza Pahlevi, M.Eng. 37

Sekolah Tinggi Ilmu Statistik (STIS) Timeouts Transaction that requests lock will only wait for a system-defined period of time. If lock has not been granted within this period, lock request times out. In this case, DBMS assumes transaction may be deadlocked, even though it may not be, and it aborts and automatically restarts the transaction. Dr. Said Mirza Pahlevi, M.Eng. 38

Sekolah Tinggi Ilmu Statistik (STIS) Deadlock Prevention DBMS looks ahead to see if transaction would cause deadlock and never allows deadlock to occur. Could order transactions using transaction timestamps:  Wait-Die - only an older transaction can wait for younger one, otherwise transaction is aborted (dies) and restarted with same timestamp.  Wound-Wait - only a younger transaction can wait for an older one. If older transaction requests lock held by younger one, younger one is aborted (wounded). Dr. Said Mirza Pahlevi, M.Eng. 39

Sekolah Tinggi Ilmu Statistik (STIS) Wait-Die Transactions given a timestamp when they arrive …. ts(T 1 ) T 1 can only wait for T 2 if ts(T 1 )< ts(T 2 )...else die Dr. Said Mirza Pahlevi, M.Eng. 40

Sekolah Tinggi Ilmu Statistik (STIS) Wound-Wait Transactions given a timestamp when they arrive … ts(T 1 ) T 1 wounds T 2 if ts(T 1 )< ts(T 2 ) else T 1 waits “Wound”: T 2 rolls back (if it cannot finish in small interval of time) and gives lock to T 1 Dr. Said Mirza Pahlevi, M.Eng. 41

Sekolah Tinggi Ilmu Statistik (STIS) Deadlock Detection and Recovery DBMS allows deadlock to occur but recognizes it and breaks it. Usually handled by construction of wait-for graph (WFG) showing transaction dependencies:  Create a node for each transaction.  Create edge T i  T j, if T i waiting to lock item locked by T j. Deadlock exists if and only if WFG contains cycle. WFG is created at regular intervals. Dr. Said Mirza Pahlevi, M.Eng. 42

Sekolah Tinggi Ilmu Statistik (STIS) Example - Wait-For-Graph (WFG) Dr. Said Mirza Pahlevi, M.Eng. 43

Sekolah Tinggi Ilmu Statistik (STIS) Granularity of Data Items Size of data items chosen as unit of protection by concurrency control protocol. Ranging from coarse to fine:  The entire database  A file  A page (or area or database spaced)  A record  A field value of a record Dr. Said Mirza Pahlevi, M.Eng. 44

Sekolah Tinggi Ilmu Statistik (STIS) Granularity of Data Items Tradeoff:  Coarser, the lower the degree of concurrency;  Finer, more locking information that is needed to be stored. Best item size depends on the types of transactions.  What will happen if we use database lock for transaction updating a single record/tuple?  What will happen if we use tuple lock for transaction updating 95% of tuple? Dr. Said Mirza Pahlevi, M.Eng. 45

Sekolah Tinggi Ilmu Statistik (STIS) Hierarchy of Granularity Could represent granularity of locks in a hierarchical structure. Root node represents entire database, level 1s represent files, etc. When node is locked, all its descendants are also locked. DBMS should check hierarchical path before granting lock. Dr. Said Mirza Pahlevi, M.Eng. 46

Sekolah Tinggi Ilmu Statistik (STIS) Levels of Locking Dr. Said Mirza Pahlevi, M.Eng. 47 If page2 is locked, the record1, record2, field1 and field2 are locked If lock request on record1, check page2, file2 and database

Sekolah Tinggi Ilmu Statistik (STIS) Intension Lock Intention lock could be used to lock all ancestors of a locked node. Intention locks can be read or write. Applied top-down, released bottom-up. 48

Sekolah Tinggi Ilmu Statistik (STIS) Intention Lock If another transaction requests a lock on any of descendants of the locked node, the DBMS checks the hierachical path from the root to the requested node. A transaction may request a lock on a node and a descendant of the node is already locked. Dr. Said Mirza Pahlevi, M.Eng. 49

Sekolah Tinggi Ilmu Statistik (STIS) Locking Level + 2PL 1. No lock can be granted once any node has been locked. 2. No node may be locked until its parent is locked by an intention lock. 3. No node may be unlocked until all its descendants are unlocked Dr. Said Mirza Pahlevi, M.Eng. 50