SlideShare a Scribd company logo
1 of 34
Download to read offline
CONCURRENCY
CONTOL
Copyright @ www.bcanotes.com
DEFINITION
 Concurrency means allowing more than one transaction
to run simultaneously on the same database.
 When several transactions run concurrently database
consistency can be destroyed.
 To remove this problem Concurrency control is used.
Copyright @ www.bcanotes.com
Need of Concurrency Control (CC)
 The concurrent execution of transactions may lead,
if uncontrolled, to problems such as an inconsistent
database.
 CC techniques are used to ensure that multiple
transactions submitted by various users do not
interfere with one another in a way that produces
incorrect results.
 The effect on a database of any number of
transactions executing in parallel must be the same
as if they were executed one after another.
Copyright @ www.bcanotes.com
Advantages of Concurrent Execution of Transactions
 Improvement Throughput
 Reduced Waiting Time
Copyright @ www.bcanotes.com
Problems of Concurrent Execution of
Transactions
 For Concurrency problems following control
mechanism is required:
 Lost Update Problem
 The Temporary Update (Uncommitted Dependency) Problem
 The Incorrect Summary (Inconsistent Analysis) Problem
Copyright @ www.bcanotes.com
The Lost Update Problem
In this problem, 2 transactions accessing the
same database item have their operations
interleaved in a way that makes the database
item incorrect.
Copyright @ www.bcanotes.com
Consider the following Example
Lost Update Problem…
Step T1 T2 Result
1 Read (A) A=100
2 A=A-50
3 Read (A) A=100
4 A=A+50
5 Write (A) A=50
6 Read (B) B=200
7 Write (A) A=150
8 B=B+50
9 Write (B) B=250
Copyright @ www.bcanotes.com
The Temporary Update (Uncommitted
Dependency) Problem
This problem occurs when one transaction is
allowed to see the intermediate results of
another transaction before it is committed.
Copyright @ www.bcanotes.com
Consider the Example - The Temporary Update
(Uncommitted Dependency) Problem
Step T1 T2 Result
1 Start Transaction A=200
2 Read (A) A=200
3 A=A-100 A=200
4 Write (A) Start Transaction A=100
5 Read (A) A=100
6 A=A+150 A=100
7 ROLL BACK Write (A) A=250
8 Commit A=250
Since the transaction is Aborted so the database will be
restored to its original state Rs 200.
Copyright @ www.bcanotes.com
The Incorrect Summary (Inconsistent
Analysis) Problem
 This problem occurs when a transaction reads
several values from a database while a second
transaction updates some of them.
 For e.g. Values of variable A, B, C and Sum
are in column 3,4,5 and 6. The initial values
of Sum is 100, 50, 25 and 0 respectively.
Copyright @ www.bcanotes.com
T1 T2 A B C SUM Remarks
R(A,a) R(A,a) Rs.100 Rs.50 Rs.25 0
sum=sum+A A=A-10 Rs.100 Rs.50 Rs.25 100 Value of Sum is changed due
to T1 operation and content
of local variable ‘a’ is
changed to 90
R(B,b) W(A,a) Rs.90 Rs.50 Rs.25 100 Write operation on A is
performed by T2, so A=90
sum=sum+B R(C,c) Rs.90 Rs.50 Rs.25 150 Value of Sum is changed due
to T1 Operation.
c=c+10 Rs.90 Rs.50 Rs.25 150 Content of local variable ‘c’ is
changed to 35
W(C,c) Rs.90 Rs.50 Rs.35 150 WRITE operation on C is
performed by T2 i.e. = 35
R(C,c) Rs.90 Rs.50 Rs.35 150 Value of C is read out as 35
by T1
sum=sum+C Rs.90 Rs.50 Rs.35 185 Value of Sum is changed due
to T1 operation i.e. 185
The Incorrect Summary (Inconsistent Analysis)
Problem
Copyright @ www.bcanotes.com
Concurrency Control Schemes
 Concurrency control schemes are divided
into 2 categories:
 Pessimistic or Conservative Approach
 Optimistic Approach
Copyright @ www.bcanotes.com
Pessimistic Approach
 This approach says that there must be some
concurrency control techniques deployed before
the transactions are allowed to access the database.
 Methods of Pessimistic approach:
 Locking Protocol
 Time Stamp Based Protocol
Copyright @ www.bcanotes.com
Locking for Concurrency Control
 Locking
It is a procedure used to control concurrent access to data. In
this method when one transaction is accessing the database, a
Lock may deny access to other transactions to produce incorrect
results.
 Lock
It is a variable associated with a data item. It describes the
status of the item with respect to possible operation that
can be applied to it.
Copyright @ www.bcanotes.com
Types of Lock
 Binary Lock-Two States (Lock and Unlock)
 Share/Exclusive Lock (Read/Write)
Copyright @ www.bcanotes.com
Locking Operations
 Read_lock(A)= Lock-S(A)
 Write_lock(A)=Lock-X(A)
 Unlock(A)
S-Shared Lock
X-Exclusive Lock
Copyright @ www.bcanotes.com
Compatibility of Locks
Shared Lock Exclusive Lock
Shared Lock Yes No
Exclusive Lock No No
Copyright @ www.bcanotes.com
Locking Example
T1 T2
Lock-X (A)
Read (A)
A=A+50
Write (A)
Unlock (A)
Lock-X (A)
Read (A)
A=A-40
Write (A)
Unlock (A)
Lock-X (B)
Read (B)
B=B+100
Write (B)
Unlock (B)
Copyright @ www.bcanotes.com
Problems with Locking
 Dead Lock:
It happens whenever a transaction waits for a lock to be
unlock (to access the data).
 Problem of Starvation
When the data requested by 1 transaction is held by some
other transactions again and again and the requested data
is not given.
Copyright @ www.bcanotes.com
Deadlock Example
T1 T2
Lock-X (B)
Read (B)
B=B+50
Write (B)
Lock-S (A)
Read (A)
Lock-S (B)
Wait..........
Wait..........
Lock-X (A)
Wait..........
Wait..........
Copyright @ www.bcanotes.com
Starvation Example
 T2 holds data item on Shared-mode lock.
 T1 request Exclusive-mode lock on same data item.
 T1 has to wait while T2 release it.
 Meanwhile T3 requests same data item for Shared- mode lock
and gets it from T2.
 T1 still waiting.
 Now T4 requests same data item for Shared-mode lock and
gets it from T3.
 T1 still waiting and is said to be Starved.
Copyright @ www.bcanotes.com
Pessimistic Execution
 Validate
 Read
 Compute
 Write
Copyright @ www.bcanotes.com
Two Phase Locking
 Expanding/Growing Phase:
New Locks on items can be acquired but
none can be released.
 Shrinking Phase:
Existing Locks can be released but no
new ones can be acquired.
T1
Lock-X (A)
Read (A)
A=A+50
Write (A)
Lock-X (B)
Read (B)
B=B+50
Write (B)
Unlock (A)
Unlock (B)
Copyright @ www.bcanotes.com
Problems in Two-Phase Locking
 Deadlock
 Cascading roll back
Copyright @ www.bcanotes.com
Time-Stamp (TS) based Protocol
In this, a unique fixed timestamp is associated
with each transaction to keep the order of the
transaction. It is denoted by TS (T1).
Copyright @ www.bcanotes.com
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)
Copyright @ www.bcanotes.com
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.
Copyright @ www.bcanotes.com
Implementation Method
 W-timestamp (Q) denotes the largest TS of any
transaction that executed write (Q) successfully.
 R-timestamp (Q) denotes the largest TS of any
transaction that executed read (Q) successfully.
Copyright @ www.bcanotes.com
Optimistic Approach
 It allows transaction to proceed in unsynchronized
way and only checks/locks conflicts at the end.
 Based on idea that conflicts are rare.
Copyright @ www.bcanotes.com
Validation Based Protocol
 It consist of 3 phases depending upon whether it is
Read only transaction or Read-Write transaction.
 Phases are:
 Read Phase
 Validation Phase
 Write Phase Copyright @ www.bcanotes.com
Validation Based Protocol Phases
 Read Phase:
In this every transaction reads the values of all
the data elements it needs from the database
and stores them in Local variables.
All updates are applied to the Local copy of the
data and not to the original database.
Copyright @ www.bcanotes.com
Validation Based Protocol Phases…
 Validation Phase:
 Come after end of Read phase.
 Certain checks are performed to ensure that no conflict
has occurred.
 For Read only transactions this phase consist of checking
that the data elements read are ok, no conflict is there
then it is Committed.
 If conflict is there then transaction is Aborted or
Restarted.
 For Updating transactions, it checks whether current
transaction leaves database in a consistent state, if not
then transaction is Aborted.
Copyright @ www.bcanotes.com
Validation Based Protocol Phases…
 Write Phase:
 This phase is for only Read-Write transaction
not for Read only transaction.
 If the transaction has passed the validation
