Distributed database management systems require concurrency control to guarantee serializability of transactions executed across multiple locations, making it a complex problem to solve.
Optimistic concurrency control assumes that transactions tend to coexist without conflict, permitting transactions access data without needing locks and checking for conflicts before committing. While this reduces overhead costs significantly, it can become problematic in an environment with high competition for resources.
Locking mechanisms
Locking is a technique designed to prevent multiple transactions from simultaneously accessing and editing the same piece of data simultaneously, much like placing a “Do Not Disturb” sign on a hotel room door while someone is inside.
Locking is used in database systems primarily to guarantee transaction isolation and data consistency, since concurrent execution can produce differing results compared to serial execution.
However, using locks has several drawbacks such as deadlocks and performance issues. One of the primary problems associated with locking mechanisms is contention for locks which may cause unnecessary delays within systems and race conditions that are hard to debug and resolve.
Thankfully, there are ways to combat these problems. Some databases employ timestamp ordering techniques to ensure each transaction executes in the proper sequence and eliminate the need for locks while simultaneously decreasing operations by eliminating row locks; additionally it improves performance by decreasing work required to update data – however this method works only if conflicts between transactions are infrequent.
Deadlock detection and resolution
Deadlock detection and resolution are central elements of concurrency control. A deadlock is defined as any instance where several processes are waiting on one resource that another process has acquired; to identify one requires identifying cycles in the system wait-for graph; while to resolve one requires breaking existing dependencies within it and allocating those resources back to those waiting processes so they may resume execution.
There have been various deadlock detection and resolution mechanisms proposed in the literature, each handling dynamic entity-resource relationships generated from seize/release statements differently. Most techniques involve either removing or rolling back entities in situations that might lead to deadlock, an expensive operation which can significantly lower throughput of systems.
One more efficient approach is to first identify a strongly connected component (SCC) in an ER graph and then remove all entities not belonging to it, thus reducing displacement of entities while shortening detection time. Unfortunately, however, this approach still requires significant system overhead and may not always provide optimal results; furthermore it’s impossible to reposition all entities quickly in such cases.
Optimistic and Pessimistic
Many databases employ either an optimistic or pessimistic concurrency control scheme to ensure database transactions maintain data integrity. Optimistic concurrency control schemes allow multiple users to modify data without locking it for updates; when transactions attempt to commit, however, the database checks whether there are any conflicting changes from other transactions; otherwise it rolls back and must be retried.
Optimistic concurrency control can be effective in environments with few update collisions and can help increase throughput by enabling transactions to complete without incurring unnecessary locks on shared data resources. If contention for data resources is high and retrying transactions takes too much time, performance may suffer significantly.
Pessimistic concurrency control requires obtaining and maintaining locks before transactions can update data records, which can slow down operations due to their overhead requirements. Pessimistic locking should only be used when you anticipate frequent updates with potential conflicts occurring frequently – TiDB uses solidDB’s pessimistic locking mechanism; you can choose either pessimistic or optimistic locks at table level but cannot utilize both simultaneously for one table.