TiDB 死锁问题排查

使用 insert into on duplicate key update 语句插入更新数据时,出现死锁问题。具体要怎么排查?有没有详细日志可以查看,帮助排查问题?

报错信息:
Caused by: java.sql.BatchUpdateException: Deadlock found when trying to get lock; try restarting transaction
at sun.reflect.GeneratedConstructorAccessor230.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createBatchUpdateException(SQLError.java:1162)
at com.mysql.jdbc.StatementImpl.handleExceptionForBatch(StatementImpl.java:1290)
at com.mysql.jdbc.StatementImpl.executeBatchUsingMultiQueries(StatementImpl.java:1199)
at com.mysql.jdbc.StatementImpl.executeBatchInternal(StatementImpl.java:1013)
at com.mysql.jdbc.StatementImpl.executeBatch(StatementImpl.java:970)
at com.weimob.flink.cdp.common.JDBCUpsertByFieldWriter.flush(JDBCUpsertByFieldWriter.java:123)
… 11 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
at sun.reflect.GeneratedConstructorAccessor332.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:951)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2441)
at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:845)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:939)
at com.mysql.jdbc.StatementImpl.executeBatchUsingMultiQueries(StatementImpl.java:1197)
… 14 more

您好,可以检查下这个时间段的 tidb.log 日志是否有 deadlock 多谢。

已经解决了,十分感谢您的帮助。 tidb.log 搜索 Deadlock found when trying to get lock; try restarting transaction,可以定为到产生死锁对应的 sql。然后业务上根据数据库的主键做了key by,解决死锁问题。

1 个赞

:+1:

然后业务上根据数据库的主键做了key by
key by 是什么呢 谢谢讲解

厉害:+1:

针对搜索的条件做主键就可以了

此话题已在最后回复的 1 分钟后被自动关闭。不再允许新回复。