When using X and S locks to lock data objects, some rules need to be agreed, such as when to apply for an X lock or S lock, hold the lock time, and when to release. Called these rules for the blockade agreement (locking Protocol). The different rules governing the blockade form a variety of blockade agreements. Different blocking protocols provide certain guarantee for the correct dispatch of concurrent operation to different extent.
一、一级 Blockade Protocol
The first-level blockade protocol is that a transaction T must have an X lock on the data R before it is modified until the end of the transaction is released. The end of a transaction includes a normal end (COMMIT) and an abnormal end (ROLLBACK).
A lockdown protocol prevents loss of modification and guarantees that the transaction T is recoverable. Use of the first level of the blockade protocol can resolve the problem of loss modification.
In the first level blockade protocol, if only read data does not modify it, it does not need to be locked, it does not guarantee repeatable read and not read "dirty" data.
二、二级 Blockade Protocol
The second-order blockade protocol is: first-level blockade protocol plus transaction T before reading the data r must be added s lock, read the rear can release S lock.
The two-level blockade protocol, in addition to preventing the loss of changes, can further prevent the reading of "dirty" data. However, in the level two blockade protocol, the S lock can be released after reading the data, so it does not guarantee repeatable reading.
三、三级 Blockade Protocol
The level three blockade protocol is that a first-level blockade protocol plus transaction T must be added s lock to the data R before it is released until the end of the transaction.
The level three blockade protocol, in addition to preventing loss of modifications and not reading "dirty" data, further prevents the unreadable.
The main difference between these three-level agreements is what operations need to be blocked and when to release them.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Network/basis/