Skip to content

Commit

Permalink
Merge pull request #1447 from laurynas-biveinis/bug1537554-5.7
Browse files Browse the repository at this point in the history
Bug1537554 5.7
  • Loading branch information
laurynas-biveinis committed Feb 23, 2017
2 parents 5e82516 + b36a8e9 commit 2d2d36e
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 19 deletions.
53 changes: 53 additions & 0 deletions mysql-test/include/percona_signal_handling.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Test the effect of various signals on the server
#
--let $test_error_log= $MYSQLTEST_VARDIR/tmp/test_threadpool_sig_handler.err
--let $restart_parameters=restart:--log-error=$test_error_log
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--source include/restart_mysqld.inc

SELECT @@GLOBAL.thread_handling;

--let $mysqld_pid_file=`SELECT @@GLOBAL.pid_file`

--echo # Test SIGPIPE, SIGTSTP, SIGINT, which should be ignored
exec kill -PIPE `cat $mysqld_pid_file`;
exec kill -TSTP `cat $mysqld_pid_file`;
exec kill -INT `cat $mysqld_pid_file`;

--echo # Test SIGHUP, which should result in status dump in the error log
exec kill -HUP `cat $mysqld_pid_file`;

SELECT 1;

--echo #
--echo # Bug 805805: attaching to percona-server with gdb disconnects clients
--echo # Bug 1060136: safe_process.cc/safe_process.pl should not kill mysqld on SIGSTOP/SIGCONT
--echo #

exec kill -STOP `cat $mysqld_pid_file`;
exec kill -CONT `cat $mysqld_pid_file`;

SELECT 1;

--echo #
--echo # Bug 1537554: SIGTERM kills server instead of shutdown w/ threadpool
--echo #

--source include/expect_crash.inc
exec kill -TERM `cat $mysqld_pid_file`;
--source include/wait_until_disconnected.inc

--let $restart_parameters=
--source include/start_mysqld.inc

# Test for SIGHUP output
--let SEARCH_FILE=$test_error_log
--let SEARCH_PATTERN=Status information:
--source include/search_pattern_in_file.inc

# Test for SIGTERM output
--let SEARCH_PATTERN=mysqld.*: Shutdown complete
--source include/search_pattern_in_file.inc

--remove_file $test_error_log
2 changes: 1 addition & 1 deletion mysql-test/include/wait_until_disconnected.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if ($disconnect_timeout)
let $mysql_errno= 0;
while (!$mysql_errno)
{
--error 0,1040,1053,2002,2003,2006,2013
--error 0,1040,1053,1317,2002,2003,2006,2013
show session status;

dec $counter;
Expand Down
26 changes: 23 additions & 3 deletions mysql-test/r/percona_signal_handling.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
SELECT 2+2;
2+2
4
#
# Test server signal handling with one-thread-per-connection handler
#
# restart:--log-error=MYSQLTEST_VARDIR/tmp/test_threadpool_sig_handler.err
SELECT @@GLOBAL.thread_handling;
@@GLOBAL.thread_handling
one-thread-per-connection
# Test SIGPIPE, SIGTSTP, SIGINT, which should be ignored
# Test SIGHUP, which should result in status dump in the error log
SELECT 1;
1
1
#
# Bug 805805: attaching to percona-server with gdb disconnects clients
# Bug 1060136: safe_process.cc/safe_process.pl should not kill mysqld on SIGSTOP/SIGCONT
#
SELECT 1;
1
1
#
# Bug 1537554: SIGTERM kills server instead of shutdown w/ threadpool
#
# restart
23 changes: 23 additions & 0 deletions mysql-test/r/percona_signal_handling_threadpool.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Test server signal handling with threadpool
#
# restart:--log-error=MYSQLTEST_VARDIR/tmp/test_threadpool_sig_handler.err
SELECT @@GLOBAL.thread_handling;
@@GLOBAL.thread_handling
pool-of-threads
# Test SIGPIPE, SIGTSTP, SIGINT, which should be ignored
# Test SIGHUP, which should result in status dump in the error log
SELECT 1;
1
1
#
# Bug 805805: attaching to percona-server with gdb disconnects clients
# Bug 1060136: safe_process.cc/safe_process.pl should not kill mysqld on SIGSTOP/SIGCONT
#
SELECT 1;
1
1
#
# Bug 1537554: SIGTERM kills server instead of shutdown w/ threadpool
#
# restart
14 changes: 6 additions & 8 deletions mysql-test/t/percona_signal_handling.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# A regression testcase for:
# - bug 1060136: verifies that the server is not killed on SIGSTOP;
# - bug 805805: verifies that the connection to the server is not killed on SIGSTOP/SIGCONT.
--source include/not_embedded.inc
--source include/not_windows.inc
--source include/one_thread_per_connection.inc

let $mysqld_pid_file=`SELECT @@GLOBAL.pid_file`;
--echo #
--echo # Test server signal handling with one-thread-per-connection handler
--echo #

exec kill -STOP `cat $mysqld_pid_file`;
exec kill -CONT `cat $mysqld_pid_file`;

SELECT 2+2;
--source include/percona_signal_handling.inc
1 change: 1 addition & 0 deletions mysql-test/t/percona_signal_handling_threadpool-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--thread-handling=pool-of-threads
9 changes: 9 additions & 0 deletions mysql-test/t/percona_signal_handling_threadpool.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--source include/not_embedded.inc
--source include/not_windows.inc
--source include/have_pool_of_threads.inc

--echo #
--echo # Test server signal handling with threadpool
--echo #

--source include/percona_signal_handling.inc
23 changes: 16 additions & 7 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4868,6 +4868,22 @@ int mysqld_main(int argc, char **argv)

my_init_signals();

#ifndef EMBEDDED_LIBRARY
// Move connection handler initialization after the signal handling has been
// set up. Percona Server threadpool constructor is heavy, and creates a
// timer thread. If done before my_init_signals(), this thread will have
// the default signal mask, breaking SIGTERM etc. handing.
// This is not a problem with upstream loadable thread scheduler plugins, as
// its constructor is light and actual initialization is done later.
// This bit should be reverted once Percona Server threadpool becomes a
// plugin.
if (Connection_handler_manager::init())
{
sql_print_error("Could not allocate memory for connection handling");
unireg_abort(MYSQLD_ABORT_EXIT);
}
#endif

size_t guardize= 0;
#ifndef _WIN32
int retval= pthread_attr_getguardsize(&connection_attrib, &guardize);
Expand Down Expand Up @@ -8169,13 +8185,6 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
&global_datetime_format))
return 1;

#ifndef EMBEDDED_LIBRARY
if (Connection_handler_manager::init())
{
sql_print_error("Could not allocate memory for connection handling");
return 1;
}
#endif
if (Global_THD_manager::create_instance())
{
sql_print_error("Could not allocate memory for thread handling");
Expand Down

0 comments on commit 2d2d36e

Please sign in to comment.