SlideShare a Scribd company logo
5
Most read
7
Most read
13
Most read
Subject : Database Management System
Topic : Concurrency Control
CONTENTS
• What is Concurrency Control?
• Lock Based Protocol
• Two Phase Locking Protocol
• Deadlock
What is Concurrency Control?
The technique is used to protect data when multiple users
are accessing same data concurrently (same time) is
called concurrency control
Concurrency Control in Database Management System
Lock Based Protocol
• Lock is a mechanism to control concurrent access to data
item
• Data items can be locked in two modes:
1) Exclusive (X) Mode :- Data item can be both read as well as
written. X-lock is requested using lock-X instruction
2) Shared (S) Mode :- Data item can only be read. S-lock is
requested using lock-S instruction
• Lock requests are made to concurrency-control manager
• Transaction can proceed only after request is granted
Lock Based Protocol
• Lock-compatibility Matrix :
S X
S TRUE FALSE
X FALSE FALSE
• 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 transaction
• Any number of transactions can hold shared locks on an
item, But if any transaction holds an exclusive on the item
no other transaction may hold any lock on the item
Lock Based Protocol
• If a lock cannot be granted, the requesting transaction is
made to wait till all incompatible locks held by other
transaction have been released. The lock is then granted.
• Example:
T1: lock-S(A); // Grant-S(A,T1)
read (A);
unlock(A);
lock-S(B); // Grant-S(B,T1)
read (B);
unlock(B);
display(A+B)
Pitfalls of Lock Based Protocol
• Locking as above is not sufficient to guarantee serializability -
if A and B get updated in-between the read of A and B, the
displayed sum would be wrong.
• A locking protocol is a set of rules followed by all transactions
while requesting and releasing locks. Locking protocols restrict
the set of possible schedules.
Pitfalls of Lock Based Protocol
• Neither T3 nor T4 can make progress — executing lock-S(B)
causes T4 to wait for T3 to release its lock on B, while executing
lock-X(A) causes T3 to wait for T4 to release its lock on A.
• Such a situation is called a deadlock.
– To handle a deadlock one of T3 or T4 must be rolled back
and its locks released.
Pitfalls of Lock Based Protocol
• Starvation is also possible if concurrency control manager is
badly designed. For example:
– A transaction may be waiting for an X-lock on an item, while
a sequence of other transactions request and are granted an
S-lock on the same item.
– The same transaction is repeatedly rolled back due to
deadlocks.
• Concurrency control manager can be designed to prevent
starvation.
Concurrency Control in Database Management System
Two Phase Locking Protocol
• This is a protocol which ensures conflict-serializable schedules.
• Phase 1: Growing Phase
– transaction may obtain locks
– transaction may not release locks
• Phase 2: Shrinking Phase
– transaction may release locks
– transaction may not obtain locks
• The protocol assures serializability. It can be proved that the
transactions can be serialized in the order of their lock points
(i.e. the point where a transaction acquired its final lock).
Two Phase Locking Protocol
• Two-phase locking does not ensure freedom from deadlocks
• Cascading roll-back is possible under two-phase locking. To
avoid this, follow a modified protocol called strict two-phase
locking. Here a transaction must hold all its exclusive locks till
it commits/aborts.
• Rigorous two-phase locking is even stricter: here all locks are
held till commit/abort. In this protocol transactions can be
serialized in the order in which they commit.
Concurrency Control in Database Management System
Deadlock
•A set of processes is deadlocked if each process in the set is
waiting for an event that only another process in the set can
cause.
Ti Tj
Four Conditions for Deadlock
A. Mutual exclusion condition
– each resource assigned to 1 process or is available
B. Hold and wait condition
– process holding resources can request additional
C. No preemption condition
– previously granted resources cannot forcibly taken away
D. Circular wait condition
– must be a circular chain of 2 or more processes
– each is waiting for resource held by next member of the chain
Strategies of Deadlock Handling
•Deadlock prevention.
Prevents deadlocks by restraining requests made to ensure
that at least one of the four deadlock conditions cannot occur.
•Deadlock avoidance.
Dynamically grants a resource to a process if the resulting
state is safe. A state is safe if there is at least one execution
sequence that allows all processes to run to completion.
•Deadlock detection and recovery.
That Allows deadlocks to form; then finds and breaks them.
Deadlock Avoidance
WAIT-DIE Rule :
If Ti requests a lock on a data item which is already locked
by Tj , then Ti is permitted to wait if ts (Ti ) < ts (Tj ). If
ts (Ti ) >ts (Tj ) , then Ti is aborted and restarted with the sa
me timestamp.
– if ts (Ti ) <ts (Tj ) then Ti waits else Ti dies
– non-preemptive: Ti never preempts Tj
– prefers younger transactions
Deadlock Avoidance
WOUND-WAIT Rule :
If Ti requests a lock on a data item which is already locked
by Tj , then Ti is permitted to wait iff ts(Ti)>ts(Tj). If
ts(Ti)<ts(Tj), then Tj is aborted and the lock is granted to Ti.
– if ts(Ti)<ts(Tj) then Tj is wounded else Ti waits
– preemptive: Ti preempts Tj if it is younger
– prefers older transactions
Deadlock Detection
• For deadlock detection, the system must provide
– An algorithm that examines the state of the system to detect whether a
deadlock has occurred
– And an algorithm to recover from the deadlock
• A detection-and-recovery scheme requires various kinds of
overhead
– Run-time costs of maintaining necessary information and executing the
detection algorithm
Concurrency Control in Database Management System

