Skip to content
Permalink
Browse files
MDEV-20051: Add new mode to wsrep_OSU_method in which Galera checks s…
…torage engine of the effected table

Introduced a new wsrep_strict_ddl configuration variable in which
Galera checks storage engine of the effected table. If table is not
InnoDB (only storage engine currently fully supporting Galera
replication) DDL-statement will return error code:

ER_GALERA_REPLICATION_NOT_SUPPORTED
       eng "DDL-statement is forbidden as table storage engine does not support Galera replication"

However, when wsrep_replicate_myisam=ON we allow DDL-statements to
MyISAM tables. If effected table is allowed storage engine Galera
will run normal TOI.

This new setting should be for now set globally on all
nodes in a cluster. When this setting is set following DDL-clauses
accessing tables not supporting Galera replication are refused:

* CREATE TABLE (e.g. CREATE TABLE t1(a int) engine=Aria
* ALTER TABLE
* TRUNCATE TABLE
* CREATE VIEW
* CREATE TRIGGER
* CREATE INDEX
* DROP INDEX
* RENAME TABLE
* DROP TABLE

Statements on PROCEDURE, EVENT, FUNCTION are allowed as effected
tables are known only at execution. Furthermore, USER, ROLE, SERVER,
DATABASE statements are also allowed as they do not really have
effected table.
  • Loading branch information
Jan Lindström committed Feb 11, 2020
1 parent 41541a7 commit e6a50e4
Show file tree
Hide file tree
Showing 21 changed files with 690 additions and 87 deletions.
@@ -84,6 +84,7 @@ extern struct wsrep_service_st {
my_bool (*wsrep_get_debug_func)();
void (*wsrep_commit_ordered_func)(MYSQL_THD thd);
my_bool (*wsrep_thd_is_applying_func)(const MYSQL_THD thd);
ulong (*wsrep_OSU_method_get_func)(const MYSQL_THD thd);
my_bool (*wsrep_thd_has_ignored_error_func)(const MYSQL_THD thd);
void (*wsrep_thd_set_ignored_error_func)(MYSQL_THD thd, my_bool val);
} *wsrep_service;
@@ -126,9 +127,9 @@ extern struct wsrep_service_st {
#define wsrep_get_debug() wsrep_service->wsrep_get_debug_func()
#define wsrep_commit_ordered(T) wsrep_service->wsrep_commit_ordered_func(T)
#define wsrep_thd_is_applying(T) wsrep_service->wsrep_thd_is_applying_func(T)
#define wsrep_OSU_method_get(T) wsrep_service->wsrep_OSU_method_get_func(T)
#define wsrep_thd_has_ignored_error(T) wsrep_service->wsrep_thd_has_ignored_error_func(T)
#define wsrep_thd_set_ignored_error(T,V) wsrep_service->wsrep_thd_set_ignored_error_func(T,V)

#else

#define MYSQL_SERVICE_WSREP_STATIC_INCLUDED
@@ -220,9 +221,8 @@ extern "C" my_bool wsrep_get_debug();

extern "C" void wsrep_commit_ordered(MYSQL_THD thd);
extern "C" my_bool wsrep_thd_is_applying(const MYSQL_THD thd);

extern "C" ulong wsrep_OSU_method_get(const MYSQL_THD thd);
extern "C" my_bool wsrep_thd_has_ignored_error(const MYSQL_THD thd);
extern "C" void wsrep_thd_set_ignored_error(MYSQL_THD thd, my_bool val);

#endif
#endif /* MYSQL_SERVICE_WSREP_INCLUDED */
@@ -19,18 +19,27 @@
#include <my_config.h>

#ifdef WITH_WSREP

#define IF_WSREP(A,B) A

#define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A)

#define WSREP_MYSQL_DB (char *)"mysql"

#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \
if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
if (WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
goto wsrep_error_label;

#define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_) \
if (WSREP(thd) && \
wsrep_to_isolation_begin(thd, db_, table_, \
table_list_, NULL, create_info_)) \
goto wsrep_error_label;

#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_) \
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, create_info_) \
if (WSREP(thd) && wsrep_thd_is_local(thd) && \
wsrep_to_isolation_begin(thd, db_, table_, \
table_list_, alter_info_)) \
table_list_, alter_info_, create_info_)) \
goto wsrep_error_label;

