Concurrency Control

Concurrency control is used to address such conflicts which mostly occur with a multi-user system. It helps you to make sure that database transactions are performed concurrently.


CONCURRENCY CONTROL PROTOCOLS

Different concurrency control protocols offer different benefits between the amount of concurrency they allow and the amount of overhead that they impose.

  • Lock-Based Protocols
  • Two-Phase Protocols
  • Timestamp-Based Protocols
  • Validation-Based Protocols

1.Lock-based Protocols

A lock is a data variable that is associated with a data item. This lock signifies the operations that can be performed on the data item. Locks help synchronize access to the database items by concurrent transactions.

All lock requests are made to the concurrency-control manager. Transactions proceed only once the lock request is granted.

Binary Locks: A Binary lock on a data item can either locked or unlocked states.

Shared/exclusive: This type of locking mechanism separates the locks based on their uses. If a lock is acquired on a data item to perform a write operation, it is called an exclusive lock.

2.Two-Phase Protocol

Two-Phase locking protocol which is also known as a 2PL protocol. It is also called P2L. In this type of locking protocol, the transaction should acquire a lock after it releases one of its locks.

This locking protocol divides the execution phase of a transaction into three different parts.

  • In the first phase, when the transaction begins to execute, it requires permission for the locks it needs.
  • The second part is where the transaction obtains all the locks. When a transaction releases its first lock, the third phase starts.
  • In this third phase, the transaction cannot demand any new locks. Instead, it only releases the acquired locks.

3.Timestamp-based Protocols

The timestamp-based algorithm uses a timestamp to serialize the execution of concurrent transactions. This protocol ensures that every conflicting read and write operations are executed in timestamp order. The protocol uses the System Time or Logical Count as a Timestamp.

The older transaction is always given priority in this method. It uses system time to determine the timestamp of the transaction. This is the most commonly used concurrency protocol.

4.Validation-based Protocols

The validation protocol requires that each transaction Ti executes in two or three different phases in its lifetime, depending on whether it is a read-only or an update transaction. The phases are, in order,

1. Read phase. During this phase, the system executes transaction Ti. It reads the values of the various data items and stores them in variables local to Ti. It performs all write operations on temporary local variables, without updates of the actual database.

2. Validation phase. Transaction Ti performs a validation test to determine whether it can copy to the database the temporary local variables that hold the results of write operations without causing a violation of serializability.

3. Write phase. If the transaction Ti succeeds invalidation (step 2), then the system applies the actual updates to the database. Otherwise, the system rolls back to Ti. 

Post a Comment

0 Comments