SlideShare a Scribd company logo
By
NeetiArora
Assistant Professor
Advanced Educational Institute
DBMS- Concurrency Control
www.advanced.edu.in
Definition
Concurrency control is a database management system (DBMS)
concept that is used to address conflicts with the simultaneous
accessing or altering of data that can occur with a multi-user
system. It ensures that database transactions are
performed concurrently without violating the data integrity of the
respective databases. Thus concurrency control is an essential
element for correctness in any system where two or more
database transactions, executed with time overlap, can access
the same data.
www.advanced.edu.in
Descriptive Example
To illustrate the concept of concurrency control, consider two travelers who go to
electronic kiosks at the same time to purchase a train ticket to the same destination
on the same train. There's only one seat left in the coach, but without concurrency
control, it's possible that both travelers will end up purchasing a ticket for that one
seat. However, with concurrency control, the database wouldn't allow this to
happen. Both travelers would still be able to access the train seating database, but
concurrency control would preserve data accuracy and allow only one traveler to
purchase the seat.
www.advanced.edu.in
Concurrency Control Protocols can be broadly divided into two
categories −
Lock based protocols
Time stamp based protocols
www.advanced.edu.in
Lock Based Protocol
A lock is nothing but a mechanism that tells the DBMS whether a particular data item is being
used by any transaction for read/write purpose. Since there are two types of operations, i.e.
read and write, whose basic nature are different, the locks for read and write operation may
behave differently.
Read operation performed by different transactions on the same data item. The value of the
data item, if constant, can be read by any number of transactions at any given time. If a
transaction is reading the content of a sharable data item, then any number of other processes
can be allowed to read the content of the same data item.
Write operation is something different. When a transaction writes some value into a data item,
the content of that data item remains in an inconsistent state, starting from the moment when
the writing operation begins up to the moment the writing operation is over.
But if any transaction is writing into a sharable data item, then no other transaction will be
allowed to read or write that same data item.
www.advanced.edu.in
Lock-based Protocols
Database systems equipped with lock-based protocols use a mechanism by which any transaction
cannot read or write data until it acquires an appropriate lock on it. Locks are of two kinds −
Binary Locks − A lock on a data item can be in two states; it is either locked or unlocked.
Shared/Exclusive Lock−
Shared Lock: A transaction may acquire shared lock on a data item in order to read its content. The
lock is shared in the sense that any other transaction can acquire the shared lock on that same data
item for reading purpose.
Exclusive Lock: A transaction may acquire exclusive lock on a data item in order to both read/write
into it. The lock is excusive in the sense that no other transaction can acquire any kind of lock (either
shared or exclusive) on that same data item.
www.advanced.edu.in
There are four types of lock protocols available −
Simplistic Lock Protocol
Simplistic lock-based protocols allow transactions to obtain a lock on every object before a 'write'
operation is performed. Transactions may unlock the data item after completing the ‘write’
operation.
Pre-claiming Lock Protocol
Pre-claiming protocols evaluate their operations and create a list of data items on which they need
locks. Before initiating an execution, the transaction requests the system for all the locks it needs
beforehand. If all the locks are granted, the transaction executes and releases all the locks when all
its operations are over. If all the locks are not granted, the transaction rolls back and waits until all
the locks are granted.
www.advanced.edu.in
Two Phase Locking Protocol
The Two Phase Locking Protocol assumes that a transaction can only be in one of two phases.
 Growing Phase: In this phase the transaction can only acquire locks, but cannot release any lock.
The transaction enters the growing phase as soon as it acquires the first lock it wants. From now on it has
no option but to keep acquiring all the locks it would need. It cannot release any lock at this phase even if it
has finished working with a locked data item. Ultimately the transaction reaches a point where all the lock it
may need has been acquired. This point is called Lock Point.
 Shrinking Phase: After Lock Point has been reached, the transaction enters the shrinking phase.
