Commit cc76953c authored by Georgi Kodinov's avatar Georgi Kodinov

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.
parent 4adc0476
...@@ -740,17 +740,55 @@ cmd="$cmd $args" ...@@ -740,17 +740,55 @@ cmd="$cmd $args"
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null" test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
log_notice "Starting $MYSQLD daemon with databases from $DATADIR" 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 while true
do do
rm -f $safe_mysql_unix_port "$pid_file" # Some extra safety rm -f $safe_mysql_unix_port "$pid_file" # Some extra safety
start_time=`date +%M%S`
eval_log_error "$cmd" eval_log_error "$cmd"
end_time=`date +%M%S`
if test ! -f "$pid_file" # This is removed if normal shutdown if test ! -f "$pid_file" # This is removed if normal shutdown
then then
break break
fi 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 if @TARGET_LINUX@ && test $KILL_MYSQLD -eq 1
then then
# Test if one process was hanging. # Test if one process was hanging.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment