Transaction And Concurrency Control for Computer Science and MCA students

Explain two phase locking techniques in concurrency control.

Multiple transactions can be executed simultaneously, in a multiprogramming environment. It means that two or more transaction is executed concurrently. It may be the chance that one transaction corrupt or destroy the other transaction. So it is most important to control the concurrency of transactions. There are concurrency control protocols that ensure the ACID property of transaction.

Concurrency control protocols can be divided into two types
  • Lock based protocols
  • Time stamp based protocols
Two-Phase Locking protocol is a lock based protocol and there are two types of locks.

Binary Locks:
  • A binary lock can have two states or values: locked /1 and unlocked/0. If the value of the lock on item A is 1 or state is locked, then item A cannot be accessed. If the value of the lock on item A is 0 or state is unlocked then item can be accessed.
Shared/exclusive:
  • In general, you can perform two types of operation on data item. Read the data and write/update the data. If an exclusive lock is applied on data item then you can perform a write operation. If a shared lock is applied on data item then you can perform a read operation.
  • For getting an exclusive (write) lock, a transaction must first acquire a shared (read) lock and then upgrade it to an exclusive lock.
Two-Phase locking protocol executes in three phase of a transaction.
1. Lock Acquisition
2. Modification of Data
3. Release Locks

At the beginning of transaction, it tries to permission for the locks it requires. After getting the lock, it performs the transaction. In third phase the transaction cannot demand any new locks; it only releases the acquired locks.

Two-phase locking has two phases
  • Growing : locks are being acquired by the transaction.
  • Shrinking : locks held by the transaction are being released.

Explain serializibility in transaction in detail?

Serializability
  • In multiprogramming environment more than one transaction executes concurrently. It may be the case that several concurrent transactions are trying to access the same data item at a time. As a result the data may corrupt. In order to smooth transaction, the instructions within these concurrent transactions must be ordered in some way so there will be no problem in accessing and releasing the shared data item. There are two types of serializability.
Conflict Serializability:
  • Two instructions of two different transactions may want to access the same data item in order to perform a read/write operation and conflict may arise. Conflict Serializability specifies the order in which these two instructions will be executed in case there is any conflict. A conflict arises if at least one or both of the instructions is a write operation.
Important points in Conflict Serializability:
  • If two instructions of the two concurrent transactions are both for read operation, then there will be no conflict, and can be allowed to take place in any order.
  • If one of the instructions is a read operation and the other instruction is a write operation, then they are in conflict, hence their ordering is important. In this case two cases are possible.
  • 1. If the read instruction is made first, then it reads the old data value and after reading is over, the new value of the data item is written.
    2. If the write instruction is made first, then updates the data item with the new value and the read instruction reads the newly updated value.
  • If both the transactions are write operation, then they are in conflict but order is not matter, because the transactions do not read the value updated by each other.
View Serializability:
  • It can be derived by creating another schedule out of an existing schedule, with the same set of transactions.
  • For View Equivalent, let us consider that there are two serialized transactions T1 and T2.
  • S1 and S2 are two schedules.
  • If T1 reads the initial data in S1, then it also reads the initial data in S2.
  • If T1 reads the value written by T2 in S1, then it also reads the value written by T2 in S2.
  • If T1 performs the final write on the data value in S1, then it also performs the final write on the data value in S2.

Write short note on ACID Property.

ACID properties are an important concept for databases. The abbreviation stands for Atomicity, Consistency, Isolation, and Durability. A database system must maintain these properties for reliable transaction.

Atomicity: This property says that all operation of a transaction must be completed or nothing should happen. It means that a transaction must be treated as an atomic unit. There should not be any state or operation of a transaction is left partially completed.

Consistency: If any transaction completed successfully, then database must remain in a consistent state. It should not destroy the other transaction or data in a database.

Isolation: There is more than one transactions are being executed simultaneously and in parallel, in a database system. Any transactions will not affect/destroy the existence of any other transaction.All the transaction in the system will executes in such a way that it is the only transaction in the system.

Durability: All the transaction should be durable in the database, means if you update any data and transaction is committed, and then the updated value should remain durable. If a transaction commits but the system fails due to some hardware or other problem before the data could be written on to the disk, then that data will be updated once the system works fine.