0% found this document useful (0 votes)
14 views9 pages

Concurrency Control Techniques in Databases

The report on 'Concurrency Control in Databases' discusses essential mechanisms for managing simultaneous database operations to ensure data integrity and consistency. It covers various techniques including two-phase locking, timestamp ordering, multiversion concurrency control, and validation methods, each with its advantages and drawbacks. The conclusion emphasizes the importance of these techniques in maintaining the ACID properties of transactions in multi-user environments.

Uploaded by

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

Concurrency Control Techniques in Databases

The report on 'Concurrency Control in Databases' discusses essential mechanisms for managing simultaneous database operations to ensure data integrity and consistency. It covers various techniques including two-phase locking, timestamp ordering, multiversion concurrency control, and validation methods, each with its advantages and drawbacks. The conclusion emphasizes the importance of these techniques in maintaining the ACID properties of transactions in multi-user environments.

Uploaded by

333jayanth333
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Concurrency Control in Databases]

VISVESVARAYA TECHNOLOGICAL UNIVERSITY


JNANA SANGAMA, BELAGAVI-590014

Report on

“Concurrency Control in Databases”


Submitted in the partial fulfillment of the requirement of IV Semester in
DATABASE MANAGEMENT SYSTEM -(BCS403)

Submitted By
Jayanth G - 1DT22IS066
Keerthan Raj B - 1DT22IS072
Kavya B A - 1DT22IS071
Lava Kumar - 1DT22IS081

Under the guidance of


[Link] B R

DEPARTMENT OF INFORMATION SCIENCE and ENGINEERING


DAYANANDA SAGAR ACADEMY OF TECHNOLOGY and MANAGEMENT
Udayapura, Kanakapura Main Road, Opp. Art of Living, Bengaluru-82

2023-2024
[Concurrency Control in Databases]

DAYANANDA SAGAR ACADEMY OF TECHNOLOGY AND MANAGEMENT


(Affiliated to Visvesvaraya Technological University, Belagavi and Approved by AICTE, New Delhi)
(Accrediated by NAAC with A+ Grade)
Udayapura, Kanakapura Main Road, Opp. Art of Living, Bengaluru-560082
(Accredited 3 years by NBA, New Delhi)
Department of Information Science and Engineering
CERTIFICATE

This is to certify that the case study work entitled “Concurrency Control in

Databases” is carried out by JAYANTH G (1DT22IS066),KAVYA B


A(1DT22IS071),KEERTHANRAJ B (1DT22IS072), Lava kumar (1DT22IS081)
in the partial fulfillment for the requirement of IV semester DBMS in Information
Science and Engineering of the Visvesvaraya Technological University, Belagavi,
during the year 2023-2024. It is certified that all corrections/suggestions indicated for the
internal assessment have been incorporated in the report. This report has been approved
as it satisfies the academic requirements in respect of case study work.

GAGANA B R Dr. Nandini Prasad K S


Assistant Professor Dean-Foreign Affairs
DBMS &HOD
DSATM,Bangalore Dept. of ISE
DSATM, Bangalore
[Concurrency Control in Databases]

TABLE OF CONTENTS

[Link] TITLE PAGE NO

1 Introduction 1
2 Two-phase locking techniques for Concurrency control 2
3 Concurrency control based on Timestamp ordering 3
4 Multiversion Concurrency control techniques 4
5 Validation Concurrency control techniques 5

6 Conclusion 6
[Concurrency Control in Databases]

Concurrency Control in Databases

INTRODUCTION:

Concurrency control in databases is an essential component of database management


systems (DBMS) designed to handle simultaneous operations without compromising
data integrity and consistency. When multiple users or applications access and modify
the database at the same time, the system must ensure that these concurrent
transactions do not interfere with each other in a way that leads to incorrect or
inconsistent data. Concurrency control mechanisms achieve this by employing various
strategies such as locking protocols, timestamp ordering, and multiversion
concurrency control (MVCC). Locking protocols, including Two-Phase Locking
(2PL), ensure that transactions acquire and release locks in a manner that prevents
conflicts and maintains serializability. Timestamp ordering assigns unique timestamps
to each transaction to maintain a consistent execution order. MVCC, on the other
hand, provides each transaction with a "snapshot" of the database, allowing read
operations to occur without locking and reducing contention. These techniques
collectively uphold the ACID properties (Atomicity, Consistency, Isolation,
Durability) of transactions, ensuring that even in a high-concurrency environment, the
database remains reliable and performs efficiently. As databases continue to grow in
complexity and scale, robust concurrency control mechanisms are increasingly vital
for maintaining the seamless operation and accuracy of data in multi-user
environment

Dept. of ISE,DSATM 2023-24 1


[Concurrency Control in Databases]

Two-phase locking techniques for Concurrency control


1. Growing Phase:

o During this phase, a transaction may acquire locks but may not release any locks.
o This means that as the transaction proceeds, it requests the necessary locks on the data items
it wants to read or write.
o The transaction can obtain shared (read) or exclusive (write) locks depending on the
operation it needs to perform.
o The growing phase continues until the transaction has acquired all the locks it needs.
2. Shrinking Phase:
o In the shrinking phase, the transaction releases the locks it has acquired but cannot acquire
any new locks.
o Once a transaction starts releasing locks, it cannot request any more locks.
o This phase begins when the transaction releases its first lock and continues until all locks held
by the transaction are released.

Types of 2PL

1. Strict Two-Phase Locking (Strict 2PL):


o In this variation, a transaction holds all its exclusive (write) locks until it commits or aborts.
o This ensures that no other transaction can read or write to the data items being modified by
the transaction until it completes.
o Strict 2PL provides a higher level of isolation and is widely used in practice.
2. Rigorous Two-Phase Locking (Rigorous 2PL):
o A transaction holds all its locks (both shared and exclusive) until it commits or aborts.
o This ensures that no other transaction can read or write to any data items being accessed by
the transaction until it completes.
o Rigorous 2PL provides the highest level of isolation.
3. Conservative Two-Phase Locking (Conservative 2PL):
o Also known as Static 2PL, this variation requires a transaction to lock all the data items it
needs before it begins execution.
o If it cannot acquire all the required locks at the beginning, it waits until all locks are
available.
o This approach prevents deadlocks but can lead to delays if locks are not readily available.

Benefits of Two-Phase Locking

 Serializability: 2PL ensures that the schedule of transactions is serializable, meaning that the
outcome is the same as if the transactions were executed one after the other in some order.
 Isolation: By controlling the acquisition and release of locks, 2PL provides the necessary isolation
between transactions, preventing conflicts and ensuring data consistency.

Drawbacks of Two-Phase Locking

 Deadlocks: Since transactions may need to wait for locks held by other transactions, deadlocks can
occur. Deadlock detection and resolution mechanisms are required to handle such situations.

Reduced Concurrency: Holding locks for the duration of a transaction can reduce the level of
concurrency and throughput, especially in high-transaction environments.

Dept. of ISE,DSATM 2023-24 2


[Concurrency Control in Databases]

Timestamp Ordering Concurrency Control


Key Concepts

1. Timestamp:
o A unique identifier, often based on the system clock, assigned to each transaction when it
starts.
o It represents the transaction's start time and is used to order transactions chronologically.
2. Read Timestamp (RTS):
o For each data item, the read timestamp is the largest timestamp of any transaction that has
successfully read that item.
3. Write Timestamp (WTS):
o For each data item, the write timestamp is the largest timestamp of any transaction that has
successfully written to that item.

Basic Rules

1. Read Operation:
o If a transaction TiT_iTi with timestamp TS(Ti)TS(T_i)TS(Ti) requests to read a data item
XXX:
 If TS(Ti)TS(T_i)TS(Ti) < WTS(X), the read is rejected, and TiT_iTi is rolled back.
This is because TiT_iTi is trying to read a value that has already been overwritten by
a newer transaction.
 Otherwise, the read is allowed, and RTS(X) is updated to
max⁡(RTS(X),TS(Ti))\max(RTS(X), TS(T_i))max(RTS(X),TS(Ti)).
2. Write Operation:
o If a transaction TiT_iTi with timestamp TS(Ti)TS(T_i)TS(Ti) requests to write a data item
XXX:
 If TS(Ti)TS(T_i)TS(Ti) < RTS(X), the write is rejected, and TiT_iTi is rolled back.
This ensures TiT_iTi does not overwrite a value that has been read by a newer
transaction.
 If TS(Ti)TS(T_i)TS(Ti) < WTS(X), the write is rejected, and TiT_iTi is rolled back.
This prevents TiT_iTi from overwriting a value written by a newer transaction.
 Otherwise, the write is allowed, and WTS(X) is updated to TS(Ti)TS(T_i)TS(Ti).

Advantages

 No Deadlocks: Since transactions are ordered by timestamps, there are no circular wait conditions,
eliminating deadlocks.
 High Concurrency: Transactions can often proceed without waiting, especially if their timestamps
do not conflict with those of other transactions.

Disadvantages

 Transaction Rollbacks: Transactions can be frequently rolled back if there are many conflicting
operations, leading to performance issues.
 Timestamp Management: Maintaining and comparing timestamps can introduce overhead

Dept. of ISE,DSATM 2023-24 3


[Concurrency Control in Databases]

Multiversion Concurrency control


techniques
1. Versioning:

o MVCC maintains multiple versions of each data item that is modified by transactions.
o Each version corresponds to a specific point in time when the data item was modified.
o Versions are typically identified by timestamps, transaction identifiers, or sequence numbers.
2. Reads and Writes:
o Reads: Transactions read from a consistent snapshot of the database, typically based
on the transaction's start time or a specific timestamp.
 Read operations do not block write operations, allowing transactions to read data
without waiting for exclusive locks.
 Transactions read the most recent committed version of each data item that is valid
based on the transaction's snapshot.
o Writes: Transactions create a new version of a data item when performing updates.
 Updates are typically performed on private copies of data items (copy-on-write
strategy) to avoid conflicting with concurrent transactions reading the same data
item.

Techniques and Variants

1. Snapshot Isolation:
o Each transaction executes based on a consistent snapshot of the database taken at the
beginning of the transaction.
o Ensures that a transaction sees a consistent view of the database, even if data is modified by
other transactions during its execution.
2. Multi-Version Timestamp Ordering:
o Combines MVCC with timestamp ordering to ensure serializability.
o Transactions are ordered based on timestamps to avoid conflicts, and MVCC is used to
manage versions of data items.
3. Visibility Rules:
o Transactions are allowed to see only those versions of data items that were committed before
the transaction started (based on its snapshot time).
o Ensures that transactions do not read or write uncommitted data, maintaining database
consistency.

Advantages of MVCC

 Improved Concurrency: Allows for higher levels of concurrency compared to traditional locking
mechanisms.
 Read Consistency: Provides consistent reads without blocking write operations, enhancing
performance.
 No Deadlocks: Since read operations do not block write operations, MVCC eliminates deadlock
scenarios common in locking mechanisms.

Disadvantages of MVCC

 Increased Storage Overhead: Maintaining multiple versions of data items requires additional
storage space.
 Complexity: Implementing and managing MVCC systems can be more complex than traditional
locking mechanisms.

Dept. of ISE,DSATM 2023-24 4


[Concurrency Control in Databases]

Validation Concurrency control techniques


1. Optimistic Approach:
o Transactions are allowed to proceed without acquiring locks or checking for conflicts during
their execution phase.
o This approach assumes that conflicts between transactions (e.g., concurrent updates to the
same data item) are rare.
2. Validation Phase:
o Transactions are validated before they commit to ensure that their execution did not conflict
with other transactions.
o During validation, the system checks if any conflicts occurred. If conflicts are detected,
appropriate actions such as transaction rollback or retry may be taken.
3. Versioning or Timestamps:
o Versions of data items or timestamps are often used to track changes made by transactions.
o These versions or timestamps help determine if a transaction’s changes conflict with changes
made by other transactions.

Techniques and Strategies

1. Timestamp-Based Validation:
o Each transaction is assigned a unique timestamp or version number.
o Before committing, the transaction’s timestamp or version is compared with the timestamps
or versions of other transactions that have accessed the same data items.
o Conflicts are detected if two transactions have overlapping time intervals or versions.
2. Conflict Detection:
o Common conflicts include:
 Read-Write Conflict: A transaction reads a data item that has been modified by
another transaction before it commits.
 Write-Write Conflict: Two transactions attempt to write to the same data item
concurrently.
3. Resolution Strategies:
o If conflicts are detected during validation, the database system may employ strategies such
as:
 Transaction Rollback: Rollback conflicting transactions and allow them to retry.
 Wait-and-Retry: Delay committing conflicting transactions and retry them after
other transactions have completed.
 Deadlock Detection: Detect and resolve deadlocks, if any occur during validation.

Advantages of Validation Concurrency Control

 High Concurrency: Transactions can proceed concurrently without blocking each other, leading to
better overall system throughput.
 No Locking Overhead: Avoids the overhead of acquiring, managing, and releasing locks, which can
improve performance in systems with low contention.
 Reduced Deadlock Risk: By avoiding locks, the risk of deadlock situations is minimized.

Disadvantages of Validation Concurrency Control

 Increased Rollback Rate: Transactions may need to be rolled back and retried more frequently if
conflicts occur, potentially impacting performance.
 Validation Overhead: The validation phase adds overhead to transaction processing, especially in
systems with h

Dept. of ISE,DSATM 2023-24 5


[Concurrency Control in Databases]

CONCLUSION:

Concurrency control in databases stands as a cornerstone of ensuring the integrity and


reliability of data transactions in environments where multiple users concurrently access and
modify the database. By employing sophisticated mechanisms such as locking protocols,
timestamp-based ordering, multiversion concurrency control (MVCC), and optimistic
validation techniques, database systems manage the intricate dance of allowing transactions to
execute simultaneously while preserving consistency and isolation. These methods are
designed to prevent scenarios like data inconsistency or lost updates that can arise when
transactions overlap.
Locking mechanisms, such as two-phase locking (2PL), enforce strict rules on how
transactions acquire and release locks on data items, ensuring that conflicts are managed and
transactions proceed in a serialized manner when necessary. Timestamp-based ordering
assigns unique timestamps to transactions, enabling a systematic approach to scheduling and
ensuring that each transaction sees a consistent view of the database at its start time.
MVCC takes a different approach by maintaining multiple versions of data items, allowing
transactions to read a consistent snapshot of the database without blocking each other, thus
enhancing concurrency and performance. On the other hand, validation-based techniques, like
optimistic concurrency control, let transactions proceed without immediate lock acquisition,
validating them only upon commit to detect and resolve conflicts dynamically.
While these techniques provide robust solutions to concurrency challenges, they also
introduce complexities such as increased storage requirements for maintaining multiple
versions or the overhead of managing transaction rollbacks in case of conflicts. Nonetheless,
their implementation is crucial for upholding the ACID properties—Atomicity, Consistency,
Isolation, and Durability—ensuring that database operations remain reliable and data integrity
is preserved even in demanding and dynamic computing environments.

Dept. of ISE,DSATM 2023-24 6

Common questions

Powered by AI

Pessimistic concurrency control, like Two-Phase Locking, assumes conflicts are likely and hence locks resources to manage conflicts, ensuring data consistency and isolation but at the cost of reduced concurrency and potential deadlocks . It suits environments with high contention where conflicts are frequent. Optimistic concurrency control, as seen in validation techniques, allows transactions to proceed without locks, assuming conflicts are rare. It postpones conflict resolution to the validation phase, leading to higher concurrency and no deadlocks, but may suffer from increased rollbacks in high-contention scenarios . Thus, the choice depends on the specific transaction workload characteristics, where the trade-off lies between ensuring consistency and maximizing throughput .