More Related Content

What's hot (20)

PPT
15. Transactions in DBMS
koolkampus
 
PPTX
Distributed database
ReachLocal Services India
 
PPTX
Database recovery
Vritti Malhotra
 
PPTX
Transaction states and properties
Chetan Mahawar
 
PPTX
DeadLock in Operating-Systems
Venkata Sreeram
 
PPT
12. Indexing and Hashing in DBMS
koolkampus
 
PPTX
DBMS - RAID
MythiliMurugan3
 
PPTX
Paging and segmentation
Piyush Rochwani
 
PPTX
2 phase locking protocol DBMS
Dhananjaysinh Jhala
 
PDF
Symbol table in compiler Design
Kuppusamy P
 
PPTX
Database System Architectures
Information Technology
 
PPTX
Distributed dbms architectures
Pooja Dixit
 
PPTX
File allocation methods (1)
Dr. Jasmine Beulah Gnanadurai
 
DOCX
Concurrency Control Techniques
Raj vardhan
 
PPTX
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Gyanmanjari Institute Of Technology
 
PDF
Token, Pattern and Lexeme
A. S. M. Shafi
 
PPTX
Network layer - design Issues
قصي نسور
 
PPTX
Tree - Data Structure
Ashim Lamichhane
 
PPTX
Consensus Algorithms.pptx
Rajapriya82
 
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
15. Transactions in DBMS
koolkampus
 
Distributed database
ReachLocal Services India
 
Database recovery
Vritti Malhotra
 
Transaction states and properties
Chetan Mahawar
 
DeadLock in Operating-Systems
Venkata Sreeram
 
12. Indexing and Hashing in DBMS
koolkampus
 
DBMS - RAID
MythiliMurugan3
 
Paging and segmentation
Piyush Rochwani
 
2 phase locking protocol DBMS
Dhananjaysinh Jhala
 
Symbol table in compiler Design
Kuppusamy P
 
Database System Architectures
Information Technology
 
Distributed dbms architectures
Pooja Dixit
 
File allocation methods (1)
Dr. Jasmine Beulah Gnanadurai
 
Concurrency Control Techniques
Raj vardhan
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Gyanmanjari Institute Of Technology
 
Token, Pattern and Lexeme
A. S. M. Shafi
 
Network layer - design Issues
قصي نسور
 
Tree - Data Structure
Ashim Lamichhane
 
Consensus Algorithms.pptx
Rajapriya82
 
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 

Similar to Concurrency Control in Database Management System (20)

PPTX
concurrency control
rajshreemuthiah
 
PPTX
Concurrency control
Jaya Jeswani
 
PPTX
BCT 2312 - Chapter 3 - Concurrency Control Techniques in DBMSs.pptx
gikurujoseph53
 
PPTX
Concurrency control PPT
ShushrutGupta
 