In this phase the transaction can only release locks, but cannot acquire any new lock. The transaction enters
the shrinking phase as soon as it releases the first lock after crossing the Lock Point.
Strict Two-Phase Locking
The first phase of Strict-2PL is same as 2PL. After acquiring all the locks in the first phase, the transaction
continues to execute normally. But in contrast to 2PL, Strict-2PL does not release a lock after using it. Strict-
2PL holds all the locks until the commit point and releases all the locks at a time.
www.advanced.edu.in
Timestamp-based Protocols
A timestamp is a tag that can be attached to any transaction or any data item, which denotes a specific time on
which the transaction or data item had been activated in any way. This protocol uses either system time or logical
counter as a timestamp. Every transaction has a timestamp associated with it, and the ordering is determined by
the age of the transaction.
The timestamp of a data item can be of the following two types:
W-timestamp (Q): This means the latest time when the data item Q has been written into.
R-timestamp (Q): This means the latest time when the data item Q has been read from.
www.advanced.edu.in
How should timestamps be used?
For Read operations: If a transaction Ti issues a read(X) operation −
If TS(Ti) < W-timestamp(X)
Operation rejected.
If TS(Ti) >= W-timestamp(X)
Operation executed.
All data-item timestamps updated.
For Write operations: If a transaction Ti issues a write(X) operation −
If TS(Ti) < R-timestamp(X)
Operation rejected.
If TS(Ti) < W-timestamp(X)
Operation rejected and Ti rolled back.
Otherwise, operation executed.
www.advanced.edu.in
Thomas’s Write Rule Timestamp Ordering Protocol (TWRTSO Protocol)
When Transaction Ti issues READ Operation :
a) If TS(Ti) < WTS(Q), then
ROLLBACK Ti.
b) Otherwise,allowed to execute READ operation by transaction Ti and
Set RTS(Q) = max(RTS(Q), TS(Ti))
When Transaction Ti issues WRITE Operation :
a) If TS(Ti) < RTS(Q), then
ROLLBACK Ti.
a) If TS(Ti) < WTS(Q), then Ignore WRITE operation by Ti and
Continue the execution of Ti.
c) Otherwise, Allowed to execute the WRITE operation by transaction Ti and
Set WTS(Q) = TS(Ti)
www.advanced.edu.in
Neeti Arora
Assistant Professor
neetiarorapkl@gmail.com
Advanced Educational Institutions,
70 km Milestone,
Delhi-Mathura Road, Distt. Palwal, Haryana-121105
+91–1275–398400, 302222
www.advanced.edu.in
www.advanced.edu.in

More Related Content

PPTX
Concurrency in database system
PDF
Concurrency control
DOC
Concurrency control
PPT
Databases: Locking Methods
PPTX
protocols of concurrency control
PPT
Databases: Concurrency Control
PDF
Chapter 5 Database Transaction Management
PPT
Dbms sixth chapter_part-1_2011
Concurrency in database system
Concurrency control
Concurrency control
Databases: Locking Methods
protocols of concurrency control
Databases: Concurrency Control
Chapter 5 Database Transaction Management
Dbms sixth chapter_part-1_2011

What's hot (20)

PPT
Dbms ii mca-ch9-transaction-processing-2013
PPTX
Advanced DBMS presentation
PPTX
Transaction and concurrency control
PPT
Chapter18
PPT
Unit06 dbms
PPT
Transaction management
PDF
Introduction to database-Transaction Concurrency and Recovery
PPT
Concurrent transactions
PPT
15. Transactions in DBMS
DOCX
Multiversion Concurrency Control Techniques
PPTX
Transaction states and properties
PPTX
CS 542 -- Concurrency Control, Distributed Commit
PPT
Transactions (Distributed computing)
PPT
Transaction slide
PPTX
Transactions
PPTX
Transaction Management
PPTX
Deadlock in database
PPTX
Vani dbms
PPT
Distributed Transaction
PPT
Chapter17
Dbms ii mca-ch9-transaction-processing-2013
Advanced DBMS presentation
Transaction and concurrency control
Chapter18
Unit06 dbms
Transaction management
Introduction to database-Transaction Concurrency and Recovery
Concurrent transactions
15. Transactions in DBMS
Multiversion Concurrency Control Techniques
Transaction states and properties
CS 542 -- Concurrency Control, Distributed Commit
Transactions (Distributed computing)
Transaction slide
Transactions
Transaction Management
Deadlock in database
Vani dbms
Distributed Transaction
Chapter17
Ad

Viewers also liked (20)

PPTX
DBMS (Deadlock, deadlock prevention, 2phase locking)
PPT
multi-threading
PPTX
System Data Modelling Tools
PPT
Two phase commit protocol in dbms
PPTX
Validation based protocol
PPTX
Paging-R.D.Sivakumar
PPTX
Normalization in Database
PPTX
Normalization in DBMS
PPTX
Exception handling in Java
PPT
PPTX
OSI Model | Computer Science
ODP
Exception Handling In Java
PPTX
Normalization
PPT
Database Management Systems (DBMS)
PPT
Transaction concurrency control
PPT
Concurrency control
PPT
Test Life Cycle
PDF
Transaction & Concurrency Control
PPTX
Dbms slides
PDF
Database design & Normalization (1NF, 2NF, 3NF)
DBMS (Deadlock, deadlock prevention, 2phase locking)
multi-threading
System Data Modelling Tools
Two phase commit protocol in dbms
Validation based protocol
Paging-R.D.Sivakumar
Normalization in Database
Normalization in DBMS
Exception handling in Java
OSI Model | Computer Science
Exception Handling In Java
Normalization
Database Management Systems (DBMS)
Transaction concurrency control
Concurrency control
Test Life Cycle
Transaction & Concurrency Control
Dbms slides
Database design & Normalization (1NF, 2NF, 3NF)
Ad

