记录下来的日志,我想看ClientPreparedStatement的第 953 行到底发生了什么,结果在下载的源文件里死活找不到对应的入口:
Caused by: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transactionat com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:123)at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)... 186 common frames omitted
我查找ClientPreparedStatement的第 953 行:
protected <M extends Message> ResultSetInternalMethods executeInternal(int maxRowsToRetrieve, M sendPacket, boolean createStreamingResultSet,boolean queryIsSelectOnly, ColumnDefinition metadata, boolean isBatch) throws SQLException {synchronized (checkClosed().getConnectionMutex()) {try {JdbcConnection locallyScopedConnection = this.connection;((PreparedQuery<?>) this.query).getQueryBindings().setNumberOfExecutions(((PreparedQuery<?>) this.query).getQueryBindings().getNumberOfExecutions() + 1);ResultSetInternalMethods rs;CancelQueryTask timeoutTask = null;try {timeoutTask = startQueryTimer(this, getTimeoutInMillis());if (!isBatch) {statementBegins();}rs = ((NativeSession) locallyScopedConnection.getSession()).execSQL(this, null, maxRowsToRetrieve, (NativePacketPayload) sendPacket,createStreamingResultSet, getResultSetFactory(), metadata, isBatch);if (timeoutTask != null) {stopQueryTimer(timeoutTask, true, true);timeoutTask = null;}} finally {if (!isBatch) {this.query.getStatementExecuting().set(false);}stopQueryTimer(timeoutTask, false, false);}return rs;} catch (NullPointerException npe) {checkClosed(); // we can't synchronize ourselves against async connection-close due to deadlock issues, so this is the next best thing for// this particular corner case.throw npe;}}} // 这一行在文件中是第953行
人傻了,通过字节码发现确实是存在的对应的一段操作方法的,那我就纳闷了,后来突然想起来代码增强这一件事,去 Github 上还真找到了,这一部分就是用来增强一些方法的异常捕获能力。当build源码时会触发增强,详情看 build.xml
