Skip to content

Commit 3595516

Browse files
committed
MDEV-36923 : Add warning messages for applier FK failures
Add warning messages if applier write set execution fails because of foreign key constraint error. Warnings are printed by default and can be disabled using SET GLOBAL wsrep_mode=APPLIER_DISABLE_FK_WARNINGS.
1 parent 2f5bad2 commit 3595516

15 files changed

+306
-19
lines changed

include/mysql/service_wsrep.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum Wsrep_service_key_type
1414
#else
1515

1616
/* Copyright (c) 2015, 2020, MariaDB Corporation Ab
17-
2018 Codership Oy <[email protected]>
17+
2018, 2025, Codership Oy <[email protected]>
1818
1919
This program is free software; you can redistribute it and/or modify
2020
it under the terms of the GNU General Public License as published by
@@ -96,6 +96,7 @@ extern struct wsrep_service_st {
9696
void (*wsrep_thd_kill_UNLOCK_func)(const MYSQL_THD thd);
9797
void (*wsrep_thd_set_wsrep_PA_unsafe_func)(MYSQL_THD thd);
9898
uint32 (*wsrep_get_domain_id_func)();
99+
my_bool (*wsrep_applier_log_warnings)(const MYSQL_THD thd);
99100
} *wsrep_service;
100101

101102
#define MYSQL_SERVICE_WSREP_INCLUDED
@@ -146,6 +147,7 @@ extern struct wsrep_service_st {
146147
#define wsrep_report_bf_lock_wait(T,I) wsrep_service->wsrep_report_bf_lock_wait(T,I)
147148
#define wsrep_thd_set_PA_unsafe(T) wsrep_service->wsrep_thd_set_PA_unsafe_func(T)
148149
#define wsrep_get_domain_id(T) wsrep_service->wsrep_get_domain_id_func(T)
150+
#define wsrep_applier_log_warnings(T) wsrep_service->wsrep_applier_log_warnings_func(T)
149151
#else
150152

151153
#define MYSQL_SERVICE_WSREP_STATIC_INCLUDED
@@ -256,5 +258,6 @@ extern "C" void wsrep_report_bf_lock_wait(const THD *thd,
256258
/* declare parallel applying unsafety for the THD */
257259
extern "C" void wsrep_thd_set_PA_unsafe(MYSQL_THD thd);
258260
extern "C" uint32 wsrep_get_domain_id();
261+
extern "C" my_bool wsrep_applier_log_warnings(const MYSQL_THD thd);
259262
#endif
260263
#endif /* MYSQL_SERVICE_WSREP_INCLUDED */

