Skip to content

Commit c511f99

Browse files
UG#21405865 - LOG WARNING WHEN A DISABLED STORAGE ENGINE IS SET BY RELATED SYS VAR.
The patch logs a warning when default_storage_engine or default_tmp_storage_engine is set to a disabled storage engine specified in the disabled_storage_engines option.
1 parent a639ea1 commit c511f99

7 files changed

+83
-6
lines changed

mysql-test/r/disabled_storage_engines.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
CALL mtr.add_suppression("default_storage_engine is set to a disabled storage engine .*");
2+
CALL mtr.add_suppression("default_tmp_storage_engine is set to a disabled storage engine .*");
13
CREATE TABLE t1(c1 int) ENGINE=HEAP;
24
ERROR HY000: Storage engine MEMORY is disabled (Table creation is disallowed).
35
CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
@@ -60,6 +62,8 @@ INSTALL PLUGIN example SONAME 'ha_example.so';
6062
CREATE TABLE t1(a int) ENGINE=EXAMPLE;
6163
ERROR HY000: Storage engine EXAMPLE is disabled (Table creation is disallowed).
6264
UNINSTALL PLUGIN example;
65+
SET default_storage_engine=MyISAM;
66+
SET default_tmp_storage_engine=MyISAM;
6367
CREATE TABLE t1(a int) ENGINE=MYISAM;
6468
DROP TABLE t1;
6569
# restart

mysql-test/t/disabled_storage_engines.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
--source include/have_example_plugin.inc
1212
--source include/not_embedded.inc
1313

14+
CALL mtr.add_suppression("default_storage_engine is set to a disabled storage engine .*");
15+
CALL mtr.add_suppression("default_tmp_storage_engine is set to a disabled storage engine .*");
16+
17+
1418
--ERROR ER_DISABLED_STORAGE_ENGINE
1519
CREATE TABLE t1(c1 int) ENGINE=HEAP;
1620

@@ -110,6 +114,9 @@ eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';
110114
CREATE TABLE t1(a int) ENGINE=EXAMPLE;
111115
UNINSTALL PLUGIN example;
112116

117+
SET default_storage_engine=MyISAM;
118+
SET default_tmp_storage_engine=MyISAM;
119+
113120
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
114121
--shutdown_server
115122
--source include/wait_until_disconnected.inc

sql/handler.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,7 @@ bool ha_is_storage_engine_disabled(handlerton *se_handle)
549549
se_name.append(",");
550550
boost::algorithm::to_upper(se_name);
551551
if(strstr(normalized_se_str.c_str(), se_name.c_str()))
552-
{
553-
my_error(ER_DISABLED_STORAGE_ENGINE, MYF(0),
554-
ha_resolve_storage_engine_name(se_handle));
555552
return true;
556-
}
557553
}
558554
return false;
559555
}

sql/mysqld.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4192,6 +4192,22 @@ a file name for --log-bin-index option", opt_binlog_index_name);
41924192
{
41934193
std::string disabled_se_str(opt_disabled_storage_engines);
41944194
ha_set_normalized_disabled_se_str(disabled_se_str);
4195+
4196+
// Log warning if default_storage_engine is a disabled storage engine.
4197+
handlerton *default_se_handle=
4198+
plugin_data<handlerton*>(global_system_variables.table_plugin);
4199+
if (ha_is_storage_engine_disabled(default_se_handle))
4200+
sql_print_warning("default_storage_engine is set to a "
4201+
"disabled storage engine %s.", default_storage_engine);
4202+
4203+
// Log warning if default_tmp_storage_engine is a disabled storage engine.
4204+
handlerton *default_tmp_se_handle=
4205+
plugin_data<handlerton*>(global_system_variables.temp_table_plugin);
4206+
if (ha_is_storage_engine_disabled(default_tmp_se_handle))
4207+
sql_print_warning("default_tmp_storage_engine is set to a "
4208+
"disabled storage engine %s.",
4209+
default_tmp_storage_engine);
4210+
41954211
}
41964212

41974213
if (total_ha_2pc > 1 || (1 == total_ha_2pc && opt_bin_log))

