您好,登錄后才能下訂單哦!
innodb_rollback_on_timeout
innodb_lock_wait_timeout
最開始看到innodb_rollback_on_timeout 時,沒有好好理解transaction timeout的意思.以為只要是連接超時就會觸發,今天研究了一下.只能說巨坑;
以下測試.隔離級別皆為RR模式.測試過程.
實驗一:
innodb_rollback_on_timeout =on
innodb_lock_wait_timeout=20
---------------------------------------|----------------------------------------|------------------------------------------------
session 1 | session 2 | session 3
---------------------------------------|----------------------------------------|------------------------------------------------
begin; | |select * from information_schema.innodb_trx
| | order by trx_started;
---------------------------------------|----------------------------------------|------------------------------------------------
insert into t8 values (20,'ddd'); | | 1
---------------------------------------|----------------------------------------|------------------------------------------------
| begin; | 2
---------------------------------------|----------------------------------------|------------------------------------------------
| update t8 set test1='yyy' where id =19;| 2
---------------------------------------|----------------------------------------|------------------------------------------------
| | 2
update t8 set test1='xxx' where id =19;| |
---------------------------------------|----------------------------------------|------------------------------------------------
堵塞 | | 2
---------------------------------------|----------------------------------------|------------------------------------------------
20s后超時 | | 1
事務結束; | commit; | 0
---------------------------------------|----------------------------------------|------------------------------------------------
select * from t8;
20這個id沒有;19被改為yyy;
實驗二:
innodb_rollback_on_timeout =off
innodb_lock_wait_timeout=20
---------------------------------------|---------------------------------------|-----------------------------------------------
session 1 | session 2 | session 3
---------------------------------------|---------------------------------------|-----------------------------------------------
begin; | | select * from information_schema.innodb_trx
| | order by trx_started;
---------------------------------------|---------------------------------------|-----------------------------------------------
insert into t8 values (20,'ddd'); | | 1
---------------------------------------|---------------------------------------|-----------------------------------------------
| begin; | 2
|update t8 set test1='yyy' where id =19;|
---------------------------------------|---------------------------------------|-----------------------------------------------
update t8 set test1='xxx' where id =19;| | 2
---------------------------------------|---------------------------------------|-----------------------------------------------
堵塞 | | 2
---------------------------------------|---------------------------------------|-----------------------------------------------
20s后超時 | | 2
事務未結束 | |
---------------------------------------|---------------------------------------|-----------------------------------------------
commit; | commit; | 0
---------------------------------------|---------------------------------------|-----------------------------------------------
select * from t8;
20這個id存在;19被改為yyy;
結果就是:如果innodb_rollback_on_timeout 為on,事務在innodb_lock_wait_timeout超時后,當前sql會報超時,并使整個事務都回滾,然后結束事務;
如果innodb_rollback_on_timeout 為off(默認值),事務在innodb_lock_wait_timeout超時后,當前sql會超時,并終止,回滾當前sql,但整個事務不回滾,事務不結束,必須顯示的回滾或提交;
一句話:innodb_rollback_on_timeout 沒什么卵用.純碎就是坑;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。