CONCURRENCY CONTOL
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Advantages of Concurrent Execution of Transactions
Improvement Throughput
Reduced Waiting Time
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Consider the following Example
Lost Update Problem…
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Consider the Example - The Temporary Update (Uncommitted Dependency) Problem
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
The Incorrect Summary (Inconsistent Analysis) Problem
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Concurrency Control Schemes
Concurrency control schemes are divided into 2 categories:
Pessimistic or Conservative Approach
Optimistic Approach
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Types of Lock
Binary Lock-Two States (Lock and Unlock)
Share/Exclusive Lock (Read/Write)
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Locking Operations
Read_lock(A)= Lock-S(A)
Write_lock(A)=Lock-X(A)
Unlock(A)
S-Shared Lock
X-Exclusive Lock
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Compatibility of Locks
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Locking Example
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Pessimistic Execution
Validate
Read
Compute
Write
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Problems in Two-Phase Locking
Deadlock
Cascading roll back
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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).
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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)
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
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.
Concurrency Control ------------------------------------------------------------------------------------- Next Slide
Optimistic Execution
Read
Compute
Validate
Write
1. What is concurrency control in IT and software? |
2. Why is concurrency control important in IT and software? |
3. What are some common techniques used for concurrency control? |
4. How does concurrency control impact performance in IT and software systems? |
5. Can you give an example of a real-life scenario where concurrency control is important? |
|
Explore Courses for IT & Software exam
|