mysql 5.6 read-committed隔離等級下並發插入唯一索引導致死結一例

來源:互聯網
上載者:User

標籤:避免   _id   price   ***   啟用   grant   style   tin   comm   

今天,某個環境又發生了死結,如下:

*** (1) TRANSACTION:
TRANSACTION 735307073, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 6 lock struct(s), heap size 1184, 3 row lock(s), undo log entries 1
MySQL thread id 2754, OS thread handle 0x7f29cd89a700, query id 751744317 127.0.0.1 osm update
insert into tb_trd_secu_command(
machine_date, company_no, product_id,
product_code, product_name, unit_id, unit_code,
unit_name, asset_account, stock_account, command_operator,
command_executor, command_date, command_time, command_id,
batch_no, exchange_no, asset_type, stock_type,
stock_code, stock_name, currency_type, command_dir,
limit_price, command_qty, command_amt, order_qty,
cancel_qty, command_status, execution_status, execution_amt,
execution_qty, frozen_amt)
value(
v_machine_date, v_company_no, v_product_id,
v_product_code, v_product_name, v_unit_id, v_unit_code,
v_unit_name, v_asset_account, v_stock_account, v_command_operator,
v_command_executor, v_command_date, v_command_time, v_command_id,
v_batch_no, v_exchange_no, v_asset_type, v_stock_type,
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 10538 page no 4 n bits 296 index `idx_tb_trd_secu_command_1` of table `db_trd`.`tb_trd_secu_command` trx id 735307073 lock_mode X locks gap before rec insert intention waiting
*** (2) TRANSACTION:
TRANSACTION 735307149, ACTIVE 0 sec inserting, thread declared inside InnoDB 1
mysql tables in use 1, locked 1
4 lock struct(s), heap size 1184, 2 row lock(s), undo log entries 1
MySQL thread id 2744, OS thread handle 0x7f29cd8db700, query id 751750715 127.0.0.1 osm update
insert into tb_trd_secu_command(
machine_date, company_no, product_id,
product_code, product_name, unit_id, unit_code,
unit_name, asset_account, stock_account, command_operator,
command_executor, command_date, command_time, command_id,
batch_no, exchange_no, asset_type, stock_type,
stock_code, stock_name, currency_type, command_dir,
limit_price, command_qty, command_amt, order_qty,
cancel_qty, command_status, execution_status, execution_amt,
execution_qty, frozen_amt)
value(
v_machine_date, v_company_no, v_product_id,
v_product_code, v_product_name, v_unit_id, v_unit_code,
v_unit_name, v_asset_account, v_stock_account, v_command_operator,
v_command_executor, v_command_date, v_command_time, v_command_id,
v_batch_no, v_exchange_no, v_asset_type, v_stock_type,
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 10538 page no 4 n bits 296 index `idx_tb_trd_secu_command_1` of table `db_trd`.`tb_trd_secu_command` trx id 735307149 lock mode S locks gap before rec
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 10538 page no 4 n bits 296 index `idx_tb_trd_secu_command_1` of table `db_trd`.`tb_trd_secu_command` trx id 735307149 lock_mode X locks gap before rec insert intention waiting
*** WE ROLL BACK TRANSACTION (2)

其中idx_tb_trd_secu_command_1是唯一索引。

看了下參數,當前隔離等級是read-committed,不過參數innodb_locks_unsafe_for_binlog是預設值OFF。

又仔細看了下官方文檔, innodb_locks_unsafe_for_binlog和read-committed一方面是一樣的,啟用後,可以使得InnoDB gap鎖最小化,但是在兩種情境(外鍵約束和唯一索引)中,仍然不可避免的存在gap鎖。

不管交易管理層級如何設定,只要存在唯一性限制式並且可能insert/delete/update同一key值的記錄,死結都將無法100%的避免,只能是機率降低。

mysql 5.6 read-committed隔離等級下並發插入唯一索引導致死結一例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.