Skip to content

Commit 58c03e8

Browse files
author
Daniele Sciascia
committed
MDEV-15794 Fix and re-enable test galera_var_retry_autocommit
The test was not deterministic and would occasionally fail, due to the use of `sleep`. This patch is a complete rewrite of the test using proper sync points.
1 parent dc0613e commit 58c03e8

File tree

4 files changed

+143
-71
lines changed

4 files changed

+143
-71
lines changed

mysql-test/suite/galera/disabled.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,5 @@ galera_ist_mysqldump : MDEV-13549 Galera test failures
2727
galera_ssl_upgrade : MDEV-13549 Galera test failures
2828
galera.MW-329 : wsrep_local_replays not stable
2929
galera.MW-328A : have_deadlocks test not stable
30-
galera_var_retry_autocommit : MDEV-15794 Test failure on galera.galera_var_retry_autocommit
3130
galera_var_auto_inc_control_on : MDEV-15803 Test failure on galera.galera_var_auto_inc_control_on
3231
query_cache : MDEV-15805 Test failure on galera.query_cache
33-

mysql-test/suite/galera/r/galera_var_retry_autocommit.result

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,54 @@
1-
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=InnoDB;
2-
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.f2 = SLEEP(5);
1+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
32
SET SESSION wsrep_retry_autocommit = 0;
4-
INSERT INTO t1 (f1) VALUES (1),(2);;
3+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue';
4+
INSERT INTO t1 (f1) VALUES (2);
5+
SET DEBUG_SYNC = 'now WAIT_FOR before_rep';
56
TRUNCATE TABLE t1;
67
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
8+
SELECT COUNT(*) = 0 FROM t1;
9+
COUNT(*) = 0
10+
1
11+
SET DEBUG_SYNC = 'RESET';
12+
DROP TABLE t1;
13+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
714
SET SESSION wsrep_retry_autocommit = 1;
8-
INSERT INTO t1 (f1) VALUES (3),(4);;
9-
TRUNCATE TABLE t1;
10-
SELECT * FROM test.t1;
11-
f1 f2
12-
3 0
13-
4 0
14-
CREATE PROCEDURE repeated_truncate ()
15-
BEGIN
16-
DECLARE i INT;
17-
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
18-
SET i = 0;
19-
WHILE i <= 1000 DO
15+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue';
16+
INSERT INTO t1 (f1) VALUES (2);
17+
SET DEBUG_SYNC = 'now WAIT_FOR before_rep';
2018
TRUNCATE TABLE t1;
21-
SET i = i + 1;
22-
END WHILE;
23-
END|
24-
CALL repeated_truncate();
19+
SELECT COUNT(*) = 1 FROM t1;
20+
COUNT(*) = 1
21+
1
22+
SET DEBUG_SYNC = 'RESET';
23+
DROP TABLE t1;
24+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
2525
SET SESSION wsrep_retry_autocommit = 1;
26-
INSERT INTO t1 (f1) VALUES (5),(6);
26+
SET GLOBAL debug_dbug = '+d,sync.wsrep_retry_autocommit';
27+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue EXECUTE 2';
28+
INSERT INTO t1 VALUES (2);;
29+
SET DEBUG_SYNC = 'now WAIT_FOR before_rep';
30+
TRUNCATE TABLE t1;
31+
SET DEBUG_SYNC = 'now WAIT_FOR wsrep_retry_autocommit_reached';
32+
SELECT COUNT(*) = 0 FROM t1;
33+
COUNT(*) = 0
34+
1
35+
SET DEBUG_SYNC = 'now SIGNAL wsrep_retry_autocommit_continue WAIT_FOR before_rep';
36+
TRUNCATE TABLE t1;
37+
SELECT COUNT(*) = 0 FROM t1;
38+
COUNT(*) = 0
39+
1
2740
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
28-
SET SESSION wsrep_retry_autocommit = 1024;
29-
INSERT INTO t1 (f1) VALUES (7),(8);;
30-
include/diff_servers.inc [servers=1 2]
41+
SET DEBUG_SYNC = 'RESET';
42+
SET GLOBAL debug_dbug = NULL;
43+
DROP TABLE t1;
44+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
45+
SET SESSION wsrep_retry_autocommit = 64;
46+
SET GLOBAL debug_dbug = '+d,sync.wsrep_retry_autocommit';
47+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue EXECUTE 64';
48+
INSERT INTO t1 VALUES (2);
49+
SELECT COUNT(*) = 1 FROM t1;
50+
COUNT(*) = 1
51+
1
52+
SET DEBUG_SYNC = 'RESET';
53+
SET GLOBAL debug_dbug = NULL;
3154
DROP TABLE t1;
32-
DROP PROCEDURE repeated_truncate;

mysql-test/suite/galera/t/galera_var_retry_autocommit.test

Lines changed: 88 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,141 @@
11
#
2-
# Test that the wsrep_retry_autocommit variable is respected. We use an INSERT that
3-
# proceeds very slowly due to extra SLEEP() in a trigger
2+
# Test that the wsrep_retry_autocommit variable is respected.
43
#
54

65
--source include/galera_cluster.inc
76
--source include/have_innodb.inc
7+
--source include/have_debug_sync.inc
88

9-
--connection node_1
10-
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=InnoDB;
11-
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.f2 = SLEEP(5);
9+
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
1210

1311
#
1412
# With wsrep_retry_autocommit = 0, error is certain
1513
#
1614

1715
--connection node_1
16+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
17+
1818
SET SESSION wsrep_retry_autocommit = 0;
19-
--send INSERT INTO t1 (f1) VALUES (1),(2);
19+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue';
20+
--send INSERT INTO t1 (f1) VALUES (2)
21+
22+
--connection node_1a
23+
SET DEBUG_SYNC = 'now WAIT_FOR before_rep';
2024

2125
--connection node_2
22-
--sleep 1
2326
TRUNCATE TABLE t1;
2427

2528
--connection node_1
2629
--error ER_LOCK_DEADLOCK
2730
--reap
31+
SELECT COUNT(*) = 0 FROM t1;
32+
33+
SET DEBUG_SYNC = 'RESET';
34+
DROP TABLE t1;
35+
2836

2937
#
3038
# With wsrep_retry_autocommit = 1, success against one TRUNCATE
3139
#
3240

3341
--connection node_1
42+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
43+
3444
SET SESSION wsrep_retry_autocommit = 1;
35-
--send INSERT INTO t1 (f1) VALUES (3),(4);
45+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue';
46+
--send INSERT INTO t1 (f1) VALUES (2)
47+
48+
--connection node_1a
49+
SET DEBUG_SYNC = 'now WAIT_FOR before_rep';
3650

3751
--connection node_2
38-
--sleep 1
3952
TRUNCATE TABLE t1;
4053

4154
--connection node_1
42-
--error 0
4355
--reap
44-
SELECT * FROM test.t1;
56+
SELECT COUNT(*) = 1 FROM t1;
57+
58+
SET DEBUG_SYNC = 'RESET';
59+
DROP TABLE t1;
60+
4561

4662
#
47-
# With wsrep_retry_autocommit = 1, failure against multiple TRUNCATEs
63+
# With wsrep_retry_autcommit = 1, failure against multiple TRUNCATEs
4864
#
4965

66+
--connection node_1
67+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
68+
69+
SET SESSION wsrep_retry_autocommit = 1;
70+
SET GLOBAL debug_dbug = '+d,sync.wsrep_retry_autocommit';
71+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue EXECUTE 2';
72+
73+
--send INSERT INTO t1 VALUES (2);
74+
75+
--connection node_1a
76+
SET DEBUG_SYNC = 'now WAIT_FOR before_rep';
77+
5078
--connection node_2
51-
DELIMITER |;
52-
CREATE PROCEDURE repeated_truncate ()
53-
BEGIN
54-
DECLARE i INT;
55-
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
56-
57-
SET i = 0;
58-
WHILE i <= 1000 DO
59-
TRUNCATE TABLE t1;
60-
SET i = i + 1;
61-
END WHILE;
62-
END|
63-
DELIMITER ;|
64-
65-
# Begin streaming TRUNCATEs
66-
--let $truncate_connection_id = `SELECT CONNECTION_ID()`
67-
--send CALL repeated_truncate()
79+
TRUNCATE TABLE t1;
80+
81+
--connection node_1a
82+
SET DEBUG_SYNC = 'now WAIT_FOR wsrep_retry_autocommit_reached';
83+
SELECT COUNT(*) = 0 FROM t1;
84+
SET DEBUG_SYNC = 'now SIGNAL wsrep_retry_autocommit_continue WAIT_FOR before_rep';
85+
86+
--connection node_2
87+
TRUNCATE TABLE t1;
88+
89+
--connection node_1a
90+
SELECT COUNT(*) = 0 FROM t1;
6891

