3693 Georgi Kodinov 2012-01-17 [merge]
merged bug #11754014
modified:
include/my_global.h
mysql-test/suite/sys_vars/r/character_sets_dir_basic.result
mysql-test/suite/sys_vars/r/plugin_dir_basic.result
mysql-test/suite/sys_vars/t/character_sets_dir_basic.test
sql/mysqld.cc
sql/sql_plugin.cc
sql/sql_udf.cc
3692 Georgi Kodinov 2011-11-10
Bug #11761530: 54035: MSYQLD_SAFE BEHAVIOUR CONSUMES TOO MUCH CPU IF IT IS UNABLE TO RESTART MY
Added a trottling mechanism to mysqld_safe.
On every 5 sub-second restarts it will wait for a second before attempting again.
Note that this requires 'sleep' and 'date' command line utilities.
The code would adjust and will do nothing if any of them is not present.
modified:
scripts/mysqld_safe.sh
3691 Nirbhay Choubey 2012-01-17 [merge]
Null-merge from mysql-5.1.
=== modified file 'include/my_global.h'
--- a/include/my_global.h 2011-09-21 10:40:41 +0000
+++ b/include/my_global.h 2012-01-16 10:04:28 +0000
@@ -1364,11 +1364,31 @@ do { doubleget_union _tmp; \
#ifndef HAVE_DLERROR
#ifdef _WIN32
+#define DLERROR_GENERATE(errmsg, error_number) \
+ char win_errormsg[2048]; \
+ if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, \
+ 0, error_number, 0, win_errormsg, 2048, NULL)) \
+ { \
+ char *ptr; \
+ for (ptr= &win_errormsg[0] + strlen(win_errormsg) - 1; \
+ ptr >= &win_errormsg[0] && strchr("\r\n\t\0x20", *ptr); \
+ ptr--) \
+ *ptr= 0; \
+ errmsg= win_errormsg; \
+ } \
+ else \
+ errmsg= ""
#define dlerror() ""
-#else
+#define dlopen_errno GetLastError()
+#else /* _WIN32 */
#define dlerror() "No support for dynamic loading (static build?)"
-#endif
-#endif
+#define DLERROR_GENERATE(errmsg, error_number) errmsg= dlerror()
+#define dlopen_errno errno
+#endif /* _WIN32 */
+#else /* HAVE_DLERROR */
+#define DLERROR_GENERATE(errmsg, error_number) errmsg= dlerror()
+#define dlopen_errno errno
+#endif /* HAVE_DLERROR */
/*
=== modified file 'mysql-test/suite/sys_vars/r/character_sets_dir_basic.result'
--- a/mysql-test/suite/sys_vars/r/character_sets_dir_basic.result 2010-02-17 03:14:09 +0000
+++ b/mysql-test/suite/sys_vars/r/character_sets_dir_basic.result 2012-01-16 10:04:28 +0000
@@ -1,20 +1,20 @@
select @@global.character_sets_dir;
@@global.character_sets_dir
-MYSQL_CHARSETSDIR/
+MYSQL_CHARSETSDIR
select @@session.character_sets_dir;
ERROR HY000: Variable 'character_sets_dir' is a GLOBAL variable
show global variables like 'character_sets_dir';
Variable_name Value
-character_sets_dir MYSQL_CHARSETSDIR/
+character_sets_dir MYSQL_CHARSETSDIR
show session variables like 'character_sets_dir';
Variable_name Value
-character_sets_dir MYSQL_CHARSETSDIR/
+character_sets_dir MYSQL_CHARSETSDIR
select * from information_schema.global_variables where variable_name='character_sets_dir';
VARIABLE_NAME VARIABLE_VALUE
-CHARACTER_SETS_DIR MYSQL_CHARSETSDIR/
+CHARACTER_SETS_DIR MYSQL_CHARSETSDIR
select * from information_schema.session_variables where variable_name='character_sets_dir';
VARIABLE_NAME VARIABLE_VALUE
-CHARACTER_SETS_DIR MYSQL_CHARSETSDIR/
+CHARACTER_SETS_DIR MYSQL_CHARSETSDIR
set global character_sets_dir="foo";
ERROR HY000: Variable 'character_sets_dir' is a read only variable
set session character_sets_dir="foo";
=== modified file 'mysql-test/suite/sys_vars/r/plugin_dir_basic.result'
--- a/mysql-test/suite/sys_vars/r/plugin_dir_basic.result 2011-08-16 09:08:10 +0000
+++ b/mysql-test/suite/sys_vars/r/plugin_dir_basic.result 2012-01-16 10:04:28 +0000
@@ -1,20 +1,20 @@
select @@global.plugin_dir;
@@global.plugin_dir
-MYSQL_TMP_DIR
+MYSQL_TMP_DIR/
select @@session.plugin_dir;
ERROR HY000: Variable 'plugin_dir' is a GLOBAL variable
show global variables like 'plugin_dir';
Variable_name Value
-plugin_dir MYSQL_TMP_DIR
+plugin_dir MYSQL_TMP_DIR/
show session variables like 'plugin_dir';
Variable_name Value
-plugin_dir MYSQL_TMP_DIR
+plugin_dir MYSQL_TMP_DIR/
select * from information_schema.global_variables where variable_name='plugin_dir';
VARIABLE_NAME VARIABLE_VALUE
-PLUGIN_DIR MYSQL_TMP_DIR
+PLUGIN_DIR MYSQL_TMP_DIR/
select * from information_schema.session_variables where variable_name='plugin_dir';
VARIABLE_NAME VARIABLE_VALUE
-PLUGIN_DIR MYSQL_TMP_DIR
+PLUGIN_DIR MYSQL_TMP_DIR/
set global plugin_dir=1;
ERROR HY000: Variable 'plugin_dir' is a read only variable
set session plugin_dir=1;
=== modified file 'mysql-test/suite/sys_vars/t/character_sets_dir_basic.test'
--- a/mysql-test/suite/sys_vars/t/character_sets_dir_basic.test 2010-02-17 03:14:09 +0000
+++ b/mysql-test/suite/sys_vars/t/character_sets_dir_basic.test 2012-01-16 10:04:28 +0000
@@ -1,17 +1,26 @@
#
# show the global and session values;
#
---replace_result $MYSQL_CHARSETSDIR MYSQL_CHARSETSDIR
+
+# workaround to adjust for the directory separators being different in
+# different OSes : slash on unixes and backslash or slash on windows.
+# TODO: fix with a proper comparison in mysqltest
+let $rcd= `SELECT REPLACE('$MYSQL_CHARSETSDIR', '\\\\\', '.')`;
+let $rcd= `SELECT REPLACE('$rcd', '/', '.')`;
+let $regex_charsetdir= `SELECT '/$rcd[\\\\\/\\\\\]/MYSQL_CHARSETSDIR/'`;
+
+--replace_regex $regex_charsetdir
select @@global.character_sets_dir;
+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.character_sets_dir;
---replace_result $MYSQL_CHARSETSDIR MYSQL_CHARSETSDIR
+--replace_regex $regex_charsetdir
show global variables like 'character_sets_dir';
---replace_result $MYSQL_CHARSETSDIR MYSQL_CHARSETSDIR
+--replace_regex $regex_charsetdir
show session variables like 'character_sets_dir';
---replace_result $MYSQL_CHARSETSDIR MYSQL_CHARSETSDIR
+--replace_regex $regex_charsetdir
select * from information_schema.global_variables where variable_name='character_sets_dir';
---replace_result $MYSQL_CHARSETSDIR MYSQL_CHARSETSDIR
+--replace_regex $regex_charsetdir
select * from information_schema.session_variables where variable_name='character_sets_dir';
#
=== modified file 'scripts/mysqld_safe.sh'
--- a/scripts/mysqld_safe.sh 2011-11-17 08:13:43 +0000
+++ b/scripts/mysqld_safe.sh 2011-11-10 13:46:51 +0000
@@ -740,17 +740,55 @@ cmd="$cmd $args"
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
+
+# variable to track the current number of "fast" (a.k.a. subsecond) restarts
+fast_restart=0
+# maximum number of restarts before trottling kicks in
+max_fast_restarts=5
+# flag whether a usable sleep command exists
+have_sleep=1
+
while true
do
rm -f $safe_mysql_unix_port "$pid_file" # Some extra safety
+ start_time=`date +%M%S`
+
eval_log_error "$cmd"
+ end_time=`date +%M%S`
+
if test ! -f "$pid_file" # This is removed if normal shutdown
then
break
fi
+
+ # sanity check if time reading is sane and there's sleep
+ if test $end_time -gt 0 -a $have_sleep -gt 0
+ then
+ # throttle down the fast restarts
+ if test $end_time -eq $start_time
+ then
+ fast_restart=`expr $fast_restart + 1`
+ if test $fast_restart -ge $max_fast_restarts
+ then
+ log_notice "The server is respawning too fast. Sleeping for 1 second."
+ sleep 1
+ sleep_state=$?
+ if test $sleep_state -gt 0
+ then
+ log_notice "The server is respawning too fast and no working sleep command. Turning off trottling."
+ have_sleep=0
+ fi
+
+ fast_restart=0
+ fi
+ else
+ fast_restart=0
+ fi
+ fi
+
if @TARGET_LINUX@ && test $KILL_MYSQLD -eq 1
then
# Test if one process was hanging.
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc 2011-12-13 15:44:19 +0000
+++ b/sql/mysqld.cc 2012-01-17 09:38:34 +0000
@@ -7476,8 +7476,10 @@ static int fix_paths(void)
(void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir
(void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
(void) my_load_path(pidfile_name, pidfile_name_ptr, mysql_real_data_home);
- (void) my_load_path(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr :
- get_relative_path(PLUGINDIR), mysql_home);
+
+ convert_dirname(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr :
+ get_relative_path(PLUGINDIR), NullS);
+ (void) my_load_path(opt_plugin_dir, opt_plugin_dir, mysql_home);
opt_plugin_dir_ptr= opt_plugin_dir;
my_realpath(mysql_unpacked_real_data_home, mysql_real_data_home, MYF(0));
=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc 2011-11-10 06:43:34 +0000
+++ b/sql/sql_plugin.cc 2012-01-16 10:04:28 +0000
@@ -463,18 +463,22 @@ static st_plugin_dl *plugin_dl_add(const
dlpathlen=
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS) -
dlpath;
+ (void) unpack_filename(dlpath, dlpath);
plugin_dl.ref_count= 1;
/* Open new dll handle */
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
{
- const char *errmsg=dlerror();
+ const char *errmsg;
+ int error_number= dlopen_errno;
+ DLERROR_GENERATE(errmsg, error_number);
+
if (!strncmp(dlpath, errmsg, dlpathlen))
{ // if errmsg starts from dlpath, trim this prefix.
errmsg+=dlpathlen;
if (*errmsg == ':') errmsg++;
if (*errmsg == ' ') errmsg++;
}
- report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, errno, errmsg);
+ report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, error_number, errmsg);
DBUG_RETURN(0);
}
/* Determine interface version */
=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc 2011-06-30 15:46:53 +0000
+++ b/sql/sql_udf.cc 2012-01-16 10:04:28 +0000
@@ -221,10 +221,15 @@ void udf_init()
char dlpath[FN_REFLEN];
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", tmp->dl,
NullS);
+ (void) unpack_filename(dlpath, dlpath);
if (!(dl= dlopen(dlpath, RTLD_NOW)))
{
+ const char *errmsg;
+ int error_number= dlopen_errno;
+ DLERROR_GENERATE(errmsg, error_number);
+
/* Print warning to log */
- sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl, errno, dlerror());
+ sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl, error_number, errmsg);
/* Keep the udf in the hash so that we can remove it later */
continue;
}
@@ -469,12 +474,18 @@ int mysql_create_function(THD *thd,udf_f
{
char dlpath[FN_REFLEN];
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", udf->dl, NullS);
+ (void) unpack_filename(dlpath, dlpath);
+
if (!(dl = dlopen(dlpath, RTLD_NOW)))
{
+ const char *errmsg;
+ int error_number= dlopen_errno;
+ DLERROR_GENERATE(errmsg, error_number);
+
DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)",
- udf->dl, errno, dlerror()));
+ udf->dl, error_number, errmsg));
my_error(ER_CANT_OPEN_LIBRARY, MYF(0),
- udf->dl, errno, dlerror());
+ udf->dl, error_number, errmsg);
goto err;
}
new_dl=1;
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-5.5 branch (Georgi.Kodinov:3691 to 3693) Bug#11754014 | Georgi Kodinov | 17 Jan |