Skip to content

Commit 88a1592

Browse files
sciascidNirbhay Choubey
authored andcommitted
MW-286 Avoid spurious deadlock errors when wsrep_on is disabled
If a conflict happens under wsrep_on, the THD's wsrep_conflict_state is typically set to MUST_ABORT and cleared later, when transaction is aborted. However, when wsrep_on is disabled, no check is performed to see whether wsrep_conflict_state is set. So this potentially creates spurious deadlock errors on the subsequent statement that runs with wsrep_on enabled. To avoid this problem wsrep_thd_set_conflict_state() sets the conflict state only if wsrep_on is enabled.
1 parent a12fa57 commit 88a1592

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE ten (f1 INTEGER);
2+
INSERT INTO ten VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3+
CREATE TABLE t1 (f1 INTEGER) Engine=InnoDB;
4+
INSERT INTO t1 (f1) SELECT 000000 + (10000 * a1.f1) + (1000 * a2.f1) + (100 * a3.f1) + (10 * a4.f1) + a5.f1 FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4, ten AS a5;
5+
INSERT INTO t1 (f1) SELECT 100000 + (10000 * a1.f1) + (1000 * a2.f1) + (100 * a3.f1) + (10 * a4.f1) + a5.f1 FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4, ten AS a5;;
6+
SET GLOBAL wsrep_desync = TRUE;
7+
SET wsrep_on = FALSE;
8+
ALTER TABLE t1 ADD PRIMARY KEY (f1);
9+
ERROR 70100: Query execution was interrupted
10+
SET wsrep_on = TRUE;
11+
SET GLOBAL wsrep_desync = FALSE;
12+
DROP TABLE t1;
13+
DROP TABLE ten;

mysql-test/suite/galera/t/MW-286.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# MW-286 Spurious deadlock error after error with wsrep_desync and wsrep_on
3+
#
4+
5+
--source include/galera_cluster.inc
6+
--source include/have_innodb.inc
7+
--source include/big_test.inc
8+
9+
--connection node_1
10+
CREATE TABLE ten (f1 INTEGER);
11+
INSERT INTO ten VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
12+
13+
CREATE TABLE t1 (f1 INTEGER) Engine=InnoDB;
14+
15+
# Insert some values before the ALTER
16+
INSERT INTO t1 (f1) SELECT 000000 + (10000 * a1.f1) + (1000 * a2.f1) + (100 * a3.f1) + (10 * a4.f1) + a5.f1 FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4, ten AS a5;
17+
18+
# Insert more values while the ALTER is running
19+
--send INSERT INTO t1 (f1) SELECT 100000 + (10000 * a1.f1) + (1000 * a2.f1) + (100 * a3.f1) + (10 * a4.f1) + a5.f1 FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4, ten AS a5;
20+
21+
--connection node_2
22+
SET GLOBAL wsrep_desync = TRUE;
23+
SET wsrep_on = FALSE;
24+
25+
--error ER_QUERY_INTERRUPTED
26+
ALTER TABLE t1 ADD PRIMARY KEY (f1);
27+
28+
SET wsrep_on = TRUE;
29+
SET GLOBAL wsrep_desync = FALSE;
30+
31+
DROP TABLE t1;
32+
DROP TABLE ten;

sql/sql_class.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ extern "C" void wsrep_thd_set_query_state(
846846
extern "C" void wsrep_thd_set_conflict_state(
847847
THD *thd, enum wsrep_conflict_state state)
848848
{
849-
thd->wsrep_conflict_state= state;
849+
if (WSREP(thd)) thd->wsrep_conflict_state= state;
850850
}
851851

852852

0 commit comments

Comments
 (0)