6992
--connection node_1
70-
SET SESSION wsrep_retry_autocommit = 1;
71-
--sleep 1
7293
--error ER_LOCK_DEADLOCK
73-
INSERT INTO t1 (f1) VALUES (5),(6);
94+
--reap
95+
96+
SET DEBUG_SYNC = 'RESET';
97+
SET GLOBAL debug_dbug = NULL;
98+
DROP TABLE t1;
99+
74100

75101
#
76-
# With wsrep_retry_autocommit = 1024, success against multiple TRUNCATEs
102+
# With wsrep_retry_autocommit = 64, success against 64 TRUNCATEs
77103
#
78104

79105
--connection node_1
80-
SET SESSION wsrep_retry_autocommit = 1024;
81-
--send INSERT INTO t1 (f1) VALUES (7),(8);
106+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
82107

83-
--sleep 6
108+
SET SESSION wsrep_retry_autocommit = 64;
109+
SET GLOBAL debug_dbug = '+d,sync.wsrep_retry_autocommit';
110+
SET DEBUG_SYNC = 'wsrep_before_replication SIGNAL before_rep WAIT_FOR continue EXECUTE 64';
84111

85-
# Once he stream of TRUNCATEs is complete
86-
--connection node_2
87-
--reap
112+
--send INSERT INTO t1 VALUES (2)
113+
114+
--disable_query_log
115+
--disable_result_log
116+
--let $count = 64
117+
while ($count)
118+
{
119+
--connection node_1a
120+
SET DEBUG_SYNC = 'now WAIT_FOR before_rep';
121+
122+
--connection node_2
123+
TRUNCATE TABLE t1;
124+
125+
--connection node_1a
126+
SET DEBUG_SYNC = 'now WAIT_FOR wsrep_retry_autocommit_reached';
127+
SELECT COUNT(*) = 1 FROM t1;
128+
SET DEBUG_SYNC = 'now SIGNAL wsrep_retry_autocommit_continue';
129+
130+
--dec $count
131+
}
132+
--enable_result_log
133+
--enable_query_log
88134

89-
# the INSERT will eventually be sucessfull
90135
--connection node_1
91-
--error 0
92136
--reap
137+
SELECT COUNT(*) = 1 FROM t1;
93138

94-
--let $diff_servers = 1 2
95-
--source include/diff_servers.inc
96-
139+
SET DEBUG_SYNC = 'RESET';
140+
SET GLOBAL debug_dbug = NULL;
97141
DROP TABLE t1;
98-
DROP PROCEDURE repeated_truncate;

sql/sql_parse.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7187,6 +7187,15 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
71877187
com_statement_info[thd->get_command()].m_key);
71887188
MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(),
71897189
thd->query_length());
7190+
7191+
DBUG_EXECUTE_IF("sync.wsrep_retry_autocommit",
7192+
{
7193+
const char act[]=
7194+
"now "
7195+
"SIGNAL wsrep_retry_autocommit_reached "
7196+
"WAIT_FOR wsrep_retry_autocommit_continue";
7197+
DBUG_ASSERT(!debug_sync_set_action(thd, STRING_WITH_LEN(act)));
7198+
});
71907199
}
71917200
mysql_parse(thd, rawbuf, length, parser_state);
71927201

0 commit comments

Comments
 (0)