mysql-test/suite/galera/r/MW-369.result

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ SET SESSION DEBUG_SYNC = 'now SIGNAL signal.wsrep_apply_cb';
258258
SET GLOBAL DEBUG_DBUG = "";
259259
SET DEBUG_SYNC = 'RESET';
260260
connection node_1;
261+
# Now there should be 1 WSREP Foreign key constraint warning
262+
include/assert_grep.inc [Foreign key warning in table]
261263
connection node_2;
262264
SELECT * FROM pg;
263265
f1 f2
@@ -268,3 +270,44 @@ f1 p_id f2
268270
1 1 0
269271
DROP TABLE cg;
270272
DROP TABLE pg;
273+
connection node_1;
274+
CREATE TABLE `pg-` (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
275+
CREATE TABLE `cg-` (f1 INTEGER PRIMARY KEY, p_id INTEGER,
276+
f2 INTEGER,
277+
CONSTRAINT `fk_1-$$` FOREIGN KEY (p_id) REFERENCES `pg-` (f1)) ;
278+
INSERT INTO `pg-` VALUES (1, 0);
279+
INSERT INTO `pg-` VALUES (2, 0);
280+
connection node_1;
281+
SET AUTOCOMMIT=ON;
282+
START TRANSACTION;
283+
UPDATE `pg-` SET f2 = 1 WHERE f1 = 1;
284+
connection node_1a;
285+
SET SESSION wsrep_sync_wait = 0;
286+
SET GLOBAL DEBUG_DBUG = "d,sync.wsrep_apply_cb";
287+
connection node_2;
288+
INSERT INTO `cg-` VALUES (1, 1, 0);
289+
connection node_1a;
290+
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
291+
connection node_1;
292+
SET SESSION DEBUG_SYNC = "wsrep_before_certification SIGNAL before_certification_reached WAIT_FOR continue_before_certification";
293+
COMMIT;
294+
connection node_1a;
295+
SET SESSION DEBUG_SYNC = "now WAIT_FOR before_certification_reached";
296+
SET SESSION DEBUG_SYNC = 'now SIGNAL continue_before_certification';
297+
SET SESSION DEBUG_SYNC = 'now SIGNAL signal.wsrep_apply_cb';
298+
SET GLOBAL DEBUG_DBUG = "";
299+
SET DEBUG_SYNC = 'RESET';
300+
connection node_1;
301+
call mtr.add_suppression("WSREP: Foreign key warning");
302+
# Now there should be 2 WSREP Foreign key constraint warnings
303+
include/assert_grep.inc [Foreign key warning in table]
304+
connection node_2;
305+
SELECT * FROM `pg-`;
306+
f1 f2
307+
1 1
308+
2 0
309+
SELECT * FROM `cg-`;
310+
f1 p_id f2
311+
1 1 0
312+
DROP TABLE `cg-`;
313+
DROP TABLE `pg-`;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,6 @@ truncate user_session;
380380
set debug_sync = reset;
381381
connection node_1;
382382
drop table user_session,user;
383+
# Now there should be 10 WSREP Foreign key constraint warnings
384+
include/assert_grep.inc [Foreign key warning in table]
385+
call mtr.add_suppression("WSREP: Foreign key warning in table");

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ SET GLOBAL wsrep_mode='A';
2020
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of 'A'
2121
SET GLOBAL wsrep_mode=NULL;
2222
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of 'NULL'
23-
SET GLOBAL wsrep_mode=128;
24-
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of '128'
23+
SET GLOBAL wsrep_mode=65536;
24+
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of '65536'
2525
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM;
2626
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
2727
SET GLOBAL wsrep_mode=1;
@@ -56,6 +56,10 @@ SET GLOBAL wsrep_mode=REPLICATE_ARIA;
5656
SELECT @@wsrep_mode;
5757
@@wsrep_mode
5858
REPLICATE_ARIA
59+
SET GLOBAL wsrep_mode=APPLIER_DISABLE_FK_WARNINGS;
60+
SELECT @@wsrep_mode;
61+
@@wsrep_mode
62+
APPLIER_DISABLE_FK_WARNINGS
5963
SET GLOBAL wsrep_mode=DISALLOW_LOCAL_GTID;
6064
SELECT @@wsrep_mode;
6165
@@wsrep_mode

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323

2424
--source include/galera_cluster.inc
25-
--source include/have_innodb.inc
25+
--source include/have_debug.inc
2626
--source include/have_debug_sync.inc
2727

2828
CREATE TABLE p (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
@@ -334,9 +334,49 @@ INSERT INTO pg VALUES (2, 0);
334334
--connection node_1
335335
--reap
336336

337+
--echo # Now there should be 1 WSREP Foreign key constraint warning
338+
--let $assert_count = 1
339+
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
340+
--let $assert_text = Foreign key warning in table
341+
--let $assert_select = Foreign key warning in table
342+
--source include/assert_grep.inc
343+
344+
337345
--connection node_2
338346
SELECT * FROM pg;
339347
SELECT * FROM cg;
340348

341349
DROP TABLE cg;
342350
DROP TABLE pg;
351+
352+
--connection node_1
353+
CREATE TABLE `pg-` (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
354+
CREATE TABLE `cg-` (f1 INTEGER PRIMARY KEY, p_id INTEGER,
355+
f2 INTEGER,
356+
CONSTRAINT `fk_1-$$` FOREIGN KEY (p_id) REFERENCES `pg-` (f1)) ;
357+
358+
INSERT INTO `pg-` VALUES (1, 0);
359+
INSERT INTO `pg-` VALUES (2, 0);
360+
361+
--let mw_369_parent_query = UPDATE `pg-` SET f2 = 1 WHERE f1 = 1
362+
--let $mw_369_child_query = INSERT INTO `cg-` VALUES (1, 1, 0)
363+
--source MW-369.inc
364+
365+
# Commit succeeds
366+
--connection node_1
367+
--reap
368+
call mtr.add_suppression("WSREP: Foreign key warning");
369+
370+
--echo # Now there should be 2 WSREP Foreign key constraint warnings
371+
--let $assert_count = 2
372+
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
373+
--let $assert_text = Foreign key warning in table
374+
--let $assert_select = Foreign key warning in table
375+
--source include/assert_grep.inc
376+
377+
--connection node_2
378+
SELECT * FROM `pg-`;
379+
SELECT * FROM `cg-`;
380+
381+
DROP TABLE `cg-`;
382+
DROP TABLE `pg-`;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,17 @@ while($counter > 0)
159159
--connection node_1
160160

161161
drop table user_session,user;
162+
163+
let $wsrep_mode = `SELECT @@GLOBAL.wsrep_mode`;
164+
165+
if ($wsrep_mode != APPLIER_DISABLE_FK_WARNINGS)
166+
{
167+
--echo # Now there should be 10 WSREP Foreign key constraint warnings
168+
--let $assert_count = 10
169+
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
170+
--let $assert_text = Foreign key warning in table
171+
--let $assert_select = Foreign key warning in table
172+
--source include/assert_grep.inc
173+
}
174+
175+
call mtr.add_suppression("WSREP: Foreign key warning in table");

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SET GLOBAL wsrep_mode='A';
2222
--error ER_WRONG_VALUE_FOR_VAR
2323
SET GLOBAL wsrep_mode=NULL;
2424
--error ER_WRONG_VALUE_FOR_VAR
25-
SET GLOBAL wsrep_mode=128;
25+
SET GLOBAL wsrep_mode=65536;
2626
--error ER_PARSE_ERROR
2727
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM;
2828
#
@@ -44,8 +44,11 @@ SET GLOBAL wsrep_mode=REPLICATE_MYISAM;
4444
SELECT @@wsrep_mode;
4545
SET GLOBAL wsrep_mode=REPLICATE_ARIA;
4646
SELECT @@wsrep_mode;
47+
SET GLOBAL wsrep_mode=APPLIER_DISABLE_FK_WARNINGS;
48+
SELECT @@wsrep_mode;
4749
SET GLOBAL wsrep_mode=DISALLOW_LOCAL_GTID;
4850
SELECT @@wsrep_mode;
51+
4952
SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY';
5053
SELECT @@wsrep_mode;
5154
SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID';

mysql-test/suite/sys_vars/r/sysvars_wsrep.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ VARIABLE_COMMENT Set of WSREP features that are enabled.
357357
NUMERIC_MIN_VALUE NULL
358358
NUMERIC_MAX_VALUE NULL
359359
NUMERIC_BLOCK_SIZE NULL
360-
ENUM_VALUE_LIST STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID,BF_ABORT_MARIABACKUP
360+
ENUM_VALUE_LIST STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID,BF_ABORT_MARIABACKUP,APPLIER_DISABLE_FK_WARNINGS
361361
READ_ONLY NO
362362
COMMAND_LINE_ARGUMENT REQUIRED
363363
GLOBAL_VALUE_PATH NULL

sql/service_wsrep.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,15 @@ extern "C" my_bool wsrep_thd_is_local_transaction(const THD *thd)
418418
return (wsrep_thd_is_local(thd) &&
419419
thd->wsrep_cs().transaction().active());
420420
}
421+
422+
extern "C" my_bool wsrep_applier_log_warnings(const THD *thd)
423+
{
424+
/* Applier will log warning on fk errors if
425+
(1) wsrep_mode != WSREP_MODE_APPLIER_DISABLE_FK_WARNINGS AND
426+
(2) thd executing is applier
427+
(3) there is no error log warning flooding
428+
*/
429+
return (!wsrep_check_mode(WSREP_MODE_APPLIER_DISABLE_FK_WARNINGS) &&
430+
thd->wsrep_cs().mode() == wsrep::client_state::m_high_priority &&
431+
!wsrep_protect_against_warning_flood(WSREP_APPLIER_FK_ERROR));
432+
}

sql/sql_plugin_services.inl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ static struct wsrep_service_st wsrep_handler = {
185185
wsrep_thd_kill_LOCK,
186186
wsrep_thd_kill_UNLOCK,
187187
wsrep_thd_set_PA_unsafe,
188-
wsrep_get_domain_id
188+
wsrep_get_domain_id,
189+
wsrep_applier_log_warnings
189190
};
190191

191192
static struct thd_specifics_service_st thd_specifics_handler=

0 commit comments

Comments
 (0)