当前位置:网站首页>MySQ deadlock
MySQ deadlock
2022-07-30 03:32:00 【Leon_Jinhai_Sun】
Deadlock means that two or more transactions occupy each other on the same resource and request to lock the resources occupied by each other, resulting in a vicious circle.
Condition:
1. Two or more transactions
2. Each transaction already holds a lock and applies for a new lock
3. Lock resources can only be held by the same transaction at the same time or are incompatible
4. Transactions wait for each other circularly due to holding locks and applying for locks
Transaction 1 and transaction 2 set row locks for the rows with id=1 and id=2 respectively.Then transaction 1 is waiting for transaction 2 to release the row lock with id=2, and transaction 2 is waiting for transaction 1 to release the row lock with id=1.Transaction 1 and transaction 2 are waiting for each other's resources to be released, that is, they enter a deadlock state.
The way to solve the deadlock:
1. Set the timeout period.When a transaction wait time reaches the threshold, it is rolled back and another transaction continues.The disadvantage is that the waiting time is too long and it is often unacceptable, and the time is too short and it is easy to accidentally hurt the ordinary lock waiting.
2. Use deadlock detection processing.After a deadlock is found, a transaction in the deadlock chain is actively rolled back (the transaction that holds the least row-level exclusive lock is rolled back/minimum amount of undo), so that other transactions can continue to execute.
The principle of deadlock detection is to construct a directed graph with transactions as vertices and locks as edges, and to determine whether there is a cycle in the directed graph, which means deadlock.
The disadvantage is that each new blocked thread has to determine whether it is deadlocked because of its addition, which is time-consuming.
Solutions:
1. Turn off deadlock detection.
2. Control the amount of concurrent access.For example, at most 10 threads are updating the same row at the same time, so the cost of deadlock detection is very low, and this problem will not occur.
How to avoid deadlock?
1. Set the index reasonably so that SQL can locate fewer rows through the index as much as possible.
2. Adjust the SQL execution order to avoid the SQL that holds the lock for a long time in front of the transaction.
3. Try to split large transactions into small transactions.
4. Do not explicitly lock in systems with high concurrency.
5. Lower the isolation level.
边栏推荐
猜你喜欢

JIT vs AOT

day10--在Linux上安装mysql

【GPU并行计算】利用OpenCL&OpenCLUtilty进行GPU并行计算

OpenFeign realize load balance

(RCE)远程代码/命令执行漏洞漏洞练习

The relationship between the number of Oracle processes and the number of sessions

Starlight does not ask passers-by!The young lady on the Wuhan campus successfully switched to software testing in three months and received a salary of 9k+13!

解决谷歌浏览器跨域问题has been blocked by CORS policy: The request client is not a secure context and the resou

开放地址法哈希实现——线性探测法

LoadBalancer load balancing
随机推荐
Nacos命名空间
Overview of Federated Learning (1) - Background, Definition and Value of Federated Learning
Sentinel Traffic Guard
JUC(八):synchronized小练习
雪花是否一样问题
记录NLP各种资源网址
JUC (7): Thread Safety Analysis of Variables
The relationship between the number of Oracle processes and the number of sessions
精品:淘宝/天猫获取购买到的商品订单详情 API
【Node访问MongoDB数据库】
Nacos集群分区
【JS】iframe 嵌入页面用法
NLP自然语言处理(二)
Drools(7):WorkBench
【无标题】
JUC(七):变量的线程安全分析
NLP Natural Language Processing (1)
Three years of experience will only be a little bit (functional testing), and you may not even be able to find a job after resigning.
路由过滤器
请问下,datax同步到oceanbase数据库时,按照主键更新方式写入,下拉框里的内容要如何填写?