"Database System Concepts" 19 - Concurrency Control

When multiple transactions execute concurrently in the database, data consistency may no longer be maintained. It is necessary for the system to control the interaction between transactions, and this is achieved through a mechanism known as concurrency control. The most commonly used mechanisms are various blocking protocols, timestamp ordering mechanisms, validity checking techniques and multi-version mechanisms.
1. A locking protocol is a set of rules that specify when a transaction locks and unlocks data items in a database.
The two-phase locking protocol allows a transaction to lock new data items only if the transaction has not released locks on any data items. The protocol guarantees serializability, but cannot avoid deadlocks. In the absence of information about how data items are accessed, a two-phase blocking protocol is sufficient, if necessary, to guarantee serializability.
The strict two-phase blocking protocol requires that all exclusive locks held by the transaction must be released at the end of the transaction. The purpose is to ensure the resiliency and non-cascading of the result scheduling; the strong two-phase blocking protocol requires all the locks held by the transaction. It must be released at the end of the transaction.
Graph-based blocking protocols restrict the order in which data items are accessed, thereby eliminating the need for two-phase blocking and ensuring serializability without deadlocks.
Many blocking protocols do not prevent deadlocks. One way to prevent deadlock is to use an order of data items and apply for locks in an order consistent with that order; another way to prevent deadlock is to use preemption and transaction rollback. To control preemption, we assign each transaction a unique timestamp. These timestamps are used to decide whether the transaction should wait or roll back. If a transaction is rolled back, it retains the original timestamp across restarts.
If there is no mechanism to prevent deadlocks, the system must handle them with deadlock detection and recovery mechanisms. To this end, the system constructs a waiting graph, and the system will be in a deadlock state if and only if the waiting graph contains cycles. When a detection algorithm determines that a deadlock exists, the system resolves the deadlock by rolling back one or more transactions.
In some cases, it may be better to aggregate multiple data items into a group and process them as aggregated data items, which involves the level of granularity. The system allows data items of various sizes, and defines a hierarchy of data items, where small data items are nested within large data items. This hierarchy can be represented graphically as a tree. Blocking is performed in the order from the root node to the leaf node; unlocking is performed in the order from the leaf node to the root node. But although this protocol can guarantee serializability, it cannot avoid deadlock.

Second, the timestamp ordering mechanism guarantees serializability by choosing an order between each pair of transactions in advance. Each transaction in the system corresponds to a unique timestamp, which determines the serializable order of transactions. If the timestamp of transaction Ti is less than the timestamp of transaction Tj, the mechanism guarantees that the resulting schedule is equivalent to the serial schedule where transaction Ti appears before transaction Tj. The mechanism guarantees this by rolling back food that violates that order.

3. The multi-version concurrency control mechanism is based on creating a new version of a data item when each transaction writes the data item. When a read operation is issued, the system selects one of the versions to read. Using timestamps, the concurrency control mechanism guarantees that the version to read is chosen in a way that ensures serializability.
4.

Learning materials: Database System Concepts, by Abraham Silberschatz, Henry F.Korth, S.Sudarshan


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325466663&siteId=291194637