phase successfully then all the changes made
by the transaction to the Local copy are made
to Final database.
Copyright @ www.bcanotes.com
Optimistic Execution
 Read
 Compute
 Validate
 Write
Copyright @ www.bcanotes.com

More Related Content

What's hot

Unit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptxUnit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptxDrkhanchanaR
 
Unit 5 internal sorting &amp; files
Unit 5  internal sorting &amp; filesUnit 5  internal sorting &amp; files
Unit 5 internal sorting &amp; filesDrkhanchanaR
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sortingKaushal Shah
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting TechniquesRafay Farooq
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeManishPrajapati78
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & QueueDrkhanchanaR
 
3.2 insertion sort
3.2 insertion sort3.2 insertion sort
3.2 insertion sortKrish_ver2
 
Transaction
TransactionTransaction
TransactionAmin Omi
 
3.3 shell sort
3.3 shell sort3.3 shell sort
3.3 shell sortKrish_ver2
 
Binary search tree
Binary search treeBinary search tree
Binary search treeKousalya M
 
Data structure
Data structureData structure
Data structureMohd Arif
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary searchZia Ush Shamszaman
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Flynce Miguel
 

What's hot (20)

Unit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptxUnit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptx
 
Quick sort
Quick sortQuick sort
Quick sort
 
Unit 5 internal sorting &amp; files
Unit 5  internal sorting &amp; filesUnit 5  internal sorting &amp; files
Unit 5 internal sorting &amp; files
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Index in sql server
Index in sql serverIndex in sql server
Index in sql server
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
3.2 insertion sort
3.2 insertion sort3.2 insertion sort
3.2 insertion sort
 
Transaction
TransactionTransaction
Transaction
 
Sql joins
Sql joinsSql joins
Sql joins
 
3.3 shell sort
3.3 shell sort3.3 shell sort
3.3 shell sort
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
DFS_New.pptx
DFS_New.pptxDFS_New.pptx
DFS_New.pptx
 
Data structure
Data structureData structure
Data structure
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)
 

Similar to CONCURRENCY CONTOL notes.pdf

DBMS Presentation.pptx
DBMS Presentation.pptxDBMS Presentation.pptx
DBMS Presentation.pptxPravinBhargav1
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov
 
Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptxBibus Poudel
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryZainab Almugbel
 
Concurrency note.pdf
Concurrency note.pdfConcurrency note.pdf
Concurrency note.pdfBijayNag1
 
concurrency control.ppt
concurrency control.pptconcurrency control.ppt
concurrency control.pptBikalAdhikari4
 
Distributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlDistributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlbalamurugan.k Kalibalamurugan
 
7. transaction mang
7. transaction mang7. transaction mang
7. transaction mangkhoahuy82
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency ControlDilum Bandara
 
Mba ebooks ! Edhole
Mba ebooks ! EdholeMba ebooks ! Edhole
Mba ebooks ! EdholeEdhole.com
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency controlJaved Khan
 

Similar to CONCURRENCY CONTOL notes.pdf (20)

DBMS Presentation.pptx
DBMS Presentation.pptxDBMS Presentation.pptx
DBMS Presentation.pptx
 
Dbms module iii
Dbms module iiiDbms module iii
Dbms module iii
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database Transactions
 
Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptx
 
Advanced DBMS presentation
Advanced DBMS presentationAdvanced DBMS presentation
Advanced DBMS presentation
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theory
 
chp13.pdf
chp13.pdfchp13.pdf
chp13.pdf
 
Concurrency note.pdf
Concurrency note.pdfConcurrency note.pdf
Concurrency note.pdf
 
concurrency control.ppt
concurrency control.pptconcurrency control.ppt
concurrency control.ppt
 
UNIT II.pptx
UNIT II.pptxUNIT II.pptx
UNIT II.pptx
 
Dbms
DbmsDbms
Dbms
 
Distributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlDistributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency control
 
7. transaction mang
7. transaction mang7. transaction mang
7. transaction mang
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
 
Mba ebooks ! Edhole
Mba ebooks ! EdholeMba ebooks ! Edhole
Mba ebooks ! Edhole
 
Autonomous transaction
Autonomous transactionAutonomous transaction
Autonomous transaction
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency control
 
MySQL Overview
MySQL OverviewMySQL Overview
MySQL Overview
 
DBMS UNIT IV.pptx
DBMS UNIT IV.pptxDBMS UNIT IV.pptx
DBMS UNIT IV.pptx
 
Unit06 dbms
Unit06 dbmsUnit06 dbms
Unit06 dbms
 

