Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 18 Concurrency control Section 18.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112.

Similar presentations


Presentation on theme: "Chapter 18 Concurrency control Section 18.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112."— Presentation transcript:

1 Chapter 18 Concurrency control Section 18.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112

2 Agenda Lock types Lock types Shared (Read Lock) Shared (Read Lock) Exclusive(Write Lock) Exclusive(Write Lock) Update lock (prevents deadlock) Update lock (prevents deadlock) Increment Lock Increment Lock Compatibility Matrix Compatibility Matrix Upgrading Lock (deadlock scenario) Upgrading Lock (deadlock scenario)

3 Lock Types Shared Lock (read lock) read operation on the same element do not create conflict read operation on the same element do not create conflict no need to starve other transaction who wants to read that element no need to starve other transaction who wants to read that element no limit on number of transaction to acquire Shared lock on same element no limit on number of transaction to acquire Shared lock on same element Exclusive Lock (write lock) 2 concurrent write operation on Element A creates conflicting behavior 2 concurrent write operation on Element A creates conflicting behavior Can perform both read and write operation Can perform both read and write operation - Must use corresponding lock before read or write operation - All locks must be followed by unlock - S and E locks can not overlap

4 Lock Types Shared - Exclusive Lock Example: T1T2 T1T2 sl 1 (A); r 1 (A); sl 2 (A); r 2 (A); sl 2 (B); r 2 (B); sl 2 (A); r 2 (A); sl 2 (B); r 2 (B); xl 1 (B) Denied xl 1 (B) Denied u 2 (A); u 2 (B); u 2 (A); u 2 (B); xl 1 (B); r 1 (B); w 1 (B); xl 1 (B); r 1 (B); w 1 (B); u 1 (A); u 1 (B); u 1 (A); u 1 (B); Where sl – shared lock, xl – exclusive lock, u - unlock

5 Complexity Matrix As lock system gets more complex, CM is used to describe policies about various locks and their relationships with other locks As lock system gets more complex, CM is used to describe policies about various locks and their relationships with other locks Example: Shared – Exclusive lock policy with CM | Lock Requested | Lock Requested | S X | S X----------------------------------|--------------------------------------------------- LockS| Yes No LockS| Yes No heldX| No No in mode|

6 Upgrading Lock (deadlock scenario) Some transactions need X lock after using S lock for several operations Some transactions need X lock after using S lock for several operations Scenario 1. T1T2 T1T2 sl 1 (A); r 1 (A); sl 2 (A); r 2 (A); sl 2 (B); r 2 (B); sl 2 (A); r 2 (A); sl 2 (B); r 2 (B); sl 1 (B); r 1 (B); sl 1 (B); r 1 (B); xl 1 (B) Denied xl 1 (B) Denied u 2 (A); u 2 (B); u 2 (A); u 2 (B); xl 1 (B); r 1 (B); w 1 (B); xl 1 (B); r 1 (B); w 1 (B); u 1 (A); u 1 (B); u 1 (A); u 1 (B);

7 Upgrading Lock (deadlock scenario) Continued… Scenario 2. T1T2 T1T2 sl 1 (A) sl 1 (A) sl 2 (A) sl 2 (A) xl 1 (B) Denied xl 1 (B) Denied Both transaction encounters 2 way deadlock and waits indefinitely

8 Lock Types (Continued…) Update Lock (ul) introduced to avoid deadlock scenario introduced to avoid deadlock scenario ul(A) allows transaction to read not write but latter can be upgraded for X lock ul(A) allows transaction to read not write but latter can be upgraded for X lock while S lock can't be upgraded to be X lock while S lock can't be upgraded to be X lock Can grant U lock while S lock is already active Can grant U lock while S lock is already active once U lock is active no further lock S or X are allowed once U lock is active no further lock S or X are allowed

9 Lock Types (Continued…) Update Lock (ul) Shared – Exclusive lock policy with CM | Lock Requested | Lock Requested | S X U | S X U----------------------------------|--------------------------------------------------- LockS| Yes No Yes LockS| Yes No Yes heldX| No No No in modeU| No No No

10 Lock Types (Continued…) Increment Lock used to increment/decrement element used to increment/decrement element Applications: bank money transfer, Ai plane ticket Applications: bank money transfer, Ai plane ticket Any number of increment lock can be applied on element A without causing any in-consistent behavior Any number of increment lock can be applied on element A without causing any in-consistent behavior Add or sub order is not important a +b = b + a Add or sub order is not important a +b = b + aExmaple: INC (A, c) Where A is database element, c = constant + or -

11 Lock Types (Continued…) Update Lock (ul) Shared – Exclusive lock policy with CM | Lock Requested | Lock Requested | S X I | S X I----------------------------------|--------------------------------------------------- LockS| Yes No No LockS| Yes No No heldX| No No No in modeI| No No yes


Download ppt "Chapter 18 Concurrency control Section 18.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112."

Similar presentations


Ads by Google