Presentation is loading. Please wait.

Presentation is loading. Please wait.

ACS-4902 R. McFadyen 1 Chapter 18 Database Concurrency Control Locking 18.1 Shared/Exclusive (aka Read/Write) Locks Lock Operations Read_lock(X) Write_lock(X)

Similar presentations


Presentation on theme: "ACS-4902 R. McFadyen 1 Chapter 18 Database Concurrency Control Locking 18.1 Shared/Exclusive (aka Read/Write) Locks Lock Operations Read_lock(X) Write_lock(X)"— Presentation transcript:

1 ACS-4902 R. McFadyen 1 Chapter 18 Database Concurrency Control Locking 18.1 Shared/Exclusive (aka Read/Write) Locks Lock Operations Read_lock(X) Write_lock(X) unlock(X) Lock conversion Two-phase (2PL) Guaranteeing Serializability Basic, conservative, strict, rigorous 2PL Deadlock Prevention: Wait-die, wound-wait Detection: wait-for graph Starvation

2 ACS-4902 R. McFadyen 2 Database Concurrency Control Two locks modes: (a) shared (read) (b) exclusive (write). Shared mode: shared lock (X) More than one transaction can apply share lock on X for reading its value but no write lock can be applied on X by any other transaction. Exclusive mode: Write lock (X) Only one write lock on X can exist at any time and no shared lock can be applied by any other transaction on X. Conflict/compatibility matrix

3 ACS-4902 R. McFadyen 3 Database Concurrency Control Lock Manager: Managing locks on data items on behalf of transactions Lock table: Lock manager uses it to store the identify of transaction locking a data item, the data item, lock mode.

4 ACS-4902 R. McFadyen 4 Database Concurrency Control All transactions must be well-formed. A transaction is well-formed if: It must lock the data item before it reads or writes to it. It must not lock an already locked data items and it must not try to unlock a free data item.

5 ACS-4902 R. McFadyen 5

6 6 Consider the processing by the lock manager and the contents of the lock table

7 ACS-4902 R. McFadyen 7 Database Concurrency Control Two Phase Locking Two Phases: (a) Locking (Growing) (b) Unlocking (Shrinking). Locking (Growing) Phase: A transaction applies locks (read or write) on desired data items one at a time. Unlocking (Shrinking) Phase: A transaction unlocks its locked data items one at a time. Requirement: For a transaction these two phases must be mutually exclusive, that is, during locking phase unlocking phase must not start and during unlocking phase locking phase must not begin. Guarantees serializability

8 ACS-4902 R. McFadyen 8

9 9 Consider the processing by the lock manager and the contents of the lock table

10 ACS-4902 R. McFadyen 10 Database Concurrency Control 2PL variations: Conservative: Prevents deadlock by locking all desired data items before transaction begins execution. (Not practical) Basic: Transaction locks data items incrementally. This may cause deadlock which is dealt with. Strict: A stricter version of Basic algorithm where exclusive locks are released after a transaction terminates (commits or rolled-back). This is the most commonly used two-phase locking algorithm. Rigorous: No locks at all are released until commit or abort

11 ACS-4902 R. McFadyen 11 Database Concurrency Control Lock conversion Lock upgrade: existing read lock to write lock if Ti has a read-lock (X) and Tj has no read-lock (X) (i  j) then convert read-lock (X) to write-lock (X) else force Ti to wait until Tj unlocks X Lock downgrade: existing write lock to read lock Ti has a write-lock (X) (*no transaction can have any lock on X*) convert write-lock (X) to read-lock (X)


Download ppt "ACS-4902 R. McFadyen 1 Chapter 18 Database Concurrency Control Locking 18.1 Shared/Exclusive (aka Read/Write) Locks Lock Operations Read_lock(X) Write_lock(X)"

Similar presentations


Ads by Google