0% found this document useful (0 votes)
60 views32 pages

Concurrency Control Techniques Unit III

Uploaded by

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

Concurrency Control Techniques Unit III

Uploaded by

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

Concurrency Control Techniques

Concurrency control
• Concurrency control concept comes under the Transaction in
database management system (DBMS). It is a procedure in
DBMS which helps us for the management of two
simultaneous processes to execute without conflicts between
each other, these conflicts occur in multi user systems.
• Concurrency can simply be said to be executing multiple
transactions at a time. It is required to increase time
efficiency. If many transactions try to access the same data,
then inconsistency arises. Concurrency control required to
maintain consistency data.
• For example, if we take ATM machines and do not use
concurrency, multiple persons cannot draw money at a
time.This is where we need concurrency.
Concurrency Control Problems

• There are several problems that arise when


numerous transactions are executed
simultaneously in a random manner. The
database transaction consist of two major
operations “Read” and “Write”. It is very
important to manage these operations in the
concurrent execution of the transactions in
order to maintain the consistency of the data.
Dirty Read Problem(Write-Read
conflict)
• Dirty read problem occurs when one transaction updates an item
but due to some unconditional events that transaction fails but
before the transaction performs rollback, some other transaction
reads the updated value. Thus creates an inconsistency in the
database. Dirty read problem comes under the scenario of Write-
Read conflict between the transactions in the database
• The lost update problem can be illustrated with the below scenario
between two transactions T1 and T2.
• Transaction T1 modifies a database record without committing the
changes.
• T2 reads the uncommitted data changed by T1
• T1 performs rollback
• T2 has already read the uncommitted data of T1 which is no longer
valid, thus creating inconsistency in the database.
Lost update problem
• Lost update problem occurs when two or more
transactions modify the same data, resulting in the update
being overwritten or lost by another transaction. The lost
update problem can be illustrated with the below scenario
between two transactions T1 and T2.
• T1 reads the value of an item from the database.
• T2 starts and reads the same database item.
• T1 updates the value of that data and performs a commit.
• T2 updates the same data item based on its initial read and
performs commit.
• This results in the modification of T1 gets lost by the T2’s
write which causes a lost update problem in the database.
Concurrency Control Protocols

• Concurrency control protocols are the set of rules


which are maintained in order to solve the
concurrency control problems in the database. It
ensures that the concurrent transactions can execute
properly while maintaining the database consistency.
The concurrent execution of a transaction is provided
with atomicity, consistency, isolation, durability, and
serializability via the concurrency control protocols.
• Locked based concurrency control protocol
• Timestamp based concurrency control protocol
Locked based Protocol

• In locked based protocol, each transaction needs to acquire locks


before they start accessing or modifying the data items. There are
two types of locks used in databases.
• Shared Lock : Shared lock is also known as read lock which allows
multiple transactions to read the data simultaneously. The
transaction which is holding a shared lock can only read the data
item but it can not modify the data item.
• Exclusive Lock : Exclusive lock is also known as the write lock.
Exclusive lock allows a transaction to update a data item. Only one
transaction can hold the exclusive lock on a data item at a time.
While a transaction is holding an exclusive lock on a data item, no
other transaction is allowed to acquire a shared/exclusive lock on
the same data item.
Two Phase Locking Protocol :
• Two Phase Locking Protocol : Two phase locking is a widely used
technique which ensures strict ordering of lock acquisition and
release. Two phase locking protocol works in two phases.
– Growing Phase : In this phase, the transaction starts acquiring locks
before performing any modification on the data items. Once a
transaction acquires a lock, that lock can not be released until the
transaction reaches the end of the execution.
– Shrinking Phase : In this phase, the transaction releases all the
acquired locks once it performs all the modifications on the data item.
Once the transaction starts releasing the locks, it can not acquire any
locks further.
• Strict Two Phase Locking Protocol : It is almost similar to the two
phase locking protocol the only difference is that in two phase
locking the transaction can release its locks before it commits, but
in case of strict two phase locking the transactions are only allowed
to release the locks only when they performs commits.
Timestamp based Protocol

• In this protocol each transaction has a timestamp


attached to it. Timestamp is nothing but the time
in which a transaction enters into the system.
• The conflicting pairs of operations can be
resolved by the timestamp ordering protocol
through the utilization of the timestamp values of
the transactions. Therefore, guaranteeing that
the transactions take place in the correct order.
Advantages of Concurrency

In general, concurrency means, that more than one transaction can


work on a system. The advantages of a concurrent system are:
• Waiting Time: It means if a process is in a ready state but still the
process does not get the system to get execute is called waiting
time. So, concurrency leads to less waiting time.
• Response Time: The time wasted in getting the response from the
cpu for the first time, is called response time. So, concurrency leads
to less Response Time.
• Resource Utilization: The amount of Resource utilization in a
particular system is called Resource Utilization. Multiple
transactions can run parallel in a system. So, concurrency leads to
more Resource Utilization.
• Efficiency: The amount of output produced in comparison to given
input is called efficiency. So, Concurrency leads to more Efficiency.
Disadvantages of Concurrency

• Disadvantages of Concurrency
• Disadvantages of Concurrency
• Overhead: Implementing concurrency control requires additional
overhead, such as acquiring and releasing locks on database objects. This
overhead can lead to slower performance and increased resource
consumption, particularly in systems with high levels of concurrency.
• Deadlocks: Deadlocks can occur when two or more transactions are
waiting for each other to release resources, causing a circular dependency
that can prevent any of the transactions from completing. Deadlocks can
be difficult to detect and resolve, and can result in reduced throughput
and increased latency.
• Reduced concurrency: Concurrency control can limit the number of users
or applications that can access the database simultaneously. This can lead
to reduced concurrency and slower performance in systems with high
levels of concurrency.
• Complexity: Implementing concurrency control can be
complex, particularly in distributed systems or in
systems with complex transactional logic. This
complexity can lead to increased development and
maintenance costs.
• Inconsistency: In some cases, concurrency control can
lead to inconsistencies in the database. For example, a
transaction that is rolled back may leave the database
in an inconsistent state, or a long-running transaction
may cause other transactions to wait for extended
periods, leading to data staleness and reduced
accuracy.
Schedule

• A schedule is a series of operations from one or more transactions.


A schedule can be of two types:
• Serial Schedule: When one transaction completely executes before
starting another transaction, the schedule is called a serial
schedule. A serial schedule is always consistent. e.g.; If a schedule S
has debit transaction T1 and credit transaction T2, possible serial
schedules are T1 followed by T2 (T1->T2) or T2 followed by T1 ((T2-
>T1). A serial schedule has low throughput and less resource
utilization.
• Concurrent Schedule: When operations of a transaction are
interleaved with operations of other transactions of a schedule, the
schedule is called a Concurrent schedule. e.g.; the Schedule of debit
and credit transactions shown in Table 1 is concurrent. But
concurrency can lead to inconsistency in the database. The above
example of a concurrent schedule is also inconsistent.
Transaction failure:

• A transaction has to abort when it fails to


execute or when it reaches a point from
where it can’t go any further.
• This is called transaction failure where only a
few transactions or processes are hurt.
Reasons for a transaction failure
could be −
• Logical errors − Where a transaction cannot complete because it
has some code error or any internal error condition.
• System errors − Where the database system itself terminates an
active transaction because the DBMS is not able to execute it, or it
has to stop because of some system condition.
• For example, in case of deadlock or resource unavailability, the
system aborts an active transaction.
System Crash

• There are problems − external to the system −


that may cause the system to stop abruptly and
cause the system to crash.
• For example, interruptions in power supply may
cause the failure of underlying hardware or
software failure.
• Examples may include operating system errors.
Disk Failure

• In early days of technology evolution, it was a


common problem where hard-disk drives or
storage drives used to fail frequently.
• Disk failures include formation of bad sectors,
unreachability to the disk, disk head crash or any
other failure, which destroys all or a part of disk
storage.
Recovery Concepts
• DBMS is a highly complex system with
hundreds of transactions being executed
every second. If it fails or crashes amid
transactions, it is expected that the system
would follow some sort of algorithm or
techniques to recover lost data.
• Log based Recovery
• Shadow Paging
Log based Recovery in DBMS

• The atomicity property of DBMS states that


either all the operations of transactions must
be performed or none. The modifications
done by an aborted transaction should not be
visible to the database and the modifications
done by the committed transaction should be
visible. To achieve our goal of atomicity.
Log recovery
Log and log records

• The log is a sequence of log records, recording


all the updated activities in the database. In
stable storage, logs for each transaction are
maintained. Any operation which is
performed on the database is recorded on the
log. Prior to performing any modification to
the database, an updated log record is created
to reflect that modification. An update log
record represented as: <Ti, Xj, V1, V2> has
these fields:
• Transaction identifier: Unique Identifier of the
transaction that performed the write
operation.
• Data item: Unique identifier of the data item
written.
• Old value: Value of data item prior to write.
• New value: Value of data item after write
operation.
• Other types of log records are:
• <Ti start>: It contains information about when
a transaction Ti starts.
• <Ti commit>: It contains information about
when a transaction Ti commits.
• <Ti abort>: It contains information about
when a transaction Ti aborts.
Undo and Redo Operations

• Undo: using a log record sets the data item


specified in log record to old value.
• Redo: using a log record sets the data item
specified in log record to new value.
• the database can be modified using two approaches –
• Deferred Modification Technique: If the transaction
does not modify the database until it has partially
committed, it is said to use deferred modification
technique.
• Immediate Modification Technique: If database
modification occur while the transaction is still active,
it is said to use immediate modification technique.
(Each log follows an actual database modification. That
is, the database is modified immediately after every
operation)
Shadow paging
• Shadow paging is one of the techniques that is
used to recover from failure. We all know that
recovery means to get back the information,
which is lost. It helps to maintain database
consistency in case of failure.
• Concept of shadow paging
• Step 1 − Page is a segment of memory. Page
table is an index of pages. Each table entry
points to a page on the disk.
• Step 2 − Two page tables are used during the
life of a transaction: the current page table
and the shadow page table. Shadow page
table is a copy of the current page table.
• Step 3 − When a transaction starts, both the tables
look identical, the current table is updated for each
write operation.
• Step 4 − The shadow page is never changed during the
life of the transaction.
• Step 5 − When the current transaction is committed,
the shadow page entry becomes a copy of the current
page table entry and the disk block with the old data is
released.
• Step 6 − The shadow page table is stored in non-
volatile memory. If the system crash occurs, then the
shadow page table is copied to the current page table.
Advantages

• No need for log records.


• No undo/ Redo algorithm.
• Recovery is faster.
• Disadvantages
• Data is fragmented or scattered.
• Garbage collection problem. Database pages
containing old versions of modified data need to
be garbage collected after every transaction.

You might also like