Skip to content

Commit e6a50e4

Browse files
author
Jan Lindström
committed
MDEV-20051: Add new mode to wsrep_OSU_method in which Galera checks storage 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.
1 parent 41541a7 commit e6a50e4

21 files changed

+690
-87
lines changed

include/mysql/service_wsrep.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern struct wsrep_service_st {
8484
my_bool (*wsrep_get_debug_func)();
8585
void (*wsrep_commit_ordered_func)(MYSQL_THD thd);
8686
my_bool (*wsrep_thd_is_applying_func)(const MYSQL_THD thd);
87+
ulong (*wsrep_OSU_method_get_func)(const MYSQL_THD thd);
8788
my_bool (*wsrep_thd_has_ignored_error_func)(const MYSQL_THD thd);
8889
void (*wsrep_thd_set_ignored_error_func)(MYSQL_THD thd, my_bool val);
8990
} *wsrep_service;
@@ -126,9 +127,9 @@ extern struct wsrep_service_st {
126127
#define wsrep_get_debug() wsrep_service->wsrep_get_debug_func()
127128
#define wsrep_commit_ordered(T) wsrep_service->wsrep_commit_ordered_func(T)
128129
#define wsrep_thd_is_applying(T) wsrep_service->wsrep_thd_is_applying_func(T)
130+
#define wsrep_OSU_method_get(T) wsrep_service->wsrep_OSU_method_get_func(T)
129131
#define wsrep_thd_has_ignored_error(T) wsrep_service->wsrep_thd_has_ignored_error_func(T)
130132
#define wsrep_thd_set_ignored_error(T,V) wsrep_service->wsrep_thd_set_ignored_error_func(T,V)
131-
132133
#else
133134

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

221222
extern "C" void wsrep_commit_ordered(MYSQL_THD thd);
222223
extern "C" my_bool wsrep_thd_is_applying(const MYSQL_THD thd);
223-
224+
extern "C" ulong wsrep_OSU_method_get(const MYSQL_THD thd);
224225
extern "C" my_bool wsrep_thd_has_ignored_error(const MYSQL_THD thd);
225226
extern "C" void wsrep_thd_set_ignored_error(MYSQL_THD thd, my_bool val);
226-
227227
#endif
228228
#endif /* MYSQL_SERVICE_WSREP_INCLUDED */

include/wsrep.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,27 @@
1919
#include <my_config.h>
2020

2121
#ifdef WITH_WSREP
22+
2223
#define IF_WSREP(A,B) A
24+
2325
#define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A)
2426

2527
#define WSREP_MYSQL_DB (char *)"mysql"
28+
2629
#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \
27-
if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
30+
if (WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
31+
goto wsrep_error_label;
32+
33+
#define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_) \
34+
if (WSREP(thd) && \
35+
wsrep_to_isolation_begin(thd, db_, table_, \
36+
table_list_, NULL, create_info_)) \
2837
goto wsrep_error_label;
2938

30-
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_) \
39+
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, create_info_) \
3140
if (WSREP(thd) && wsrep_thd_is_local(thd) && \
3241
wsrep_to_isolation_begin(thd, db_, table_, \
33-
table_list_, alter_info_)) \
42+
table_list_, alter_info_, create_info_)) \
3443
goto wsrep_error_label;
3544

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

5867
#define IF_WSREP(A,B) B
59-
//#define DBUG_ASSERT_IF_WSREP(A)
6068
#define WSREP_DEBUG(...)
61-
//#define WSREP_INFO(...)
62-
//#define WSREP_WARN(...)
6369
#define WSREP_ERROR(...)
6470
#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0)
65-
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_)
71+
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, create_info_)
6672
#define WSREP_TO_ISOLATION_END
73+
#define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_)
6774
#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)
6875
#define WSREP_SYNC_WAIT(thd_, before_)
6976
#endif /* WITH_WSREP */
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
connection node_2;
2+
connection node_1;
3+
call mtr.add_suppression("WSREP: ALTER TABLE isolation failure");
4+
connection node_1;
5+
SET GLOBAL binlog_format='ROW';
6+
create table before_t1(a int, count int, b int, key(b)) engine=Aria;
7+
INSERT INTO before_t1 values (1,1,1);
8+
set @@global.wsrep_strict_ddl=ON;
9+
select @@global.wsrep_strict_ddl;
10+
@@global.wsrep_strict_ddl
11+
1
12+
connection node_2;
13+
set @@global.wsrep_strict_ddl=ON;
14+
select @@global.wsrep_strict_ddl;
15+
@@global.wsrep_strict_ddl
16+
1
17+
connection node_1;
18+
CREATE TABLE t1(a int) engine=Aria;
19+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
20+
SHOW WARNINGS;
21+
Level Code Message
22+
Error 4165 DDL-statement is forbidden as table storage engine does not support Galera replication
23+
Warning 1031 WSREP: wsrep_strict_ddl=true and storage engine does not support Galera replication.
24+
connection node_2;
25+
SHOW CREATE TABLE t1;
26+
ERROR 42S02: Table 'test.t1' doesn't exist
27+
connection node_1;
28+
CREATE TABLE t2(a int not null primary key) engine=InnoDB;
29+
ALTER TABLE t2 engine=MyISAM;
30+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
31+
SHOW WARNINGS;
32+
Level Code Message
33+
Error 4165 DDL-statement is forbidden as table storage engine does not support Galera replication
34+
Warning 1031 WSREP: wsrep_strict_ddl=true and storage engine does not support Galera replication.
35+
SHOW CREATE TABLE t2;
36+
Table Create Table
37+
t2 CREATE TABLE `t2` (
38+
`a` int(11) NOT NULL,
39+
PRIMARY KEY (`a`)
40+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
41+
connection node_2;
42+
SHOW CREATE TABLE t2;
43+
Table Create Table
44+
t2 CREATE TABLE `t2` (
45+
`a` int(11) NOT NULL,
46+
PRIMARY KEY (`a`)
47+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
48+
connection node_1;
49+
TRUNCATE TABLE before_t1;
50+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
51+
SELECT * FROM before_t1;
52+
a count b
53+
1 1 1
54+
connection node_2;
55+
SET SESSION wsrep_sync_wait=15;
56+
SELECT @@wsrep_sync_wait;
57+
@@wsrep_sync_wait
58+
15
59+
SELECT * FROM before_t1;
60+
a count b
61+
connection node_1;
62+
CREATE VIEW x1 AS SELECT * FROM before_t1;
63+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
64+
SHOW CREATE VIEW x1;
65+
ERROR 42S02: Table 'test.x1' doesn't exist
66+
connection node_2;
67+
SHOW CREATE VIEW x1;
68+
ERROR 42S02: Table 'test.x1' doesn't exist
69+
connection node_1;
70+
CREATE DEFINER=`root`@`localhost` TRIGGER increment_before_t1
71+
AFTER INSERT ON before_t1 FOR EACH ROW
72+
UPDATE before_t1 SET before_t1.count = before_t1.count+1;
73+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
74+
SHOW CREATE TRIGGER increment_before_t1;
75+
ERROR HY000: Trigger does not exist
76+
connection node_2;
77+
SHOW CREATE TRIGGER increment_before_t1;
78+
ERROR HY000: Trigger does not exist
79+
connection node_1;
80+
CREATE INDEX xx2 ON before_t1(a);
81+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
82+
SHOW CREATE TABLE before_t1;
83+
Table Create Table
84+
before_t1 CREATE TABLE `before_t1` (
85+
`a` int(11) DEFAULT NULL,
86+
`count` int(11) DEFAULT NULL,
87+
`b` int(11) DEFAULT NULL,
88+
KEY `b` (`b`)
89+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
90+
connection node_2;
91+
SHOW CREATE TABLE before_t1;
92+
Table Create Table
93+
before_t1 CREATE TABLE `before_t1` (
94+
`a` int(11) DEFAULT NULL,
95+
`count` int(11) DEFAULT NULL,
96+
`b` int(11) DEFAULT NULL,
97+
KEY `b` (`b`)
98+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
99+
connection node_1;
100+
DROP INDEX b ON before_t1;
101+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
102+
SHOW CREATE TABLE before_t1;
103+
Table Create Table
104+
before_t1 CREATE TABLE `before_t1` (
105+
`a` int(11) DEFAULT NULL,
106+
`count` int(11) DEFAULT NULL,
107+
`b` int(11) DEFAULT NULL,
108+
KEY `b` (`b`)
109+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
110+
connection node_2;
111+
SHOW CREATE TABLE before_t1;
112+
Table Create Table
113+
before_t1 CREATE TABLE `before_t1` (
114+
`a` int(11) DEFAULT NULL,
115+
`count` int(11) DEFAULT NULL,
116+
`b` int(11) DEFAULT NULL,
117+
KEY `b` (`b`)
118+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
119+
connection node_1;
120+
ALTER TABLE before_t1 ADD COLUMN f int;
121+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
122+
SHOW CREATE TABLE before_t1;
123+
Table Create Table
124+
before_t1 CREATE TABLE `before_t1` (
125+
`a` int(11) DEFAULT NULL,
126+
`count` int(11) DEFAULT NULL,
127+
`b` int(11) DEFAULT NULL,
128+
KEY `b` (`b`)
129+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
130+
connection node_2;
131+
SHOW CREATE TABLE before_t1;
132+
Table Create Table
133+
before_t1 CREATE TABLE `before_t1` (
134+
`a` int(11) DEFAULT NULL,
135+
`count` int(11) DEFAULT NULL,
136+
`b` int(11) DEFAULT NULL,
137+
KEY `b` (`b`)
138+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
139+
connection node_1;
140+
RENAME TABLE before_t1 to after_t1;
141+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
142+
SHOW CREATE TABLE before_t1;
143+
Table Create Table
144+
before_t1 CREATE TABLE `before_t1` (
145+
`a` int(11) DEFAULT NULL,
146+
`count` int(11) DEFAULT NULL,
147+
`b` int(11) DEFAULT NULL,
148+
KEY `b` (`b`)
149+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
150+
SHOW CREATE TABLE after_t1;
151+
ERROR 42S02: Table 'test.after_t1' doesn't exist
152+
connection node_2;
153+
SHOW CREATE TABLE before_t1;
154+
Table Create Table
155+
before_t1 CREATE TABLE `before_t1` (
156+
`a` int(11) DEFAULT NULL,
157+
`count` int(11) DEFAULT NULL,
158+
`b` int(11) DEFAULT NULL,
159+
KEY `b` (`b`)
160+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
161+
SHOW CREATE TABLE after_t1;
162+
ERROR 42S02: Table 'test.after_t1' doesn't exist
163+
connection node_1;
164+
DROP TABLE before_t1;
165+
ERROR HY000: DDL-statement is forbidden as table storage engine does not support Galera replication
166+
SHOW CREATE TABLE before_t1;
167+
Table Create Table
168+
before_t1 CREATE TABLE `before_t1` (
169+
`a` int(11) DEFAULT NULL,
170+
`count` int(11) DEFAULT NULL,
171+
`b` int(11) DEFAULT NULL,
172+
KEY `b` (`b`)
173+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
174+
connection node_2;
175+
SHOW CREATE TABLE before_t1;
176+
Table Create Table
177+
before_t1 CREATE TABLE `before_t1` (
178+
`a` int(11) DEFAULT NULL,
179+
`count` int(11) DEFAULT NULL,
180+
`b` int(11) DEFAULT NULL,
181+
KEY `b` (`b`)
182+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
183+
connection node_1;
184+
set @@global.wsrep_strict_ddl=OFF;
185+
select @@global.wsrep_strict_ddl;
186+
@@global.wsrep_strict_ddl
187+
0
188+
connection node_2;
189+
set @@global.wsrep_strict_ddl=OFF;
190+
select @@global.wsrep_strict_ddl;
191+
@@global.wsrep_strict_ddl
192+
0
193+
DROP TABLE t2;
194+
DROP TABLE before_t1;

0 commit comments

Comments
 (0)