我在这里阅读了一些关于此的帖子,但仍然不明白如何解决该错误。另外我如何破译 show engine innodb status 输出。我怀疑它是死锁或永远不会提交/回滚的事务导致它永远持有锁(这可能吗?)。
# show engine innodb status;
=====================================
2015-09-27 04:43:54 2b9cf470f700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 33 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 16140 srv_active, 0 srv_shutdown, 3941554 srv_idle
srv_master_thread log flush and writes: 3957687
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 25915
OS WAIT ARRAY INFO: signal count 25874
Mutex spin waits 1675, rounds 50212, OS waits 1581
RW-shared spins 24307, rounds 729240, OS waits 24278
RW-excl spins 16, rounds 1680, OS waits 56
Spin rounds per wait: 29.98 mutex, 30.00 RW-shared, 105.00 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 712274
Purge done for trx's n:o < 712178 undo n:o < 0 state: running but idle
History list length 1593
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 18286, OS thread handle 0x2b9cf470f700, query id 2307113 bb116-14-164-108.singnet.com.sg 116.14.164.108 meclub2359 init
show engine innodb status
---TRANSACTION 0, not started
MySQL thread id 18285, OS thread handle 0x2b9cf4444700, query id 2306954 bb116-14-164-108.singnet.com.sg 116.14.164.108 meclub2359 cleaning up
---TRANSACTION 712266, not started
MySQL thread id 18270, OS thread handle 0x2b9cf43c2700, query id 2307088 172.31.8.174 meclub2359 cleaning up
---TRANSACTION 712235, not started
MySQL thread id 18268, OS thread handle 0x2b9cf3896700, query id 2306757 172.31.8.174 meclub2359 cleaning up
---TRANSACTION 712268, not started
MySQL thread id 18267, OS thread handle 0x2b9cf4381700, query id 2307091 172.31.8.174 meclub2359 cleaning up
---TRANSACTION 712272, not started
MySQL thread id 5214, OS thread handle 0x2b9cf31dd700, query id 2307112 localhost 127.0.0.1 rdsadmin cleaning up
---TRANSACTION 712269, ACTIVE 31 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 18288, OS thread handle 0x2b9cf44c6700, query id 2307092 172.31.8.174 meclub2359 updating
UPDATE stardate SET winnersSelected=1 WHERE id='6'
------- TRX HAS BEEN WAITING 31 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 4067 page no 3 n bits 72 index `PRIMARY` of table `ebdb`.`stardate` trx id 712269 lock_mode X locks rec but not gap waiting
Record lock, heap no 3 PHYSICAL RECORD: n_fields 16; compact format; info bits 0
0: len 4; hex 00000006; asc ;;
1: len 6; hex 0000000addcd; asc ;;
2: len 7; hex 180000021d2d57; asc -W;;
3: len 30; hex 68747470733a2f2f73332d61702d736f757468656173742d312e616d617a; asc https://s3-ap-southeast-1.amaz; (total 62 bytes);
4: len 30; hex 4d75736963616c204576656e696e67207769746820456c6c696520476f75; asc Musical Evening with Ellie Gou; (total 35 bytes);
5: len 30; hex 4d75736963616c204576656e696e67207769746820456c6c696520476f75; asc Musical Evening with Ellie Gou; (total 35 bytes);
6: len 30; hex 4d75736963616c204576656e696e67207769746820456c6c696520476f75; asc Musical Evening with Ellie Gou; (total 255 bytes);
7: len 22; hex 53696e6761706f72650d0a4d6172696e612042617920; asc Singapore Marina Bay ;;
8: len 20; hex 52443230313530394d434d4543444153434d5346; asc RD201509MCMECDASCMSF;;
9: len 4; hex 80000002; asc ;;
10: len 5; hex 9997295000; asc )P ;;
11: len 5; hex 999702a000; asc ;;
12: len 4; hex 8000000c; asc ;;
13: len 1; hex 81; asc ;;
14: len 5; hex 999706e345; asc E;;
15: len 5; hex 99972ee820; asc . ;;
------------------
---TRANSACTION 712213, ACTIVE 501 sec
5 lock struct(s), heap size 1184, 1 row lock(s), undo log entries 3
MySQL thread id 18284, OS thread handle 0x2b9cf3daa700, query id 2307007 172.31.8.174 meclub2359 cleaning up
Trx read view will not see trx with id >= 712249, sees < 712141
---TRANSACTION 712197, ACTIVE 574 sec
5 lock struct(s), heap size 1184, 1 row lock(s), undo log entries 3
MySQL thread id 18283, OS thread handle 0x2b9cf4403700, query id 2306959 172.31.8.174 meclub2359 cleaning up
Trx read view will not see trx with id >= 712241, sees < 712141
---TRANSACTION 712184, ACTIVE 595 sec
5 lock struct(s), heap size 1184, 1 row lock(s), undo log entries 3
MySQL thread id 18281, OS thread handle 0x2b9cf468d700, query id 2306856 172.31.8.174 meclub2359 cleaning up
Trx read view will not see trx with id >= 712240, sees < 712141
---TRANSACTION 712141, ACTIVE 935 sec
7 lock struct(s), heap size 1184, 12 row lock(s), undo log entries 19
MySQL thread id 18279, OS thread handle 0x2b9cf4485700, query id 2306383 172.31.8.174 meclub2359 cleaning up
Trx read view will not see trx with id >= 712146, sees < 712146
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (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
562 OS file reads, 295536 OS file writes, 202242 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.24 writes/s, 0.18 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 1241027, node heap has 2 buffer(s)
0.06 hash searches/s, 0.27 non-hash searches/s
---
LOG
---
Log sequence number 87135734
Log flushed up to 87135734
Pages flushed up to 87135734
Last checkpoint at 87135734
0 pending log writes, 0 pending chkp writes
133514 log i/o's done, 0.09 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 641744896; in additional pool allocated 0
Dictionary memory allocated 264646
Buffer pool size 38271
Free buffers 20250
Database pages 18019
Old database pages 6631
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 423, not young 82
0.00 youngs/s, 0.00 non-youngs/s
Pages read 521, created 17502, written 131006
0.00 reads/s, 0.00 creates/s, 0.12 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 18019, unzip_LRU len: 0
I/O sum[4]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
4 read views open inside InnoDB
Main thread process no. 14465, id 47953069967104, state: sleeping
Number of rows inserted 55739, updated 14635, deleted 309, read 1463461
0.00 inserts/s, 0.03 updates/s, 0.00 deletes/s, 35.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
似乎有一些查询挂起? show processlist
如果是这样,我该如何调试我的应用程序中导致此问题的更多位置?我正在使用 AWS RDS、Elastic Beanstalk、NodeJS/SailsJS。
更新
我注意到这个问题只发生在一行。当我尝试 UPDATE stardate SET WinnersSelected=1 WHERE id='6' 时。
更新
我发现关闭连接的代码更改有效。但仍然很好奇,我如何从上面的输出中判断原因是什么?我认为这将是有用的。我不确定这是否是原因。
例如,我看到了
---TRANSACTION 0, not started
MySQL thread id 18285, OS thread handle 0x2b9cf4444700, query id 2306954 bb116-14-164-108.singnet.com.sg 116.14.164.108 meclub2359 cleaning up
---TRANSACTION 712235, not started
MySQL thread id 18268, OS thread handle 0x2b9cf3896700, query id 2306757 172.31.8.174 meclub2359 cleaning up
为什么清理看起来需要这么长时间?我应该担心吗?
---TRANSACTION 712269, ACTIVE 31 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 18288, OS thread handle 0x2b9cf44c6700, query id 2307092 172.31.8.174 meclub2359 updating
UPDATE stardate SET winnersSelected=1 WHERE id='6'
------- TRX HAS BEEN WAITING 31 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 4067 page no 3 n bits 72 index `PRIMARY` of table `ebdb`.`stardate` trx id 712269 lock_mode X locks rec but not gap waiting
Record lock, heap no 3 PHYSICAL RECORD: n_fields 16; compact format; info bits 0
0: len 4; hex 00000006; asc ;;
1: len 6; hex 0000000addcd; asc ;;
2: len 7; hex 180000021d2d57; asc -W;;
3: len 30; hex 68747470733a2f2f73332d61702d736f757468656173742d312e616d617a; asc https://s3-ap-southeast-1.amaz; (total 62 bytes);
4: len 30; hex 4d75736963616c204576656e696e67207769746820456c6c696520476f75; asc Musical Evening with Ellie Gou; (total 35 bytes);
5: len 30; hex 4d75736963616c204576656e696e67207769746820456c6c696520476f75; asc Musical Evening with Ellie Gou; (total 35 bytes);
6: len 30; hex 4d75736963616c204576656e696e67207769746820456c6c696520476f75; asc Musical Evening with Ellie Gou; (total 255 bytes);
7: len 22; hex 53696e6761706f72650d0a4d6172696e612042617920; asc Singapore Marina Bay ;;
8: len 20; hex 52443230313530394d434d4543444153434d5346; asc RD201509MCMECDASCMSF;;
9: len 4; hex 80000002; asc ;;
10: len 5; hex 9997295000; asc )P ;;
11: len 5; hex 999702a000; asc ;;
12: len 4; hex 8000000c; asc ;;
13: len 1; hex 81; asc ;;
14: len 5; hex 999706e345; asc E;;
15: len 5; hex 99972ee820; asc . ;;
我可以从上面的输出中说查询 UPDATE stardate SET WinnersSelected=1 WHERE id='6' 被阻止了吗?但我怎么知道是什么?
最佳答案
在处理困难的 MySQL 诊断问题时,您常常不得不求助于 gdb。你可以这样做:
gdb -ex "set pagination 0" -ex "thread apply all bt" \
--batch -p $(pidof mysqld)
然后您深入研究堆栈跟踪列表,并通过对源代码的一点了解就可以弄清楚发生了什么。
长时间“清理”的一个可能原因是某处的某个关键锁被另一个线程占用,这可能有多种原因。如果您粘贴堆栈跟踪,我就能让您了解发生了什么。
InnoDB 中的死锁实际上是一种合法的场景。它的设计方式在某些情况下(希望很少见)锁定算法会发现自己陷入死锁。这个问题通过锁等待超时得到缓解——当达到超时时,事务被中止以摆脱死锁。理论上,理想的 InnoDB 客户端代码应该编写为重试所有由于死锁而失败的事务。在实践中,重构大型代码库以符合这一原则可能非常困难,但我仍然建议选择一些关键的战斗并重构最麻烦的代码以符合这一原则。
为避免死锁,请频繁提交您的事务并避免以不可预测的顺序更新记录。当然,这将包括正确清理连接 - 正如您在您的案例中所观察到的那样。如果你不关闭连接,你可能会遇到这样一个看似无辜的场景:
问题是事务锁定了它用 SELECT 读取的行,并且在 COMMIT/ROLLBACK 之前不会解锁它们。
如果您有很多难以清理的困惑代码,您可能需要考虑不再使用连接池。 MySQL 的 session 启动开销非常低,可以很好地处理频繁的重新连接。这样,不活动的连接可能会在应用程序请求终止时自动关闭(我假设有关代码的一些事情在大量应用程序中很常见)并且您不会与正在返回到该状态下的连接池。
关于mysql - 如何解决和调试 MySQL 错误 : ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32804691/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我有一大串格式化数据(例如JSON),我想使用Psychinruby同时保留格式转储到YAML。基本上,我希望JSON使用literalstyle出现在YAML中:---json:|{"page":1,"results":["item","another"],"total_pages":0}但是,当我使用YAML.dump时,它不使用文字样式。我得到这样的东西:---json:!"{\n\"page\":1,\n\"results\":[\n\"item\",\"another\"\n],\n\"total_pages\":0\n}\n"我如何告诉Psych以想要的样式转储标量?解