ref: https://blog.csdn.net/whyangwanfu/article/details/1926675
Serializable
Transaction set is performed concurrently produced results equivalent to the results of any such scheduled transactions executed in a serial order.
Serializable by concurrency control mechanisms ( two-phase locking protocol to guarantee).
Conflict serializability
consider only read (X) and write (X) operation.
If a schedule S exchange (exchange of two consecutive instructions do not conflict) with the equivalent to a serial scheduling conflict, the scheduler S by a series of non-conflicting instructions conflict serializable.Serializable view
than the conflict serializable loose.
Recoverability
- Recoverable schedule
for each transaction Ti Ti read and write data Tj, Tj, to submit to the Ti Tj - No cascading schedule
for each transaction Ti and Tj, Tj Ti read the written data, the Ti to Tj's first reading before submitting
cascade schedule due to a transaction failure leads to a series of transaction rollback
Realization of isolation
Produced only conflict or view serializable serializable without scheduling cascade
Serializable determined
- Conflict detection serializable
transaction-vertex, configured with the FIG., Judgment ring
- Ti is read (X) to form the Tj write (X) before
- Ti, write (X) to form the Tj read (X) before
- Ti, write (X) to form the Tj write (X) prior to
satisfy any of the above structure is a one side, Ti -> Tj
- Serializable view detect
NP-complete
Concurrency Control
Lock Grant
- Shared locks S, a read lock
- Exclusive lock X, write locks
Q: How to avoid applying an exclusive lock transaction starve
A: Sort order authorization application lock lock
Two-phase locking protocol
- After the transaction to release the lock can not get a new lock
to ensure that conflict serializability is no guarantee that deadlock does not occur, the transaction is rolled back may also be cascaded - Another strict two-phase locking protocol (avoid cascading rollback), strong two-phase locking protocol (under the agreement, the transaction order can be submitted serialization), most of the database using one of these two agreements
Lock Manager
I data item, T for the transaction, which has been granted the lock for the black box
Multi-granularity locking
Some cases a plurality of data items clustered into one group, as the synchronization unit. Such as access to the entire database, for each data to perform locking operation is very time-consuming.
Intent locks
The database organized as a tree.
S transaction plus a lock on the data, to its ancestor node plus an IS lock , IS represents the subnode has an S lock
transaction data to a plus X lock, its ancestor node plus IX by
the same transaction may be added simultaneously to a node S IX locks and locks that SIX lock
Index structure Concurrency
For the transaction, look for an index twice, and found that during the indexing structure has changed, is perfectly acceptable, as long as the index lookup returns the correct set of tuples can be.
B + Tree: crab Protocol
- Search: S lock locked with a root node, the search along the tree down, after obtaining the lock child node S, S to release the lock of the parent node.
- Insertion and deletion: The search to find a leaf node, lock the leaf node with a X lock insertion deletion.
- Split and merge: the need to split or merge with a sibling node, the parent node with a X lock to lock.