SlideShare a Scribd company logo
1 of 8
1
Concurrency Control Techniques
Concurrency Control Techniques: Overview of Locking, 2PL, Timestamp ordering,
multiversioning, validation
There are number of concurrency control techniques that are used to ensure the isolation property
of concurrently executing transactions. Most of these techniques ensure serializability of
schedules using protocols (sets of rules) that guarantee serializability. One important set of
protocols employs the technique of locking data items to prevent multiple transactions from
accessing the items concurrently. Locking protocols are used in most commercial DBMSs.
Another set of concurrency control protocols use timestamps. A timestamp is a unique identifier
for each transaction, generated by the system.
The multiversion concurrency control protocols use multiple versions of a data item.
A protocol based on the concept of validation or certification of a transaction after it executes
its operations; is sometimes called optimistic protocol.
1. Locking Techniques for Concurrency Control
Transaction processing system usually allows multiple transactions to run concurrently. By
allowing multiple transactions to run concurrently will improve the performance of the system in
terms of increased throughout or improved response time, but this allows causes several
complications with consistency of the data. Ensuring consistency in spite of concurrent execution
of transaction require extra work, which is performed by the concurrency controller system of
DBMS.
What is Lock?
A lock is a variable associated with a data item that describes the status of the item with respect
to possible operations that can be applied to it. Generally, there is one lock for each data item in
the database. Locks are used as a means of synchronizing the access by concurrent transactions
to the database item.
Types of Locks
Generally 2 types of locks are used in concurrency control.
i) Binary locks, which are simple but restrictive and so are not used in practice.
ii) Shared/Exclusive locks, which provide more general locking capabilities and are used
in practical database locking schemes.
i) Binary Locks
A binary lock can have two states or values: locked and unlocked. A distinct lock is associated
with each database item A. If the value of the lock on A is 1, item A cannot be accessed by a
2
database operation that requests the item. If the value of the lock on A is 0 then item can be
accessed when requested.
We refer to the current value of the lock associated with item A as LOCK (A).
There are two operations, lock_item(A) and unlock(A) that are used with binary locking. A
transaction requests access to an item A by first issuing a lock_item(A) operation.
 If LOCK (A) = 1, the transaction is forced to wait.
 If LOCK (A) = 0 it is set to 1 (the transaction locks the item) and the transaction is
