1 / 14

Enforcing Serializability By LOCKS

Enforcing Serializability By LOCKS. By Jignesh Borisa (Cs257 ID:111). LOCKS. request from transactions Lock Table

luyu
Download Presentation

Enforcing Serializability By LOCKS

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. Enforcing Serializability By LOCKS By Jignesh Borisa (Cs257 ID:111)

  2. LOCKS request from transactions Lock Table Serializable Schedule of actions Scheduling

  3. Transaction obtains lock on the database elements. So it accesses to prevent other transactions from accessing these elements. In this scheme,there is only one kind of lock, which transactions must obtain on a database if they want to perform any operation on that element.

  4. A scheduler that uses a lock table to help perform its job. Scheduler takes request from transactions and either allow them to operate on the database or defer them. Scheduler would forward a request if and only if its execution can not possibly lead to an inconsistent database state after all action commit or abort.

  5. When a scheduler uses locks , transactions must request and release locks, in addition to reading and writing database elements. Consistency of Transactions: 1. A transaction can only read or write an element if it previously requested on that element and hasn’t yet released lock. 2.If transaction looks an element , it must later unlock that element.

  6. Legality of Schedules: Locks must have their intended meaning: no two transactions may have locked the same element without one having first released the lock. l(x):Transaction T requests a lock on database element X. (x):Transaction T releases its locks on database elements X.

  7. Example T1 T2 ------------------------------------------------------------------- l1(A);r1(A); l1(A);r2(A); A:=A+100; A=A*2; w1(A);u1(A); w2(A);u2(A); l1(B);r1(B); l2(B);r2(B); B:=B+100; B=B*2; w1(B);u1(B); w2(B);u2(B); T2’s action is performed after T1.

  8. The Locking Scheduler • The job of scheduler based on locking to grant requests if and only if the request will result in a legal schedule. • For this, lock table which tells for every database element, the transaction, if any, that currently holds a locks on that element. • Lock( element, trasaction) consisting of pairs(X,T) .

  9. Example T1 T2 A B ------------------------------------------------------------------------ l1(A);r1(A); 25 25 A:=A+100; w1(A);l1(B);u1(A); 125 l2(A);r2(A); A:=A*2; w2(A); 250 l2(B); Denied r1(B); B:=B+100; w1(B);u1(B); 150 l2(B);u2(A);r2(B); B:=B*2; w2(B);u2(B); 250

  10. Two Phase Locking • Condition under which we can guarantee that a legal schedule of consistent transactions is conflict- serializable. • Also Called as 2PL. • The 2PL condition is: In every transaction , all lock requests precede all unlock requests.

  11. Why Two Phase Locking Works • Each two phase locked transaction may be thought to execute in its entirety at the instant it issues its first unlock request. Instantaneously executs now locks required time

  12. Conversion of two phase locked transactions to a conflict-equivalent serial schedule for schedule S. n , the number of transaction in S. Basis: If n=1,there is nothing to do; S is already a serial Schedule. Induction : S involves n transactions T1,T2…Tn Ti be the transaction with the first unlock action in the entire schedule S, say ui(x).

  13. Consider some action of Ti,say wi(y). If wj(y), preceded wi(y) then action uj(y) and li(y) must intervene, in sequence of actions …wj(y);….;uj(y);…;li(y);…;wi(y);…. Since Ti is the first to unlock, ui(x) precedes uj(y) in S; that S might look like: ….;wj(Y);…;ui(x);…;uj(y);…;li(y);…;wj(y);… S can be written in the form ( Action of Ti)(Action of the other n-1 transaction)

  14. Example on Risk of Deadlock T1 T2 A B __________________________________________________ l1(A);r1(A); 25 25 l2(B);r2(B); A:=A+100 B:=B*2 w1(A) 125 w2(B); 50 l1(B) Denied l2(A) Denied

More Related