0% found this document useful (0 votes)
37 views

Concurrency Control

The document discusses concurrency control in databases which allows multiple users to access the same database simultaneously. It describes potential problems that can arise from concurrent access like lost updates, dirty reads, and non-repeatable reads. It also discusses different concurrency control techniques used in databases like locking protocols, two phase locking, timestamp ordering, and validation based protocols.

Uploaded by

asifr.official9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Concurrency Control

The document discusses concurrency control in databases which allows multiple users to access the same database simultaneously. It describes potential problems that can arise from concurrent access like lost updates, dirty reads, and non-repeatable reads. It also discusses different concurrency control techniques used in databases like locking protocols, two phase locking, timestamp ordering, and validation based protocols.

Uploaded by

asifr.official9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Concurrency Control

Introduction
• In a multi-user system, multiple users can access and use the same database at one
time, which is known as the concurrent execution of the database. It means that
the same database is executed simultaneously on a multi-user system by different
users.
• While working on the database transactions, there occurs the requirement of using
the database by multiple users for performing different operations, and in that
case, concurrent execution of the database is performed.
Introduction
• the simultaneous execution that is performed should be done in an interleaved
manner, and no operation should affect the other executing operations, thus
maintaining the consistency of the database. Thus, on making the concurrent
execution of the transaction operations, there occur several challenging problems
that need to be solved.
The conflict?
• DB operations are
• Read
• Write

• Concurrent access is quite easy if all users are just reading data. There
is no way they can interfere with one another. Though for any
practical Database, it would have a mix of READ and WRITE
operations and hence the concurrency is a challenge.
Potential problems of concurrency
• Lost Updates occur when multiple transactions select the same row and update
the row based on the value selected
• Uncommitted dependency issues occur when the second transaction selects a row
which is updated by another transaction (dirty read)
• Non-Repeatable Read occurs when a second transaction is trying to access the
same row several times and reads different data each time.
• Incorrect Summary issue occurs when one transaction takes summary over the
value of all the instances of a repeated data-item, and second transaction update
few instances of that specific data-item. In that situation, the resulting summary
does not reflect a correct result.
Lost Update problem(W-W Conflict)
• The problem occurs when two different database transactions perform the
read/write operations on the same database items in an interleaved manner (i.e.,
concurrent execution) that makes the values of the items incorrect hence making
the database inconsistent.
Lost Update Problem(w-w conflict)
• Consider the below diagram where two transactions TX and TY, are performed on
the same account A where the balance of account A is $300.
Dirty Read problem(W-R conflict)
• The dirty read problem occurs when one transaction updates an item of the
database, and somehow the transaction fails, and before the data gets rollback,
the updated database item is accessed by another transaction. There comes the
Read-Write Conflict between both transactions.
W-R Conflict
• Consider two transactions TX and TY in the below diagram performing read/write
operations on account A where the available balance in account A is $300:
Unrepeatable read problem(W-R conflict)
• Also known as Inconsistent Retrievals Problem that occurs when in a transaction,
two different values are read for the same database item.
Unrepeatable read problem
Incorrect summary problem
• Consider a situation, where one transaction is applying the aggregate function on
some records while another transaction is updating these records. The aggregate
function may calculate some values before the values have been updated and
others after they are updated.
• transaction 2 is calculating the sum of some
records while transaction 1 is updating them.
Therefore the aggregate function may
calculate some values before they have been
updated and others after they have been
updated.
Phantom Read
Why use concurrency methods
• Reasons for using Concurrency control method is DBMS:

• To apply Isolation through mutual exclusion between conflicting transactions

• To resolve read-write and write-write conflict issues

• To preserve database consistency through constantly preserving execution obstructions

• The system needs to control the interaction among the concurrent transactions. This
control is achieved using concurrent-control schemes.
Concurrency protocols
• Different concurrency control protocols offer different benefits between the
amount of concurrency they allow and the amount of overhead that they impose.
Following are the Concurrency Control techniques in DBMS:

