简体   繁体   English

如何修复 Mysql 表之前工作时的“超出锁定等待超时;尝试重新启动事务”?

[英]How to fix "Lock wait timeout exceeded; try restarting transaction" for Mysql table when it was working before?

I have a Spring Boot application which asynchronously inserts data into a table:我有一个 Spring 启动应用程序,它异步地将数据插入表中:

ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(DAYS_IN_WEEK);


for (int i = 0; i < DAYS_IN_WEEK; ++i) {
    Runnable task = new MyThread(weekStartDate.plusDays(i));
    executor.execute(task);
}

executor.shutdown();

while (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
    // wait until the processes in the executor will be terminated
}

log.info("Insertion is finished.");

Here is MyThread:这是我的线程:

public class MyThread implements Runnable {

    // ..........

    public MyThread(LocalDate date) {
        // ..........
    }

    public void run() {
        log.info("date - {}", date.format(dateTimeFormatter));

        /*
          The similar script is being executed:
      
          "insert into my_table(col1, col2, ..., colN)" +
          "    (select col1, col2, ..., date" +
          "     from another_table " +
          "     where date = :date" +
          "    )";
        */
    }
}

The thing is that it was working perfectly throughout of months but now I get问题是它在几个月内都运行良好,但现在我明白了

2022-09-26 12:34:28.280 ERROR 5664 --- [pool-2-thread-3] ohengine.jdbc.spi.SqlExceptionHelper: Lock wait timeout exceeded; try restarting transaction 2022-09-26 12:36:58.529 ERROR 5664 --- [pool-2-thread-6] ohengine.jdbc.spi.SqlExceptionHelper: Lock wait timeout exceeded; try restarting transaction 2022-09-26 12:39:26.070 ERROR 5664 --- [pool-2-thread-4] ohengine.jdbc.spi.SqlExceptionHelper: Lock wait timeout exceeded; try restarting transaction 2022-09-26 12:45:34.697 ERROR 5664 --- [pool-2-thread-5] ohengine.jdbc.spi.SqlExceptionHelper: Lock wait timeout exceeded; try restarting transaction

exception.例外。 All I've searched for mention about nested transactions and locks on the same record or data, but the thing is that it was working before and also there cannot be record locks or modifications of the same record in different threads since each thread is executed on a data based on dates which can never be the same for different dates.我已经搜索过有关嵌套事务和同一记录或数据上的锁的所有内容,但事实是它之前工作过,并且由于每个线程都是在基于日期的数据,不同日期永远不会相同。

The database is Aurora Serverless 2.08.3 and there were no configuration changes (innodb_lock_wait_timeout, etc.) from my side (not sure if there is from AWS itself).数据库是 Aurora Serverless 2.08.3,我这边没有配置更改(innodb_lock_wait_timeout 等)(不确定 AWS 本身是否有更改)。

Also, SHOW ENGINE INNODB STATUS;另外, SHOW ENGINE INNODB STATUS; doesn't show that there is a locked tables or rows.不显示有锁定的表或行。 sudo killall -9 mysqld didn't help either. sudo killall -9 mysqld也没有帮助。

So the questions is: What can be wrong with the application which was working 2 days ago perfectly with no incident?所以问题是: 2 天前运行正常且没有发生任何事故的应用程序有什么问题?

So any help would be highly appreciated.因此,我们将不胜感激任何帮助。

I found the problem.我发现了问题。

The thing was, that I was removed a redundant column in the entity class which described the table which the data should be selected from and inserted into the resulting table.问题是,我在实体 class 中删除了一个冗余列,该列描述了应从中选择数据并将其插入到结果表中的表。 Afterwards, I didn't removed the same column in the DB table.之后,我没有删除数据库表中的同一列。

Most probably, that was somehow affecting on the locking mechanism in MySQL. Once I removed the corresponding column in the table, the locking issue was resolved.最有可能的是,这在某种程度上影响了 MySQL 中的锁定机制。一旦我删除了表中的相应列,锁定问题就解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL错误:超过了锁定等待超时; 尝试重新启动事务查询 - MySQL Error: Lock wait timeout exceeded; try restarting transaction Query 超过了锁定等待超时; 尝试使用spring和Mysql重新启动事务Java - Lock wait timeout exceeded; try restarting transaction Java with spring and Mysql 由于“超过了锁定等待超时,导致事务失败; 尝试重新开始交易” - Transactions fails due to “Lock wait timeout exceeded; try restarting transaction” 超过锁定等待超时; 尝试使用JDBC重新启动事务 - Lock wait timeout exceeded; try restarting transaction using JDBC java.sql.SQLException:超出了锁定等待超时; 尝试重新启动事务异常在MYSQL中发生 - java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction exception occur in MYSQL 超过了锁定等待超时; 尝试在spring_Hibernate_Mysql中重新启动事务 - Lock wait timeout exceeded; try restarting transaction in spring_Hibernate_Mysql 发出java.lang.Exception:超出了锁定等待超时; 尝试重新启动事务 - Issue java.lang.Exception: Lock wait timeout exceeded; try restarting transaction 获取WARN:SQL错误:1205,SQLState:41000错误:超出锁定等待超时; 尝试重新启动事务。 使用休眠保存记录 - Getting WARN: SQL Error: 1205, SQLState: 41000 ERROR: Lock wait timeout exceeded; try restarting transaction. Saving a record in using hibernate 由于挂起事务 FK 插入,Mysql 事务获得“超出锁定等待超时” - Mysql transaction getting 'Lock wait timeout exceeded' because of pending transaction FK insert hibernate锁定等待超时超时; - hibernate Lock wait timeout exceeded;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM