当前位置:网站首页>Livelocks and deadlocks of concurrency control
Livelocks and deadlocks of concurrency control
2022-07-05 21:59:00 【Short section senior】
Blocking technology can effectively solve the consistency problem of parallel operation , But it also brings some new problems
Deadlock
Live lock
Live lock
Business T1 Blocked data R
Business T2 And ask for a blockade R, therefore T2 wait for .
T3 And ask for a blockade R, When T1 The release of the R After the blockade on, the system first approved T3 Request ,T2 Still waiting .
T4 And ask for a blockade R, When T3 The release of the R After the blockade, the system approved T4 Request ……
T2 It's possible to wait forever , This is the case with live locks
Avoid live locks : Adopt a first come, first serve strategy
When multiple transaction requests block the same data object
These transactions are queued in the order in which they are requested to be blocked
Once the lock on the data object is released , First approve the first transaction in the application queue to obtain the lock
Deadlock
Business T1 Blocked data R1
T2 Blocked data R2
T1 And ask for a blockade R2, because T2 It's blocked R2, therefore T1 wait for T2 Release R2 The lock on the
next T2 And apply for a blockade R1, because T1 It's blocked R1,T2 Can only wait T1 Release R1 The lock on the
such T1 Waiting for the T2, and T2 Waiting again T1,T1 and T2 Two things can never end , Formation of a deadlock
The solution to deadlock
Two kinds of methods
1. Deadlock prevention
2. Deadlock diagnosis and release
Deadlock prevention
The cause of deadlock is that two or more transactions have blocked some data objects , Then they all request to lock the data objects that have been blocked for other transactions , So there's a dead wait .
Preventing deadlock is to destroy the condition of deadlock
Ways to prevent deadlocks
(1) One time blockade
Each transaction is required to lock all data to be used at one time , Otherwise, we can't carry on
The problem is
Reduce system concurrency
It is difficult to accurately determine the blocking object in advance
The data in the database is constantly changing , Data that was not required to be blocked , It may become a blocking object during execution , So it's hard to determine exactly what data objects each firm is blocking in advance .
resolvent : Lock all data objects that may be blocked in the process of transaction execution , This further reduces concurrency .
(2) Sequential blockade
Sequential blocking method is to specify a blocking order for data objects in advance , Everything is blocked in this order .
Problems of sequential blockade method
Maintenance cost
There are many blocked data objects in database system , And with the insertion of data 、 Delete, etc. and change constantly , It's very difficult to maintain the blocking order of such resources , Cost is very high .
Difficult to achieve
The blocking request of a transaction can be determined dynamically with the execution of the transaction , It's hard to determine which objects are blocked by each transaction first , So it's very difficult to impose blockades in the prescribed order
Conclusion
The deadlock prevention strategy widely used in the operating system is not suitable for the characteristics of the database
The method of diagnosing and releasing deadlock is more commonly used in database management system to solve the problem of deadlock
Deadlock diagnosis and release
Deadlock diagnosis
(1) Overtime method
If the waiting time of a transaction exceeds the specified time limit , Think of a deadlock
advantage : Implement a simple
shortcoming
It is possible to misjudge the deadlock
If the time limit is set too long , It can't be found in time after deadlock
(2) Waiting graph
The transaction waiting graph is used to dynamically reflect the waiting situation of all transactions
The transaction waiting graph is a directed graph G=(T,U)
T For the set of nodes , Each node represents a running transaction
U A collection of sides , Each side represents the transaction waiting
if T1 wait for T2, be T1,T2 Draw a directed edge between , from T1 Point to T2
chart (a) in , Business T1 wait for T2,T2 wait for T1, There's a deadlock
chart (b) in , Business T1 wait for T2,T2 wait for T3,T3 wait for T4,T4 Waiting again T1, There's a deadlock
chart (b) in , Business T3 May still be waiting T2, There are small circuits in the large circuits
The concurrency control subsystem periodically ( For example, every few seconds ) Generate transaction wait graph , Detect transactions . If a circuit is found in the diagram , It means there is a deadlock in the system .
Deadlock Relieving
Choose a transaction with the least deadlock cost , Undo it
Release all locks held by this transaction , Enable other transactions to continue
Welcome to join me for wechat exchange and discussion ( Please note csdn Add )
边栏推荐
- GCC9.5离线安装
- A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
- Did you brush the real title of the blue bridge cup over the years? Come here and teach you to counter attack!
- Dbeaver executes multiple insert into error processing at the same time
- Environment configuration problem record
- regular expression
- Reptile practice
- Ad637 notes d'utilisation
- Evolution of large website architecture and knowledge system
- Interprocess communication in the "Chris Richardson microservice series" microservice architecture
猜你喜欢
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
Xlrd common operations
[Yugong series] go teaching course in July 2022 004 go code Notes
"Chris Richardson microservices series" uses API gateway to build microservices
PIP install beatifulsoup4 installation failed
Sentinel production environment practice (I)
Dbeaver executes multiple insert into error processing at the same time
PyGame practical project: write Snake games with 300 lines of code
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
随机推荐
大约SQL现场“这包括”与“包括在”字符串的写法
DataGrid directly edits and saves "design defects"
Recovery technology with checkpoints
Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
AD637 usage notes
Create a virtual machine on VMware (system not installed)
Codeforces 12D Ball 树形阵列模拟3排序元素
MMAP
AD637使用笔记
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
GCC9.5离线安装
kingbaseES V8R3数据安全案例之---审计记录清除案例
Multiplexing of Oracle control files
POJ 3237 tree (tree chain splitting)
An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
Efficiency difference between row first and column first traversal of mat data types in opencv
oracle 控制文件的多路复用
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
华为快游戏调用登录接口失败,返回错误码 -1
regular expression