Skip to content

Commit daecacf

Browse files
Nisha Gopalakrishnanltangvald
authored andcommitted
Bug#28867993: POSSIBLE ISSUE WITH MYSQL SERVER RESTART
Analysis ======== Creation of database with the same name as of redo log files is allowed. We currently do not restrict creation of databases with the same name as redo log files. This may cause issues during server start-up. Fix === Creation of databases with names which are same as the redo log file names are not allowed. (cherry picked from commit 2a58dc71a18ba644ddbd63413fcc7ebeca74cdb0)
1 parent a91c19e commit daecacf

File tree

6 files changed

+99
-5
lines changed

6 files changed

+99
-5
lines changed

sql/handler.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7794,3 +7794,39 @@ void warn_fk_constraint_violation(THD *thd,TABLE *table, int error)
77947794
break;
77957795
}
77967796
}
7797+
7798+
7799+
/**
7800+
Checks if the file name is reserved word used by SE by invoking
7801+
the handlerton method.
7802+
7803+
@param unused1 thread handler which is unused.
7804+
@param plugin SE plugin.
7805+
@param name Database name.
7806+
7807+
@retval true If the name is reserved word.
7808+
@retval false If the name is not reserved word.
7809+
*/
7810+
static my_bool is_reserved_db_name_handlerton(THD *unused1, plugin_ref plugin,
7811+
void *name)
7812+
{
7813+
handlerton *hton= plugin_data(plugin, handlerton *);
7814+
if (hton->state == SHOW_OPTION_YES && hton->is_reserved_db_name)
7815+
return (hton->is_reserved_db_name(hton, (const char *)name));
7816+
return false;
7817+
}
7818+
7819+
7820+
/**
7821+
Check if the file name is reserved word used by SE.
7822+
7823+
@param name Database name.
7824+
7825+
@retval true If the name is a reserved word.
7826+
@retval false If the name is not a reserved word.
7827+
*/
7828+
bool ha_check_reserved_db_name(const char* name)
7829+
{
7830+
return (plugin_foreach(NULL, is_reserved_db_name_handlerton,
7831+
MYSQL_STORAGE_ENGINE_PLUGIN, (char *)name));
7832+
}

sql/handler.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define HANDLER_INCLUDED
33

44
/*
5-
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
5+
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
66
77
This program is free software; you can redistribute it and/or
88
modify it under the terms of the GNU General Public License
@@ -888,6 +888,17 @@ struct handlerton
888888
const char *table_name,
889889
bool is_sql_layer_system_table);
890890

891+
/**
892+
Check if the given database name is reserved.
893+
894+
@param hton Handlerton for SE.
895+
@param name Database name.
896+
897+
@retval true Database name is reserved by SE.
898+
@retval false Database name is not reserved.
899+
*/
900+
bool (*is_reserved_db_name)(handlerton *hton, const char *name);
901+
891902
uint32 license; /* Flag for Engine License */
892903
void *data; /* Location for engines to keep personal structures */
893904
};
@@ -3458,5 +3469,6 @@ inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
34583469
void print_keydup_error(TABLE *table, KEY *key, const char *msg, myf errflag);
34593470
void print_keydup_error(TABLE *table, KEY *key, myf errflag);
34603471
void warn_fk_constraint_violation(THD *thd, TABLE *table, int error);
3472+
bool ha_check_reserved_db_name(const char *name);
34613473

34623474
#endif /* HANDLER_INCLUDED */

sql/sql_db.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -567,6 +567,12 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
567567
(void)global_schema_lock.lock();
568568
#endif
569569

570+
if (ha_check_reserved_db_name(db))
571+
{
572+
my_error(ER_WRONG_DB_NAME, MYF(0), db);
573+
DBUG_RETURN(-1);
574+
}
575+
570576
if (lock_schema_name(thd, db))
571577
DBUG_RETURN(-1);
572578

storage/innobase/handler/ha_innodb.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,17 @@ normalize_table_name_low(
11211121
ibool set_lower_case); /* in: TRUE if we want to set
11221122
name to lower case */
11231123

1124+
/*****************************************************************//**
1125+
Checks if the filename name is reserved in InnoDB.
1126+
@return true if the name is reserved */
1127+
static
1128+
bool
1129+
innobase_check_reserved_file_name(
1130+
/*===================*/
1131+
handlerton* hton, /*!< in: handlerton of Innodb */
1132+
const char* name); /*!< in: Name of the database */
1133+
1134+
11241135
/*************************************************************//**
11251136
Check for a valid value of innobase_commit_concurrency.
11261137
@return 0 for valid innodb_commit_concurrency */
@@ -2976,6 +2987,7 @@ innobase_init(
29762987
innobase_release_temporary_latches;
29772988

29782989
innobase_hton->data = &innodb_api_cb;
2990+
innobase_hton->is_reserved_db_name= innobase_check_reserved_file_name;
29792991

29802992
ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
29812993

@@ -17486,3 +17498,30 @@ ib_warn_row_too_big(const dict_table_t* table)
1748617498
" ROW_FORMAT=COMPRESSED ": ""
1748717499
, prefix ? DICT_MAX_FIXED_COL_LEN : 0);
1748817500
}
17501+
17502+
/*****************************************************************//**
17503+
Checks if the file name is reserved in InnoDB. Currently
17504+
redo log files(ib_logfile*) is reserved.
17505+
@return true if the name is reserved */
17506+
static
17507+
bool
17508+
innobase_check_reserved_file_name(
17509+
/*===================*/
17510+
handlerton* hton, /*!< in: handlerton of Innodb */
17511+
const char* name) /*!< in: Name of the database */
17512+
{
17513+
CHARSET_INFO *ci= system_charset_info;
17514+
size_t logname_size = strlen(ib_logfile_basename);
17515+
17516+
/* Name is smaller than reserved name */
17517+
if (strlen(name) < logname_size) {
17518+
return (false);
17519+
}
17520+
/* Do case insensitive comparison for name. */
17521+
for (uint i=0; i < logname_size; i++) {
17522+
if (my_tolower(ci, name[i]) != ib_logfile_basename[i]){
17523+
return (false);
17524+
}
17525+
}
17526+
return (true);
17527+
}

storage/innobase/include/log0log.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
44
Copyright (c) 2009, Google Inc.
55
66
Portions of this file contain modifications contributed and copyrighted by
@@ -62,6 +62,8 @@ extern ibool log_debug_writes;
6262
# define log_do_write TRUE
6363
#endif /* UNIV_DEBUG */
6464

65+
static const char ib_logfile_basename[] = "ib_logfile";
66+
6567
/** Wait modes for log_write_up_to @{ */
6668
#define LOG_NO_WAIT 91
6769
#define LOG_WAIT_ONE_GROUP 92

storage/innobase/log/log0recv.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1997, 2017, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1997, 2018, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2012, Facebook Inc.
55
66
This program is free software; you can redistribute it and/or modify it under
@@ -3589,7 +3589,6 @@ recv_reset_log_files_for_backup(
35893589
ulint i;
35903590
ulint log_dir_len;
35913591
char name[5000];
3592-
static const char ib_logfile_basename[] = "ib_logfile";
35933592

35943593
log_dir_len = strlen(log_dir);
35953594
/* full path name of ib_logfile consists of log dir path + basename

0 commit comments

Comments
 (0)