120 likes | 543 Views
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
E N D
Concurrency ControlEnforcing 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.
The locking scheduler (contd.) • A legal schedule of consistent transactions but unfortunately it is not a serializable.
Locking schedule (contd.) • The locking scheduler delays requests in order to maintain a consistent database state.
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.
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);