allowed to access item A.
When the transaction is through using the item, it issues an unlock(A) operation, which sets
LOCK (A) to 0 (unlocks the item) so that A may be accessed by other transactions. Hence binary
lock enforces mutual exclusion on the data item.
Rules of Binary Locks
If the simple binary locking scheme described here is used, every transaction must obey the
following rules:
1) A transaction must issue the operation lock_item(A) before any read_item (A) or write,
item operations are performed in T.
2) A transaction T must issue the operation unlock(A) after all read_item (A) and
write_item (A) operations are completed in T.
3) A transaction T will not issue a lock _item (A) operation if it already holds the lock on
Item A.
4) A transaction T will not issue an unlock(A) operation unless it already holds the lock on
item A.
5) The lock manager module of the DBMS can enforce these rules. Between the lock_item
(A) and unlock(A) operations in transaction T, is said to hold the lock on item A. At most
one transaction can hold the lock on a particular item. Thus no two transactions can
access the same item concurrently.
Disadvantages of Binary Locks
As binary locking scheme is too restrictive for database items, because at most one transaction
can hold a lock on a given item. So, binary locking system cannot be used for practical purpose.
ii) Share/Exclusive (for Read/Write) Locks
Locking operations: There are three locking operations called read_lock(A), write_lock(A)
and unlock(A). A lock associated with an item A, LOCK (A), now has three possible states:
"read-locked", "write-locked," or "unlocked." A read-locked item is also called share-locked item
because other transactions are allowed to read the item, whereas a write-locked item is caused
exclusive-locked, because a single transaction exclusively holds the lock on the item.
3
Compatibility of Locks Suppose that there are A and B two different locking modes Read or
Shared(S) & Write or Exclusive(X). If a transaction T1 requests a lock of mode on item Q on
which transaction T2 currently hold a lock of mode B. If transaction can be granted lock, in spite
of the presence of the mode B lock, then we say mode A is compatible with mode B. Such a
function is shown in one matrix as shown below:
The graphs shows that if two transactions only read the same data object they do not conf1ict,
but if one transaction writes a data object and another either read or write the same data object,
then they conflict with each other. A transaction requests a shared lock on data item Q by
executing the read_lock(Q) instruction. Similarly, an exclusive lock is requested through the
write_lock(Q) instruction. A data item Q can be unlocked via the unlock(Q) instruction.
How Should Lock be Used?
To access a data item, transaction T1 must first lock that item. If the data item is already locked
by another transaction in an incompatible mode, the concurrency control manager will not grant
the lock until all incompatible locks held by other transactions have been released. Thus, T1 is
made to wait until all incompatible locks held by other transactions have been released
When we use the shared/exclusive locking scheme, the system must enforce the following rules:
a. A transaction T must issue the operation read_lock(X) or write_lock(X) before
any read_item(X) operation is performed in T.
b. A transaction T must issue the operation write_lock(X) before any write_item(X)
operation is performed in T.
c. A transaction T must issue the operation unlock(X) after all read_item(X) and
write_item(X) operations are completed in T.
d. A transaction T will not issue a read_lock(X) operation if it already holds a read
(shared) lock or a write (exclusive) lock on item X. This rule may be relaxed.
e. A transaction T will not issue a write_lock(X) operation if it already holds a read
(shared) lock or write (exclusive) lock on item X. This rule may be relaxed.
f. A transaction T will not issue an unlock(X) operation unless it already holds a
read (shared) lock or a write (exclusive) lock on item X.
4
For example, a transaction T1’ after applying the read/write or shared/exclusive lock on T1.
T1 T1’(equivalent transaction after applying read/write lock)
Example: Let x & y are two accounts that are accessed by transactions T1 & T2. T1 transfers
50/- from account x to y and is defined below.
Transaction T1 T2: simply add x & y and display the sum
Suppose that the values of accounts x and y are Rs.200 and Rs.100, respectively. If these two
transactions are executed serially, either in the order T1 and T2 or the order T2 and T1 then
transaction T2 will display the value Rs.300. If however, these transactions are executed
concurrently, as shown in Schedule 1, in this case, transaction T2 displays Rs.250, which is
incorrect. The reason for this mistake is that the transaction TI unlocked data item x too early, as
a result of which T2 shows an inconsistent state.
read(x);
read(y);
y=y+x;
write(y);
read_lock(x); Shared lock on x
read(x);
unlock(x); unlock x
write_lock(y); exclusive lock on y
read(y);
y = y + x;
write(y);
unlock(y); unlock y
read_lock(y);
read(y);
unlock(y);
read_lock(x);
read(x);
unlock(x);
sum=x+y;
display(sum);
write_lock(x);
read(x);
x = x – 50;
write(x);
unlock(x);
write_lock(y);
read(y);
y = y + 50;
write(y);
unlock(y);
5
T1 T2
write_lock(x);
read(x);
x = x – 50;
write(x);
unlock(x);
read_lock(y);
read(y);
unlock(y);
read_lock(x);
read(x);
unlock(x);
sum=x+y;
display(sum);
write_lock(y);
read(y);
y = y + 50;
write(y);
unlock(y);
Figure: Schedule 1
Hence, it can be found that using read/write locking mechanism doesn’t guarantee serializibilty.
Guaranteeing serializibilty can be done by the locking scheme called 2-phase locking scheme or
2PL mechanism.
6
Two Phase Locking (2PL) Protocol
The use of locks has helped us to create neat and clean concurrent schedule. The Two Phase
Locking Protocol defines the rules of how to acquire the locks on a data item and how to release
the locks. The Two Phase Locking Protocol assumes that a transaction can only be in one of two
phases.
i) Growing Phase: During this phase, the transaction can only acquire locks but no existing lock
can be released.
ii) Shrinking Phase: During this phase, existing locks can be released but no new locks can be
acquired.
The 2PC Locking protocol always results in a serializable schedule.
Example :: here the transaction T1 do not follow the 2PC Protocol, because the write_lock(y)
operation in T1 follows the unlock(x) operation. On enforcing the 2PC Locking scheme, the
transaction T1 can be written as T1’ as follows:
T1 T1’
Problems in Two-Phase Locking
 Deadlock - It happens whenever a transaction waits for a lock to be unlock (to access the
data).
 Cascading roll back -When the data requested by 1 transaction is held by some other
