Skip to content

Commit 38f3b99

Browse files
author
Nirbhay Choubey
committed
MDEV-8831 : enforce_storage_engine doesn't block table creation on other nodes
Check if the engine is supported/allowed before replicating the statement.
1 parent accf9b5 commit 38f3b99

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# MDEV-8831 : enforce_storage_engine doesn't block table creation on
3+
# other nodes (galera cluster)
4+
#
5+
SET @@enforce_storage_engine=INNODB;
6+
CREATE TABLE t1(i INT) ENGINE=INNODB;
7+
CREATE TABLE t2(i INT) ENGINE=MYISAM;
8+
ERROR 42000: Unknown storage engine 'MyISAM'
9+
INSERT INTO t1 VALUES(1);
10+
SHOW TABLES;
11+
Tables_in_test
12+
t1
13+
SELECT COUNT(*)=1 FROM t1;
14+
COUNT(*)=1
15+
1
16+
CREATE TABLE t2(i INT) ENGINE=MYISAM;
17+
SHOW TABLES;
18+
Tables_in_test
19+
t1
20+
t2
21+
DROP TABLE t1, t2;
22+
# End of tests
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--source include/galera_cluster.inc
2+
--source include/have_innodb.inc
3+
4+
# enforce_storage_engine should prevent the creation of tables with
5+
# non-enforced storage engines on the master node and the command
6+
# should also not replicate to other nodes.
7+
8+
--echo #
9+
--echo # MDEV-8831 : enforce_storage_engine doesn't block table creation on
10+
--echo # other nodes (galera cluster)
11+
--echo #
12+
13+
--connection node_1
14+
SET @@enforce_storage_engine=INNODB;
15+
CREATE TABLE t1(i INT) ENGINE=INNODB;
16+
--error ER_UNKNOWN_STORAGE_ENGINE
17+
CREATE TABLE t2(i INT) ENGINE=MYISAM;
18+
19+
INSERT INTO t1 VALUES(1);
20+
21+
--connection node_2
22+
SHOW TABLES;
23+
SELECT COUNT(*)=1 FROM t1;
24+
25+
CREATE TABLE t2(i INT) ENGINE=MYISAM;
26+
27+
--connection node_1
28+
SHOW TABLES;
29+
30+
# Cleanup
31+
DROP TABLE t1, t2;
32+
33+
--echo # End of tests

sql/sql_parse.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,11 +3440,16 @@ mysql_execute_command(THD *thd)
34403440
}
34413441
else
34423442
{
3443-
/* in STATEMENT format, we probably have to replicate also temporary
3444-
tables, like mysql replication does
3443+
/*
3444+
In STATEMENT format, we probably have to replicate also temporary
3445+
tables, like mysql replication does. Also check if the requested
3446+
engine is allowed/supported.
34453447
*/
3446-
if (WSREP(thd) && (!thd->is_current_stmt_binlog_format_row() ||
3447-
!create_info.tmp_table()))
3448+
if (WSREP(thd) &&
3449+
!check_engine(thd, create_table->db, create_table->table_name,
3450+
&create_info) &&
3451+
(!thd->is_current_stmt_binlog_format_row() ||
3452+
!create_info.tmp_table()))
34483453
{
34493454
WSREP_TO_ISOLATION_BEGIN(create_table->db, create_table->table_name, NULL)
34503455
}

sql/sql_table.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ static int copy_data_between_tables(THD *thd, TABLE *from,TABLE *to,
7272
Alter_table_ctx *alter_ctx);
7373

7474
static bool prepare_blob_field(THD *thd, Create_field *sql_field);
75-
static bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *);
7675
static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *,
7776
uint *, handler *, KEY **, uint *, int);
7877
static uint blob_length_by_type(enum_field_types type);
@@ -9816,8 +9815,8 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
98169815
@retval true Engine not available/supported, error has been reported.
98179816
@retval false Engine available/supported.
98189817
*/
9819-
static bool check_engine(THD *thd, const char *db_name,
9820-
const char *table_name, HA_CREATE_INFO *create_info)
9818+
bool check_engine(THD *thd, const char *db_name,
9819+
const char *table_name, HA_CREATE_INFO *create_info)
98219820
{
98229821
DBUG_ENTER("check_engine");
98239822
handlerton **new_engine= &create_info->db_type;

sql/sql_table.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,6 @@ uint explain_filename(THD* thd, const char *from, char *to, uint to_length,
284284
extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
285285
extern mysql_mutex_t LOCK_gdl;
286286

287+
bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *);
288+
287289
#endif /* SQL_TABLE_INCLUDED */

0 commit comments

Comments
 (0)