Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrency Control Enforcing Serializability by Locks

Similar presentations


Presentation on theme: "Concurrency Control Enforcing Serializability by Locks"— Presentation transcript:

1 Concurrency Control Enforcing Serializability by Locks
Krishna Nitin Tenali

2 INTRODUCTION Enforcing serializability by locks Locks
Locking scheduler Two phase locking

3 Locks It works like as follows : A request from transaction
Scheduler checks in the lock table Generates a serializable schedule of actions.

4 Consistency of transactions
Actions and locks must relate each other Transactions can only read & write only if it has a lock on the database elements involved in the transaction. Unlocking an element is compulsory. Legality of schedules No two transactions can acquire the lock on same element without the prior one releasing it.

5 Locking scheduler Grants lock requests only if it is in a legal schedule. Lock table stores the information about current locks on the elements.

6 The locking scheduler (contd.)
A legal schedule of consistent transactions but unfortunately it is not a serializable. T1 T2 A B l1(A); r1(A); A:=A+100; w1(A);u1(A); l1(B); r1(B); B:=B+100; w1(B);u1(B); l2(A); r2(A); A:=A*2; w2(A);u2(A); l2(B); r2(B); B:=B*2; w2(B);u2(B); 25 125 250 50 150

7 Locking schedule (contd.)
The locking scheduler delays requests in order to maintain a consistent database state. T1 T2 A B l1(A); r1(A); A:=A+100; w1(A);l1(B);u1(A); r1(B);B:=B+100; w1(B);u1(B); l2(A); r2(A); A:=A*2; w2(A);u2(A); L2(B); Denied l2(B); u2(A);r2(B); B:=B*2; w2(B);u2(B); 25 125 250 300

8 Two-phase locking Guarantees a legal schedule of consistent transactions is conflict-serializable. All lock requests proceed all unlock requests. The growing phase: Obtain all the locks and no unlocks allowed. The shrinking phase: Release all the locks and no locks allowed.

9 Working of Two-Phase locking
Assures serializability. Two protocols for 2PL: Strict two phase locking : Transaction holds all its write locks till commit / abort. Rigorous two phase locking : Transaction holds all locks till commit / abort. Two phase transactions are ordered in the same order as their first unlocks.

10 Failure of 2PL. 2PL fails to provide security against deadlocks.
T1: l1(A); r1(A); A:=A+100; w1(A); l1(B); u1(A); r1(B); B:=B+100; w1(B); u1(B); T2: l2(B); r2(B); B:=B*2; w2(B); l2(A); u2(B); r2(A);A:=A*2; w2(A); u2(A); T1 T2 A B l1(A); r1(A); A:=A+100; w1(A); l1(B); Denied l2(B); r2(B); B:=B*2; W2(B); l2(A); Denied 25 125 50

11 Thank You


Download ppt "Concurrency Control Enforcing Serializability by Locks"

Similar presentations


Ads by Google