sonarqube 5.2 MySQLTransactionRollbackException:尝试获取锁时发现死锁

sonarqube 5.2 MySQLTransactionRollbackException:尝试获取锁时发现死锁,sonarqube,Sonarqube,使用SonarQube 5.2,我看到以下死锁问题: 05:48:22 ERROR: Error during Sonar runner execution 05:48:22 java.lang.IllegalStateException: Fail to execute request [code=500, url=http://192.168.109.6/api/ce/submit?projectKey=CoprHD&projectName=CoprHD-controlle

使用SonarQube 5.2,我看到以下死锁问题:

05:48:22 ERROR: Error during Sonar runner execution 05:48:22 java.lang.IllegalStateException: Fail to execute request [code=500, url=http://192.168.109.6/api/ce/submit?projectKey=CoprHD&projectName=CoprHD-controller&projectBranch=bugfix-COP-19001-hotfix]: {"errors":[{"msg":"\n### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction\n ### The error may involve org.sonar.db.user.RoleMapper.insertGroupRole-Inline\n### The error occurred while setting parameters\n ### SQL: INSERT INTO group_roles (group_id, resource_id, role) VALUES (?, ?, ?)\n ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction"}]} 05:48:22 at org.sonar.batch.report.ReportPublisher.uploadMultiPartReport(ReportPublisher.java:182) 05:48:22 at org.sonar.batch.report.ReportPublisher.sendOrDumpReport(ReportPublisher.java:151) 05:48:22 at org.sonar.batch.report.ReportPublisher.execute(ReportPublisher.java:115) 05:48:22 at org.sonar.batch.phases.PhaseExecutor.publishReportJob(PhaseExecutor.java:116) 05:48:22 at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:106) 05:48:22 at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192) 05:48:22 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) 05:48:22 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) 05:48:22 at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:258) 05:48:22 at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:253) 05:48:22 at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:243) 05:48:22 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) 05:48:22 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) 05:48:22 at org.sonar.batch.bootstrap.GlobalContainer.executeAnalysis(GlobalContainer.java:153) 05:48:22 at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:110) 05:48:22 at org.sonar.runner.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:55) 05:48:22 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 05:48:22 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 05:48:22 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 05:48:22 at java.lang.reflect.Method.invoke(Method.java:606) 05:48:22 at org.sonar.runner.impl.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:61) 05:48:22 at com.sun.proxy.$Proxy0.execute(Unknown Source) 05:48:22 at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:275) 05:48:22 at org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:166) 05:48:22 at org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:153) 05:48:22 at org.sonar.runner.cli.Main.runAnalysis(Main.java:118) 05:48:22 at org.sonar.runner.cli.Main.execute(Main.java:80) 05:48:22 at org.sonar.runner.cli.Main.main(Main.java:66) 05:48:22错误:执行Sonar runner时出错 05:48:22 java.lang.IllegalStateException:无法执行请求 [代码=500,url=http://192.168.109.6/api/ce/submit?projectKey=CoprHD&projectName=CoprHD-控制器&projectBranch=bugfix-COP-19001-hotfix]: {“errors”:[{“msg”:“\n####更新数据库时出错。 原因:com.mysql.jdbc.exceptions.jdbc4.mysqltransaction回滚异常: 尝试获取锁时发现死锁;请尝试重新启动事务\n ###错误可能涉及org.sonar.db.user.RoleMapper.insertGroupRole内联\n####设置参数时出错\n ###SQL:在组角色(组id、资源id、角色)中插入值(?、、?)\n ###原因:com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException:尝试获取锁时发现死锁;尝试重新启动事务“}]} 05:48:22在org.sonar.batch.report.ReportPublisher.uploadMultiPartReport(ReportPublisher.java:182) 05:48:22在org.sonar.batch.report.ReportPublisher.sendOrDumpReport(ReportPublisher.java:151) 05:48:22在org.sonar.batch.report.ReportPublisher.execute(ReportPublisher.java:115) 05:48:22在org.sonar.batch.PhaseExecutor.publishReportJob(PhaseExecutor.java:116) 05:48:22在org.sonar.batch.phasees.PhaseExecutor.execute(PhaseExecutor.java:106) 05:48:22在org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192) 05:48:22在org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) 05:48:22在org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) 05:48:22在org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:258) 05:48:22在org.sonar.batch.scan.ProjectScanContainer.scanRecursive(ProjectScanContainer.java:253) 05:48:22在org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:243) 05:48:22在org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) 05:48:22在org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) 05:48:22在org.sonar.batch.bootstrap.GlobalContainer.executeAnalysis(GlobalContainer.java:153) 05:48:22在org.sonar.batch.bootstrapper.batch.executeTask(batch.java:110) 05:48:22在org.sonar.runner.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:55) 05:48:22在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 05:48:22在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 05:48:22在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 05:48:22位于java.lang.reflect.Method.invoke(Method.java:606) 05:48:22在org.sonar.runner.impl.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:61) 05:48:22在com.sun.proxy.$Proxy0.execute(未知源) 05:48:22在org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:275) 05:48:22在org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:166) 05:48:22在org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:153) 05:48:22在org.sonar.runner.cli.Main.runAnalysis(Main.java:118) 05:48:22在org.sonar.runner.cli.Main.execute(Main.java:80) 05:48:22在org.sonar.runner.cli.Main.Main(Main.java:66) 在搜索类似的报告时,我发现了这篇参考文献,其中指出问题已得到解决:

我还发现了一个参考,即应该将事务隔离从可重复读取更改为可读取提交。对于声纳来说,使用mysql这样做合理吗

mysql> show variables like '%wait_timeout%'; +--------------------------+----------+ | Variable_name | Value | +--------------------------+----------+ | innodb_lock_wait_timeout | 500 | | lock_wait_timeout | 31536000 | | wait_timeout | 28800 | +--------------------------+----------+ 3 rows in set (0.25 sec) mysql> show variables like '%tx_isolation%'; +---------------+-----------------+ | Variable_name | Value | +---------------+-----------------+ | tx_isolation | REPEATABLE-READ | +---------------+-----------------+ 1 row in set (0.00 sec) mysql> SELECT @@GLOBAL.tx_isolation, @@tx_isolation; +-----------------------+-----------------+ | @@GLOBAL.tx_isolation | @@tx_isolation | +-----------------------+-----------------+ | REPEATABLE-READ | REPEATABLE-READ | +-----------------------+-----------------+ mysql>显示变量,如“%wait_timeout%”; +--------------------------+----------+ |变量名称|值| +--------------------------+----------+ |innodb锁定等待超时500| |锁定等待超时31536000| |等待|超时12400| +--------------------------+----------+ 一组3行(0.25秒) mysql>显示变量,如“%tx_隔离%”; +---------------+-----------------+ |变量名称|值| +---------------+-----------------+ |tx|隔离|可重复读取| +---------------+-----------------+ 一行一组(0.00秒) mysql>选择@@GLOBAL.tx_隔离,@@tx_隔离; +-----------------------+-----------------+ |@@GLOBAL.tx|u隔离。@@tx|u隔离| +-----------------------+-----------------+ |可重复读取|可重复读取| +-----------------------+-----------------+ 有关死锁问题的更多信息,请参阅以下数据

有人知道这个问题是否应该在mysql中进行调整,还是需要在SonarQube应用程序中修复

mysql> show engine innodb status ===================================== 2015-12-18 07:42:25 7f61f03cd700 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 31 seconds ----------------- BACKGROUND THREAD ----------------- srv_master_thread loops: 44635 srv_active, 0 srv_shutdown, 1284536 srv_idle srv_master_thread log flush and writes: 1329157 ---------- SEMAPHORES ---------- OS WAIT ARRAY INFO: reservation count 224853 OS WAIT ARRAY INFO: signal count 1727534 Mutex spin waits 1578113, rounds 7231747, OS waits 74673 RW-shared spins 483413, rounds 5257332, OS waits 110301 RW-excl spins 197945, rounds 3737144, OS waits 35005 Spin rounds per wait: 4.58 mutex, 10.88 RW-shared, 18.88 RW-excl mysql>显示引擎innodb状态 ===================================== 2015-12-18 07:42:25 7f61f03cd700 INNODB监视器输出 ===================================== 从最后31秒计算的每秒平均值 ----------------- 背景线程 ----------------- srv_主线程循环:44635 srv_活动,0 srv_关闭,1284536 srv_空闲 srv_主线程日志刷新和写入:1329157 ---------- 信号量 ---------- 操作系统等待阵列信息:保留计数224853 OS等待阵列信息:信号计数1727534 互斥旋转等待1578113,轮数7231747,操作系统等待74673 RW共享旋转483413,旋转5257332,操作系统等待110301 RW excl旋转197945,旋转3737144,操作系统等待35005 每次等待旋转轮数:4.58互斥,10.88 RW共享,18.88 RW不包括 ------------------------ 最近检测到的死锁 ------------------------ 2015-12-17 05:46:47 7f61f059470 ------------------------ LATEST DETECTED DEADLOCK ------------------------ 2015-12-17 05:46:47 7f61f0594700 *** (1) TRANSACTION: TRANSACTION 17641507, ACTIVE 0 sec inserting mysql tables in use 1, locked 1 LOCK WAIT 8 lock struct(s), heap size 1184, 7 row lock(s), undo log entries 9 MySQL thread id 5021, OS thread handle 0x7f61f071a700, query id 33269201 localhost 127.0.0.1 sonar update INSERT INTO group_roles (group_id, resource_id, role) VALUES (null, 1515106, 'codeviewer') *** (1) WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 310 page no 6 n bits 472 index `group_roles_resource` of table `sonar`.`group_roles` trx id 17641507 lock_mode X insert intention waiting Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 73757072656d756d; asc supremum;; *** (2) TRANSACTION: TRANSACTION 17641509, ACTIVE 0 sec inserting mysql tables in use 1, locked 1 7 lock struct(s), heap size 1184, 4 row lock(s), undo log entries 3 MySQL thread id 5005, OS thread handle 0x7f61f0594700, query id 33269204 localhost 127.0.0.1 sonar update INSERT INTO group_roles (group_id, resource_id, role) VALUES (1, 1515107, 'admin') *** (2) HOLDS THE LOCK(S): RECORD LOCKS space id 310 page no 6 n bits 472 index `group_roles_resource` of table `sonar`.`group_roles` trx id 17641509 lock_mode X Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 73757072656d756d; asc supremum;; *** (2) WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 310 page no 6 n bits 472 index `group_roles_resource` of table `sonar`.`group_roles` trx id 17641509 lock_mode X insert intention waiting Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 73757072656d756d; asc supremum;; *** WE ROLL BACK TRANSACTION (2) ------------ TRANSACTIONS ------------ Trx id counter 18864174 Purge done for trx's n:o
<pre>
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 7482, OS thread handle 0x7f61f03cd700, query id 38116433 localhost sonar init
show engine innodb status
---TRANSACTION 18864038, not started
MySQL thread id 7478, OS thread handle 0x7f61f3349700, query id 38115903 localhost 127.0.0.1 sonar cleaning up
---TRANSACTION 18864173, not started
MySQL thread id 7475, OS thread handle 0x7f61f040e700, query id 38116432 localhost 127.0.0.1 sonar cleaning up
--------
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
7146308 OS file reads, 6478063 OS file writes, 1783568 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
 INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
    Ibuf: size 1, free list len 3077, seg size 3079, 22965 merges
    merged operations:
     insert 45672, delete mark 7198683, delete 214896
    discarded operations:
     insert 0, delete mark 0, delete 0
    Hash table size 6374777, node heap has 11107 buffer(s)
    0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 219765124434
Log flushed up to   219765124434
Pages flushed up to 219765124434
Last checkpoint at  219765124434
0 pending log writes, 0 pending chkp writes
1189792 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 3296722944; in additional pool allocated 0
Dictionary memory allocated 359878
Buffer pool size   196600
Free buffers       8192
Database pages     177301
Old database pages 65285
Modified db pages  0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 1567756, not young 296705943
0.00 youngs/s, 0.00 non-youngs/s
Pages read 7146255, created 1592527, written 5004155
0.00 reads/s, 0.00 creates/s, 0.00 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: 177301, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]