Presentation is loading. Please wait.

Presentation is loading. Please wait.

Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li.

Similar presentations


Presentation on theme: "Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li."— Presentation transcript:

1 em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li

2 em Spatiotemporal Database Laboratory Pusan National University Serializability For given transactions T 1, T 2,.., T n, Schedule (History) S is serializable if Result(S)  Result(S k ) where S k is a serial excution schedule. Note that Result(S i ) may be different from Result(S j ) (i  j ) How to detect whether S is serializable Conflict Graph

3 em Spatiotemporal Database Laboratory Pusan National University Conflict Graph T1T1 T2T2 r(a)r(a) w(a)w(a) affects r(b)r(b) w(b)w(b) S1S1 S1S1 T1T1 T2T2 r(a)r(a) w(a)w(a) r(b)r(b) w(b)w(b) S2S2 S2S2 Res(S 1 )  Res( (T 1, T 2 ) ) Res(S 1 )  Res( (T 1, T 2 ) ) Res(S 1 )  Res( (T 2, T 1 ) )

4 em Spatiotemporal Database Laboratory Pusan National University Detect Cycle in Conflict Graph T1T1 T2T2 r(a)r(a) w(a)w(a) affects r(b)r(b) w(b)w(b) T2T2 T2T2 T1T1 T1T1 If  Cycle in Conflict Graph Then Not Serializable Otherwise Serializable

5 em Spatiotemporal Database Laboratory Pusan National University How to make it serializable Control the order of execution of operations in concurrent transactions. Timestamping Ordering by timestamp on each transaction and each operation Two Phase Locking Protocol Locking on each operation

6 em Spatiotemporal Database Laboratory Pusan National University Lock-Based Protocols A lock mechanism to control concurrent access to a data item Data items can be locked in two modes : Exclusive (X) mode : Data item can be both read as well as written. X-lock is requested using lock-X instruction. Shared (S) mode : Data item can only be read. S-lock is requested using lock-S instruction. Lock requests are made to concurrency-control manager. Transaction can proceed only after request is granted.

7 em Spatiotemporal Database Laboratory Pusan National University Lock-Based Protocols (Cont.) Lock-compatibility matrix A transaction may be granted a lock on an item if the requested lock is compatible with locks already held Any number of transactions can hold shared locks If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held have been released. the lock is then granted.

8 em Spatiotemporal Database Laboratory Pusan National University Lock-Based Protocols Example of a transaction performing locking: T 2 : lock-S(A); read (A); unlock(A); lock-S(B); read (B); unlock(B);

9 em Spatiotemporal Database Laboratory Pusan National University The Two-Phase Locking Protocol This is a protocol which ensures conflict-serializable schedules. Phase 1: Growing Phase  transaction may obtain locks  transaction may not release locks Phase 2: Shrinking Phase  transaction may release locks  transaction may not obtain locks The protocol assures serializability

10 em Spatiotemporal Database Laboratory Pusan National University Lock Conversions Two-phase locking with lock conversions: First Phase:  can acquire a lock-S on item  can acquire a lock-X on item  can convert a lock-S to a lock-X (upgrade) Second Phase:  can release a lock-S  can release a lock-X  can convert a lock-X to a lock-S (downgrade) This protocol assures serializability

11 em Spatiotemporal Database Laboratory Pusan National University Where to insert Lock related operations ? A transaction T i issues the standard read/write instruction, without explicit locking calls. Automatic Acquitistion of Locks The operation read(D) is processed as: if T i has a lock on D then read(D) else begin wait until no other transaction has a lock-X on D grant T i a lock-S on D; read(D) end

12 em Spatiotemporal Database Laboratory Pusan National University Automatic Acquisition of Locks write(D) is processed as: if T i has a lock-X on D then write(D) else begin if necessary wait until no other trans. has any lock on D, if T i has a lock-S on D then upgrade lock on D to lock-X else grant T i a lock-X on D write(D) end; All locks are released after commit or abort

13 em Spatiotemporal Database Laboratory Pusan National University Lock Manager Transaction Transaction sends lock request to Lock Manager Lock Manager determines whether to allow or not Lock Table Keeps granted locks and pending locks for each item In-memory Hash Table

14 em Spatiotemporal Database Laboratory Pusan National University Problem of Two Phase Locking Protocol Deadlock Growing Phase and Shrinking Phase  Prevention and Avoidence : Impossible  Only Detetion may be possible When a deadlock occurs  Detection of Deadlock : Wait-For-Graph  Abort a transaction How to choose a transaction to kill ?

15 em Spatiotemporal Database Laboratory Pusan National University Tree Lock : A Special Locking Mechanism Only exclusive locks are allowed. The first lock by T may be on any data item. Subsequently, a data Q can be locked by T only if the parent of Q is currently locked by T. Data items may be unlocked at any time. Pairwise lock Not Allowed

16 em Spatiotemporal Database Laboratory Pusan National University Timestamp-Based Protocols Each transaction is issued a timestamp when TS(T i ) <TS(T j ) :  old transaction T i and new transaction T j Each data Q, two timestamp : W-timestamp(Q) : largest time-stamp for sucessful write(Q) R-timestamp(Q) : largest time-stamp for sucessful read(Q)

17 em Spatiotemporal Database Laboratory Pusan National University Timestamp-Based Protocols : Read Transaction T i issues a read(Q) If TS(T i )  W-timestamp(Q),  then T i needs to read a value of Q that was already overwritten.  Hence, the read operation is rejected, and T i is rolled back. If TS(T i )  W-timestamp(Q),  then the read operation is executed, and  R-timestamp(Q) is set set

18 em Spatiotemporal Database Laboratory Pusan National University Timestamp-Based Protocols : Write Transaction T i issues write(Q). If TS(T i ) < R-timestamp(Q),  then the value of Q that T i is producing was needed previously,  and the system assumed that that value would never be produced.  Hence, the write operation is rejected, and T i is rolled back. If TS(T i ) < W-timestamp(Q),  then T i is attempting to write an obsolete value of Q.  Hence, this write operation is rejected, and T i is rolled back. Otherwise,  the write operation is executed,  and W-timestamp(Q) is reset

19 em Spatiotemporal Database Laboratory Pusan National University Correctness of Timestamp-Ordering Protocol The timestamp-ordering protocol guarantees serializability since all the arcs in the precedence graph are of the form: Thus, there will be no cycles in the conflict graph Timestamp protocol : free from deadlock transaction with smaller timestamp transaction with larger timestamp

20 em Spatiotemporal Database Laboratory Pusan National University Problem of Timestamping Protocol Cascade Rollback Thomas Rule Rollback and Restarting Overhead Instead of Deadlock Detection

21 em Spatiotemporal Database Laboratory Pusan National University Long Duration Transaction Transaction of Long Duration with large number of operations Problem Expensive rollback and restart Degradation of concurrency Approach Nest Transaction Semantic Consistency rather than Serializability


Download ppt "Em Spatiotemporal Database Laboratory Pusan National University File Processing : Concurrency Control 2004, Spring Pusan National University Ki-Joune Li."

Similar presentations


Ads by Google