MOSS Concurrency Control Protocol (Distributed Locking in Database)


This is a protocol used to control concurrency in a distributed database environment. It helps to ensure the consistency and integrity of data in distributed database systems. Concurrency control in databases allows multiple transactions to access the same data simultaneously. In this article, we will discuss the rules and regulations. That is required to keep in mind while applying MOSS Concurrency Control Protocol.

Overview of Distributed Locking

Distributed locking is a mechanism. It is used to synchronize access to shared resources in a distributed computing environment. It involves locking shared resources to prevent other transactions from accessing them concurrently. Distributed locking can be classified into two types: optimistic and pessimistic locking.

  • In optimistic locking, transactions do not acquire locks before accessing shared resources. But conflicts are detected when the transactions try to commit.

  • In pessimistic locking, transactions acquire locks before accessing shared resources. Conflicts are avoided from the beginning.

MOSS Concurrency Control Protocol

MOSS is a distributed locking protocol based on optimistic locking. It is designed for multi-version concurrency control (MVCC) systems and provides transaction-level serialization. The protocol maintains the continuity of the shared data. It uses timestamp-based technology to detect and resolve conflicts. In MOSS, each transaction is assigned a unique timestamp, and each write operation also has a timestamp. When a transaction wants to access a shared resource. It first checks the timestamp of the last successful write operation on that resource. If the resource hasn't been modified Because of that timestamp, then transaction can access it. Otherwise, the transaction is rolled back. It has to be started again with a new timestamp.

Here is the algorithm −

  • Hierarchical transactions − The system is used for handling transactions that are hierarchical, meaning they have a parent-child relationship.

  • Locking data − A transaction acquires a lock on a data-item(X) in a certain mode(M).

  • Holding the lock − The transaction(T) holds onto the lock in mode(M) until it finishes.

  • Inheritance of lock − If a subtransaction(T1) commits, its parent transaction inherits the lock and keeps it until all subtransactions are finished.

  • Access to locked data − If a transaction holds a lock on a data-item(X), it can access it. However, if it inherits a lock from a subtransaction, it cannot access the data-item(X).

  • Retained lock − A retained lock is a placeholder that indicates subtransactions outside of the hierarchy cannot acquire the lock, but descendant subtransactions can.

  • Retaining lock − Once a transaction becomes a retainer of a descendant subtransaction's lock, it remains a retainer until the transaction finishes.

General Locking rules regarding this Protocol −

  • Read lock acquisition − A subtransaction(T1) can acquire a read lock on a data-item(X) if no descendant holds a write lock on X, and all subtransactions that have a write lock on X are ancestors of T1.

  • Write lock acquisition − A subtransaction(T1) can acquire a write lock on a data-item(X) if no other subtransaction holds a read/write lock on X, and all subtransactions that have a read/write lock on X are ancestors of T1.

  • Lock inheritance − When a subtransaction(T1) completes its execution, the parent transaction inherits the lock held by T1 in the same mode.

  • Lock release on commit − When a top-level subtransaction(T3) commits, all of its descendants release the locks they hold, including retained locks.

  • Lock release on abort − When a subtransaction(T3) aborts, it releases all the locks it holds, including retained locks. All subtransactions that originated from the aborting transaction are also aborted and must start from the beginning if they have started their execution.

Advantages of MOSS Protocol

The MOSS protocol has several advantages over concurrency control protocols.

  • It is designed for distributed systems. It can handle a high level of concurrency.

  • It does not require locking shared resources before access, which reduces contention and improves performance.

  • MOSS also provides transaction-level serialization, which ensures that transactions are executed in the correct order and prevents conflicts between transactions.

Example of MOSS Protocol

Consider a distributed database system that consists of multiple nodes. Each node has a copy of the same data. When a transaction wants to modify a piece of data, it first checks the timestamp of the last successful write operation on that piece of data. If the timestamp is older than the transaction's timestamp, the transaction can modify the data. Otherwise, the transaction is rolled back, and it has to restart with a new timestamp.

A comparison of MOSS protocol with other concurrency control protocols such as two-phase locking and optimistic concurrency control. MOSS protocol is designed for distributed systems and can handle a high degree of concurrency, while two-phase locking is more suitable for centralized systems. Optimistic concurrency control requires transactions to detect and resolve conflicts themselves, while MOSS provides conflict resolution at the protocol level.

Implementation of MOSS Protocol

MOSS protocol is implemented in several steps in a distributed database system.

  • Each transaction is assigned a unique timestamp. Every write operation also has a timestamp.

  • When a transaction tries to access a shared resource, it checks the timestamp of the last successful write operation on that resource.

  • If the resource has not been modified since that timestamp, the transaction can access it. Otherwise, the transaction is rolled back. It has to restart with a new timestamp.

  • Finally, conflicts between transactions are resolved by comparing their timestamps. Rolling back the transaction with the older timestamp.

Challenges while implementing

When implementing the MOSS protocol, the challenge is dealing with network latency and message delay. It may roll back transactions unnecessarily which means performance degradation. To overcome this challenge, the MOSS protocol can be optimized by reducing the number of messages sent between nodes and by using a hybrid locking technique that combines optimistic and pessimistic locking.

Conclusion

In conclusion, the MOSS Concurrency Control Protocol is a solution for distributed locking in database systems.

  • It provides high concurrency and performance while maintaining the consistency and integrity of shared data. It is designed for distributed systems and provides transaction-level serializability.

  • It helps ensure the consistency and integrity of shared data in a distributed database system.

  • It has many advantages over other concurrency control protocols. One of the main advantages is high concurrency and performance.

  • It is suitable for multi-version concurrency control systems. But, there are some challenges in implementing the MOSS protocol. These challenges are network latency and message delays. But these can be addressed by using optimized techniques.

Updated on: 17-May-2023

372 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements