Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/mysql/service_wsrep.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum Wsrep_service_key_type
#else

/* Copyright (c) 2015, 2020, MariaDB Corporation Ab
2018 Codership Oy <info@codership.com>
2018, 2025, Codership Oy <info@codership.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -96,6 +96,7 @@ extern struct wsrep_service_st {
void (*wsrep_thd_kill_UNLOCK_func)(const MYSQL_THD thd);
void (*wsrep_thd_set_wsrep_PA_unsafe_func)(MYSQL_THD thd);
uint32 (*wsrep_get_domain_id_func)();
my_bool (*wsrep_applier_log_warnings)(const MYSQL_THD thd);
} *wsrep_service;

#define MYSQL_SERVICE_WSREP_INCLUDED
Expand Down Expand Up @@ -146,6 +147,7 @@ extern struct wsrep_service_st {
#define wsrep_report_bf_lock_wait(T,I) wsrep_service->wsrep_report_bf_lock_wait(T,I)
#define wsrep_thd_set_PA_unsafe(T) wsrep_service->wsrep_thd_set_PA_unsafe_func(T)
#define wsrep_get_domain_id(T) wsrep_service->wsrep_get_domain_id_func(T)
#define wsrep_applier_log_warnings(T) wsrep_service->wsrep_applier_log_warnings_func(T)
#else

#define MYSQL_SERVICE_WSREP_STATIC_INCLUDED
Expand Down Expand Up @@ -256,5 +258,6 @@ extern "C" void wsrep_report_bf_lock_wait(const THD *thd,
/* declare parallel applying unsafety for the THD */
extern "C" void wsrep_thd_set_PA_unsafe(MYSQL_THD thd);
extern "C" uint32 wsrep_get_domain_id();
extern "C" my_bool wsrep_applier_log_warnings(const MYSQL_THD thd);
#endif
#endif /* MYSQL_SERVICE_WSREP_INCLUDED */
43 changes: 43 additions & 0 deletions mysql-test/suite/galera/r/MW-369.result
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ SET SESSION DEBUG_SYNC = 'now SIGNAL signal.wsrep_apply_cb';
SET GLOBAL DEBUG_DBUG = "";
SET DEBUG_SYNC = 'RESET';
connection node_1;
# Now there should be 1 WSREP Foreign key constraint warning
include/assert_grep.inc [Foreign key CONSTRAINT]
connection node_2;
SELECT * FROM pg;
f1 f2
Expand All @@ -268,3 +270,44 @@ f1 p_id f2
1 1 0
DROP TABLE cg;
DROP TABLE pg;
connection node_1;
CREATE TABLE `pg-` (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
CREATE TABLE `cg-` (f1 INTEGER PRIMARY KEY, p_id INTEGER,
f2 INTEGER,
CONSTRAINT `fk_1-$$` FOREIGN KEY (p_id) REFERENCES `pg-` (f1)) ;
INSERT INTO `pg-` VALUES (1, 0);
INSERT INTO `pg-` VALUES (2, 0);
connection node_1;
SET AUTOCOMMIT=ON;
START TRANSACTION;
UPDATE `pg-` SET f2 = 1 WHERE f1 = 1;
connection node_1a;
SET SESSION wsrep_sync_wait = 0;
SET GLOBAL DEBUG_DBUG = "d,sync.wsrep_apply_cb";
connection node_2;
INSERT INTO `cg-` VALUES (1, 1, 0);
connection node_1a;
SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
connection node_1;
SET SESSION DEBUG_SYNC = "wsrep_before_certification SIGNAL before_certification_reached WAIT_FOR continue_before_certification";
COMMIT;
connection node_1a;
SET SESSION DEBUG_SYNC = "now WAIT_FOR before_certification_reached";
SET SESSION DEBUG_SYNC = 'now SIGNAL continue_before_certification';
SET SESSION DEBUG_SYNC = 'now SIGNAL signal.wsrep_apply_cb';
SET GLOBAL DEBUG_DBUG = "";
SET DEBUG_SYNC = 'RESET';
connection node_1;
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
# Now there should be 2 WSREP Foreign key constraint warnings
include/assert_grep.inc [Foreign key CONSTRAINT]
connection node_2;
SELECT * FROM `pg-`;
f1 f2
1 1
2 0
SELECT * FROM `cg-`;
f1 p_id f2
1 1 0
DROP TABLE `cg-`;
DROP TABLE `pg-`;
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,4 @@ truncate user_session;
set debug_sync = reset;
connection node_1;
drop table user_session,user;
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
1 change: 1 addition & 0 deletions mysql-test/suite/galera/r/galera_fk_selfreferential.result
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ON DELETE CASCADE
INSERT INTO t1 VALUES (1, 1), (2, 1);
connection node_2;
DELETE FROM t1 WHERE f1 = 1;
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
connection node_1;
SELECT COUNT(*) = 0 FROM t1;
COUNT(*) = 0
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/galera/r/galera_multirow_rollback.result
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ id j
SELECT * FROM c;
id fk1
3 1
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
connection node_2;
SELECT * FROM p;
id j
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/galera/r/galera_var_fkchecks.result
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ INSERT INTO child VALUES (3,3);
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`))
SET SESSION foreign_key_checks = 0;
DELETE FROM parent;
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
connection node_1;
SELECT COUNT(*) = 0 FROM parent;
COUNT(*) = 0
Expand Down
8 changes: 6 additions & 2 deletions mysql-test/suite/galera/r/galera_var_wsrep_mode.result
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ SET GLOBAL wsrep_mode='A';
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of 'A'
SET GLOBAL wsrep_mode=NULL;
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of 'NULL'
SET GLOBAL wsrep_mode=128;
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of '128'
SET GLOBAL wsrep_mode=65536;
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of '65536'
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM;
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
SET GLOBAL wsrep_mode=1;
Expand Down Expand Up @@ -56,6 +56,10 @@ SET GLOBAL wsrep_mode=REPLICATE_ARIA;
SELECT @@wsrep_mode;
@@wsrep_mode
REPLICATE_ARIA
SET GLOBAL wsrep_mode=APPLIER_DISABLE_FK_WARNINGS;
SELECT @@wsrep_mode;
@@wsrep_mode
APPLIER_DISABLE_FK_WARNINGS
SET GLOBAL wsrep_mode=DISALLOW_LOCAL_GTID;
SELECT @@wsrep_mode;
@@wsrep_mode
Expand Down
42 changes: 41 additions & 1 deletion mysql-test/suite/galera/t/MW-369.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#

--source include/galera_cluster.inc
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc

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

--echo # Now there should be 1 WSREP Foreign key constraint warning
--let $assert_count = 1
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
--let $assert_text = Foreign key CONSTRAINT
--let $assert_select = Foreign key CONSTRAINT
--source include/assert_grep.inc


--connection node_2
SELECT * FROM pg;
SELECT * FROM cg;

DROP TABLE cg;
DROP TABLE pg;

--connection node_1
CREATE TABLE `pg-` (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
CREATE TABLE `cg-` (f1 INTEGER PRIMARY KEY, p_id INTEGER,
f2 INTEGER,
CONSTRAINT `fk_1-$$` FOREIGN KEY (p_id) REFERENCES `pg-` (f1)) ;

INSERT INTO `pg-` VALUES (1, 0);
INSERT INTO `pg-` VALUES (2, 0);

--let mw_369_parent_query = UPDATE `pg-` SET f2 = 1 WHERE f1 = 1
--let $mw_369_child_query = INSERT INTO `cg-` VALUES (1, 1, 0)
--source MW-369.inc

# Commit succeeds
--connection node_1
--reap
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");

--echo # Now there should be 2 WSREP Foreign key constraint warnings
--let $assert_count = 2
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
--let $assert_text = Foreign key CONSTRAINT
--let $assert_select = Foreign key CONSTRAINT
--source include/assert_grep.inc

--connection node_2
SELECT * FROM `pg-`;
SELECT * FROM `cg-`;

DROP TABLE `cg-`;
DROP TABLE `pg-`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[no_warnigs]
wsrep-mode=APPLIER_DISABLE_FK_WARNINGS

[warnings]
wsrep-mode=0
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ while($counter > 0)
--connection node_1

drop table user_session,user;

call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
3 changes: 3 additions & 0 deletions mysql-test/suite/galera/t/galera_fk_selfreferential.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ INSERT INTO t1 VALUES (1, 1), (2, 1);
--connection node_2
DELETE FROM t1 WHERE f1 = 1;

# Test now produces one FK warning
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we be sure that the test produces such warnings if we are not checking that the messages are actually being emitted, by using search_pattern_in_file.inc?


--connection node_1
SELECT COUNT(*) = 0 FROM t1;

Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/galera/t/galera_multirow_rollback.test
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ COMMIT;
SELECT * FROM p;
SELECT * FROM c;

# Test now produces one FK warning
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");

--connection node_2
SELECT * FROM p;
SELECT * FROM c;
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/galera/t/galera_var_fkchecks.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ INSERT INTO child VALUES (3,3);
SET SESSION foreign_key_checks = 0;
DELETE FROM parent;

# Test now produces one FK warning
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");

--connection node_1
SELECT COUNT(*) = 0 FROM parent;

Expand Down
5 changes: 4 additions & 1 deletion mysql-test/suite/galera/t/galera_var_wsrep_mode.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SET GLOBAL wsrep_mode='A';
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL wsrep_mode=NULL;
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL wsrep_mode=128;
SET GLOBAL wsrep_mode=65536;
--error ER_PARSE_ERROR
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM;
#
Expand All @@ -44,8 +44,11 @@ SET GLOBAL wsrep_mode=REPLICATE_MYISAM;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=REPLICATE_ARIA;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=APPLIER_DISABLE_FK_WARNINGS;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=DISALLOW_LOCAL_GTID;
SELECT @@wsrep_mode;

SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY';
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ id j
SELECT * FROM c;
id fk1
3 1
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");
connection node_2;
SELECT * FROM p;
id j
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/galera_sr/t/galera_sr_multirow_rollback.test
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ COMMIT;
SELECT * FROM p;
SELECT * FROM c;

# Test now have FK warning
call mtr.add_suppression("WSREP: Foreign key CONSTRAINT");

--connection node_2
SELECT * FROM p;
SELECT * FROM c;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/sys_vars/r/sysvars_wsrep.result
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ VARIABLE_COMMENT Set of WSREP features that are enabled.
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID,BF_ABORT_MARIABACKUP
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
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
GLOBAL_VALUE_PATH NULL
Expand Down
12 changes: 12 additions & 0 deletions sql/service_wsrep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,15 @@ extern "C" my_bool wsrep_thd_is_local_transaction(const THD *thd)
return (wsrep_thd_is_local(thd) &&
thd->wsrep_cs().transaction().active());
}

extern "C" my_bool wsrep_applier_log_warnings(const THD *thd)
{
/* Applier will log warning on fk errors if
(1) wsrep_mode != WSREP_MODE_APPLIER_DISABLE_WARNINGS AND
(2) thd executing is applier
(3) there is no error log warning flooding
*/
return (!wsrep_check_mode(WSREP_MODE_APPLIER_DISABLE_WARNINGS) &&
thd->wsrep_cs().mode() == wsrep::client_state::m_high_priority &&
!wsrep_protect_against_warning_flood(WSREP_APPLIER_FK_ERROR));
}
3 changes: 2 additions & 1 deletion sql/sql_plugin_services.inl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ static struct wsrep_service_st wsrep_handler = {
wsrep_thd_kill_LOCK,
wsrep_thd_kill_UNLOCK,
wsrep_thd_set_PA_unsafe,
wsrep_get_domain_id
wsrep_get_domain_id,
wsrep_applier_log_warnings
};

static struct thd_specifics_service_st thd_specifics_handler=
Expand Down
1 change: 1 addition & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6287,6 +6287,7 @@ static const char *wsrep_mode_names[]=
"REPLICATE_ARIA",
"DISALLOW_LOCAL_GTID",
"BF_ABORT_MARIABACKUP",
"APPLIER_DISABLE_FK_WARNINGS",
NullS
};
static Sys_var_set Sys_wsrep_mode(
Expand Down
3 changes: 3 additions & 0 deletions sql/wsrep_dummy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,6 @@ void wsrep_thd_set_PA_unsafe(THD*)

uint32 wsrep_get_domain_id()
{ return 0;}

my_bool wsrep_applier_log_warnings(const THD*)
{ return 0;}
12 changes: 3 additions & 9 deletions sql/wsrep_mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,6 @@ bool wsrep_check_mode (enum_wsrep_mode mask)
//number of limit warnings after which the suppression will be activated
#define WSREP_WARNING_ACTIVATION_THRESHOLD 10

enum wsrep_warning_type {
WSREP_DISABLED = 0,
WSREP_REQUIRE_PRIMARY_KEY= 1,
WSREP_REQUIRE_INNODB= 2,
WSREP_EXPERIMENTAL= 3,
WSREP_REQUIRE_MAX=4,
};

static ulonglong wsrep_warning_start_time=0;
static bool wsrep_warning_active[WSREP_REQUIRE_MAX+1];
static ulonglong wsrep_warning_count[WSREP_REQUIRE_MAX+1];
Expand Down Expand Up @@ -1277,6 +1269,8 @@ static const char* wsrep_warning_name(const enum wsrep_warning_type type)
return "WSREP_REQUIRE_PRIMARY_KEY"; break;
case WSREP_REQUIRE_INNODB:
return "WSREP_REQUIRE_INNODB"; break;
case WSREP_APPLIER_FK_ERROR:
return "WSREP_APPLIER_FK_ERROR"; break;
case WSREP_EXPERIMENTAL:
return "WSREP_EXPERIMENTAL"; break;

Expand Down Expand Up @@ -1306,7 +1300,7 @@ static const char* wsrep_warning_name(const enum wsrep_warning_type type)
1 Message suppressed
*/

static bool wsrep_protect_against_warning_flood(
bool wsrep_protect_against_warning_flood(
enum wsrep_warning_type warning_type)
{
ulonglong count;
Expand Down
16 changes: 14 additions & 2 deletions sql/wsrep_mysqld.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2008-2023 Codership Oy <http://www.codership.com>
/* Copyright 2008-2025 Codership Oy <http://www.codership.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -131,7 +131,17 @@ enum enum_wsrep_mode {
WSREP_MODE_REPLICATE_MYISAM= (1ULL << 3),
WSREP_MODE_REPLICATE_ARIA= (1ULL << 4),
WSREP_MODE_DISALLOW_LOCAL_GTID= (1ULL << 5),
WSREP_MODE_BF_MARIABACKUP= (1ULL << 6)
WSREP_MODE_BF_MARIABACKUP= (1ULL << 6),
WSREP_MODE_APPLIER_DISABLE_WARNINGS= (1ULL << 7)
Comment on lines -134 to +135
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added symbol WSREP_MODE_APPLIER_DISABLE_WARNINGS does not include FK_ like the added string literal APPLIER_DISABLE_FK_WARNINGS does. Is this intentional? If not, which other warnings is this setting intended to cover?

};

enum wsrep_warning_type {
WSREP_DISABLED = 0,
WSREP_REQUIRE_PRIMARY_KEY= 1,
WSREP_REQUIRE_INNODB= 2,
WSREP_EXPERIMENTAL= 3,
WSREP_APPLIER_FK_ERROR= 4,
WSREP_REQUIRE_MAX=5,
};

// Streaming Replication
Expand Down Expand Up @@ -610,6 +620,8 @@ bool wsrep_table_list_has_non_temp_tables(THD *thd, TABLE_LIST *tables);
*/
bool wsrep_foreign_key_append(THD *thd, FOREIGN_KEY_INFO *fk);

bool wsrep_protect_against_warning_flood(
enum wsrep_warning_type warning_type);
#else /* !WITH_WSREP */

/* These macros are needed to compile MariaDB without WSREP support
Expand Down
Loading