transactions again and again and the requested data is not given.
write_lock(x);
read(x);
x = x – 50;
write(x);
unlock(x);
write_lock(y);
read(y);
y = y + 50;
write(y);
unlock(y);
write_lock(x);
read(x);
x = x – 50;
write(x);
write_lock(y);
unlock(x);
read(y);
y = y + 50;
write(y);
unlock(y);
7
Concurrency Control Based on Timestamp Ordering
The Timestamp Ordering(TO) Algorithm
The timestamp-ordering protocol ensures serializability among transaction in their conflicting
read and write operations. This is the responsibility of the protocol system that the conflicting
pair of tasks should be executed according to the timestamp values of the transactions.
Timestamps
A timestamp is a unique identifier created by the DBMS to identify a transaction. Typically,
timestamp values are assigned in the order in which the transactions are submitted to the system,
so a timestamp can be thought of as the transaction start time. The timestamp of transaction T
can be referred as TS(T). Concurrency control techniques based on timestamp ordering do not
use locks; hence, deadlocks cannot occur.
In this, a unique fixed timestamp is associated with each transaction to keep the order of the
transaction. It is denoted by TS (Ti).
Example: If a transaction T1 has been assigned timestamp TS (T1) and a new transaction TS
(T2) enters the system, then TS (T1) < TS (T2).
Two methods for implementing TS
 Use the value of the system as the timestamp (System Clock).
 Use a logical counter that is incremented after a new timestamp has been assigned.
Implementation Method
The timestamp of a data item can be of the following two types:
 WTS(Q) or W-timestamp (Q): This means the latest time when the data item Q has
been written into.
 RTS(Q) or R-timestamp (Q): This means the latest time when the data item Q has been
read from.
These two timestamps are updated each time a successful read/write operation is performed on
the data item Q.
Timestamp ordering protocol works as follows:
1. If a transaction Ti issues read operation:
If TS(Ti) < WTS(Q), then the read operation is rejected and the transaction Ti is restarted
with a new timestamp value; otherwise, i.e if TS(Ti) >= WTS(Q) , the read operation is executed
and RTS(Q) is set to max(RTS(Q), TS(Ti)).
2. If a transaction Ti issues write operation:
If TS (Ti) < RTS(Q) or TS (Ti) < WTS(Q), then the write operation is rejected or
rollback and the transaction Ti is restarted with a new timestamp value; otherwise, if TS(Ti) >=
RTS(Q) or TS(Ti) >= WTS(Q) , the write operation is executed and WTS(Q) is set to TS(Ti).
8
Example:
Step T1 T2 T3 a b c
(200) (150) (175) RT(a)=0, RT(b)=0, RT(c)=0,
WT(a)=0 WT(b)=0 WT(c)=0
1 Read(b) RT(b)=200
2 Read(a) RT(a)=150
3 Read(c) RT(c)=175
4 Write(b) WT(b)=200
5 Write(a) WT(a)=200
6 Write(c)
7 Write(a)
At step1, the operationread(b) executed,as
TS(T1) < WTS(b) i.e 200 < 0 does not follows , and
RTS(b) is set to max(RTS(b), TS(T1)) i.e RTS(b)=200
Similar rules for step 2, 3
For step 4 the operationwrite(b)executed,as
TS (T1) < RTS(b) or TS (T1) < WTS(b) i.e. 200 < 200 or 200 < 0 does not follows , and
WTS(b) is set to TS(T1) i.e WTS(b)=200
Step 5 the operationwrite(a)isalsoexecuted.
At step6, howeverthe operationwrite(c) isrejectedasitdoesnotfollowsthe rule
At step7, T3 triesto write a & the read value of a i.e RTS(a) =150. But TS(T3) > RT(a) , i.e 175 > 150, T3
neednotto be aborted.

