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

Database Management System

The document discusses concurrency control in database management systems, focusing on techniques to manage multiple transactions accessing shared data simultaneously. It outlines various concurrency control problems, such as lost updates and dirty reads, and describes techniques like lock-based, timestamp-based, validation-based, and multiversion control protocols. Each technique aims to maintain data integrity and consistency while allowing concurrent transaction execution.

Uploaded by

zb96946
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)
9 views

Database Management System

The document discusses concurrency control in database management systems, focusing on techniques to manage multiple transactions accessing shared data simultaneously. It outlines various concurrency control problems, such as lost updates and dirty reads, and describes techniques like lock-based, timestamp-based, validation-based, and multiversion control protocols. Each technique aims to maintain data integrity and consistency while allowing concurrent transaction execution.

Uploaded by

zb96946
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/ 20

Database Management System

Group No 02
Members:
Zainab Batool (BS IT M1 04)
Areeba Mudassar (BS IT M1 18)
Topic

Concurrency Control
Transaction

• It is a set of operations used to perform logical unit of work.


• A transaction generally represent change in database
• Example:
• Money withdraw from ATM.
• Checking account balance.
Read and write operations are performed in the transaction.
Introduction

• Concurrency control is a mechanism used in database


management systems (DBMS) to manage multiple transactions
that access shared data simultaneously. The goal of concurrency
control is to ensure that the database remains in a consistent
state, even when multiple transactions are executed concurrently.
• Acid properties should be preserved.
Example

• Persons having joint account accessing the account to withdraw


money at same time there is the need consistency.
Problems
• Concurrency control problems in databases occur when multiple
transactions execute simultaneously, leading to conflicts that
compromise data integrity.
• Key problems include:
• Lost Updates: Overwriting changes made by another transaction.
• Dirty Reads: Reading uncommitted data from another
transaction.
• Non-repeatable Reads: Data changes between reads in the
same transaction.
Techniques :

• There are some important techniques:


1. Lock Based Protocol
2. Timestamp-Based Protocol
3. Validation-Based Protocol
4. Multiversion control protocol
Lock-based Protocol
Locking is the simplest idea to achieve isolation

• First put the lock on the item and perform the desired operation
and than unlock it.
• Read and write operations cannot be done without locking.
Types of Locks
• Shared Lock (S): Allows multiple transactions to read data but
prohibits writing.
Exclusive Lock (X): Permits one transaction to read or write
data.

Two-Phase Locking (2PL):


Updated version of locks to achieve serializability.
Growing Phase: Locks are acquired but not released.
Shrinking Phase: Locks are released but no new locks are
acquired.
......
• These protocols prevent conflicts and ensure serializability but
may lead to deadlocks.
• Example of Lock-based Protocol in Databases:
• Scenario:
• Transaction T1 wants to read and update data item X.
• Transaction T2 also wants to update X at the same time.
• Locking Process:
• T1 acquires a Shared Lock on X to read it.
.....

• T2 tries to acquire an Exclusive Lock on X to update it, but must


wait until T1 releases the lock.
• Two-Phase Locking (2PL):
• T1 and T2 can only release locks once they are done with all
operations, ensuring serializability.
Timestamp-based Protocols

• Timestamp-based Protocols order transactions using unique


timestamps to ensure serializability in database.
• Each transaction starts with new and unique Timestamp.
• Transactions can only read or write data If it does not conflict with
timestamps of other transactions it execute successfully.
• Conflicting transactions are rolled back and restarted with a new
timestamp.
Example
• Scenario:
• Transaction T1 (timestamp = 5) and T2 (timestamp = 10) both try
to access the same data item X.
• Execution Rules:
• If T1 wants to write X, but T2 has already read X, T1 is rolled back
since it has an older timestamp.
• If T2 wants to read X after T1 has written X, T2 can proceed
because it has a newer timestamp.
Validation-based Protocol
• Validation-based Protocol ensures data consistency by validating
transactions before committing/changing.
• validation based protocol is used where transactions are read only
and conflicts are low so it is called optimistic based protocol
• Phases:
• Read Phase: Transaction reads data and store it in temporary
location and performs operations in the temporary location
without affecting the database.
......

• Validation Phase: Before commit changing in database,


The system checks if the transaction conflicts with others
or not.
• Write Phase: Commits changes if validation succeeds;
otherwise, the transaction is rolled back
Example
• Scenario:
• Transaction T1 reads data A and B in the read phase.
• During T1’s execution, Transaction T2 writes to A.
• Validation Phase:
• Before T1 commits, it checks if T2’s write to A conflicts with its
operations.
• If a conflict is detected, T1 is rolled back; otherwise, it
proceeds to commit.
Multiversion Concurrency Control
• Multiversion Concurrency Control (MVCC) Based on Timestamp
Protocol ensures serializability by managing multiple data
versions using timestamps.
• How It Works:
• Each transaction gets a unique timestamp when it starts.
• Read Operation: Transactions read the version of the data with
the highest transaction's timestamp.
• Write Operation: A new version of the data is created with the
transaction's timestamp.
......
MVCC creates duplicate copies of tables/record so that data can be
safely read and update at the same time. In this method for each
version of Transaction (Ti) the system maintain:
• The Value of Version
• Read-Ts(Ti): Largest Timestamp of all the Timestamp of
transactions that have successfully Read version Ti.
• Write Ts(Ti): largest Timestamp of all the transaction that has
written the value of version Ti.
Comparison
Thank You

You might also like