国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

mysql 為何insert的時候會有lock wait timeout 異常

瀏覽:122日期:2022-06-21 08:20:02

問題描述

執行單元測試(mvn clean test)時偶爾會遇到下面的異常信息

org.springframework.dao.CannotAcquireLockException:### Error updating database. Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction### The error may involve com.foo.dao.mapper.TestMapper.insertSuccesfulPaymentOrder-Inline### The error occurred while setting parameters### SQL: insert into order(order_seq,note,user_id,product_id, pay_status) values(uuid(),’’,?,?,1)### Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction; SQL []; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

但是像這樣的錯誤 不應該只是update才會有嗎? 見官方文檔說明

A transaction that tries to access a row that is locked by another InnoDB transaction waits at most this many seconds for write access to the row before issuing the following error:

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

但我明明是insert啊。 并且還只是偶爾會有這種情況, 且稍后就正常了。

所以不明白到底是怎么回事? 怎么模擬這種情況呢?

問題解答

回答1:

我相信你已經知道此種現象是發生鎖表了,lock wait timeout 意思就是由于鎖表導致事務等待的時間過長,然后事務回滾了我想你的疑問是(為什么insert 操作會鎖表)。

我的解釋如下:一般來說在普通狀態下,是不會發生此現象的,但是你主動啟動了事務(或者不主動提交事務)就不同了,由于事務運行是需要一定時間并且將有多條指令運行,那么在此情況下,如果另外一個進程也開啟了事務并且鎖了表,并且無法短時間運行完的話(默認記得是50秒),那么第一條事務會報這樣的錯并且回滾。所以他在錯誤中提示你try restarting transaction;讓你重新執行

相關文章:
主站蜘蛛池模板: 纳雍县| 绥化市| 巫溪县| 太和县| 江永县| 威海市| 沂源县| 陇南市| 丰原市| 江陵县| 乳源| 东兴市| 福海县| 中西区| 乡宁县| 玉门市| 吴堡县| 烟台市| 沾益县| 广昌县| 松溪县| 塔城市| 共和县| 会泽县| 遵义市| 义马市| 张家口市| 淮北市| 镶黄旗| 确山县| 潼南县| 石嘴山市| 云安县| 班戈县| 华容县| 上饶市| 东丽区| 大足县| 华宁县| 泗洪县| 璧山县|