More Related Content

What's hot

Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Meghaj Mallick
 
Transaction management in DBMS
Transaction management in DBMSTransaction management in DBMS
Transaction management in DBMSMegha Sharma
 
Log based and Recovery with concurrent transaction
Log based and Recovery with concurrent transactionLog based and Recovery with concurrent transaction
Log based and Recovery with concurrent transactionnikunjandy
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Concurrency control
Concurrency controlConcurrency control
Concurrency controlvarsha singh
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPTShushrutGupta
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency controlBinte fatima
 
Lock based protocols
Lock based protocolsLock based protocols
Lock based protocolsChethanMp7
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMSkoolkampus
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemSara Ali
 

What's hot (20)

Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
 
Chapter18
Chapter18Chapter18
Chapter18
 
Transaction management in DBMS
Transaction management in DBMSTransaction management in DBMS
Transaction management in DBMS
 
Acid properties
Acid propertiesAcid properties
Acid properties
 
Log based and Recovery with concurrent transaction
Log based and Recovery with concurrent transactionLog based and Recovery with concurrent transaction
Log based and Recovery with concurrent transaction
 
concurrency-control
concurrency-controlconcurrency-control
concurrency-control
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Concurrency Control.
Concurrency Control.Concurrency Control.
Concurrency Control.
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPT
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
 
Lock based protocols
Lock based protocolsLock based protocols
Lock based protocols
 
2 phase locking protocol DBMS
2 phase locking protocol DBMS2 phase locking protocol DBMS
2 phase locking protocol DBMS
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS
 
Deadlock dbms
Deadlock dbmsDeadlock dbms
Deadlock dbms
 
Deadlock in database
Deadlock in databaseDeadlock in database
Deadlock in database
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
DBMS - RAID
DBMS - RAIDDBMS - RAID
DBMS - RAID
 

Similar to Concurrency Control Techniques

Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppthaymanot taddesse
 
concurrency-control-techniques.ppt
concurrency-control-techniques.pptconcurrency-control-techniques.ppt
concurrency-control-techniques.pptkushvithchinna900
 
Concurrency note.pdf
Concurrency note.pdfConcurrency note.pdf
Concurrency note.pdfBijayNag1
 
DBMS Presentation.pptx
DBMS Presentation.pptxDBMS Presentation.pptx
DBMS Presentation.pptxPravinBhargav1
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingMeghaj Mallick
 
Unit 5 rdbms study_material
Unit 5  rdbms study_materialUnit 5  rdbms study_material
Unit 5 rdbms study_materialgayaramesh
 
5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.pptDadiTesfaye
 
Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...IOSR Journals
 
Concurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case StudiesConcurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case StudiesPrabu U
 
Unit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovelyUnit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovelyPritishMajumdar3
 
Unit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovelyUnit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovelyPritishMajumdar3
 
db unit 4 dbms protocols in transaction
db unit 4 dbms  protocols in transactiondb unit 4 dbms  protocols in transaction
db unit 4 dbms protocols in transactionKumari Naveen
 
Concurrency Control.pptx
Concurrency Control.pptxConcurrency Control.pptx
Concurrency Control.pptxVijaySourtha
 

Similar to Concurrency Control Techniques (20)

concurrency control
concurrency controlconcurrency control
concurrency control
 
Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppt
 
concurrency-control-techniques.ppt
concurrency-control-techniques.pptconcurrency-control-techniques.ppt
concurrency-control-techniques.ppt
 
Concurrency note.pdf
Concurrency note.pdfConcurrency note.pdf
Concurrency note.pdf
 
