Skip to content

Commit 04491fc

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 509557c commit 04491fc

24 files changed

+312
-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 CONSTRAINT]
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 CONSTRAINT");
302+
# Now there should be 2 WSREP Foreign key constraint warnings
303+
include/assert_grep.inc [Foreign key CONSTRAINT]
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,4 @@ truncate user_session;
380380
set debug_sync = reset;
381381
connection node_1;
382382
drop table user_session,user;
383+
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ON DELETE CASCADE
1010
INSERT INTO t1 VALUES (1, 1), (2, 1);
1111
connection node_2;
1212
DELETE FROM t1 WHERE f1 = 1;
13+
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
1314
connection node_1;
1415
SELECT COUNT(*) = 0 FROM t1;
1516
COUNT(*) = 0

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ id j
6262
SELECT * FROM c;
6363
id fk1
6464
3 1
65+
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
6566
connection node_2;
6667
SELECT * FROM p;
6768
id j

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ INSERT INTO child VALUES (3,3);
2222
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))
2323
SET SESSION foreign_key_checks = 0;
2424
DELETE FROM parent;
25+
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
2526
connection node_1;
2627
SELECT COUNT(*) = 0 FROM parent;
2728
COUNT(*) = 0

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 CONSTRAINT
341+
--let $assert_select = Foreign key CONSTRAINT
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 CONSTRAINT");
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 CONSTRAINT
374+
--let $assert_select = Foreign key CONSTRAINT
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-`;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[no_warnigs]
2+
wsrep-mode=APPLIER_DISABLE_FK_WARNINGS
3+
4+
[warnings]
5+
wsrep-mode=0

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

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

161161
drop table user_session,user;
162+
163+
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");

0 commit comments

Comments
 (0)