PDF
PPT-concurrency Control database management system DBMS concurrent control (U...
PratikshaSatpute8
 
PPTX
CHapter four database managementm04.pptx
meharikiros2
 
PPT
concurrency-control
Saranya Natarajan
 
PPTX
Concurrency Control in Databases.Database management systems
ambikavenkatesh2
 
PDF
Concurrency Control in Database Management System
SwarnimBajra
 
PDF
Cs501 concurrency
Kamal Singh Lodhi
 
PPT
Chapter18
gourab87
 
PPTX
Concurrency Control & Deadlock Handling
Meghaj Mallick
 
PPTX
Transaction and NOSQL Chapter-Module 5.pptx
bgscseise
 
PDF
Concurrency Control, Recovery, Case Studies
Prabu U
 
PPTX
deadlock handling
Suraj Kumar
 
PPT
deadlock and locking - dbms
Surya Swaroop
 
PPT
Database management system chapter16
Md. Mahedi Mahfuj
 
PDF
Design & Development of an Advanced Database Management System Using Multiver...
IOSR Journals
 
PDF
F017213747
IOSR Journals
 
concurrency control
rajshreemuthiah
 
Concurrency control
Jaya Jeswani
 
BCT 2312 - Chapter 3 - Concurrency Control Techniques in DBMSs.pptx
gikurujoseph53
 
Concurrency control PPT
ShushrutGupta
 
PPT-concurrency Control database management system DBMS concurrent control (U...
PratikshaSatpute8
 
CHapter four database managementm04.pptx
meharikiros2
 
concurrency-control
Saranya Natarajan
 
Concurrency Control in Databases.Database management systems
ambikavenkatesh2
 
Concurrency Control in Database Management System
SwarnimBajra
 
Cs501 concurrency
Kamal Singh Lodhi
 
Chapter18
gourab87
 
Concurrency Control & Deadlock Handling
Meghaj Mallick
 
Transaction and NOSQL Chapter-Module 5.pptx
bgscseise
 
Concurrency Control, Recovery, Case Studies
Prabu U
 
deadlock handling
Suraj Kumar
 
deadlock and locking - dbms
Surya Swaroop
 
Database management system chapter16
Md. Mahedi Mahfuj
 
Design & Development of an Advanced Database Management System Using Multiver...
IOSR Journals
 
F017213747
IOSR Journals
 
Ad

More from Janki Shah (9)

PPTX
Collections in .net technology (2160711)
Janki Shah
 
PPTX
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Janki Shah
 
PPTX
File Management in Operating System
Janki Shah
 
PPT
Addressing in Computer Networks
Janki Shah
 
PPTX
Queue in Data Structure
Janki Shah
 
PPTX
Number system in Digital Electronics
Janki Shah
 
PPTX
Exception Handling in object oriented programming using C++
Janki Shah
 
PPTX
Compiler in System Programming/Code Optimization techniques in System Program...
Janki Shah
 
PPT
Sorting in Linear Time in Analysis & Design of Algorithm
Janki Shah
 
Collections in .net technology (2160711)
Janki Shah
 
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Janki Shah
 
File Management in Operating System
Janki Shah
 
Addressing in Computer Networks
Janki Shah
 
Queue in Data Structure
Janki Shah
 
Number system in Digital Electronics
Janki Shah
 
Exception Handling in object oriented programming using C++
Janki Shah
 
Compiler in System Programming/Code Optimization techniques in System Program...
Janki Shah
 
Sorting in Linear Time in Analysis & Design of Algorithm
Janki Shah
 
Ad

Recently uploaded (20)

PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PDF
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Digital water marking system project report
Kamal Acharya
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Digital water marking system project report
Kamal Acharya
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 

Concurrency Control in Database Management System

  • 1. Subject : Database Management System Topic : Concurrency Control
  • 2. CONTENTS • What is Concurrency Control? • Lock Based Protocol • Two Phase Locking Protocol • Deadlock
  • 3. What is Concurrency Control? The technique is used to protect data when multiple users are accessing same data concurrently (same time) is called concurrency control
  • 5. Lock Based Protocol • Lock is a mechanism to control concurrent access to data item • Data items can be locked in two modes: 1) Exclusive (X) Mode :- Data item can be both read as well as written. X-lock is requested using lock-X instruction 2) Shared (S) Mode :- Data item can only be read. S-lock is requested using lock-S instruction • Lock requests are made to concurrency-control manager • Transaction can proceed only after request is granted
  • 6. Lock Based Protocol • Lock-compatibility Matrix : S X S TRUE FALSE X FALSE FALSE • 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 transaction • Any number of transactions can hold shared locks on an item, But if any transaction holds an exclusive on the item no other transaction may hold any lock on the item
  • 7. Lock Based Protocol • If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held by other transaction have been released. The lock is then granted. • Example: T1: lock-S(A); // Grant-S(A,T1) read (A); unlock(A); lock-S(B); // Grant-S(B,T1) read (B); unlock(B); display(A+B)
  • 8. Pitfalls of Lock Based Protocol • Locking as above is not sufficient to guarantee serializability - if A and B get updated in-between the read of A and B, the displayed sum would be wrong. • A locking protocol is a set of rules followed by all transactions while requesting and releasing locks. Locking protocols restrict the set of possible schedules.
  • 9. Pitfalls of Lock Based Protocol • Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait for T3 to release its lock on B, while executing lock-X(A) causes T3 to wait for T4 to release its lock on A. • Such a situation is called a deadlock. – To handle a deadlock one of T3 or T4 must be rolled back and its locks released.
  • 10. Pitfalls of Lock Based Protocol • Starvation is also possible if concurrency control manager is badly designed. For example: – A transaction may be waiting for an X-lock on an item, while a sequence of other transactions request and are granted an S-lock on the same item. – The same transaction is repeatedly rolled back due to deadlocks. • Concurrency control manager can be designed to prevent starvation.
  • 12. Two Phase Locking Protocol • This is a protocol which ensures conflict-serializable schedules. • Phase 1: Growing Phase – transaction may obtain locks – transaction may not release locks • Phase 2: Shrinking Phase – transaction may release locks – transaction may not obtain locks • The protocol assures serializability. It can be proved that the transactions can be serialized in the order of their lock points (i.e. the point where a transaction acquired its final lock).
  • 13. Two Phase Locking Protocol • Two-phase locking does not ensure freedom from deadlocks • Cascading roll-back is possible under two-phase locking. To avoid this, follow a modified protocol called strict two-phase locking. Here a transaction must hold all its exclusive locks till it commits/aborts. • Rigorous two-phase locking is even stricter: here all locks are held till commit/abort. In this protocol transactions can be serialized in the order in which they commit.
  • 15. Deadlock •A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause. Ti Tj
  • 16. Four Conditions for Deadlock A. Mutual exclusion condition – each resource assigned to 1 process or is available B. Hold and wait condition – process holding resources can request additional C. No preemption condition – previously granted resources cannot forcibly taken away D. Circular wait condition – must be a circular chain of 2 or more processes – each is waiting for resource held by next member of the chain
  • 17. Strategies of Deadlock Handling •Deadlock prevention. Prevents deadlocks by restraining requests made to ensure that at least one of the four deadlock conditions cannot occur. •Deadlock avoidance. Dynamically grants a resource to a process if the resulting state is safe. A state is safe if there is at least one execution sequence that allows all processes to run to completion. •Deadlock detection and recovery. That Allows deadlocks to form; then finds and breaks them.
  • 18. Deadlock Avoidance WAIT-DIE Rule : If Ti requests a lock on a data item which is already locked by Tj , then Ti is permitted to wait if ts (Ti ) < ts (Tj ). If ts (Ti ) >ts (Tj ) , then Ti is aborted and restarted with the sa me timestamp. – if ts (Ti ) <ts (Tj ) then Ti waits else Ti dies – non-preemptive: Ti never preempts Tj – prefers younger transactions
  • 19. Deadlock Avoidance WOUND-WAIT Rule : If Ti requests a lock on a data item which is already locked by Tj , then Ti is permitted to wait iff ts(Ti)>ts(Tj). If ts(Ti)<ts(Tj), then Tj is aborted and the lock is granted to Ti. – if ts(Ti)<ts(Tj) then Tj is wounded else Ti waits – preemptive: Ti preempts Tj if it is younger – prefers older transactions
  • 20. Deadlock Detection • For deadlock detection, the system must provide – An algorithm that examines the state of the system to detect whether a deadlock has occurred – And an algorithm to recover from the deadlock • A detection-and-recovery scheme requires various kinds of overhead – Run-time costs of maintaining necessary information and executing the detection algorithm