Mysql 尝试获取锁时发现死锁

Mysql 尝试获取锁时发现死锁,mysql,database,vb.net,innodb,deadlock,Mysql,Database,Vb.net,Innodb,Deadlock,我经常面临这个例外 2015-Jan-06 14:24:59.167尝试获取时发现(严重)死锁 锁定[0]系统。异常消息=尝试获取时发现死锁 锁定源=Data.resultacumerator 我的应用程序是一个VB.Net应用程序,我正在使用MySQL连接,用于.Net 6.8.3版 在使用DataAdapter.update方法中的DataTable执行批量更新时,我遇到此异常。 整个更新过程在事务中运行 我发现了不同的线程,其中用户建议分析Innodb状态。因此,我在获得此异常后获取了状态

我经常面临这个例外

2015-Jan-06 14:24:59.167尝试获取时发现(严重)死锁 锁定[0]系统。异常消息=尝试获取时发现死锁 锁定源=Data.resultacumerator

我的应用程序是一个VB.Net应用程序,我正在使用MySQL连接,用于.Net 6.8.3版

在使用DataAdapter.update方法中的DataTable执行批量更新时,我遇到此异常。 整个更新过程在事务中运行

我发现了不同的线程,其中用户建议分析Innodb状态。因此,我在获得此异常后获取了状态。但我不知道如何分析它。以下是innodb的状态

===================================== 2015-01-06 14:25:07 2ec INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 29 seconds ----------------- BACKGROUND THREAD ----------------- srv_master_thread loops: 7208 srv_active, 0 srv_shutdown, 74547 srv_idle srv_master_thread log flush and writes: 81579 ---------- SEMAPHORES ---------- OS WAIT ARRAY INFO: reservation count 3583 OS WAIT ARRAY INFO: signal count 4766 Mutex spin waits 3514, rounds 53287, OS waits 1608 RW-shared spins 2281, rounds 46994, OS waits 1262 RW-excl spins 1304, rounds 36969, OS waits 674 Spin rounds per wait: 15.16 mutex, 20.60 RW-shared, 28.35 RW-excl ------------ TRANSACTIONS ------------ Trx id counter 1859662 Purge done for trx's n:o < 1859649 undo n:o < 0 state: running but idle History list length 1653 LIST OF TRANSACTIONS FOR EACH SESSION: ---TRANSACTION 1859651, not started MySQL thread id 127, OS thread handle 0xb00, query id 140079 N0414LEDF0275 10.0.52.40 opkeyapi cleaning up ---TRANSACTION 1859446, not started MySQL thread id 98, OS thread handle 0xf9c, query id 140081 localhost 127.0.0.1 root cleaning up ---TRANSACTION 0, not started MySQL thread id 97, OS thread handle 0x1c28, query id 140080 localhost 127.0.0.1 root cleaning up ---TRANSACTION 1859658, not started MySQL thread id 107, OS thread handle 0x1f78, query id 140109 N0414LEDF0240 10.0.52.129 opkeyapi cleaning up ---TRANSACTION 1859652, not started MySQL thread id 102, OS thread handle 0xed4, query id 140085 N0414LEDF0240 10.0.52.129 opkeyapi cleaning up ---TRANSACTION 0, not started MySQL thread id 90, OS thread handle 0x1f60, query id 81724 localhost 127.0.0.1 root cleaning up ---TRANSACTION 1859634, not started MySQL thread id 46, OS thread handle 0x159c, query id 140015 N0414LEDF0065 10.0.52.133 opkeyapi cleaning up ---TRANSACTION 1859633, not started MySQL thread id 45, OS thread handle 0x1464, query id 140011 N0414LEDF0065 10.0.52.133 opkeyapi cleaning up ---TRANSACTION 1859630, not started MySQL thread id 42, OS thread handle 0x1c00, query id 139999 N0414LEDF0250 10.0.52.128 opkeyapi cleaning up ---TRANSACTION 1859629, not started MySQL thread id 41, OS thread handle 0x1768, query id 139995 N0414LEDF0250 10.0.52.128 opkeyapi cleaning up ---TRANSACTION 1859649, not started MySQL thread id 38, OS thread handle 0x1ac8, query id 140071 N0414LEDF0085 10.0.52.63 opkeyapi cleaning up ---TRANSACTION 1859650, not started MySQL thread id 36, OS thread handle 0x17d8, query id 140075 N0414LEDF0085 10.0.52.63 opkeyapi cleaning up ---TRANSACTION 1859661, ACTIVE 0 sec 39 lock struct(s), heap size 2496, 100 row lock(s), undo log entries 224 MySQL thread id 126, OS thread handle 0x2ec, query id 140356 N0414LEDF0275 10.0.52.40 opkeyapi init show engine innodb status Trx read view will not see trx with id >= 1859662, sees < 1859662 -------- FILE I/O -------- I/O thread 0 state: wait Windows aio (insert buffer thread) I/O thread 1 state: wait Windows aio (log thread) I/O thread 2 state: wait Windows aio (read thread) I/O thread 3 state: wait Windows aio (read thread) I/O thread 4 state: wait Windows aio (read thread) I/O thread 5 state: wait Windows aio (read thread) I/O thread 6 state: wait Windows aio (write thread) I/O thread 7 state: wait Windows aio (write thread) I/O thread 8 state: wait Windows aio (write thread) I/O thread 9 state: wait Windows aio (write thread) Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] , ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0 Pending flushes (fsync) log: 0; buffer pool: 0 22934 OS file reads, 39569 OS file writes, 9117 OS fsyncs 3.07 reads/s, 16384 avg bytes/read, 0.55 writes/s, 0.38 fsyncs/s ------------------------------------- INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 36, seg size 38, 2078 merges merged operations: insert 16494, delete mark 25, delete 2 discarded operations: insert 0, delete mark 0, delete 0 Hash table size 1602143, node heap has 366 buffer(s) 53.93 hash searches/s, 61.00 non-hash searches/s --- LOG --- Log sequence number 4140114089 Log flushed up to 4139522989 Pages flushed up to 4138539042 Last checkpoint at 4138539042 0 pending log writes, 0 pending chkp writes 5282 log i/o's done, 0.17 log i/o's/second ---------------------- BUFFER POOL AND MEMORY ---------------------- Total memory allocated 410091520; in additional pool allocated 0 Dictionary memory allocated 608237 Buffer pool size 24704 Free buffers 1024 Database pages 23314 Old database pages 8586 Modified db pages 249 Pending reads 0 Pending writes: LRU 0, flush list 0, single page 0 Pages made young 9750, not young 279685 0.59 youngs/s, 19.55 non-youngs/s Pages read 22848, created 10791, written 32759 3.07 reads/s, 3.28 creates/s, 0.31 writes/s Buffer pool hit rate 993 / 1000, young-making rate 1 / 1000 not 50 / 1000 Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s LRU len: 23314, unzip_LRU len: 0 I/O sum[15]:cur[77], unzip sum[0]:cur[0] -------------- ROW OPERATIONS -------------- 0 queries inside InnoDB, 0 queries in queue 1 read views open inside InnoDB Main thread id 2656, state: sleeping Number of rows inserted 21162, updated 2520, deleted 131, read 48116841 7.48 inserts/s, 0.31 updates/s, 0.00 deletes/s, 53.38 reads/s ---------------------------- END OF INNODB MONITOR OUTPUT ============================ ===================================== 2015-01-06 14:25:07 2ec INNODB监视器输出 ===================================== 从最后29秒计算的每秒平均值 ----------------- 背景线程 ----------------- srv_主线程循环:7208个srv_活动,0个srv_关闭,74547个srv_空闲 srv_主线程日志刷新和写入:81579 ---------- 信号量 ---------- OS等待阵列信息:保留计数3583 OS等待阵列信息:信号计数4766 互斥旋转等待3514次,轮数53287次,操作系统等待1608次 RW共享旋转2281次,旋转46994次,操作系统等待1262次 RW excl旋转1304圈,旋转36969圈,操作系统等待674圈 每次等待旋转轮数:15.16互斥,20.60 RW共享,28.35 RW不包括 ------------ 交易 ------------ Trx id计数器1859662 为trx的n:o<1859649撤消n:o<0状态完成清除:运行但空闲 历史记录列表长度1653 每个会话的事务列表: ---事务1859651,未启动 MySQL线程id 127,操作系统线程句柄0xb00,查询id 140079 N0414LEDF0275 10.0.52.40 opkeyapi清理 ---事务1859446,未启动 MySQL线程id 98,操作系统线程句柄0xf9c,查询id 140081 localhost 127.0.0.1根目录清理 ---事务0,未启动 MySQL线程id 97,操作系统线程句柄0x1c28,查询id 140080localhost 127.0.0.1根目录清理 ---事务1859658,未启动 MySQL线程id 107,操作系统线程句柄0x1f78,查询id 140109 N0414LEDF0240 10.0.52.129 opkeyapi清理 ---事务1859652,未启动 MySQL线程id 102,操作系统线程句柄0xed4,查询id 140085 N0414LEDF0240 10.0.52.129 opkeyapi清理 ---事务0,未启动 MySQL线程id 90,操作系统线程句柄0x1f60,查询id 81724 localhost 127.0.0.1根清理 ---事务1859634,未启动 MySQL线程id 46,操作系统线程句柄0x159c,查询id 140015 N0414LEDF0065 10.0.52.133 opkeyapi清理 ---事务1859633,未启动 MySQL线程id 45,操作系统线程句柄0x1464,查询id 140011 N0414LEDF0065 10.0.52.133 opkeyapi清理 ---事务1859630,未启动 MySQL线程id 42,操作系统线程句柄0x1c00,查询id 139999 N0414LEDF0250 10.0.52.128 opkeyapi清理 ---事务1859629,未启动 MySQL线程id 41,操作系统线程句柄0x1768,查询id 139995 N0414LEDF0250 10.0.52.128 opkeyapi清理 ---事务1859649,未启动 MySQL线程id 38,操作系统线程句柄0x1ac8,查询id 140071 N0414LEDF0085 10.0.52.63 opkeyapi清理 ---事务1859650,未启动 MySQL线程id 36,操作系统线程句柄0x17d8,查询id 140075 N0414LEDF0085 10.0.52.63 opkeyapi清理 ---事务处理1859661,活动0秒 39锁结构,堆大小2496,100行锁,撤消日志项224 MySQL线程id 126,操作系统线程句柄0x2ec,查询id 140356 N0414LEDF0275 10.0.52.40 opkeyapi init 显示引擎innodb状态 Trx读取视图将不会看到id大于等于1859662的Trx,而会看到id小于1859662的Trx -------- 文件I/O -------- I/O线程0状态:等待Windows aio(插入缓冲区线程) I/O线程1状态:等待Windows aio(日志线程) I/O线程2状态:等待Windows aio(读取线程) I/O线程3状态:等待Windows aio(读取线程) I/O线程4状态:等待Windows aio(读取线程) I/O线程5状态:等待Windows aio(读取线程) I/O线程6状态:等待Windows aio(写入线程) I/O线程7状态:等待Windows aio(写入线程) I/O线程8状态:等待Windows aio(写入线程) I/O线程9状态:等待Windows aio(写入线程) 挂起的正常aio读取:0[0,0,0,0],aio写入:0[0,0,0,0], ibuf aio读取:0,日志i/o:0,同步i/o:0 挂起的刷新(fsync)日志:0;缓冲池:0 22934个操作系统文件读取,39569个操作系统文件写入,9117个操作系统fsyncs 3.07读取/秒,16384平均字节/读取,0.55写入/秒,0.38 fsyncs/s ------------------------------------- 插入缓冲区和自适应哈希索引 ------------------------------------- Ibuf:尺寸1,自由列表长度36,seg尺寸38,2078合并 合并操作: 插入16494,删除标记25,删除2 丢弃的操作: 插入0,删除标记0,删除0 哈希表大小1602143,节点堆有366个缓冲区 53.93哈希搜索/s,61.00非哈希搜索/s --- 日志 --- 日志序列号4140114089 日志刷新至4139522989 页面刷新到4138539042 最后一个检查站4138539042 0个挂起的日志写入,0个挂起的chkp写入 5282日志i/o完成,0.17日志i/o/秒 ---------------------- 缓冲池和内存 ---------------------- 分配的总内存410091520;在分配的其他池中0 字典内存分配608237 缓冲池大小24704 可用缓冲区1024 数据库第23314页 旧数据库第8586页 修改数据库第249页 挂起读取0 挂起写入:LRU 0、刷新列表0、单页0 页面年轻9750,而不是年轻279685 0.59扬格/秒,19.55非扬格/秒 读22848页,写10791页,写32759页 3.07读取/秒,3.28创建/秒,0.31写入/秒 缓冲池命中率993/1000,年轻制造率1/1000而非50/1000 页面预读0.00/s,无访问权收回0.00/s,随机预读0.00/s LRU-len:23314,解压_-LRU-len:0 I/O总和[15]:cur[77],解压总和[0]:cur[0] -------------- 行操作 -------------- InnoDB中有0个查询,队列中有0个查询 1读取InnoDB内部打开的视图 主线程id 2656,状态:休眠 行数
------------------------
LATEST DETECTED DEADLOCK
------------------------
2015-01-06 11:47:02 da8
*** (1) TRANSACTION:
TRANSACTION 24103246, ACTIVE 16 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 376, 2 row lock(s)
MySQL thread id 3, OS thread handle 0xde8, query id 102 localhost 127.0.0.1 test
 updating
update test set test=1 where test=1
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 489 page no 3 n bits 80 index `PRIMARY` of table `test`.`t
est` trx id 24103246 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000016fc940; asc    o @;;
 2: len 7; hex a80000026e0110; asc     n  ;;

*** (2) TRANSACTION:
TRANSACTION 24103245, ACTIVE 63 sec starting index read, thread declared inside
InnoDB 5000
mysql tables in use 1, locked 1
3 lock struct(s), heap size 376, 2 row lock(s)
MySQL thread id 4, OS thread handle 0xda8, query id 103 localhost 127.0.0.1 test
 updating
update test set test=4 where test=4
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 489 page no 3 n bits 80 index `PRIMARY` of table `test`.`t
est` trx id 24103245 lock_mode X locks rec but not gap
Record lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000016fc940; asc    o @;;
 2: len 7; hex a80000026e0110; asc     n  ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 489 page no 3 n bits 80 index `PRIMARY` of table `test`.`t
est` trx id 24103245 lock_mode X locks rec but not gap waiting
Record lock, heap no 5 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: len 4; hex 80000004; asc     ;;
 1: len 6; hex 0000016fc940; asc    o @;;
 2: len 7; hex a80000026e0137; asc     n 7;;

*** WE ROLL BACK TRANSACTION (2)
------------
TRANSACTIONS
------------