Multiversion Concurrency Control Techniques


It is essential to maintain data consistency and prevent concurrency issues in database systems. It should be multiple transactions accessing the same data simultaneously. Multiversion Concurrency Control (MVCC) techniques provide an efficient and effective way to achieve this.

In this article, we will discuss Multiversion Concurrency Control (MVCC) techniques, its various types, and properties.

Concurrency Control Protocols

Database systems provide concurrency control to ensure isolation among transactions. It maintains consistency of the database through consistent execution of transactions. It also resolves conflicts arising from read-write and write-read operations. There are various techniques used for concurrency control −

  • Two-phase locking protocol

  • Time-stamp ordering protocol

  • Multi-version concurrency control

  • Validation concurrency control

Let's discuss the two-phase locking protocol briefly. Locking is an essential operation in the protocol that provides permission to read or write a data item. The two-phase locking protocol is a process that enables acquiring shared resources without creating the possibility of deadlock. The protocol involves three main activities:

  • (i) Lock Acquisition

  • (ii) Modification of Data

  • (iii) Release of Lock

In distributed systems, two-phase locking prevents deadlock by releasing all the acquired resources if it's impossible to acquire all the required resources without waiting for another process to finish using a lock. This ensures that no process holds a shared resource while waiting for another process to release it, thus preventing deadlock due to resource contention.

A transaction in the two-phase locking protocol can assume either the growing phase or the shrinking phase.

  • In the growing phase, a transaction can acquire locks but cannot release any lock until it reaches the lock point, which is the point where a transaction acquires all the necessary locks.

  • In the shrinking phase, a transaction can only release locks but cannot acquire any new locks.

Multiversion concurrency control (MVCC)

Multi-version protocol aims to reduce the delay for read operations. It maintains multiple versions of data items. Whenever a write operation is performed, the protocol creates a new version of the transaction data to ensure conflict-free and successful read operations.

The newly created version contains the following information −

  • Content − This field contains the data value of that version.

  • Write_timestamp − This field contains the timestamp of the transaction that created the new version.

  • Read_timestamp − This field contains the timestamp of the transaction that will read the newly created value.

By creating multiple versions of the data, the multi-version protocol ensures that read operations can access the appropriate version of the data without encountering conflicts. The protocol thus enables efficient concurrency control and reduces delays in read operations.

Various Types of MVCC

These are compared in the following table

MVCC Type

Description

Advantages

Disadvantages

Snapshot-based

Creates a snapshot of the database at the start of a transaction and uses it to provide necessary data for the transaction

Easy to implement

Significant overhead due to storing multiple versions of data

Timestamp-based

Assigns a unique timestamp to each transaction that creates a new version of a record; used to determine data visibility to transactions

More efficient than snapshot-based MVCC

Requires additional storage to store timestamps

History-based

Stores a complete history of all changes made to a record, allowing for easy rollback of transactions

Provides highest level of data consistency

Most complex of the MVCC techniques

Hybrid

Combines two or more MVCC techniques to balance performance and data consistency

Provides benefits of multiple MVCC techniques

More complex to implement than individual techniques

Benefits of multiversion concurrency control (MVCC)

MVCC is a technique that helps databases manage multiple transactions happening at the same time. When a DBMS implements MVCC correctly, it provides several benefits, such as −

Less need for database locks

With MVCC, the database can allow multiple transactions to read and write data without locking the entire database.

Fewer issues with multiple transactions trying to access the same data

MVCC helps reduce conflicts between transactions accessing the same data.

Faster access to read data

Since MVCC allows multiple transactions to read data at the same time, it improves the speed of reading data.

Records are still protected during write operations

MVCC ensures that data is protected from being changed by other transactions while a transaction is making changes to it.

Fewer database deadlocks

Deadlocks occur when two or more transactions are waiting for each other to release a lock, causing the system to come to a halt. MVCC can reduce the number of these occurrences.

Drawbacks of Multiversion concurrency control (MVCC)

Although multiversion concurrency control (MVCC) provides several benefits, there are two main disadvantages to this approach −

  • Concurrent update control methods can be challenging to implement.

  • The database can become bloated with multiple versions of records, which increases its overall size.

However, for most users and developers, the complexity involved in implementing MVCC concurrency control methods is hidden. Database vendors provide this functionality behind the scenes, so developers can write SQL and end-users can use applications as usual without having to worry about the underlying details of how MVCC works. This means that the use of MVCC is generally transparent to most users and developers.

Comparison between MVCC and Locking

MVCC

Locking

Approach

Creates a new version of a record with an incremented version number during write operation

Locks a record during write operation

Read operations

Concurrent read operations can occur on the old version of the record while the new version is being updated

Concurrent read operations are not allowed until the lock is released

Write operations

Writes operate on a new version of the record, allowing multiple writes to occur simultaneously

Only one write can occur at a time, as the record is locked during the write operation

Locks

No locks are needed, which eliminates the need for contention and deadlock management

Locks are used, which can lead to contention and deadlock issues

Record versions

The database grows in size as new versions of records are created, leading to potential bloat

The database remains the same size, as no new versions of records are created

Conclusion

MVCC techniques provide an efficient and effective way to achieve data consistency. It prevents concurrency issues in a database system. Each MVCC technique has its advantages and disadvantages. So, appropriate techniques should be chosen based on specific requirements and application characteristics. It is essential to consider the performance, efficiency, and data consistency when choosing an MVCC technique.

Updated on: 17-May-2023

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements