dbms_DBMS | 并发控制
dbms
Management of concurrent transaction execution is known as “Concurrency Control”. Transaction management in DBMS handles all transaction, to ensure serializability and isolation of transaction. DBMS implement concurrency control technique so that the consistency and integrity of the database can be hold.
并發(fā)事務(wù)執(zhí)行的管理稱為“并發(fā)控制” 。 DBMS中的事務(wù)管理處理所有事務(wù),以確保事務(wù)的可串行性和隔離性。 DBMS實(shí)施并發(fā)控制技術(shù),以便可以保持?jǐn)?shù)據(jù)庫的一致性和完整性。
The processes of managing simultaneously operation such that update, create, insert, delete on the database without having an interface with one another, known as concurrency control. It can be performed by various methods such as locking technique, time stamp technique, validation based technique.
同時(shí)管理操作的過程,例如在數(shù)據(jù)庫上相互更新,創(chuàng)建,插入,刪除而無需相互接口,這稱為并發(fā)控制。 它可以通過各種方法執(zhí)行,例如鎖定技術(shù),時(shí)間戳技術(shù),基于驗(yàn)證的技術(shù)。
并發(fā)控制的鎖定技術(shù) (Locking Technique for Concurrency Control)
Locking is a procedure which controls concurrent access of the data. If one transaction is accessing the database, a lock may be denied access to other transaction to prevent the incorrect result. Locking technique is one of the most widely used mechanisms to ensure serializability. The principle of locking technique is that a transaction must obtain read or write lock in the database before it can perform a read or write operation.
鎖定是控制并發(fā)訪問數(shù)據(jù)的過程。 如果一個(gè)事務(wù)正在訪問數(shù)據(jù)庫,則可以拒絕鎖訪問其他事務(wù),以防止產(chǎn)生錯(cuò)誤的結(jié)果。 鎖定技術(shù)是確保可序列化性的最廣泛使用的機(jī)制之一。 鎖定技術(shù)的原理是,事務(wù)必須先獲得數(shù)據(jù)庫中的讀取或?qū)懭腈i定,然后它才能執(zhí)行讀取或?qū)懭氩僮鳌?
There are some basic rules for locking technique are as following:
鎖定技術(shù)有一些基本規(guī)則,如下所示:
If a transaction has read lock on the data item, it can read the item but can’t update it.
如果事務(wù)對(duì)數(shù)據(jù)項(xiàng)具有讀取鎖定,則它可以讀取該項(xiàng)目但不能更新它。
If a transaction has read lock on the data item, other transaction can read on data item but can’t write on the data item.
如果事務(wù)對(duì)數(shù)據(jù)項(xiàng)具有讀取鎖定,則其他事務(wù)可以在數(shù)據(jù)項(xiàng)上讀取,但不能在數(shù)據(jù)項(xiàng)上寫入。
If a transaction has to write lock on the data item, it can both read and update data item.
如果事務(wù)必須在數(shù)據(jù)項(xiàng)上寫鎖,則它可以讀取和更新數(shù)據(jù)項(xiàng)。
If a transaction has to write lock on data item then the other transaction neither read nor write on the data item.
如果一個(gè)事務(wù)必須在數(shù)據(jù)項(xiàng)上寫鎖,則另一個(gè)事務(wù)既不在該數(shù)據(jù)項(xiàng)上讀寫。
鎖定方式 (Mode of Locking)
There are basically two types of modes in which a data item may be locked:
基本上有兩種模式可以鎖定數(shù)據(jù)項(xiàng):
Shared Lock
共享鎖
Exclusive Lock
排他鎖
1)共享鎖 (1) Shared Lock)
If a transaction T has a shared lock on the data item q, then T can read but can’t write on q data item. It is denoted by (S).
如果事務(wù)T在數(shù)據(jù)項(xiàng)q上具有共享鎖,則T可以在q數(shù)據(jù)項(xiàng)上讀取但不能寫入。 用( S )表示。
2)排他鎖 (2) Exclusive Lock)
If transaction T has an exclusive lock on data item q, then T can read and write both on the data item. It is denoted by (X).
如果事務(wù)T對(duì)數(shù)據(jù)項(xiàng)q具有排他鎖,則T可以在數(shù)據(jù)項(xiàng)上進(jìn)行讀寫操作。 用( X )表示。
In order to access the data item, these conditions should be followed:
為了訪問數(shù)據(jù)項(xiàng),應(yīng)遵循以下條件:
Transaction T must first lock it. If the data item is already locked by another transaction which is not comparable then T must wait until have been released & unlock.
事務(wù)T必須首先將其鎖定。 如果數(shù)據(jù)項(xiàng)已經(jīng)被另一個(gè)不可比較的事務(wù)鎖定,則T必須等待直到被釋放并解鎖。
The transaction must hold a lock on data item when it is accessed.
事務(wù)在訪問時(shí)必須對(duì)數(shù)據(jù)項(xiàng)保持鎖定。
After that unlock it.
之后,將其解鎖。
A matrix given below shows the comparability between two lock modes:
下面給出的矩陣顯示了兩種鎖定模式之間的可比性:
| S | T | T |
| X | F | F |
| 小號(hào) | ? | ? |
| X | F | F |
Example:
例:
Consider the following 2 transaction T(read(a), read(b)).
考慮以下2個(gè)事務(wù)T(read(a),read(b)) 。
| T1 | T2 |
| read(a) read(b) if a=0 then b=b+1 write(b) | |
| T1 | T2 |
| read(a) read(b) if a=0 then b=b+1 write(b) | |
Find lock and unlock instruction of the transaction T1 & T2. Then observe the locking protocol? The execution of transaction is deadlock?
查找交易T1和T2的鎖定和解鎖指令。 然后遵守鎖定協(xié)議? 交易的執(zhí)行是否陷入僵局?
Solution:
解:
Lock and unlock instruction:
鎖定和解鎖說明:
| T1 | T2 |
| lock S(a) read(a) lock X(b) read(b) if a=0 then b=b+1 write(b) unlock(b) unlock(a) lock S(b) read(b) lock (a) read(a) if b=0 then a=a+1 write(a) unlock(a) unlock(b) |
| T1 | T2 |
| T1 | T2 |
| lock S(a) | |
| lock S(b) | |
| lock X(b) | |
| lock X(a) |
| T1 | T2 |
| 鎖S(a) | |
| 鎖S(b) | |
| 鎖X(b) | |
| 鎖X(a) |
Yes, transaction has deadlock.
是的,交易陷入僵局。
翻譯自: https://www.includehelp.com/dbms/concurrency-control.aspx
dbms
總結(jié)
以上是生活随笔為你收集整理的dbms_DBMS | 并发控制的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ruby array_Ruby中带有示例
- 下一篇: c语言宏函数怎么传递宏参数_C语言中的宏