Skip to content

Commit 5f26a72

Browse files
authored
Merge pull request #231 from codership/MW-388-5.7
MW-388 for bugs/5.7
2 parents 2cfe070 + 8b13a19 commit 5f26a72

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(255)) Engine=InnoDB;
2+
CREATE PROCEDURE insert_proc ()
3+
BEGIN
4+
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
5+
BEGIN
6+
GET DIAGNOSTICS CONDITION 1 @errno = MYSQL_ERRNO;
7+
END;
8+
INSERT INTO t1 VALUES (1, 'node 1'),(2, 'node 1');
9+
INSERT INTO t1 VALUES (3, 'node 1');
10+
END|
11+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
12+
INSERT INTO t1 VALUES (1, 'node 2');;
13+
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
14+
SET SESSION wsrep_sync_wait = 0;
15+
SET SESSION DEBUG_SYNC = 'wsrep_before_replication SIGNAL wsrep_before_replication_reached WAIT_FOR wsrep_before_replication_continue';
16+
CALL insert_proc ();;
17+
SET SESSION DEBUG_SYNC = "now WAIT_FOR wsrep_before_replication_reached";
18+
SET GLOBAL DEBUG = "";
19+
SET DEBUG_SYNC = "now SIGNAL wsrep_before_replication_continue";
20+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
21+
SELECT @errno;
22+
@errno
23+
1213
24+
SELECT * FROM t1;
25+
f1 f2
26+
1 node 2
27+
3 node 1
28+
SELECT * FROM t1;
29+
f1 f2
30+
1 node 2
31+
3 node 1
32+
DROP TABLE t1;
33+
DROP PROCEDURE insert_proc;

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

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--source include/galera_cluster.inc
2+
--source include/have_innodb.inc
3+
4+
--connection node_1
5+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(255)) Engine=InnoDB;
6+
7+
DELIMITER |;
8+
CREATE PROCEDURE insert_proc ()
9+
BEGIN
10+
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
11+
BEGIN
12+
GET DIAGNOSTICS CONDITION 1 @errno = MYSQL_ERRNO;
13+
END;
14+
INSERT INTO t1 VALUES (1, 'node 1'),(2, 'node 1');
15+
INSERT INTO t1 VALUES (3, 'node 1');
16+
END|
17+
DELIMITER ;|
18+
19+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
20+
21+
--connection node_2
22+
--send INSERT INTO t1 VALUES (1, 'node 2');
23+
24+
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
25+
--connection node_1a
26+
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
27+
28+
--connection node_1
29+
SET SESSION wsrep_sync_wait = 0;
30+
SET SESSION DEBUG_SYNC = 'wsrep_before_replication SIGNAL wsrep_before_replication_reached WAIT_FOR wsrep_before_replication_continue';
31+
--send CALL insert_proc ();
32+
33+
--connection node_1a
34+
SET SESSION DEBUG_SYNC = "now WAIT_FOR wsrep_before_replication_reached";
35+
36+
--connection node_1a
37+
SET GLOBAL DEBUG = "";
38+
SET DEBUG_SYNC = "now SIGNAL wsrep_before_replication_continue";
39+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
40+
41+
--connection node_2
42+
--reap
43+
44+
--connection node_1
45+
# We expect no errors here, because the handler in insert_proc() caught the deadlock error
46+
--reap
47+
SELECT @errno;
48+
SELECT * FROM t1;
49+
50+
--connection node_2
51+
SELECT * FROM t1;
52+
53+
DROP TABLE t1;
54+
DROP PROCEDURE insert_proc;

sql/sql_parse.cc

+18
Original file line numberDiff line numberDiff line change
@@ -5578,6 +5578,24 @@ case SQLCOM_PREPARE:
55785578
thd->send_kill_message();
55795579
if (thd->is_error() || (thd->variables.option_bits & OPTION_MASTER_SQL_ERROR))
55805580
trans_rollback_stmt(thd);
5581+
#ifdef WITH_WSREP
5582+
else if (thd->sp_runtime_ctx &&
5583+
(thd->wsrep_conflict_state == MUST_ABORT ||
5584+
thd->wsrep_conflict_state == CERT_FAILURE))
5585+
{
5586+
/*
5587+
The error was cleared, but THD was aborted by wsrep and
5588+
wsrep_conflict_state is still set accordingly. This
5589+
situation is expected if we are running a stored procedure
5590+
that declares a handler that catches ER_LOCK_DEADLOCK error.
5591+
In which case the error may have been cleared in method
5592+
sp_rcontext::handle_sql_condition().
5593+
*/
5594+
trans_rollback_stmt(thd);
5595+
thd->wsrep_conflict_state= NO_CONFLICT;
5596+
thd->killed= THD::NOT_KILLED;
5597+
}
5598+
#endif /* WITH_WSREP */
55815599
else
55825600
{
55835601
/* If commit fails, we should be able to reset the OK status. */

0 commit comments

Comments
 (0)