Presentation on theme: "Concurrency Control Enforcing Serializability by Locks Krishna Nitin Tenali."— Presentation transcript:
Concurrency Control Enforcing Serializability by Locks Krishna Nitin Tenali
INTRODUCTION Enforcing serializability by locks – Locks – Locking scheduler – Two phase locking
Locks It works like as follows : – A request from transaction – Scheduler checks in the lock table – Generates a serializable schedule of actions.
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.
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. T1T2AB 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 25 50 150
7 Locking schedule (contd.) The locking scheduler delays requests in order to maintain a consistent database state. T1T2AB 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 25 125 300
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.
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.