Two-Phase Locking (2PL) involves acquiring and releasing locks in two distinct phases: a growing phase where locks can be acquired but not released, followed by a shrinking phase where locks can be released but not acquired. This method ensures serializability but may lead to deadlocks and reduced concurrency because transactions hold locks for their entire duration . On the other hand, Multiversion Concurrency Control (MVCC) avoids locking by maintaining multiple versions of data items, allowing reads to occur on consistent snapshots while writes create new versions. This approach provides high concurrency and no locking-induced deadlocks, but at the cost of increased storage overhead and complexity in version management .

Multiversion Timestamp Ordering improves on traditional timestamp ordering by incorporating versioning in its concurrency control strategy. It not only orders transactions by timestamps to avoid conflicts but also uses MVCC to manage multiple versions of data items. This allows transactions to read from a consistent snapshot of versions, effectively handling read-write and write-write conflicts without blocking other transactions . Consequently, it provides enhanced concurrency and avoids some limitations of traditional timestamp ordering, such as frequent transaction rollbacks due to conflicts .

Snapshot Isolation in MVCC ensures that a transaction sees a consistent view of the database by operating on a snapshot taken at the transaction's start time. Each transaction reads from this snapshot, which remains unaffected by other concurrent transactions' updates or deletions during its execution. This maintains consistency by ensuring that the transaction does not encounter changes made by other transactions after it started, thus providing a stable view of the database as it appeared at its snapshot time .

Conservative Two-Phase Locking (Conservative 2PL), also known as Static 2PL, requires transactions to acquire all necessary locks upfront before execution, preventing deadlocks as it avoids the circular wait condition typical of dynamic lock acquisition . However, this approach can negatively impact system performance as it might lead to increased waiting times and reduced concurrency, especially if the required locks are not immediately available. Transactions may experience delays and lead to reduced throughput in environments where resource contention is high .

Two-Phase Locking (2PL) ensures transaction isolation by making transactions acquire and release locks in two distinct phases, which helps maintain serializability and prevent conflicts between transactions . The main benefits include ensuring a high level of isolation and consistency and enabling a serializable schedule of transactions . However, the drawbacks include the potential for deadlocks, as transactions wait for each other’s locks, and reduced concurrency, since locks are held throughout the transaction's duration, limiting throughput, especially in high-transaction scenarios .

MVCC improves concurrency by allowing transactions to read consistent snapshots of the database without blocking write operations, unlike traditional locking mechanisms that require transactions to obtain locks on data items. This is achieved by maintaining multiple versions of each data item, enabling read operations to proceed without waiting for exclusive locks and thus reducing contention between transactions . MVCC eliminates deadlocks commonly seen with lock-based concurrency control as reads do not block writes, enhancing performance and concurrency .

Timestamp Ordering Concurrency Control prevents deadlocks by assigning unique timestamps to transactions and ordering them chronologically. This approach ensures that there are no circular wait conditions since each transaction is processed in a predefined order, thus eliminating deadlocks . A potential downside is that transactions may be frequently rolled back if there are many conflicting operations, which can negatively impact performance due to increased transaction aborts and retries .

Validation Concurrency Control handles conflict detection during the validation phase, where it checks for read-write and write-write conflicts based on the versions or timestamps of transactions that accessed the same data items. If conflicts are detected, strategies like transaction rollback or retry are employed to resolve them . Advantages include high concurrency since transactions can proceed without locks and the absence of locking overhead, which improves performance in low-contention environments . Moreover, it reduces the risk of deadlocks by avoiding locks, allowing for better transaction processing efficiency .

In Timestamp Ordering Concurrency Control, Read and Write Timestamps are critical for maintaining data consistency. The Read Timestamp (RTS) of a data item records the largest timestamp of any transaction that has successfully read the item, while the Write Timestamp (WTS) marks the largest timestamp of any transaction that has successfully written to it . These timestamps ensure that transactions read and write data items in a sequence that reflects their chronological order. For instance, a transaction's read request of a data item is rejected if its timestamp is less than the item's WTS, preventing it from reading overwritten data. Similarly, a write request is rejected if the transaction's timestamp is less than the item's RTS or WTS, preventing it from impacting the data consistency by overwriting recent changes .

You might also like