Skip to content

Commit 85bcc7d

Browse files
Daniele Sciasciasysprg
authored andcommitted
MDEV-35446 Sporadic failure of galera.galera_insert_multi
Test failed sporadically when --ps-protocol was enabled: a transaction that was BF aborted on COMMIT would succeed instead of reporting the expected deadlock error. The reason for the failure was that, depending on timing, the transaction was BF aborted while the COMMIT statement was being prepared through a COM_STMT_PREPARE command. In the failing cases, the transaction was BF aborted after COM_STMT_PREPARE had already disabled the diagnostics area of the client. Attempt to override the deadlock error towards the end of dispatch_command() would be skipped, resulting in a successful COMMIT even if the transaction is aborted. This bug affected the following MTR tests: - galera_insert_multi - galera_nopk_unicode Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
1 parent b8ad202 commit 85bcc7d

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
connection node_2;
2+
connection node_1;
3+
connect bf_trx, 127.0.0.1, root, , test, $NODE_MYPORT_1;
4+
connect victim_trx, 127.0.0.1, root, , test, $NODE_MYPORT_2;
5+
connect node_2_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_2;
6+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
7+
connection victim_trx;
8+
START TRANSACTION;
9+
INSERT INTO t1 VALUES (2), (1);
10+
connection node_2_ctrl;
11+
SET GLOBAL debug_dbug = '+d,sync.wsrep_apply_cb';
12+
connection bf_trx;
13+
INSERT INTO t1 VALUES (1), (2);
14+
connection node_2_ctrl;
15+
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
16+
SET GLOBAL debug_dbug = '';
17+
connection victim_trx;
18+
SET DEBUG_SYNC = "wsrep_at_dispatch_end_before_result SIGNAL signal.wsrep_apply_cb WAIT_FOR bf_abort";
19+
COMMIT;
20+
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
21+
SET DEBUG_SYNC = 'RESET';
22+
DROP TABLE t1;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
!include ../galera_2nodes.cnf
2+
3+
[mysqltest]
4+
ps-protocol
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# MDEV-35446
3+
#
4+
# Test BF abort of a transaction under PS protocol, after
5+
# a statement is prepared (and the diagnostics area is
6+
# disabled).
7+
#
8+
9+
--source include/have_debug_sync.inc
10+
--source include/galera_cluster.inc
11+
12+
#
13+
# Setup: bf_trx executes in node_1 and will BF abort victim_trx.
14+
#
15+
--connect bf_trx, 127.0.0.1, root, , test, $NODE_MYPORT_1
16+
--connect victim_trx, 127.0.0.1, root, , test, $NODE_MYPORT_2
17+
--connect node_2_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_2
18+
19+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
20+
21+
--connection victim_trx
22+
START TRANSACTION;
23+
INSERT INTO t1 VALUES (2), (1);
24+
25+
--connection node_2_ctrl
26+
SET GLOBAL debug_dbug = '+d,sync.wsrep_apply_cb';
27+
28+
--connection bf_trx
29+
INSERT INTO t1 VALUES (1), (2);
30+
31+
--connection node_2_ctrl
32+
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
33+
SET GLOBAL debug_dbug = '';
34+
35+
#
36+
# COMMIT the victim_trx and expect a deadlock error.
37+
# Here we park the client in a sync point at the end of prepare
38+
# command (COM_STMT_PREPARE), where the diagnostics area of the
39+
# client has already been disabled. The client signals the
40+
# applier to continue and will be BF aborted.
41+
# If bug is present, the transaction is aborted, but the COMMIT
42+
# statement succeeds (instead of returning deadlock error).
43+
#
44+
--connection victim_trx
45+
46+
--disable_ps_protocol
47+
SET DEBUG_SYNC = "wsrep_at_dispatch_end_before_result SIGNAL signal.wsrep_apply_cb WAIT_FOR bf_abort";
48+
--enable_ps_protocol
49+
50+
--error ER_LOCK_DEADLOCK
51+
COMMIT;
52+
53+
#
54+
# Cleanup
55+
#
56+
SET DEBUG_SYNC = 'RESET';
57+
DROP TABLE t1;

sql/sql_parse.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,8 @@ static bool wsrep_command_no_result(char command)
11651165
{
11661166
return (command == COM_STMT_FETCH ||
11671167
command == COM_STMT_SEND_LONG_DATA ||
1168-
command == COM_STMT_CLOSE);
1168+
command == COM_STMT_CLOSE ||
1169+
command == COM_STMT_PREPARE);
11691170
}
11701171
#endif /* WITH_WSREP */
11711172
#ifndef EMBEDDED_LIBRARY
@@ -2439,6 +2440,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
24392440
{
24402441
WSREP_DEBUG("THD is killed at dispatch_end");
24412442
}
2443+
if (thd->lex->sql_command != SQLCOM_SET_OPTION)
2444+
{
2445+
DEBUG_SYNC(thd, "wsrep_at_dispatch_end_before_result");
2446+
}
24422447
wsrep_after_command_before_result(thd);
24432448
if (wsrep_current_error(thd) && !wsrep_command_no_result(command))
24442449
{

0 commit comments

Comments
 (0)