Skip to content

Commit 6a614d6

Browse files
mkaruzajanlindstrom
authored andcommitted
MDEV-22707: galera got stuck after flush tables
Deadlock is possible between applier thread and local committing thread with active FLUSH TABLE. Applier thread should skip table share checks and locks when opening table. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
1 parent 1ff8588 commit 6a614d6

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CREATE TABLE t1(f2 INT) ENGINE=InnoDB;
2+
connect node_1_applier_thd, 127.0.0.1, root, , test, $NODE_MYPORT_1;
3+
SET GLOBAL debug_dbug = "+d,sync.wsrep_apply_cb";
4+
connection node_2;
5+
SET SESSION wsrep_sync_wait = 0;
6+
INSERT INTO t1 (f2) VALUES (2);
7+
connection node_1_applier_thd;
8+
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
9+
connection node_1;
10+
SET SESSION wsrep_sync_wait = 0;
11+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL wsrep_before_replication_reached WAIT_FOR continue';
12+
INSERT INTO t1 (f2) VALUES (1);
13+
connect node_1_flush_thd, 127.0.0.1, root, , test, $NODE_MYPORT_1;
14+
SET DEBUG_SYNC="now WAIT_FOR wsrep_before_replication_reached";
15+
SET GLOBAL debug_dbug = "+d,sync.wsrep_before_mdl_wait";
16+
FLUSH TABLES;
17+
connect node_1_sync_release_thd, 127.0.0.1, root, , test, $NODE_MYPORT_1;
18+
SET GLOBAL debug_dbug = "";
19+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_before_mdl_wait";
20+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
21+
SET DEBUG_SYNC = "now SIGNAL continue";
22+
SET DEBUG_SYNC = "RESET";
23+
connection node_1;
24+
connection node_1_flush_thd;
25+
connection node_2;
26+
DROP TABLE t1;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# MDEV-22707 galera got stuck after flush tables
3+
#
4+
5+
--source include/galera_cluster.inc
6+
--source include/have_innodb.inc
7+
--source include/have_debug.inc
8+
--source include/have_debug_sync.inc
9+
10+
CREATE TABLE t1(f2 INT) ENGINE=InnoDB;
11+
12+
--connect node_1_applier_thd, 127.0.0.1, root, , test, $NODE_MYPORT_1
13+
SET GLOBAL debug_dbug = "+d,sync.wsrep_apply_cb";
14+
15+
--connection node_2
16+
SET SESSION wsrep_sync_wait = 0;
17+
--send INSERT INTO t1 (f2) VALUES (2)
18+
19+
--connection node_1_applier_thd
20+
# Wait for `sync.wsrep_apply_cb_reached` signal
21+
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
22+
23+
--connection node_1
24+
SET SESSION wsrep_sync_wait = 0;
25+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL wsrep_before_replication_reached WAIT_FOR continue';
26+
--send INSERT INTO t1 (f2) VALUES (1)
27+
28+
--connect node_1_flush_thd, 127.0.0.1, root, , test, $NODE_MYPORT_1
29+
SET DEBUG_SYNC="now WAIT_FOR wsrep_before_replication_reached";
30+
SET GLOBAL debug_dbug = "+d,sync.wsrep_before_mdl_wait";
31+
--send FLUSH TABLES
32+
33+
--connect node_1_sync_release_thd, 127.0.0.1, root, , test, $NODE_MYPORT_1
34+
# First clear all DBUG points
35+
SET GLOBAL debug_dbug = "";
36+
# Now signal threads to continue execution
37+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_before_mdl_wait";
38+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
39+
SET DEBUG_SYNC = "now SIGNAL continue";
40+
SET DEBUG_SYNC = "RESET";
41+
42+
--connection node_1
43+
--reap
44+
45+
--connection node_1_flush_thd
46+
--reap
47+
48+
--connection node_2
49+
--reap
50+
51+
DROP TABLE t1;

sql/sql_base.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,12 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
18591859
DBUG_RETURN(FALSE);
18601860
}
18611861

1862+
#ifdef WITH_WSREP
1863+
if (!((flags & MYSQL_OPEN_IGNORE_FLUSH) ||
1864+
(wsrep_on(thd) && thd->wsrep_applier)))
1865+
#else
18621866
if (!(flags & MYSQL_OPEN_IGNORE_FLUSH))
1867+
#endif
18631868
{
18641869
if (share->tdc->flushed)
18651870
{

0 commit comments

Comments
 (0)