MySQL 5.7锁定等待超时

时间:2019-09-30 15:10:36

标签: mysql

当我在MySQL 5.7中运行此命令时:

select * from user where user_id = 5 for update

抛出Lock wait timeout错误。我知道这可能是由于我的代码中未提交交易引起的:

        @Override
        @Transactional(timeout = 120)
        public Map<Long, UserLockResponse> lock(UserLockInfo userLockInfo) {
            SqlSession sqlSession = sqlSessionFactory.openSession(false);
            Map<Long, UserLockResponse> userLockResponseMap = new HashMap<>();
            try {
                WalletRecord walletRecord = getWalletRecordByUserIdForUpdate(userLockInfo.getUserId(), sqlSession);
                if (walletRecord == null) {
                    throw WalletException.POCKET_NOT_EXISTS_EXCEPTION;
                }
                Executor.sendWebsocketAsync(userLockResponseMap);
                sqlSession.commit();
                return userLockResponseMap;
            } finally {
                if (sqlSession != null) {
                    sqlSession.close();
                }
            }
        }

当sendWebsocketAsync方法遇到错误时,提交操作无法执行,可能不会释放事务,但是我在finally块中关闭了sql会话(> 15min),事务应该自动回滚。为什么第二个sql被阻止了?谢谢你!

0 个答案:

没有答案