DBMS Presentation.pptx
DBMS Presentation.pptxDBMS Presentation.pptx
DBMS Presentation.pptx
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock Handling
 
Unit 5 rdbms study_material
Unit 5  rdbms study_materialUnit 5  rdbms study_material
Unit 5 rdbms study_material
 
Cs501 concurrency
Cs501 concurrencyCs501 concurrency
Cs501 concurrency
 
5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt
 
UNIT II.pptx
UNIT II.pptxUNIT II.pptx
UNIT II.pptx
 
F017213747
F017213747F017213747
F017213747
 
F017213747
F017213747F017213747
F017213747
 
Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...
 
Unit 6
Unit 6Unit 6
Unit 6
 
2 con control
2 con control2 con control
2 con control
 
Concurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case StudiesConcurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case Studies
 
Unit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovelyUnit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovely
 
Unit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovelyUnit 4 Concurrency control.pptx dbms lovely
Unit 4 Concurrency control.pptx dbms lovely
 
db unit 4 dbms protocols in transaction
db unit 4 dbms  protocols in transactiondb unit 4 dbms  protocols in transaction
db unit 4 dbms protocols in transaction
 
Concurrency Control.pptx
Concurrency Control.pptxConcurrency Control.pptx
Concurrency Control.pptx
 

More from Raj vardhan

Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3Raj vardhan
 
Internet Basics Unit-7
Internet Basics  Unit-7Internet Basics  Unit-7
Internet Basics Unit-7Raj vardhan
 
Local Area Network – Wired LAN
Local Area Network – Wired LANLocal Area Network – Wired LAN
Local Area Network – Wired LANRaj vardhan
 
Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5Raj vardhan
 
UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CUNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CRaj vardhan
 
Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture Raj vardhan
 
UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices Raj vardhan
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteUnit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteRaj vardhan
 
Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2Raj vardhan
 
Swachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project ReportSwachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project ReportRaj vardhan
 
Network Topology
Network TopologyNetwork Topology
Network TopologyRaj vardhan
 
Microsoft Office Word Introduction Complete
Microsoft Office Word  Introduction CompleteMicrosoft Office Word  Introduction Complete
Microsoft Office Word Introduction CompleteRaj vardhan
 
Digital money Revolution Introduction
Digital money Revolution IntroductionDigital money Revolution Introduction
Digital money Revolution IntroductionRaj vardhan
 
Definition of Business
Definition of BusinessDefinition of Business
Definition of BusinessRaj vardhan
 
Business Terms & Concepts
Business Terms & ConceptsBusiness Terms & Concepts
Business Terms & ConceptsRaj vardhan
 
Number System Conversion | BCA
Number System Conversion | BCANumber System Conversion | BCA
Number System Conversion | BCARaj vardhan
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FITRaj vardhan
 
FIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCAFIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCARaj vardhan
 
Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205 Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205 Raj vardhan
 

More from Raj vardhan (20)

Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3
 
Internet Basics Unit-7
Internet Basics  Unit-7Internet Basics  Unit-7
Internet Basics Unit-7
 
Local Area Network – Wired LAN
Local Area Network – Wired LANLocal Area Network – Wired LAN
Local Area Network – Wired LAN
 
Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5
 
UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CUNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN C
 
Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture
 
UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteUnit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 Complete
 
Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2
 
Swachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project ReportSwachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project Report
 
Network Topology
Network TopologyNetwork Topology
Network Topology
 
Microsoft Office Word Introduction Complete
Microsoft Office Word  Introduction CompleteMicrosoft Office Word  Introduction Complete
Microsoft Office Word Introduction Complete
 
Digital money Revolution Introduction
Digital money Revolution IntroductionDigital money Revolution Introduction
Digital money Revolution Introduction
 
C Programming
C ProgrammingC Programming
C Programming
 
Definition of Business
Definition of BusinessDefinition of Business
Definition of Business
 
Business Terms & Concepts
Business Terms & ConceptsBusiness Terms & Concepts
Business Terms & Concepts
 
Number System Conversion | BCA
Number System Conversion | BCANumber System Conversion | BCA
Number System Conversion | BCA
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FIT
 
FIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCAFIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCA
 
Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205 Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

Concurrency Control Techniques

  • 1. 1 Concurrency Control Techniques Concurrency Control Techniques: Overview of Locking, 2PL, Timestamp ordering, multiversioning, validation There are number of concurrency control techniques that are used to ensure the isolation property of concurrently executing transactions. Most of these techniques ensure serializability of schedules using protocols (sets of rules) that guarantee serializability. One important set of protocols employs the technique of locking data items to prevent multiple transactions from accessing the items concurrently. Locking protocols are used in most commercial DBMSs. Another set of concurrency control protocols use timestamps. A timestamp is a unique identifier for each transaction, generated by the system. The multiversion concurrency control protocols use multiple versions of a data item. A protocol based on the concept of validation or certification of a transaction after it executes its operations; is sometimes called optimistic protocol. 1. Locking Techniques for Concurrency Control Transaction processing system usually allows multiple transactions to run concurrently. By allowing multiple transactions to run concurrently will improve the performance of the system in terms of increased throughout or improved response time, but this allows causes several complications with consistency of the data. Ensuring consistency in spite of concurrent execution of transaction require extra work, which is performed by the concurrency controller system of DBMS. What is Lock? A lock is a variable associated with a data item that describes the status of the item with respect to possible operations that can be applied to it. Generally, there is one lock for each data item in the database. Locks are used as a means of synchronizing the access by concurrent transactions to the database item. Types of Locks Generally 2 types of locks are used in concurrency control. i) Binary locks, which are simple but restrictive and so are not used in practice. ii) Shared/Exclusive locks, which provide more general locking capabilities and are used in practical database locking schemes. i) Binary Locks A binary lock can have two states or values: locked and unlocked. A distinct lock is associated with each database item A. If the value of the lock on A is 1, item A cannot be accessed by a
  • 2. 2 database operation that requests the item. If the value of the lock on A is 0 then item can be accessed when requested. We refer to the current value of the lock associated with item A as LOCK (A). There are two operations, lock_item(A) and unlock(A) that are used with binary locking. A transaction requests access to an item A by first issuing a lock_item(A) operation.  If LOCK (A) = 1, the transaction is forced to wait.  If LOCK (A) = 0 it is set to 1 (the transaction locks the item) and the transaction is allowed to access item A. When the transaction is through using the item, it issues an unlock(A) operation, which sets LOCK (A) to 0 (unlocks the item) so that A may be accessed by other transactions. Hence binary lock enforces mutual exclusion on the data item. Rules of Binary Locks If the simple binary locking scheme described here is used, every transaction must obey the following rules: 1) A transaction must issue the operation lock_item(A) before any read_item (A) or write, item operations are performed in T. 2) A transaction T must issue the operation unlock(A) after all read_item (A) and write_item (A) operations are completed in T. 3) A transaction T will not issue a lock _item (A) operation if it already holds the lock on Item A. 4) A transaction T will not issue an unlock(A) operation unless it already holds the lock on item A. 5) The lock manager module of the DBMS can enforce these rules. Between the lock_item (A) and unlock(A) operations in transaction T, is said to hold the lock on item A. At most one transaction can hold the lock on a particular item. Thus no two transactions can access the same item concurrently. Disadvantages of Binary Locks As binary locking scheme is too restrictive for database items, because at most one transaction can hold a lock on a given item. So, binary locking system cannot be used for practical purpose. ii) Share/Exclusive (for Read/Write) Locks Locking operations: There are three locking operations called read_lock(A), write_lock(A) and unlock(A). A lock associated with an item A, LOCK (A), now has three possible states: "read-locked", "write-locked," or "unlocked." A read-locked item is also called share-locked item because other transactions are allowed to read the item, whereas a write-locked item is caused exclusive-locked, because a single transaction exclusively holds the lock on the item.
  • 3. 3 Compatibility of Locks Suppose that there are A and B two different locking modes Read or Shared(S) & Write or Exclusive(X). If a transaction T1 requests a lock of mode on item Q on which transaction T2 currently hold a lock of mode B. If transaction can be granted lock, in spite of the presence of the mode B lock, then we say mode A is compatible with mode B. Such a function is shown in one matrix as shown below: The graphs shows that if two transactions only read the same data object they do not conf1ict, but if one transaction writes a data object and another either read or write the same data object, then they conflict with each other. A transaction requests a shared lock on data item Q by executing the read_lock(Q) instruction. Similarly, an exclusive lock is requested through the write_lock(Q) instruction. A data item Q can be unlocked via the unlock(Q) instruction. How Should Lock be Used? To access a data item, transaction T1 must first lock that item. If the data item is already locked by another transaction in an incompatible mode, the concurrency control manager will not grant the lock until all incompatible locks held by other transactions have been released. Thus, T1 is made to wait until all incompatible locks held by other transactions have been released When we use the shared/exclusive locking scheme, the system must enforce the following rules: a. A transaction T must issue the operation read_lock(X) or write_lock(X) before any read_item(X) operation is performed in T. b. A transaction T must issue the operation write_lock(X) before any write_item(X) operation is performed in T. c. A transaction T must issue the operation unlock(X) after all read_item(X) and write_item(X) operations are completed in T. d. A transaction T will not issue a read_lock(X) operation if it already holds a read (shared) lock or a write (exclusive) lock on item X. This rule may be relaxed. e. A transaction T will not issue a write_lock(X) operation if it already holds a read (shared) lock or write (exclusive) lock on item X. This rule may be relaxed. f. A transaction T will not issue an unlock(X) operation unless it already holds a read (shared) lock or a write (exclusive) lock on item X.
  • 4. 4 For example, a transaction T1’ after applying the read/write or shared/exclusive lock on T1. T1 T1’(equivalent transaction after applying read/write lock) Example: Let x & y are two accounts that are accessed by transactions T1 & T2. T1 transfers 50/- from account x to y and is defined below. Transaction T1 T2: simply add x & y and display the sum Suppose that the values of accounts x and y are Rs.200 and Rs.100, respectively. If these two transactions are executed serially, either in the order T1 and T2 or the order T2 and T1 then transaction T2 will display the value Rs.300. If however, these transactions are executed concurrently, as shown in Schedule 1, in this case, transaction T2 displays Rs.250, which is incorrect. The reason for this mistake is that the transaction TI unlocked data item x too early, as a result of which T2 shows an inconsistent state. read(x); read(y); y=y+x; write(y); read_lock(x); Shared lock on x read(x); unlock(x); unlock x write_lock(y); exclusive lock on y read(y); y = y + x; write(y); unlock(y); unlock y read_lock(y); read(y); unlock(y); read_lock(x); read(x); unlock(x); sum=x+y; display(sum); write_lock(x); read(x); x = x – 50; write(x); unlock(x); write_lock(y); read(y); y = y + 50; write(y); unlock(y);
  • 5. 5 T1 T2 write_lock(x); read(x); x = x – 50; write(x); unlock(x); read_lock(y); read(y); unlock(y); read_lock(x); read(x); unlock(x); sum=x+y; display(sum); write_lock(y); read(y); y = y + 50; write(y); unlock(y); Figure: Schedule 1 Hence, it can be found that using read/write locking mechanism doesn’t guarantee serializibilty. Guaranteeing serializibilty can be done by the locking scheme called 2-phase locking scheme or 2PL mechanism.
  • 6. 6 Two Phase Locking (2PL) Protocol The use of locks has helped us to create neat and clean concurrent schedule. The Two Phase Locking Protocol defines the rules of how to acquire the locks on a data item and how to release the locks. The Two Phase Locking Protocol assumes that a transaction can only be in one of two phases. i) Growing Phase: During this phase, the transaction can only acquire locks but no existing lock can be released. ii) Shrinking Phase: During this phase, existing locks can be released but no new locks can be acquired. The 2PC Locking protocol always results in a serializable schedule. Example :: here the transaction T1 do not follow the 2PC Protocol, because the write_lock(y) operation in T1 follows the unlock(x) operation. On enforcing the 2PC Locking scheme, the transaction T1 can be written as T1’ as follows: T1 T1’ Problems in Two-Phase Locking  Deadlock - It happens whenever a transaction waits for a lock to be unlock (to access the data).  Cascading roll back -When the data requested by 1 transaction is held by some other transactions again and again and the requested data is not given. write_lock(x); read(x); x = x – 50; write(x); unlock(x); write_lock(y); read(y); y = y + 50; write(y); unlock(y); write_lock(x); read(x); x = x – 50; write(x); write_lock(y); unlock(x); read(y); y = y + 50; write(y); unlock(y);
  • 7. 7 Concurrency Control Based on Timestamp Ordering The Timestamp Ordering(TO) Algorithm The timestamp-ordering protocol ensures serializability among transaction in their conflicting read and write operations. This is the responsibility of the protocol system that the conflicting pair of tasks should be executed according to the timestamp values of the transactions. Timestamps A timestamp is a unique identifier created by the DBMS to identify a transaction. Typically, timestamp values are assigned in the order in which the transactions are submitted to the system, so a timestamp can be thought of as the transaction start time. The timestamp of transaction T can be referred as TS(T). Concurrency control techniques based on timestamp ordering do not use locks; hence, deadlocks cannot occur. In this, a unique fixed timestamp is associated with each transaction to keep the order of the transaction. It is denoted by TS (Ti). Example: If a transaction T1 has been assigned timestamp TS (T1) and a new transaction TS (T2) enters the system, then TS (T1) < TS (T2). Two methods for implementing TS  Use the value of the system as the timestamp (System Clock).  Use a logical counter that is incremented after a new timestamp has been assigned. Implementation Method The timestamp of a data item can be of the following two types:  WTS(Q) or W-timestamp (Q): This means the latest time when the data item Q has been written into.  RTS(Q) or R-timestamp (Q): This means the latest time when the data item Q has been read from. These two timestamps are updated each time a successful read/write operation is performed on the data item Q. Timestamp ordering protocol works as follows: 1. If a transaction Ti issues read operation: If TS(Ti) < WTS(Q), then the read operation is rejected and the transaction Ti is restarted with a new timestamp value; otherwise, i.e if TS(Ti) >= WTS(Q) , the read operation is executed and RTS(Q) is set to max(RTS(Q), TS(Ti)). 2. If a transaction Ti issues write operation: If TS (Ti) < RTS(Q) or TS (Ti) < WTS(Q), then the write operation is rejected or rollback and the transaction Ti is restarted with a new timestamp value; otherwise, if TS(Ti) >= RTS(Q) or TS(Ti) >= WTS(Q) , the write operation is executed and WTS(Q) is set to TS(Ti).
  • 8. 8 Example: Step T1 T2 T3 a b c (200) (150) (175) RT(a)=0, RT(b)=0, RT(c)=0, WT(a)=0 WT(b)=0 WT(c)=0 1 Read(b) RT(b)=200 2 Read(a) RT(a)=150 3 Read(c) RT(c)=175 4 Write(b) WT(b)=200 5 Write(a) WT(a)=200 6 Write(c) 7 Write(a) At step1, the operationread(b) executed,as TS(T1) < WTS(b) i.e 200 < 0 does not follows , and RTS(b) is set to max(RTS(b), TS(T1)) i.e RTS(b)=200 Similar rules for step 2, 3 For step 4 the operationwrite(b)executed,as TS (T1) < RTS(b) or TS (T1) < WTS(b) i.e. 200 < 200 or 200 < 0 does not follows , and WTS(b) is set to TS(T1) i.e WTS(b)=200 Step 5 the operationwrite(a)isalsoexecuted. At step6, howeverthe operationwrite(c) isrejectedasitdoesnotfollowsthe rule At step7, T3 triesto write a & the read value of a i.e RTS(a) =150. But TS(T3) > RT(a) , i.e 175 > 150, T3 neednotto be aborted.