diff --git a/mysql-test/suite/galera/r/enforce_storage_engine.result b/mysql-test/suite/galera/r/enforce_storage_engine.result new file mode 100644 index 00000000000..a3513fc2789 --- /dev/null +++ b/mysql-test/suite/galera/r/enforce_storage_engine.result @@ -0,0 +1,22 @@ +# +# MDEV-8831 : enforce_storage_engine doesn't block table creation on +# other nodes (galera cluster) +# +SET @@enforce_storage_engine=INNODB; +CREATE TABLE t1(i INT) ENGINE=INNODB; +CREATE TABLE t2(i INT) ENGINE=MYISAM; +ERROR 42000: Unknown storage engine 'MyISAM' +INSERT INTO t1 VALUES(1); +SHOW TABLES; +Tables_in_test +t1 +SELECT COUNT(*)=1 FROM t1; +COUNT(*)=1 +1 +CREATE TABLE t2(i INT) ENGINE=MYISAM; +SHOW TABLES; +Tables_in_test +t1 +t2 +DROP TABLE t1, t2; +# End of tests diff --git a/mysql-test/suite/galera/t/enforce_storage_engine.test b/mysql-test/suite/galera/t/enforce_storage_engine.test new file mode 100644 index 00000000000..5f07dd53a3e --- /dev/null +++ b/mysql-test/suite/galera/t/enforce_storage_engine.test @@ -0,0 +1,33 @@ +--source include/galera_cluster.inc +--source include/have_innodb.inc + +# enforce_storage_engine should prevent the creation of tables with +# non-enforced storage engines on the master node and the command +# should also not replicate to other nodes. + +--echo # +--echo # MDEV-8831 : enforce_storage_engine doesn't block table creation on +--echo # other nodes (galera cluster) +--echo # + +--connection node_1 +SET @@enforce_storage_engine=INNODB; +CREATE TABLE t1(i INT) ENGINE=INNODB; +--error ER_UNKNOWN_STORAGE_ENGINE +CREATE TABLE t2(i INT) ENGINE=MYISAM; + +INSERT INTO t1 VALUES(1); + +--connection node_2 +SHOW TABLES; +SELECT COUNT(*)=1 FROM t1; + +CREATE TABLE t2(i INT) ENGINE=MYISAM; + +--connection node_1 +SHOW TABLES; + +# Cleanup +DROP TABLE t1, t2; + +--echo # End of tests diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 2141e6884f7..9c6f7c028ad 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3440,11 +3440,16 @@ mysql_execute_command(THD *thd) } else { - /* in STATEMENT format, we probably have to replicate also temporary - tables, like mysql replication does + /* + In STATEMENT format, we probably have to replicate also temporary + tables, like mysql replication does. Also check if the requested + engine is allowed/supported. */ - if (WSREP(thd) && (!thd->is_current_stmt_binlog_format_row() || - !create_info.tmp_table())) + if (WSREP(thd) && + !check_engine(thd, create_table->db, create_table->table_name, + &create_info) && + (!thd->is_current_stmt_binlog_format_row() || + !create_info.tmp_table())) { WSREP_TO_ISOLATION_BEGIN(create_table->db, create_table->table_name, NULL) } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d3a72533ec8..b05bdc901d1 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -72,7 +72,6 @@ static int copy_data_between_tables(THD *thd, TABLE *from,TABLE *to, Alter_table_ctx *alter_ctx); static bool prepare_blob_field(THD *thd, Create_field *sql_field); -static bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *); static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *, uint *, handler *, KEY **, uint *, int); static uint blob_length_by_type(enum_field_types type); @@ -9816,8 +9815,8 @@ err: @retval true Engine not available/supported, error has been reported. @retval false Engine available/supported. */ -static bool check_engine(THD *thd, const char *db_name, - const char *table_name, HA_CREATE_INFO *create_info) +bool check_engine(THD *thd, const char *db_name, + const char *table_name, HA_CREATE_INFO *create_info) { DBUG_ENTER("check_engine"); handlerton **new_engine= &create_info->db_type; diff --git a/sql/sql_table.h b/sql/sql_table.h index 85a339314ac..a8124177840 100644 --- a/sql/sql_table.h +++ b/sql/sql_table.h @@ -284,4 +284,6 @@ uint explain_filename(THD* thd, const char *from, char *to, uint to_length, extern MYSQL_PLUGIN_IMPORT const char *primary_key_name; extern mysql_mutex_t LOCK_gdl; +bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *); + #endif /* SQL_TABLE_INCLUDED */