#define WSREP_TO_ISOLATION_END \
@@ -56,14 +65,12 @@
* (e.g. embedded) */

#define IF_WSREP(A,B) B
//#define DBUG_ASSERT_IF_WSREP(A)
#define WSREP_DEBUG(...)
//#define WSREP_INFO(...)
//#define WSREP_WARN(...)
#define WSREP_ERROR(...)
#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0)
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_)
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, create_info_)
#define WSREP_TO_ISOLATION_END
#define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_)
#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)
#define WSREP_SYNC_WAIT(thd_, before_)
#endif /* WITH_WSREP */
@@ -0,0 +1,194 @@
connection node_2;
connection node_1;
call mtr.add_suppression("WSREP: ALTER TABLE isolation failure");
connection node_1;
SET GLOBAL binlog_format='ROW';
create table before_t1(a int, count int, b int, key(b)) engine=Aria;
INSERT INTO before_t1 values (1,1,1);
set @@global.wsrep_strict_ddl=ON;
select @@global.wsrep_strict_ddl;
@@global.wsrep_strict_ddl
1
connection node_2;
set @@global.wsrep_strict_ddl=ON;
select @@global.wsrep_strict_ddl;
@@global.wsrep_strict_ddl
1
connection node_1;
CREATE TABLE t1(a int) engine=Aria;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW WARNINGS;
Level Code Message
Error 4165 DDL-statement is forbidden as table storage engine does not support Galera replication
Warning 1031 WSREP: wsrep_strict_ddl=true and storage engine does not support Galera replication.
connection node_2;
SHOW CREATE TABLE t1;
ERROR 42S02: Table 'test.t1' doesn't exist
connection node_1;
CREATE TABLE t2(a int not null primary key) engine=InnoDB;
ALTER TABLE t2 engine=MyISAM;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW WARNINGS;
Level Code Message
Error 4165 DDL-statement is forbidden as table storage engine does not support Galera replication
Warning 1031 WSREP: wsrep_strict_ddl=true and storage engine does not support Galera replication.
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
connection node_2;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
connection node_1;
TRUNCATE TABLE before_t1;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SELECT * FROM before_t1;
a count b
1 1 1
connection node_2;
SET SESSION wsrep_sync_wait=15;
SELECT @@wsrep_sync_wait;
@@wsrep_sync_wait
15
SELECT * FROM before_t1;
a count b
connection node_1;
CREATE VIEW x1 AS SELECT * FROM before_t1;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW CREATE VIEW x1;
ERROR 42S02: Table 'test.x1' doesn't exist
connection node_2;
SHOW CREATE VIEW x1;
ERROR 42S02: Table 'test.x1' doesn't exist
connection node_1;
CREATE DEFINER=`root`@`localhost` TRIGGER increment_before_t1
AFTER INSERT ON before_t1 FOR EACH ROW
UPDATE before_t1 SET before_t1.count = before_t1.count+1;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW CREATE TRIGGER increment_before_t1;
ERROR HY000: Trigger does not exist
connection node_2;
SHOW CREATE TRIGGER increment_before_t1;
ERROR HY000: Trigger does not exist
connection node_1;
CREATE INDEX xx2 ON before_t1(a);
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_2;
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_1;
DROP INDEX b ON before_t1;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_2;
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_1;
ALTER TABLE before_t1 ADD COLUMN f int;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_2;
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_1;
RENAME TABLE before_t1 to after_t1;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
SHOW CREATE TABLE after_t1;
ERROR 42S02: Table 'test.after_t1' doesn't exist
connection node_2;
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
SHOW CREATE TABLE after_t1;
ERROR 42S02: Table 'test.after_t1' doesn't exist
connection node_1;
DROP TABLE before_t1;
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_2;
SHOW CREATE TABLE before_t1;
Table Create Table
before_t1 CREATE TABLE `before_t1` (
`a` int(11) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `b` (`b`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
connection node_1;
set @@global.wsrep_strict_ddl=OFF;
select @@global.wsrep_strict_ddl;
@@global.wsrep_strict_ddl
0
connection node_2;
set @@global.wsrep_strict_ddl=OFF;
select @@global.wsrep_strict_ddl;
@@global.wsrep_strict_ddl
0
DROP TABLE t2;
DROP TABLE before_t1;

0 comments on commit e6a50e4

Please sign in to comment.