Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrency Control A.Sri Harsha 211 18.3 Enforcing Serializability of Locks.

Similar presentations


Presentation on theme: "Concurrency Control A.Sri Harsha 211 18.3 Enforcing Serializability of Locks."— Presentation transcript:

1 Concurrency Control A.Sri Harsha 211 18.3 Enforcing Serializability of Locks

2 Agenda Serializability Issue The Locking Scheme Legal Schedules Two-Phase Locking The Risk of Deadlock

3 Serializability Issue Serializability is one major issue of concern when dealing with transactions. Suppose there is a collection of transactions performing their actions. Then, these actions may or may not be serializable. If it is not serializable, then it is not desired. It is the job of the scheduler to prevent the order of actions that lead to unserializable behavior. The most common method of preventing unserialable behavior is by using locks.

4 The Locking Scheme Scheduler uses a locking scheme to enforce conflict-serializability. The scheduler takes requests from the transactions and either allow them to operate on database or defer them until such time as it is safe to allow then to execute. A Lock table is used to guide this decision. Transactions much request and release locks for reading and writing database elements.

5 The Locking Scheme (Contd.)‏ Consistency of Transactions: A transaction can only read and write an element if it previously requested a lock on that element and hasn't yet released that lock. If a transaction locks an element, it must later unlock that element. Legality of Schedules: No two transactions may have locked the same element without one having first released the lock.

6 Identify the legal schedules...... S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B)‏ r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)‏ S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B)‏ l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B)‏ S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B)‏ l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)‏ Legal Schedules

7 S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B)‏ r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)‏ S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B)‏ l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B)‏ S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B)‏ l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)‏ Legal Schedule Legal Schedules (Contd.)‏

8 Two Phase Locking(2PL)‏ In a two-phase locking the transactions are divided into two phases. In the first phase, a lock is obtained by the transaction. In the second phase, the same transaction releases the lock. Once a lock is acquired by a transaction it cannot acquire additional locks. The 2PL condition in verbatim: In every transaction, all lock requests precede all unlock requests.

9 Two Phase Locking(2PL)‏ In a two-phase locking the transactions are divided into two phases. In the first phase, locks are acquired by the transaction. In the second phase, the same transaction releases the locks. Once a lock is released by a transaction it cannot acquire additional locks. The 2PL condition in verbatim: In every transaction, all lock requests precede all unlock requests.

10 Two Phase Locking(2PL) Contd. T i = ……. l i (A) ………... u i (A) ……... no unlocks no locks # locks held by Ti Time Growing Shrinking Phase Phase

11 The Risk of Deadlock Two Phase Locking doesn't solve the potential occurrence of a deadlock scenario. In a deadlock scenario, a lot of transactions are forced by the scheduler to wait forever for a lock held by another transaction.

12 The Risk of Deadlock (Contd.)‏ T 1 : l 1 (A); r 1 (A); A := A + 100; w 1 (A); l 1 (B); u 1 (A); r 1 (B); B := B + 100; w 1 (B); u 1 (B); T 2 : l 2 (B); r 2 (B); B := B*2; w 2 (B); l 2 (A); u 2 (B);r 2 (A); A := A*2; w 2 (A); u 2 (A); T 1 T 2 A B l 1 (A); r 1 (A); A := A + 100; w 1 (A); l 1 (B); Denied l 2 (B); r 2 (B); B := B * 2; w 2 (B); l 2 (A); Denied 25 25 125 50 Neither transaction can proceed and they wait forever.


Download ppt "Concurrency Control A.Sri Harsha 211 18.3 Enforcing Serializability of Locks."

Similar presentations


Ads by Google