Open In App
Related Articles

Graph Based Concurrency Control Protocol in DBMS

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Graph-based concurrency control protocols are used in database management systems (DBMS) to ensure that concurrent transactions do not interfere with each other and maintain the consistency of the database.

In graph-based concurrency control, transactions are represented as nodes in a graph, and the conflicts between transactions are represented as edges between the nodes. A conflict between two transactions occurs when they access the same data item, and at least one of the transactions performs a write operation.

The graph-based concurrency control protocol operates as follows:

When a transaction starts, a node is created in the graph representing the transaction.

When a transaction accesses a data item, it acquires a shared or exclusive lock on the item, and the corresponding node is added to the graph. If a transaction tries to acquire an exclusive lock on an item that is already locked by another transaction, a conflict edge is added between the nodes representing the two transactions.

When a transaction completes, all the edges incident on its node are removed from the graph.

Before granting a lock to a transaction, the protocol checks the graph for any cycles. If a cycle exists, it means that there is a conflict between transactions, and one of them needs to be rolled back to break the cycle.

The advantage of graph-based concurrency control is that it can handle more complex transaction dependencies than other protocols, such as two-phase locking. However, it can also be more computationally expensive and may not scale well for large databases with a large number of transactions. Therefore, the choice of concurrency control protocol depends on the specific requirements and characteristics of the database and the application.

Graph-Based Protocols are yet another way of implementing Lock Based Protocols

As we know the prime problems with Lock Based Protocol have been avoiding Deadlocks and ensuring a Strict Schedule. We’ve seen that Strict Schedules are possible with the following Strict or Rigorous 2-PL. We’ve even seen that Deadlocks can be avoided if we follow Conservative 2-PL but the problem with this protocol is it cannot be used practically. Graph-Based Protocols are used as an alternative to 2-PL. Tree Based Protocols is a simple implementation of Graph Based Protocol

A prerequisite of this protocol is that we know the order to access a Database Item. For this, we implement a Partial Ordering on a set of the Database Items (D) {d1, d2, d3, ….., dn} . The protocol following the implementation of Partial Ordering is stated as- 

  • If di –> dj then any transaction accessing both di and dj must access di before accessing dj.
  • Implies that the set D may now be viewed as a directed acyclic graph (DAG), called a database graph.

Tree Based Protocol: 

  • Partial Order on Database items determines a tree-like structure.
  • Only Exclusive Locks are allowed.
  • The first lock by Ti may be on any data item. Subsequently, a data Q can be locked by Ti only if the parent of Q is currently locked by Ti.
  • Data items can be unlocked at any time.


Following the Tree based Protocol ensures Conflict Serializability and Deadlock Free schedule. We need not wait for unlocking a Data item as we did in 2-PL protocol, thus increasing the concurrency. 

Now, let us see an Example, following is a Database Graph which will be used as a reference for locking the items subsequently. 

222

Image – Database Graph 

Let’s look at an example based on the above Database Graph. We have three Transactions in this schedule and this is a skeleton example, i.e, we will only see how Locking and Unlocking work, let’s keep this simple and not make this complex by adding operations on data.

 T1T2T3
1Lock-X(A)  
2Lock-X(B)  
3 Lock-X(D) 
4 Lock-X(H) 
5 Unlock-X(D) 
6Lock-X(E)  
7Lock-X(D)  
8Unlock-X(B)  
9Unlock-X(E)  
10  Lock-X(B)
11  Lock-X(E)
12 Unlock-X(H) 
13Lock-X(B)  
14Lock-X(G)  
15Unlock-X(D)  
16  Unlock-X(E)
17  Unlock-X(B)
18Unlock-X(G)  

From the above example, first see that the schedule is Conflict Serializable. Serializability for Locks can be written as T2 –> T1 –> T3
Data items Locked and Unlocked are following the same rule as given above and follow the Database Graph. 

Thus, let’s revise once more what are the key points of Graph-Based Protocols. 

Advantage:

  • Ensures Conflict Serializable Schedule.
  • Ensures Deadlock Free Schedule
  • Unlocking can be done anytime

With some advantages come some disadvantages also. 

Disadvantage:

  • Unnecessary locking overheads may happen sometimes, like if we want both D and E, then at least we have to lock B to follow the protocol.
  • Cascading Rollbacks is still a problem. We don’t follow a rule of when Unlock operation may occur so this problem persists for this protocol. Overall this protocol is mostly known and used for its unique way of implementing Deadlock Freedom.                                           

Last Updated : 14 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads