1 / 21

File Processing : Concurrency Control

File Processing : Concurrency Control. 2004, Spring Pusan National University Ki-Joune Li. 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.

Télécharger la présentation

File Processing : Concurrency Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. For given transactions T1, T2,.., Tn, Schedule (History) S is serializable if Result(S)  Result(Sk) where Sk is a serial excution schedule. Note that Result(Si ) may be different from Result(Sj ) (i  j ) How to detect whether S is serializable Conflict Graph Serializability Spatiotemporal Database Laboratory Pusan National University

  3. S2 T1 r(a) r(b) affects T2 w(a) w(b) Conflict Graph S1 r(b) T1 r(a) affects Res(S1)  Res( (T1, T2) ) Spatiotemporal Database Laboratory Pusan National University T2 w(a) w(b) Res(S1)  Res( (T1, T2) ) Res(S1)  Res( (T2, T1) )

  4. T1 T2 Detect Cycle in Conflict Graph • If  Cycle in Conflict Graph • Then Not Serializable • Otherwise Serializable T1 r(a) r(b) affects T2 w(a) w(b) Spatiotemporal Database Laboratory Pusan National University

  5. 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 How to make it serializable Spatiotemporal Database Laboratory Pusan National University

  6. 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. Lock-Based Protocols Spatiotemporal Database Laboratory Pusan National University

  7. 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. Lock-Based Protocols (Cont.) Spatiotemporal Database Laboratory Pusan National University

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

  9. 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 The Two-Phase Locking Protocol Spatiotemporal Database Laboratory Pusan National University

  10. 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 Lock Conversions Spatiotemporal Database Laboratory Pusan National University

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

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

  13. 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 Spatiotemporal Database Laboratory Pusan National University

  14. 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 ? Spatiotemporal Database Laboratory Pusan National University

  15. 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 Spatiotemporal Database Laboratory Pusan National University Not Allowed

  16. Each transaction is issued a timestamp when TS(Ti) <TS(Tj) : old transaction Ti and new transaction Tj 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) Timestamp-Based Protocols Spatiotemporal Database Laboratory Pusan National University

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

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

  19. 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 Correctness of Timestamp-Ordering Protocol transaction with smaller timestamp transaction with larger timestamp Spatiotemporal Database Laboratory Pusan National University

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

  21. 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 Spatiotemporal Database Laboratory Pusan National University

More Related