• Lock-Based Protocols
• Two Phase Locking Protocol
• Timestamp-Based Protocols
• Validation-Based Protocols
Lock Based Protocol
• Lock Based Protocols in DBMS is a mechanism in which a transaction
cannot Read or Write the data until it acquires an appropriate lock.

• Locks/ isolates a particular transaction to a single user.

• A lock is a data variable which is associated with a data item. This lock
signifies that operations that can be performed on the data item.

• Transactions proceed only once the lock request is granted.


Types of Lock based
• Binary Locks: A Binary lock on a data item can either locked or unlocked states.

• Shared/exclusive: This type of locking mechanism separates the locks in DBMS based
on their uses. If a lock is acquired on a data item to perform a write operation, it is
called an exclusive lock.
Shared Lock (S):
A shared lock is also called a Read-only lock. With the shared lock, the data item can be shared between
transactions. This is because you will never have permission to update data on the data item.

Exclusive Lock (X):


With the Exclusive Lock, a data item can be read as well as written. This is exclusive and can't be held
concurrently on the same data item. X-lock is requested using lock-x instruction. Transactions may unlock the
data item after finishing the 'write' operation.
Shared Exclusive Locks
Simplistic Lock Protocol
• This type of lock-based protocols allows transactions to obtain a lock on every object
before beginning operation. Transactions may unlock the data item after finishing the
'write' operation.
Pre-claiming Locking
• Pre-claiming lock protocol helps to evaluate operations and create a list of required data
items which are needed to initiate an execution process. In the situation when all locks
are granted, the transaction executes. After that, all locks release when all of its
operations are over.
Strict-Two Phase Locking Method (2PL)

• 2PL ensures serializability by applying a


lock to the transaction data which blocks
other transactions to access the same data
simultaneously.
• Growing Phase
• Shrinking Phase

• Transaction Execution Phases


• First Phase: Acquire Locks
• 2nd Phase: Complete transaction.
• 3rd Phase: Release Locks. Cant obtain any
more locks during this phase.
Types of 2PL
• Strict Two-Phase Locking Method
• Strict-Two phase locking system is almost similar to 2PL. The only difference is that Strict-2PL
never releases a lock after using it. It holds all the locks until the commit point and releases
all the locks at one go when the process is over.
• Centralized 2PL
• In Centralized 2 PL, a single site is responsible for lock management process. It has only one
lock manager for the entire DBMS.
• Primary copy 2PL
• Primary copy 2PL mechanism, many lock managers are distributed to different sites. After
that, a particular lock manager is responsible for managing the lock for a set of data items.
When the primary copy has been updated, the change is propagated to the slaves.
• Distributed 2PL
• In this kind of two-phase locking mechanism, Lock managers are distributed to all sites. They
are responsible for managing locks for data at that site. If no data is replicated, it is equivalent
to primary copy 2PL. Communication costs of Distributed 2PL are quite higher than primary
copy 2PL
TimeStamp based Protocol
• This algorithm uses System Time or Logical Counter as a timestamp to
serialize the execution of concurrent transactions.
• ensures that every conflicting read and write operations are executed
in a timestamp order.
• The older transaction are given priority. This is the most commonly
used concurrency protocol.
Validation Based Protocol
• Validation based Protocol also known as Optimistic Concurrency Control
Technique.

• In this protocol, the local copies of the transaction data are updated rather
than the data itself, which results in less interference while execution of the
transaction.

• The Validation based Protocol is performed in the following three phases:


• Read Phase
• Validation Phase
• Write Phase
VBP
• Read Phase
• In the Read Phase, the data values from the database can be read by a
transaction but the write operation or updates are only applied to the local
data copies, not the actual database.
• Validation Phase
• In Validation Phase, the data is checked to ensure that there is no violation of
serializability while applying the transaction updates to the database.
• Write Phase
• In the Write Phase, the updates are applied to the database if the validation is
successful, else; the updates are not applied, and the transaction is rolled
back.

You might also like