Similar to Concurrency control ms neeti (20)

PDF
Advanced Database Chapter 4.pdf shnsbxlajmndm woweosmkl m,xcnkl C NOOxcx xcbnxc
PDF
Concurrency note.pdf
PPTX
Concurrency control PPT
PPTX
Concurrency Control in Distributed Database.
DOCX
Dbms voc 5 unit
PDF
Design & Development of an Advanced Database Management System Using Multiver...
PDF
F017213747
PDF
F017213747
PPTX
Transaction management
PDF
Unit 5 rdbms study_material
PPTX
Concurrent control
PDF
Mba ebooks ! Edhole
PPTX
DBMS Presentation.pptx
PPTX
Overview of Concurrency Control & Recovery in Distributed Databases
PPTX
DBMS Pravin concurrency control technique.pptx
PPTX
Transaction management
PPTX
Concurrency Control
PPTX
Concurrency control
PPTX
Optimistic concurrency control in Distributed Systems
Advanced Database Chapter 4.pdf shnsbxlajmndm woweosmkl m,xcnkl C NOOxcx xcbnxc
Concurrency note.pdf
Concurrency control PPT
Concurrency Control in Distributed Database.
Dbms voc 5 unit
Design & Development of an Advanced Database Management System Using Multiver...
F017213747
F017213747
Transaction management
Unit 5 rdbms study_material
Concurrent control
Mba ebooks ! Edhole
DBMS Presentation.pptx
Overview of Concurrency Control & Recovery in Distributed Databases
DBMS Pravin concurrency control technique.pptx
Transaction management
Concurrency Control
Concurrency control
Optimistic concurrency control in Distributed Systems

Recently uploaded (20)

PPTX
Construction Project Organization Group 2.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Welding lecture in detail for understanding
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Well-logging-methods_new................
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
additive manufacturing of ss316l using mig welding
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Digital Logic Computer Design lecture notes
Construction Project Organization Group 2.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Automation-in-Manufacturing-Chapter-Introduction.pdf
bas. eng. economics group 4 presentation 1.pptx
Welding lecture in detail for understanding
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Well-logging-methods_new................
Model Code of Practice - Construction Work - 21102022 .pdf
CH1 Production IntroductoryConcepts.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
573137875-Attendance-Management-System-original
additive manufacturing of ss316l using mig welding
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mechanical Engineering MATERIALS Selection
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Operating System & Kernel Study Guide-1 - converted.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
UNIT 4 Total Quality Management .pptx
Digital Logic Computer Design lecture notes

