Skip to content

Commit b20c0a6

Browse files
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 0c0a891 + daa2d48 commit b20c0a6

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Bug #21983865 UNEXPECTED DEADLOCK WITH INNODB_AUTOINC_LOCK_MODE=0
3+
#
4+
create table t1(f1 int not null auto_increment primary key) engine=innodb;
5+
# Hold autoinc_lock on table t1 from connection con1
6+
set debug_sync='ib_after_row_insert SIGNAL others WAIT_FOR continue_others';
7+
insert into t1 values(NULL);
8+
# Create 40 connections and make it to wait for autoinc_lock on table t1.
9+
# Release the auto_inc lock on table t1 for connection con1
10+
set debug_sync='now SIGNAL continue_others';
11+
# Now all 40 connections can finish the insert operation on t1.
12+
drop table t1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--innodb-autoinc-lock-mode=0
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--source include/have_debug.inc
2+
--source include/have_innodb.inc
3+
--source include/have_debug_sync.inc
4+
--source include/count_sessions.inc
5+
6+
--echo #
7+
--echo # Bug #21983865 UNEXPECTED DEADLOCK WITH INNODB_AUTOINC_LOCK_MODE=0
8+
--echo #
9+
10+
create table t1(f1 int not null auto_increment primary key) engine=innodb;
11+
12+
--echo # Hold autoinc_lock on table t1 from connection con1
13+
connect (con1, localhost, root);
14+
set debug_sync='ib_after_row_insert SIGNAL others WAIT_FOR continue_others';
15+
--send insert into t1 values(NULL)
16+
17+
connection default;
18+
--echo # Create 40 connections and make it to wait for autoinc_lock on table t1.
19+
--disable_query_log
20+
set debug_sync='now WAIT_FOR others';
21+
let $1=2;
22+
while ($1 < 40) {
23+
connect (con$1,localhost,root);
24+
--send insert into t1 values(NULL)
25+
inc $1;
26+
connection default;
27+
}
28+
29+
connect (con40,localhost,root);
30+
--enable_query_log
31+
--echo # Release the auto_inc lock on table t1 for connection con1
32+
set debug_sync='now SIGNAL continue_others';
33+
34+
--echo # Now all 40 connections can finish the insert operation on t1.
35+
let $1=1;
36+
connection default;
37+
disconnect con40;
38+
while ($1 < 40) {
39+
connection con$1;
40+
--reap
41+
connection default;
42+
disconnect con$1;
43+
inc $1;
44+
}
45+
46+
drop table t1;
47+
--source include/wait_until_count_sessions.inc

storage/innobase/lock/lock0lock.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7169,7 +7169,7 @@ DeadlockChecker::get_next_lock(const lock_t* lock, ulint heap_no) const
71697169
ut_ad(heap_no == ULINT_UNDEFINED);
71707170
ut_ad(lock_get_type_low(lock) == LOCK_TABLE);
71717171

7172-
lock = UT_LIST_GET_PREV(
7172+
lock = UT_LIST_GET_NEXT(
71737173
un_member.tab_lock.locks, lock);
71747174
}
71757175

@@ -7232,7 +7232,8 @@ DeadlockChecker::get_first_lock(ulint* heap_no) const
72327232
/* Table locks don't care about the heap_no. */
72337233
*heap_no = ULINT_UNDEFINED;
72347234
ut_ad(lock_get_type_low(lock) == LOCK_TABLE);
7235-
lock = UT_LIST_GET_PREV(un_member.tab_lock.locks, lock);
7235+
dict_table_t* table = lock->un_member.tab_lock.table;
7236+
lock = UT_LIST_GET_FIRST(table->locks);
72367237
}
72377238

72387239
/* Must find at least two locks, otherwise there cannot be a

0 commit comments

Comments
 (0)