Hi
We are facing deadlock on one of our innodb table. DDL of data_event table is given below.
create table data_event
( data_id INTEGER primaryKey,
node_id VARCHAR(50) primaryKey,
channel_id VARCHAR(50) not null,
transaction_id VARCHAR(1000),
batch_id INTEGER,
batched BOOLEANINT(1) not null );
create index idx_de_batchid_nodeid on (batch_id,node_id);
create index idx_de_batched_nodeid_channel on (batched,node_id,channel_id);
The column batched has two values either 0 or 1 where 0 represents that the record is not processed ( not batched ) and 1 represents it has been processed. By deafult the value of batched is 0.
For every minute, the update query will run on the data_event table to update the batched column. Insert the record into data_event table can happen at any time whenever a transaction is completed. We are facing the deadlock issue on this table as insert and update query runs at the same time. Please find the Innodb status below.
------------------------
LATEST DETECTED DEADLOCK
------------------------
110901 10:35:45
*** (1) TRANSACTION:
TRANSACTION 0 1503817595, ACTIVE 5 sec, process no 12100, OS thread id 2340395952 inserting
mysql tables in use 10, locked 10
LOCK WAIT 983 lock struct(s), heap size 77120, undo log entries 171
MySQL thread id 672, query id 1939410 10.0.65.18 posuser
insert into datasync_bo_till.data_event (node_id, data_id, channel_id, transaction_id) (select node_id, last_insert_id(), 'bo_till_item_master_channel', datasync_bo_till.fn_transaction_id() from datasync_bo_till.node c where
c.node_group_id='till' and c.sync_enabled=1 and (@sync_node_disabled is null or @sync_node_disabled != c.node_id) )
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 223 page no 17148 n bits 376 index `idx_de_batched_nodeid_channel` of table `datasync_bo_till/data_event` trx id 0 1503817595 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 171 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032301; asc # ;;
*** (2) TRANSACTION:
TRANSACTION 0 1503817736, ACTIVE 0 sec, process no 12100, OS thread id 2340195248 fetching rows, thread declared inside InnoDB 492
mysql tables in use 1, locked 1
5 lock struct(s), heap size 1024
MySQL thread id 436, query id 1939276 localhost 10.0.65.12 root Searching rows for update
update data_event set batch_id = 91678, batched = 1 where batched = 0
and node_id = 'S007T026' and channel_id = 'bo_till_item_master_channel'
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 223 page no 17148 n bits 376 index `idx_de_batched_nodeid_channel` of table `datasync_bo_till/data_event` trx id 0 1503817736 lock_mode X
Record lock, heap no 82 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032307; asc # ;;
Record lock, heap no 171 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032301; asc # ;;
Record lock, heap no 187 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032302; asc # ;;
Record lock, heap no 203 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032303; asc # ;;
Record lock, heap no 219 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032304; asc # ;;
Record lock, heap no 235 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032305; asc # ;;
Record lock, heap no 251 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032306; asc # ;;
Record lock, heap no 274 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032308; asc # ;;
Record lock, heap no 290 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032309; asc # ;;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 223 page no 17148 n bits 376 index `idx_de_batched_nodeid_channel` of table `datasync_bo_till/data_event` trx id 0 1503817736 lock_mode X waiting
Record lock, heap no 164 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 8003230a; asc # ;;
*** WE ROLL BACK TRANSACTION (2)
Can anyone help us out to find the way to overcome the deadlock?
We are facing deadlock on one of our innodb table. DDL of data_event table is given below.
create table data_event
( data_id INTEGER primaryKey,
node_id VARCHAR(50) primaryKey,
channel_id VARCHAR(50) not null,
transaction_id VARCHAR(1000),
batch_id INTEGER,
batched BOOLEANINT(1) not null );
create index idx_de_batchid_nodeid on (batch_id,node_id);
create index idx_de_batched_nodeid_channel on (batched,node_id,channel_id);
The column batched has two values either 0 or 1 where 0 represents that the record is not processed ( not batched ) and 1 represents it has been processed. By deafult the value of batched is 0.
For every minute, the update query will run on the data_event table to update the batched column. Insert the record into data_event table can happen at any time whenever a transaction is completed. We are facing the deadlock issue on this table as insert and update query runs at the same time. Please find the Innodb status below.
------------------------
LATEST DETECTED DEADLOCK
------------------------
110901 10:35:45
*** (1) TRANSACTION:
TRANSACTION 0 1503817595, ACTIVE 5 sec, process no 12100, OS thread id 2340395952 inserting
mysql tables in use 10, locked 10
LOCK WAIT 983 lock struct(s), heap size 77120, undo log entries 171
MySQL thread id 672, query id 1939410 10.0.65.18 posuser
insert into datasync_bo_till.data_event (node_id, data_id, channel_id, transaction_id) (select node_id, last_insert_id(), 'bo_till_item_master_channel', datasync_bo_till.fn_transaction_id() from datasync_bo_till.node c where
c.node_group_id='till' and c.sync_enabled=1 and (@sync_node_disabled is null or @sync_node_disabled != c.node_id) )
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 223 page no 17148 n bits 376 index `idx_de_batched_nodeid_channel` of table `datasync_bo_till/data_event` trx id 0 1503817595 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 171 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032301; asc # ;;
*** (2) TRANSACTION:
TRANSACTION 0 1503817736, ACTIVE 0 sec, process no 12100, OS thread id 2340195248 fetching rows, thread declared inside InnoDB 492
mysql tables in use 1, locked 1
5 lock struct(s), heap size 1024
MySQL thread id 436, query id 1939276 localhost 10.0.65.12 root Searching rows for update
update data_event set batch_id = 91678, batched = 1 where batched = 0
and node_id = 'S007T026' and channel_id = 'bo_till_item_master_channel'
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 223 page no 17148 n bits 376 index `idx_de_batched_nodeid_channel` of table `datasync_bo_till/data_event` trx id 0 1503817736 lock_mode X
Record lock, heap no 82 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032307; asc # ;;
Record lock, heap no 171 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032301; asc # ;;
Record lock, heap no 187 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032302; asc # ;;
Record lock, heap no 203 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032303; asc # ;;
Record lock, heap no 219 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032304; asc # ;;
Record lock, heap no 235 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032305; asc # ;;
Record lock, heap no 251 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032306; asc # ;;
Record lock, heap no 274 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032308; asc # ;;
Record lock, heap no 290 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 80032309; asc # ;;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 223 page no 17148 n bits 376 index `idx_de_batched_nodeid_channel` of table `datasync_bo_till/data_event` trx id 0 1503817736 lock_mode X waiting
Record lock, heap no 164 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8000; asc ;; 1: len 8; hex 5330303754303236; asc S007T026;; 2: len 27; hex 626f5f74696c6c5f6974656d5f6d61737465725f6368616e6e656c; asc bo_till_item_master_channel;; 3: len 4; hex 8003230a; asc # ;;
*** WE ROLL BACK TRANSACTION (2)
Can anyone help us out to find the way to overcome the deadlock?