A deadlock occurs when multiple transactions hold and request locks on the same resource at the same time as a result of cyclic dependency. Deadlocks occur when a transaction attempts to lock a resource in a different order. Take the two transactions on the StockPrice table for example:
Business 1
START TRANSACTION;
UPDATE stockprice SET close = 45.50 WHERE stock_id = 4 and date = ' 2002-05-01 ';
UPDATE stockprice SET close = 19.80 WHERE stoc
This article is mainly through an experiment to describe, the process is more boring.Experiment PreparationCREATE TABLE Test_lock (ID int auto_increment PRIMARY key, stock int) Engine=innodb;Insert into Test_lock (id,stock) value (1,50);Here I make the stack information as simple as possible, the names of the 25 main functions and the entry parametersIn order to highlight the topic, I add this to the opening deadlock detection function list, altogeth
Deadlock Reason:
To extract the corresponding data of query data and modify the Stat table, all of them modify the same data, carry out large amount of data, and simultaneously, cause database deadlock and block;
Related knowledge:
1. SQL deadlock and blocking: http://searchdatabase.techtarget.com.cn/tips/275/2080775.s
Like debugging the lock in userspace, it mainly involves:
1. Locate the lock deadlock and print out the call stack.
2. Find out who is using this mutex.
For example, in kernel config, enable is associated with lock/mutex, such as config_debug_mutex and config_detect_hung_tasks. In this way, when a deadlock occurs, wait for a period of time (120 seconds by default). The kernel detects the
First, the concept of deadlock
Synchronization of multiple threads can cause deadlocks if they are poorly designed. A deadlock is when multiple threads share certain resources while waiting for the other to release resources, causing the program to stagnate.
Deadlock can cause the program to stall, so we must be careful to avoid deadlocks when we write multi-t
If there are two locks Lock1 (Mutex_gard mode) and lock;The order of the two calls is different, there will be waiting for each other, resulting in deadlock;To avoid deadlocks, we can:1, each thread lock in the same order of invocation;2, the use of std:: Lock ();In a method called by both the main thread and the child threadStd::lock (Mutex1,mutex2,....);When it's locked.In addition: The mutex itself also has the lock and unlock methodC + + multithre
Tags: bug isolated multiple nod read/write Mutex detection log sharing found that when the SQL statement of the backup table runs at the same time as the SQL statement that deletes part of the data from the table, MySQL detects the deadlock and prints out the log Case descriptionDuring a timed script run, MySQL detects a dead
The problem, literally, is that the program has a deadlock, which causes the w3wp process to restart. Usually this problem is difficult to find out the reason. I know two instances that could cause this problem
1. Lock or ReaderWriterLock is used in the program, and the locking resource has been contention
Here's a little piece of code:
Copy Code code as follows:
The type of _rwlock is ReaderWriterLock
_rwlock.acquirewriterlock (10
check if the system has entered an unsafe zone, which allows the system to deadlock during operation. However, the detection mechanism set up by the system can detect the occurrence of the deadlock in time, and determine the process and resources related to the deadlock, then take appropriate measures to remove the deadlock
more obscure, when transaction A is executed, in addition to locking in the level two index, it will also be locked on the clustered index, and the order of locking on the clustered index is [1,4,2,3,5], while transaction B is executed with only a lock on the clustered index, and the lock order is [1,2,3,4,5], which creates the possibility of deadlock.
Figure 3.4 Gap lock conflict
InnoDB at the RR level, as in the case of a
, machine, program from v $ session where sid in(Select session_id from v $ locked_object)If there are output results, it indicates a deadlock exists and you can see which machine is deadlocked. Field description:Username: the database user used by the deadlock statement;Lockwait: the status of the deadlock. If there is content, it indicates the deadlock.Status:
Case descriptionDuring a timed script run, it is found that when the SQL statement of the backup table runs concurrently with the SQL statement that deletes the data in the table, MySQL detects the deadlock and prints out the log.Two SQL statements are as follows:(1) INSERT INTO backup_table select * from source_table(
complementary measure to the Deadlock Detection. When a dead or dead lock is detected in the system, the process must be freed from the deadlock state. A common implementation method is to undo or suspend some processes to recycle some resources, and then allocate these resources to the blocked processes so that they are ready to continue running. Deadlock Detec
from dual;Commit First connection, run in command window:Begin--Modify T1 firstUpdate T1 set id=2where id=1;--Wait 20sDbms_lock.sleep (20);--Re-modify T2Update T2 Set id=2where id=1;End/Operation Result:ORA-00060: Deadlock detected while waiting for resourceORA-06512: On line 9 A second connection: Begin--Modify T2 firstUpdate T2 Set id=2where id=1;--Wait 20sDbms_lock.sleep (20);--Re-modify T1Update T1 set id=2where id=1;End/Operation Result:PL/
it to the exclusive lock on the resource. The update lock is not enough for data update-the exclusive lock is still required for actual data modification. Serialized access to exclusive locks can avoid deadlock Conversion. update locks are retained until the transaction ends or when they are converted to exclusive locks.
4. intention lock (IX, IU, IS)
The intention lock is not an independent locking mode, but a mechanism for identifying which resourc
Case DescriptionDuring the running of the scheduled script, it is found that when the SQL statement for backing up the table and the SQL statement for deleting some data in the table run simultaneously, mysql will detect the deadlock and print the log.The two SQL statements are as follows:(1) insert into backup_table s
Case DescriptionDuring the running of the scheduled script, it is found that when the SQL statement for backing up the table and the SQL statement for deleting some data in the table run simultaneously, mysql will detect the deadlock and print the log.The two SQL statements are as follows:(1) insert into backup_table s
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.