Recently uploaded

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
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
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
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
 
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
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
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
 
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
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

CONCURRENCY CONTOL notes.pdf

  • 2. DEFINITION  Concurrency means allowing more than one transaction to run simultaneously on the same database.  When several transactions run concurrently database consistency can be destroyed.  To remove this problem Concurrency control is used. Copyright @ www.bcanotes.com
  • 3. Need of Concurrency Control (CC)  The concurrent execution of transactions may lead, if uncontrolled, to problems such as an inconsistent database.  CC techniques are used to ensure that multiple transactions submitted by various users do not interfere with one another in a way that produces incorrect results.  The effect on a database of any number of transactions executing in parallel must be the same as if they were executed one after another. Copyright @ www.bcanotes.com
  • 4. Advantages of Concurrent Execution of Transactions  Improvement Throughput  Reduced Waiting Time Copyright @ www.bcanotes.com
  • 5. Problems of Concurrent Execution of Transactions  For Concurrency problems following control mechanism is required:  Lost Update Problem  The Temporary Update (Uncommitted Dependency) Problem  The Incorrect Summary (Inconsistent Analysis) Problem Copyright @ www.bcanotes.com
  • 6. The Lost Update Problem In this problem, 2 transactions accessing the same database item have their operations interleaved in a way that makes the database item incorrect. Copyright @ www.bcanotes.com
  • 7. Consider the following Example Lost Update Problem… Step T1 T2 Result 1 Read (A) A=100 2 A=A-50 3 Read (A) A=100 4 A=A+50 5 Write (A) A=50 6 Read (B) B=200 7 Write (A) A=150 8 B=B+50 9 Write (B) B=250 Copyright @ www.bcanotes.com
  • 8. The Temporary Update (Uncommitted Dependency) Problem This problem occurs when one transaction is allowed to see the intermediate results of another transaction before it is committed. Copyright @ www.bcanotes.com
  • 9. Consider the Example - The Temporary Update (Uncommitted Dependency) Problem Step T1 T2 Result 1 Start Transaction A=200 2 Read (A) A=200 3 A=A-100 A=200 4 Write (A) Start Transaction A=100 5 Read (A) A=100 6 A=A+150 A=100 7 ROLL BACK Write (A) A=250 8 Commit A=250 Since the transaction is Aborted so the database will be restored to its original state Rs 200. Copyright @ www.bcanotes.com
  • 10. The Incorrect Summary (Inconsistent Analysis) Problem  This problem occurs when a transaction reads several values from a database while a second transaction updates some of them.  For e.g. Values of variable A, B, C and Sum are in column 3,4,5 and 6. The initial values of Sum is 100, 50, 25 and 0 respectively. Copyright @ www.bcanotes.com
  • 11. T1 T2 A B C SUM Remarks R(A,a) R(A,a) Rs.100 Rs.50 Rs.25 0 sum=sum+A A=A-10 Rs.100 Rs.50 Rs.25 100 Value of Sum is changed due to T1 operation and content of local variable ‘a’ is changed to 90 R(B,b) W(A,a) Rs.90 Rs.50 Rs.25 100 Write operation on A is performed by T2, so A=90 sum=sum+B R(C,c) Rs.90 Rs.50 Rs.25 150 Value of Sum is changed due to T1 Operation. c=c+10 Rs.90 Rs.50 Rs.25 150 Content of local variable ‘c’ is changed to 35 W(C,c) Rs.90 Rs.50 Rs.35 150 WRITE operation on C is performed by T2 i.e. = 35 R(C,c) Rs.90 Rs.50 Rs.35 150 Value of C is read out as 35 by T1 sum=sum+C Rs.90 Rs.50 Rs.35 185 Value of Sum is changed due to T1 operation i.e. 185 The Incorrect Summary (Inconsistent Analysis) Problem Copyright @ www.bcanotes.com
  • 12. Concurrency Control Schemes  Concurrency control schemes are divided into 2 categories:  Pessimistic or Conservative Approach  Optimistic Approach Copyright @ www.bcanotes.com
  • 13. Pessimistic Approach  This approach says that there must be some concurrency control techniques deployed before the transactions are allowed to access the database.  Methods of Pessimistic approach:  Locking Protocol  Time Stamp Based Protocol Copyright @ www.bcanotes.com
  • 14. Locking for Concurrency Control  Locking It is a procedure used to control concurrent access to data. In this method when one transaction is accessing the database, a Lock may deny access to other transactions to produce incorrect results.  Lock It is a variable associated with a data item. It describes the status of the item with respect to possible operation that can be applied to it. Copyright @ www.bcanotes.com
  • 15. Types of Lock  Binary Lock-Two States (Lock and Unlock)  Share/Exclusive Lock (Read/Write) Copyright @ www.bcanotes.com
  • 16. Locking Operations  Read_lock(A)= Lock-S(A)  Write_lock(A)=Lock-X(A)  Unlock(A) S-Shared Lock X-Exclusive Lock Copyright @ www.bcanotes.com
  • 17. Compatibility of Locks Shared Lock Exclusive Lock Shared Lock Yes No Exclusive Lock No No Copyright @ www.bcanotes.com
  • 18. Locking Example T1 T2 Lock-X (A) Read (A) A=A+50 Write (A) Unlock (A) Lock-X (A) Read (A) A=A-40 Write (A) Unlock (A) Lock-X (B) Read (B) B=B+100 Write (B) Unlock (B) Copyright @ www.bcanotes.com
  • 19. Problems with Locking  Dead Lock: It happens whenever a transaction waits for a lock to be unlock (to access the data).  Problem of Starvation When the data requested by 1 transaction is held by some other transactions again and again and the requested data is not given. Copyright @ www.bcanotes.com
  • 20. Deadlock Example T1 T2 Lock-X (B) Read (B) B=B+50 Write (B) Lock-S (A) Read (A) Lock-S (B) Wait.......... Wait.......... Lock-X (A) Wait.......... Wait.......... Copyright @ www.bcanotes.com
  • 21. Starvation Example  T2 holds data item on Shared-mode lock.  T1 request Exclusive-mode lock on same data item.  T1 has to wait while T2 release it.  Meanwhile T3 requests same data item for Shared- mode lock and gets it from T2.  T1 still waiting.  Now T4 requests same data item for Shared-mode lock and gets it from T3.  T1 still waiting and is said to be Starved. Copyright @ www.bcanotes.com
  • 22. Pessimistic Execution  Validate  Read  Compute  Write Copyright @ www.bcanotes.com
  • 23. Two Phase Locking  Expanding/Growing Phase: New Locks on items can be acquired but none can be released.  Shrinking Phase: Existing Locks can be released but no new ones can be acquired. T1 Lock-X (A) Read (A) A=A+50 Write (A) Lock-X (B) Read (B) B=B+50 Write (B) Unlock (A) Unlock (B) Copyright @ www.bcanotes.com
  • 24. Problems in Two-Phase Locking  Deadlock  Cascading roll back Copyright @ www.bcanotes.com
  • 25. Time-Stamp (TS) based Protocol In this, a unique fixed timestamp is associated with each transaction to keep the order of the transaction. It is denoted by TS (T1). Copyright @ www.bcanotes.com
  • 26. 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) Copyright @ www.bcanotes.com
  • 27. 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. Copyright @ www.bcanotes.com
  • 28. Implementation Method  W-timestamp (Q) denotes the largest TS of any transaction that executed write (Q) successfully.  R-timestamp (Q) denotes the largest TS of any transaction that executed read (Q) successfully. Copyright @ www.bcanotes.com
  • 29. Optimistic Approach  It allows transaction to proceed in unsynchronized way and only checks/locks conflicts at the end.  Based on idea that conflicts are rare. Copyright @ www.bcanotes.com
  • 30. Validation Based Protocol  It consist of 3 phases depending upon whether it is Read only transaction or Read-Write transaction.  Phases are:  Read Phase  Validation Phase  Write Phase Copyright @ www.bcanotes.com
  • 31. Validation Based Protocol Phases  Read Phase: In this every transaction reads the values of all the data elements it needs from the database and stores them in Local variables. All updates are applied to the Local copy of the data and not to the original database. Copyright @ www.bcanotes.com
  • 32. Validation Based Protocol Phases…  Validation Phase:  Come after end of Read phase.  Certain checks are performed to ensure that no conflict has occurred.  For Read only transactions this phase consist of checking that the data elements read are ok, no conflict is there then it is Committed.  If conflict is there then transaction is Aborted or Restarted.  For Updating transactions, it checks whether current transaction leaves database in a consistent state, if not then transaction is Aborted. Copyright @ www.bcanotes.com
  • 33. Validation Based Protocol Phases…  Write Phase:  This phase is for only Read-Write transaction not for Read only transaction.  If the transaction has passed the validation phase successfully then all the changes made by the transaction to the Local copy are made to Final database. Copyright @ www.bcanotes.com
  • 34. Optimistic Execution  Read  Compute  Validate  Write Copyright @ www.bcanotes.com