Concurrency control ms neeti

  • 1. By NeetiArora Assistant Professor Advanced Educational Institute DBMS- Concurrency Control www.advanced.edu.in
  • 2. Definition Concurrency control is a database management system (DBMS) concept that is used to address conflicts with the simultaneous accessing or altering of data that can occur with a multi-user system. It ensures that database transactions are performed concurrently without violating the data integrity of the respective databases. Thus concurrency control is an essential element for correctness in any system where two or more database transactions, executed with time overlap, can access the same data. www.advanced.edu.in
  • 3. Descriptive Example To illustrate the concept of concurrency control, consider two travelers who go to electronic kiosks at the same time to purchase a train ticket to the same destination on the same train. There's only one seat left in the coach, but without concurrency control, it's possible that both travelers will end up purchasing a ticket for that one seat. However, with concurrency control, the database wouldn't allow this to happen. Both travelers would still be able to access the train seating database, but concurrency control would preserve data accuracy and allow only one traveler to purchase the seat. www.advanced.edu.in
  • 4. Concurrency Control Protocols can be broadly divided into two categories − Lock based protocols Time stamp based protocols www.advanced.edu.in
  • 5. Lock Based Protocol A lock is nothing but a mechanism that tells the DBMS whether a particular data item is being used by any transaction for read/write purpose. Since there are two types of operations, i.e. read and write, whose basic nature are different, the locks for read and write operation may behave differently. Read operation performed by different transactions on the same data item. The value of the data item, if constant, can be read by any number of transactions at any given time. If a transaction is reading the content of a sharable data item, then any number of other processes can be allowed to read the content of the same data item. Write operation is something different. When a transaction writes some value into a data item, the content of that data item remains in an inconsistent state, starting from the moment when the writing operation begins up to the moment the writing operation is over. But if any transaction is writing into a sharable data item, then no other transaction will be allowed to read or write that same data item. www.advanced.edu.in
  • 6. Lock-based Protocols Database systems equipped with lock-based protocols use a mechanism by which any transaction cannot read or write data until it acquires an appropriate lock on it. Locks are of two kinds − Binary Locks − A lock on a data item can be in two states; it is either locked or unlocked. Shared/Exclusive Lock− Shared Lock: A transaction may acquire shared lock on a data item in order to read its content. The lock is shared in the sense that any other transaction can acquire the shared lock on that same data item for reading purpose. Exclusive Lock: A transaction may acquire exclusive lock on a data item in order to both read/write into it. The lock is excusive in the sense that no other transaction can acquire any kind of lock (either shared or exclusive) on that same data item. www.advanced.edu.in
  • 7. There are four types of lock protocols available − Simplistic Lock Protocol Simplistic lock-based protocols allow transactions to obtain a lock on every object before a 'write' operation is performed. Transactions may unlock the data item after completing the ‘write’ operation. Pre-claiming Lock Protocol Pre-claiming protocols evaluate their operations and create a list of data items on which they need locks. Before initiating an execution, the transaction requests the system for all the locks it needs beforehand. If all the locks are granted, the transaction executes and releases all the locks when all its operations are over. If all the locks are not granted, the transaction rolls back and waits until all the locks are granted. www.advanced.edu.in
  • 8. Two Phase Locking Protocol The Two Phase Locking Protocol assumes that a transaction can only be in one of two phases.  Growing Phase: In this phase the transaction can only acquire locks, but cannot release any lock. The transaction enters the growing phase as soon as it acquires the first lock it wants. From now on it has no option but to keep acquiring all the locks it would need. It cannot release any lock at this phase even if it has finished working with a locked data item. Ultimately the transaction reaches a point where all the lock it may need has been acquired. This point is called Lock Point.  Shrinking Phase: After Lock Point has been reached, the transaction enters the shrinking phase. In this phase the transaction can only release locks, but cannot acquire any new lock. The transaction enters the shrinking phase as soon as it releases the first lock after crossing the Lock Point. Strict Two-Phase Locking The first phase of Strict-2PL is same as 2PL. After acquiring all the locks in the first phase, the transaction continues to execute normally. But in contrast to 2PL, Strict-2PL does not release a lock after using it. Strict- 2PL holds all the locks until the commit point and releases all the locks at a time. www.advanced.edu.in
  • 9. Timestamp-based Protocols A timestamp is a tag that can be attached to any transaction or any data item, which denotes a specific time on which the transaction or data item had been activated in any way. This protocol uses either system time or logical counter as a timestamp. Every transaction has a timestamp associated with it, and the ordering is determined by the age of the transaction. The timestamp of a data item can be of the following two types: W-timestamp (Q): This means the latest time when the data item Q has been written into. R-timestamp (Q): This means the latest time when the data item Q has been read from. www.advanced.edu.in
  • 10. How should timestamps be used? For Read operations: If a transaction Ti issues a read(X) operation − If TS(Ti) < W-timestamp(X) Operation rejected. If TS(Ti) >= W-timestamp(X) Operation executed. All data-item timestamps updated. For Write operations: If a transaction Ti issues a write(X) operation − If TS(Ti) < R-timestamp(X) Operation rejected. If TS(Ti) < W-timestamp(X) Operation rejected and Ti rolled back. Otherwise, operation executed. www.advanced.edu.in
  • 11. Thomas’s Write Rule Timestamp Ordering Protocol (TWRTSO Protocol) When Transaction Ti issues READ Operation : a) If TS(Ti) < WTS(Q), then ROLLBACK Ti. b) Otherwise,allowed to execute READ operation by transaction Ti and Set RTS(Q) = max(RTS(Q), TS(Ti)) When Transaction Ti issues WRITE Operation : a) If TS(Ti) < RTS(Q), then ROLLBACK Ti. a) If TS(Ti) < WTS(Q), then Ignore WRITE operation by Ti and Continue the execution of Ti. c) Otherwise, Allowed to execute the WRITE operation by transaction Ti and Set WTS(Q) = TS(Ti) www.advanced.edu.in
  • 12. Neeti Arora Assistant Professor neetiarorapkl@gmail.com Advanced Educational Institutions, 70 km Milestone, Delhi-Mathura Road, Distt. Palwal, Haryana-121105 +91–1275–398400, 302222 www.advanced.edu.in www.advanced.edu.in