Skip to content

Commit 5527fc5

Browse files
Daniele SciasciaJan Lindström
authored andcommitted
MDEV-21613 Failed to open table mysql.wsrep_streaming_log for writing
Fix sporadic failure for MTR test galera_sr.GCF-1018B. The test sometimes fails due to an error that is logged to the error log unnecessarily. A deterministic test case (included in this patch) shows that the error is loggen when a transaction is BF aborted right before it opens the streaming log table to perform fragment removal. When that happens, the attempt to open the table fails and consequently an error is logged. There is no need to log this error, as an ER_LOCK_DEADLOCK error is returned to the client. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
1 parent 74368a1 commit 5527fc5

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
connection node_2;
2+
connection node_1;
3+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
4+
connection node_1;
5+
SET SESSION wsrep_trx_fragment_size = 1;
6+
SET DEBUG_SYNC = "wsrep_before_fragment_removal SIGNAL fragment_removal_reached WAIT_FOR fragment_removal_continue";
7+
START TRANSACTION;
8+
INSERT INTO t1 VALUES(1), (2);
9+
COMMIT;
10+
connect node_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1;
11+
connection node_ctrl;
12+
SET DEBUG_SYNC = "now WAIT_FOR fragment_removal_reached";
13+
connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1;
14+
connection node_1a;
15+
TRUNCATE TABLE t1;
16+
connection node_1;
17+
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
18+
connection node_ctrl;
19+
SET DEBUG_SYNC = 'RESET';
20+
DROP TABLE t1;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Set thread-handling as a workaround to avoid MDEV-26528.
2+
# The file can be removed once fixed.
3+
4+
!include ../galera_2nodes.cnf
5+
6+
[mysqld.1]
7+
thread-handling=pool-of-threads
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# MDEV-21613 - galera_sr.GCF-1018B MTR failed:
3+
# Failed to open table mysql.wsrep_streaming_log for writing
4+
#
5+
# A BF abort right before fragment removal caused this error to
6+
# be logged to the error log.
7+
#
8+
--source include/galera_cluster.inc
9+
--source include/have_debug_sync.inc
10+
11+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
12+
13+
--connection node_1
14+
SET SESSION wsrep_trx_fragment_size = 1;
15+
SET DEBUG_SYNC = "wsrep_before_fragment_removal SIGNAL fragment_removal_reached WAIT_FOR fragment_removal_continue";
16+
START TRANSACTION;
17+
INSERT INTO t1 VALUES(1), (2);
18+
--send COMMIT
19+
20+
--connect node_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1
21+
--connection node_ctrl
22+
SET DEBUG_SYNC = "now WAIT_FOR fragment_removal_reached";
23+
24+
25+
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
26+
--connection node_1a
27+
TRUNCATE TABLE t1;
28+
29+
30+
--connection node_1
31+
--error ER_LOCK_DEADLOCK
32+
--reap
33+
34+
--connection node_ctrl
35+
SET DEBUG_SYNC = 'RESET';
36+
DROP TABLE t1;

sql/wsrep_client_service.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ int Wsrep_client_service::prepare_fragment_for_replication(
193193
int Wsrep_client_service::remove_fragments()
194194
{
195195
DBUG_ENTER("Wsrep_client_service::remove_fragments");
196+
DEBUG_SYNC(m_thd, "wsrep_before_fragment_removal");
196197
if (wsrep_schema->remove_fragments(m_thd,
197198
Wsrep_server_state::instance().id(),
198199
m_thd->wsrep_trx().id(),

sql/wsrep_schema.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,7 @@ static int open_table(THD* thd,
251251
thd->lex->query_tables_own_last= 0;
252252

253253
if (!open_n_lock_single_table(thd, &tables, tables.lock_type, flags)) {
254-
if (thd->is_error()) {
255-
WSREP_WARN("Can't lock table %s.%s : %d (%s)",
256-
schema_name->str, table_name->str,
257-
thd->get_stmt_da()->sql_errno(), thd->get_stmt_da()->message());
258-
}
259254
close_thread_tables(thd);
260-
my_error(ER_NO_SUCH_TABLE, MYF(0), schema_name->str, table_name->str);
261255
DBUG_RETURN(1);
262256
}
263257

@@ -273,8 +267,15 @@ static int open_for_write(THD* thd, const char* table_name, TABLE** table) {
273267
LEX_CSTRING table_str= { table_name, strlen(table_name) };
274268
if (Wsrep_schema_impl::open_table(thd, &schema_str, &table_str, TL_WRITE,
275269
table)) {
276-
WSREP_ERROR("Failed to open table %s.%s for writing",
277-
schema_str.str, table_name);
270+
// No need to log an error if the query was bf aborted,
271+
// thd client will get ER_LOCK_DEADLOCK in the end.
272+
const bool interrupted= thd->killed ||
273+
(thd->is_error() &&
274+
(thd->get_stmt_da()->sql_errno() == ER_QUERY_INTERRUPTED));
275+
if (!interrupted) {
276+
WSREP_ERROR("Failed to open table %s.%s for writing",
277+
schema_str.str, table_name);
278+
}
278279
return 1;
279280
}
280281
empty_record(*table);

0 commit comments

Comments
 (0)