Concurrency Control
K.Kasthuri
○ Concurrency is a multiprogramming
environment where multiple
transactions can be executed
simultaneously.
○ Concurrency control to control the
concurrency of transactions.
2
○ Concurrency control protocols to ensure
the ACID properties.
○ The ACID properties are atomicity,
consistency, isolation, and durability of
concurrent transactions
3
○ Concurrency control protocols can be
broadly divided into two categories
1. Lock based protocols
2. Time stamp based protocols
4
1. Lock-based Protocols
○ Database systems equipped with
lock-based protocols use a
mechanism by which any transaction
cannot read or write data until it
acquires an appropriate lock on it.
Locks are of two kinds
1. Shared Lock
2. Exclusive Lock
5
1. Shared Lock (S):
• It is also known as Read-only lock.
• As the name suggests it can be shared
between transactions because while holding
this lock the transaction does not have the
permission to update data on the data item.
• S-lock is requested using lock-S instruction.
6
2. Exclusive Lock (X):
o Data item can be both read as well as written.
o This is Exclusive and cannot be held
simultaneously on the same data item.
o X-lock is requested using lock-X instruction.
7
Lock Compatibility Matrix –
8
• A transaction may be granted a lock on an item if the requested lock is
compatible with locks already held on the item by other transactions.
○ Two Phase Locking –
○ A transaction is said to follow Two Phase
Locking protocol if Locking and Unlocking can
be done in two phases.
○ 1. Growing Phase
○ 2. Shrinking Phase
○ 1. Growing Phase: New locks on data items may
be acquired but none can be released.
○ 2. Shrinking Phase: Existing locks may be
released but no new locks can be acquired.
9
Timestamp Ordering Protocol
o The main idea for this protocol is to order the
transactions based on their Timestamps.
o A schedule in which the transactions participate is
then serializable and the only equivalent serial
schedule permitted has the transactions in the
order of their Timestamp Values.
10

Dbms

  • 1.
  • 2.
    ○ Concurrency isa multiprogramming environment where multiple transactions can be executed simultaneously. ○ Concurrency control to control the concurrency of transactions. 2
  • 3.
    ○ Concurrency controlprotocols to ensure the ACID properties. ○ The ACID properties are atomicity, consistency, isolation, and durability of concurrent transactions 3
  • 4.
    ○ Concurrency controlprotocols can be broadly divided into two categories 1. Lock based protocols 2. Time stamp based protocols 4
  • 5.
    1. Lock-based Protocols ○Database systems equipped with lock-based protocols use a mechanism by which any transaction cannot read or write data until it acquires an appropriate lock on it. Locks are of two kinds 1. Shared Lock 2. Exclusive Lock 5
  • 6.
    1. Shared Lock(S): • It is also known as Read-only lock. • As the name suggests it can be shared between transactions because while holding this lock the transaction does not have the permission to update data on the data item. • S-lock is requested using lock-S instruction. 6
  • 7.
    2. Exclusive Lock(X): o Data item can be both read as well as written. o This is Exclusive and cannot be held simultaneously on the same data item. o X-lock is requested using lock-X instruction. 7
  • 8.
    Lock Compatibility Matrix– 8 • A transaction may be granted a lock on an item if the requested lock is compatible with locks already held on the item by other transactions.
  • 9.
    ○ Two PhaseLocking – ○ A transaction is said to follow Two Phase Locking protocol if Locking and Unlocking can be done in two phases. ○ 1. Growing Phase ○ 2. Shrinking Phase ○ 1. Growing Phase: New locks on data items may be acquired but none can be released. ○ 2. Shrinking Phase: Existing locks may be released but no new locks can be acquired. 9
  • 10.
    Timestamp Ordering Protocol oThe main idea for this protocol is to order the transactions based on their Timestamps. o A schedule in which the transactions participate is then serializable and the only equivalent serial schedule permitted has the transactions in the order of their Timestamp Values. 10