sql/sql_table.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4773,7 +4773,11 @@ bool create_table_impl(THD *thd,
47734773
// Check if new table creation is disallowed by the storage engine.
47744774
if (!internal_tmp_table &&
47754775
ha_is_storage_engine_disabled(create_info->db_type))
4776+
{
4777+
my_error(ER_DISABLED_STORAGE_ENGINE, MYF(0),
4778+
ha_resolve_storage_engine_name(create_info->db_type));
47764779
DBUG_RETURN(true);
4780+
}
47774781

47784782
if (check_engine(thd, db, table_name, create_info))
47794783
DBUG_RETURN(TRUE);
@@ -8557,7 +8561,11 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
85578561
(alter_info->flags & Alter_info::ALTER_OPTIONS) &&
85588562
(create_info->used_fields & HA_CREATE_USED_ENGINE) &&
85598563
ha_is_storage_engine_disabled(create_info->db_type))
8564+
{
8565+
my_error(ER_DISABLED_STORAGE_ENGINE, MYF(0),
8566+
ha_resolve_storage_engine_name(create_info->db_type));
85608567
DBUG_RETURN(true);
8568+
}
85618569

85628570
TABLE *table= table_list->table;
85638571
table->use_all_columns();

sql/sql_tablespace.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info)
145145
if ((ts_info->ts_cmd_type == CREATE_TABLESPACE ||
146146
ts_info->ts_cmd_type == ALTER_TABLESPACE) &&
147147
ha_is_storage_engine_disabled(hton))
148+
{
149+
my_error(ER_DISABLED_STORAGE_ENGINE, MYF(0),
150+
ha_resolve_storage_engine_name(hton));
148151
DBUG_RETURN(true);
152+
}
149153

150154
// If this is a tablespace related command, check the tablespace name
151155
// and acquire and MDL X lock on it.

sql/sys_vars.cc

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,48 @@ static bool check_not_null(sys_var *self, THD *thd, set_var *var)
12221222
{
12231223
return var->value && var->value->is_null();
12241224
}
1225+
1226+
1227+
/**
1228+
Check storage engine is not empty and log warning.
1229+
1230+
Checks if default_storage_engine or default_tmp_storage_engine is set
1231+
empty and return true. This method also logs warning if the
1232+
storage engine set is a disabled storage engine specified in
1233+
disabled_storage_engines.
1234+
1235+
@param self pointer to system variable object.
1236+
@param thd Connection handle.
1237+
@param var pointer to set variable object.
1238+
1239+
@return true if the set variable is empty.
1240+
false if the set variable is not empty.
1241+
*/
1242+
static bool check_storage_engine(sys_var *self, THD *thd, set_var *var)
1243+
{
1244+
if (check_not_null(self,thd,var))
1245+
return true;
1246+
1247+
if (!opt_bootstrap && !opt_noacl)
1248+
{
1249+
char buff[STRING_BUFFER_USUAL_SIZE];
1250+
String str(buff,sizeof(buff), system_charset_info), *res;
1251+
res= var->value->val_str(&str);
1252+
LEX_STRING se_name= { const_cast<char*>(res->ptr()), res->length() };
1253+
1254+
plugin_ref plugin;
1255+
if ((plugin= ha_resolve_by_name(NULL, &se_name, FALSE)))
1256+
{
1257+
handlerton *hton= plugin_data<handlerton*>(plugin);
1258+
if (ha_is_storage_engine_disabled(hton))
1259+
sql_print_warning("%s is set to a disabled storage engine %s.",
1260+
self->name.str, se_name.str);
1261+
plugin_unlock(NULL, plugin);
1262+
}
1263+
}
1264+
return false;
1265+
}
1266+
12251267
static bool check_charset(sys_var *self, THD *thd, set_var *var)
12261268
{
12271269
if (!var->value)
@@ -3959,7 +4001,7 @@ static Sys_var_plugin Sys_default_storage_engine(
39594001
"default_storage_engine", "The default storage engine for new tables",
39604002
SESSION_VAR(table_plugin), NO_CMD_LINE,
39614003
MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_storage_engine),
3962-
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_not_null));
4004+
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_storage_engine));
39634005

39644006
const char *internal_tmp_disk_storage_engine_names[] = { "MYISAM", "INNODB", 0};
39654007
static Sys_var_enum Sys_internal_tmp_disk_storage_engine(
@@ -3972,7 +4014,7 @@ static Sys_var_plugin Sys_default_tmp_storage_engine(
39724014
"default_tmp_storage_engine", "The default storage engine for new explict temporary tables",
39734015
SESSION_VAR(temp_table_plugin), NO_CMD_LINE,
39744016
MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_tmp_storage_engine),
3975-
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_not_null));
4017+
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_storage_engine));
39764018

39774019
#if defined(ENABLED_DEBUG_SYNC)
39784020
/*

0 commit comments

Comments
 (0)