Skip to content

Commit

Permalink
MDEV-24830 : Write a warning to error log if Galera replicates InnoDB…
Browse files Browse the repository at this point in the history
… table with no primary key

Two new features for Galera
* Write a warning to error log if Galera replicates table with storage engine not supported by Galera (at the moment only InnoDB is supported
** Warning is pushed to client also
** MyISAM is allowed if wsrep_replicate_myisam=ON
* Write a warning to error log if Galera replicates table with no primary key
** Warning is pushed to client also
** MyISAM is allowed if wsrep_relicate_myisam=ON
* In both cases apply flood control if > 10 same warning is writen to error log
(requires log_warnings > 1), flood control will suppress warnings for 300 seconds
  • Loading branch information
Jan Lindström committed Feb 22, 2021
1 parent 420f8e2 commit 208233b
Show file tree
Hide file tree
Showing 9 changed files with 638 additions and 44 deletions.
6 changes: 1 addition & 5 deletions mysql-test/suite/galera/r/galera_can_run_toi.result
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ SELECT @@default_storage_engine;
@@default_storage_engine
MyISAM
SET GLOBAL wsrep_replicate_myisam=OFF;
SET GLOBAL wsrep_strict_ddl=ON;
Warnings:
Warning 1287 '@@wsrep_strict_ddl' is deprecated and will be removed in a future release. Please use '@@wsrep_mode=STRICT_REPLICATION' instead
SET GLOBAL wsrep_mode=STRICT_REPLICATION;
CREATE TABLE t3 (c1 VARCHAR(10)) ENGINE=InnoDB;
ALTER TABLE t3 ENGINE=NonExistentEngine;
ERROR HY000: Galera replication not supported
Expand All @@ -38,5 +36,3 @@ t3 CREATE TABLE `t3` (
`c1` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
DROP TABLE t3;
Warnings:
Warning 1287 '@@wsrep_strict_ddl' is deprecated and will be removed in a future release. Please use '@@wsrep_mode=STRICT_REPLICATION' instead
92 changes: 92 additions & 0 deletions mysql-test/suite/galera/r/galera_strict_require_innodb.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
connection node_2;
connection node_1;
call mtr.add_suppression("WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine .*");
CREATE TABLE t1(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=INNODB;
CREATE TABLE t2(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=MYISAM;
CREATE TABLE t3(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=ARIA;
CREATE TABLE t4(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=MEMORY;
SET GLOBAL wsrep_replicate_myisam=ON;
SET GLOBAL log_warnings=2;
SET GLOBAL wsrep_mode= STRICT_REPLICATION;
INSERT INTO t1 values (1,'innodb1');
INSERT INTO t2 values (1,'myisam1');
INSERT INTO t3 values (1,'aria1');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
INSERT INTO t4 values (1,'memory1');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
SET GLOBAL wsrep_replicate_myisam=OFF;
INSERT INTO t2 values (2,'myisam2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
SET GLOBAL log_warnings=1;
INSERT INTO t1 values (2,'innodb2');
INSERT INTO t2 values (3,'myisam3');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
INSERT INTO t3 values (2,'aria2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
INSERT INTO t4 values (2,'memory2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
include/assert_grep.inc [WSREP: wsrep_mode = STRICT_REPLICATION enabled.]
SET GLOBAL log_warnings=2;
INSERT INTO t2 values (4,'myisam3');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
INSERT INTO t3 values (4,'aria2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
INSERT INTO t4 values (4,'memory2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
INSERT INTO t2 values (5,'myisam3');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
INSERT INTO t3 values (5,'aria2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
INSERT INTO t4 values (5,'memory2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
INSERT INTO t2 values (6,'myisam3');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MyISAM for table 'test'.'t2' is not supported in Galera
INSERT INTO t3 values (6,'aria2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine Aria for table 'test'.'t3' is not supported in Galera
INSERT INTO t4 values (6,'memory2');
Warnings:
Warning 1290 WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine MEMORY for table 'test'.'t4' is not supported in Galera
SELECT COUNT(*) AS EXPECT_2 FROM t1;
EXPECT_2
2
SELECT COUNT(*) AS EXPECT_6 FROM t2;
EXPECT_6
6
SELECT COUNT(*) AS EXPECT_5 FROM t3;
EXPECT_5
5
SELECT COUNT(*) AS EXPECT_5 FROM t4;
EXPECT_5
5
connection node_2;
SELECT COUNT(*) AS EXPECT_2 FROM t1;
EXPECT_2
2
SELECT COUNT(*) AS EXPECT_1 FROM t2;
EXPECT_1
1
SELECT COUNT(*) AS EXPECT_0 FROM t3;
EXPECT_0
0
SELECT COUNT(*) AS EXPECT_0 FROM t4;
EXPECT_0
0
connection node_1;
SET GLOBAL wsrep_mode= DEFAULT;
DROP TABLE t1,t2,t3,t4;
include/assert_grep.inc [WSREP: wsrep_mode = STRICT_REPLICATION enabled.]
include/assert_grep.inc [WSREP: Suppressing warnings of type 'WSREP_REQUIRE_INNODB' for up to 300 seconds because of flooding]
86 changes: 86 additions & 0 deletions mysql-test/suite/galera/r/galera_strict_require_primary_key.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
connection node_2;
connection node_1;
call mtr.add_suppression("WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table .*");
CREATE TABLE t1(a int, b varchar(50)) ENGINE=INNODB;
CREATE TABLE t2(a int, b varchar(50)) ENGINE=MYISAM;
CREATE TABLE t3(a int, b varchar(50)) ENGINE=MEMORY;
SET GLOBAL wsrep_replicate_myisam=ON;
SET GLOBAL log_warnings=2;
SET GLOBAL wsrep_mode= REQUIRED_PRIMARY_KEY;
INSERT INTO t1 values (1,'test1');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t2 values (1,'myisam1');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t2' should have PRIMARY KEY defined.
INSERT INTO t3 values (1,'memory');
SET GLOBAL wsrep_replicate_myisam=OFF;
INSERT INTO t2 values (2,'mysam2');
INSERT INTO t1 values (2,'test2');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (3,'test3');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (4,'test4');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (5,'test5');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
SET GLOBAL log_warnings=1;
INSERT INTO t1 values (21,'not1');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (22,'not2');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
include/assert_grep.inc [WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled.]
SET GLOBAL log_warnings=2;
INSERT INTO t1 values (6,'test6');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (7,'test7');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (8,'test8');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (9,'test9');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (10,'test10');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (11,'test11');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (12,'test12');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
INSERT INTO t1 values (13,'test13');
Warnings:
Warning 1290 WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table 'test'.'t1' should have PRIMARY KEY defined.
SELECT COUNT(*) AS EXPECT_15 FROM t1;
EXPECT_15
15
SELECT COUNT(*) AS EXPECT_2 FROM t2;
EXPECT_2
2
SELECT COUNT(*) AS EXPECT_1 FROM t3;
EXPECT_1
1
connection node_2;
SELECT COUNT(*) AS EXPECT_15 FROM t1;
EXPECT_15
15
SELECT COUNT(*) AS EXPECT_1 FROM t2;
EXPECT_1
1
SELECT COUNT(*) AS EXPECT_0 FROM t3;
EXPECT_0
0
connection node_1;
DROP TABLE t1,t2,t3;
include/assert_grep.inc [WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled.]
include/assert_grep.inc [WSREP: Suppressing warnings of type 'WSREP_REQUIRE_PRIMARY_KEY' for up to 300 seconds because of flooding]
4 changes: 2 additions & 2 deletions mysql-test/suite/galera/t/galera_can_run_toi.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SET sql_mode='';
SET SESSION default_storage_engine=MyISAM;
SELECT @@default_storage_engine;
SET GLOBAL wsrep_replicate_myisam=OFF;
SET GLOBAL wsrep_strict_ddl=ON;
SET GLOBAL wsrep_mode=STRICT_REPLICATION;
CREATE TABLE t3 (c1 VARCHAR(10)) ENGINE=InnoDB;
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
ALTER TABLE t3 ENGINE=NonExistentEngine;
Expand All @@ -30,5 +30,5 @@ DROP TABLE t3;
SET GLOBAL sql_mode=default;
SET GLOBAL default_storage_engine=default;
SET GLOBAL wsrep_replicate_myisam=default;
SET GLOBAL wsrep_strict_ddl=default;
SET GLOBAL wsrep_mode=default;
--enable_query_log
95 changes: 95 additions & 0 deletions mysql-test/suite/galera/t/galera_strict_require_innodb.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# Write a warning to error log if Galera replicates table with storage engine
# not supported by Galera
#
# For MyISAM
# * push warning to client if wsrep_mode == STRICT_REPLICATION and wsrep_replicate_myisam=off
# * push warning to error log if log_warnings > 1
# For Memory
# * push warning to client if wsrep_mode == STRICT_REPLICATION
# * push warning to error log if log_warnings > 1
# ( Note here Aria and case wsrep_replicate_aria=ON)
#
# In both cases apply flood control if > 10 same warning
#
--source include/galera_cluster.inc
--source include/have_aria.inc

call mtr.add_suppression("WSREP: wsrep_mode = STRICT_REPLICATION enabled. Storage engine .*");

CREATE TABLE t1(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=INNODB;
CREATE TABLE t2(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=MYISAM;
CREATE TABLE t3(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=ARIA;
CREATE TABLE t4(a int NOT NULL PRIMARY KEY, b varchar(50)) ENGINE=MEMORY;

SET GLOBAL wsrep_replicate_myisam=ON;
SET GLOBAL log_warnings=2;
SET GLOBAL wsrep_mode= STRICT_REPLICATION;

INSERT INTO t1 values (1,'innodb1');
INSERT INTO t2 values (1,'myisam1');
INSERT INTO t3 values (1,'aria1');
INSERT INTO t4 values (1,'memory1');

SET GLOBAL wsrep_replicate_myisam=OFF;
INSERT INTO t2 values (2,'myisam2');

SET GLOBAL log_warnings=1;
INSERT INTO t1 values (2,'innodb2');
INSERT INTO t2 values (3,'myisam3');
INSERT INTO t3 values (2,'aria2');
INSERT INTO t4 values (2,'memory2');

# test flood control
--let $assert_count = 3
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
--let $assert_text = WSREP: wsrep_mode = STRICT_REPLICATION enabled.
--let $assert_select = WSREP: wsrep_mode = STRICT_REPLICATION enabled.
--source include/assert_grep.inc

SET GLOBAL log_warnings=2;
INSERT INTO t2 values (4,'myisam3');
INSERT INTO t3 values (4,'aria2');
INSERT INTO t4 values (4,'memory2');
INSERT INTO t2 values (5,'myisam3');
INSERT INTO t3 values (5,'aria2');
INSERT INTO t4 values (5,'memory2');
INSERT INTO t2 values (6,'myisam3');
INSERT INTO t3 values (6,'aria2');
INSERT INTO t4 values (6,'memory2');

SELECT COUNT(*) AS EXPECT_2 FROM t1;
SELECT COUNT(*) AS EXPECT_6 FROM t2;
SELECT COUNT(*) AS EXPECT_5 FROM t3;
SELECT COUNT(*) AS EXPECT_5 FROM t4;

--connection node_2
SELECT COUNT(*) AS EXPECT_2 FROM t1;
SELECT COUNT(*) AS EXPECT_1 FROM t2;
SELECT COUNT(*) AS EXPECT_0 FROM t3;
SELECT COUNT(*) AS EXPECT_0 FROM t4;

--connection node_1
SET GLOBAL wsrep_mode= DEFAULT;
DROP TABLE t1,t2,t3,t4;

#
# Verify no flood
#
--let $assert_count = 10
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
--let $assert_text = WSREP: wsrep_mode = STRICT_REPLICATION enabled.
--let $assert_select = WSREP: wsrep_mode = STRICT_REPLICATION enabled.
--source include/assert_grep.inc
--let $assert_count = 1
--let $assert_text = WSREP: Suppressing warnings of type 'WSREP_REQUIRE_INNODB' for up to 300 seconds because of flooding
--let $assert_select = WSREP: Suppressing warnings of type 'WSREP_REQUIRE_INNODB' for up to 300 seconds because of flooding
--source include/assert_grep.inc

# reset env
--disable_query_log
SET GLOBAL wsrep_replicate_myisam=DEFAULT;
SET GLOBAL log_warnings=DEFAULT;
SET GLOBAL wsrep_mode=DEFAULT;
--disable_query_log

90 changes: 90 additions & 0 deletions mysql-test/suite/galera/t/galera_strict_require_primary_key.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#
# Write a warning to error log if Galera replicates table with no primary key
#
# For InnoDB
# * push warning to client if wsrep_mode == REQUIRED_PRIMARY_KEY
# * push warning to error log if log_warnings > 1
# For MyIsam
# * push warning if wsrep_replicate_myisam=ON
#
# In both cases apply flood control if > 10 same warning
#
--source include/galera_cluster.inc

call mtr.add_suppression("WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled. Table .*");

CREATE TABLE t1(a int, b varchar(50)) ENGINE=INNODB;
CREATE TABLE t2(a int, b varchar(50)) ENGINE=MYISAM;
CREATE TABLE t3(a int, b varchar(50)) ENGINE=MEMORY;

SET GLOBAL wsrep_replicate_myisam=ON;
SET GLOBAL log_warnings=2;
SET GLOBAL wsrep_mode= REQUIRED_PRIMARY_KEY;

INSERT INTO t1 values (1,'test1');
INSERT INTO t2 values (1,'myisam1');
INSERT INTO t3 values (1,'memory');

SET GLOBAL wsrep_replicate_myisam=OFF;
INSERT INTO t2 values (2,'mysam2');

# test flood control
INSERT INTO t1 values (2,'test2');
INSERT INTO t1 values (3,'test3');
INSERT INTO t1 values (4,'test4');
INSERT INTO t1 values (5,'test5');

# these should not write warning to error log
SET GLOBAL log_warnings=1;
INSERT INTO t1 values (21,'not1');
INSERT INTO t1 values (22,'not2');

--let $assert_count = 6
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
--let $assert_text = WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled.
--let $assert_select = WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled.
--source include/assert_grep.inc

# force flood
SET GLOBAL log_warnings=2;
INSERT INTO t1 values (6,'test6');
INSERT INTO t1 values (7,'test7');
INSERT INTO t1 values (8,'test8');
INSERT INTO t1 values (9,'test9');
INSERT INTO t1 values (10,'test10');
INSERT INTO t1 values (11,'test11');
INSERT INTO t1 values (12,'test12');
INSERT INTO t1 values (13,'test13');

SELECT COUNT(*) AS EXPECT_15 FROM t1;
SELECT COUNT(*) AS EXPECT_2 FROM t2;
SELECT COUNT(*) AS EXPECT_1 FROM t3;

--connection node_2
SELECT COUNT(*) AS EXPECT_15 FROM t1;
SELECT COUNT(*) AS EXPECT_1 FROM t2;
SELECT COUNT(*) AS EXPECT_0 FROM t3;

--connection node_1
DROP TABLE t1,t2,t3;

#
# Verify warning is on error log and check that no flood
#
--let $assert_count = 9
--let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err
--let $assert_text = WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled.
--let $assert_select = WSREP: wsrep_mode = REQUIRED_PRIMARY_KEY enabled.
--source include/assert_grep.inc
--let $assert_count = 1
--let $assert_text = WSREP: Suppressing warnings of type 'WSREP_REQUIRE_PRIMARY_KEY' for up to 300 seconds because of flooding
--let $assert_select = WSREP: Suppressing warnings of type 'WSREP_REQUIRE_PRIMARY_KEY' for up to 300 seconds because of flooding
--source include/assert_grep.inc

# reset env
--disable_query_log
SET GLOBAL wsrep_replicate_myisam=DEFAULT;
SET GLOBAL log_warnings=DEFAULT;
SET GLOBAL wsrep_mode=DEFAULT;
--disable_query_log

Loading

0 comments on commit 208233b

Please sign in to comment.