From a11a7b7a8db6b2151321ae2b3f4a9702de72160a Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Thu, 12 Nov 2009 12:17:31 +0100 Subject: WL#4949, Remove use of LOCK_alarm by instead using SO_SNDTIME0/SO_RCVTIME0 --- configure.in | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/net_serv.cc | 2 ++ 2 files changed, 65 insertions(+) diff --git a/configure.in b/configure.in index 9fe5c741a03..227f7844037 100644 --- a/configure.in +++ b/configure.in @@ -859,9 +859,72 @@ AC_CHECK_DECLS(MHA_MAPSIZE_VA, #include ] ) +fi + +dnl Use of ALARMs to wakeup on timeout on sockets +dnl +dnl This feature makes use of a mutex and is a scalability hog we +dnl try to avoid using. However we need support for SO_SNDTIMEO and +dnl SO_RCVTIMEO socket options for this to work. So we will check +dnl if this feature is supported by a simple AC_RUN_IFELSE macro. However +dnl on some OS's there is support for setting those variables but +dnl they are silently ignored. For those OS's we will not attempt +dnl o use SO_SNDTIMEO and SO_RCVTIMEO even if it is said to work. +dnl See Bug#29093 for the problem with SO_SND/RCVTIMEO on HP/UX. +dnl To use alarm is simple, simply avoid setting anything. + + +AC_CACHE_CHECK([whether SO_SNDTIMEO and SO_RCVTIMEO work], + [mysql_cv_socket_timeout], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[ + #include + #include + #include + ]],[[ + int fd = socket(AF_INET, SOCK_STREAM, 0); + struct timeval tv; + int ret= 0; + tv.tv_sec= 2; + tv.tv_usec= 0; + ret|= setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + ret|= setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + return !!ret; + ]])], + [mysql_cv_socket_timeout=yes], + [mysql_cv_socket_timeout=no], + [mysql_cv_socket_timeout=no + AC_MSG_WARN([Socket timeout options disabled due to cross-compiling])]) + ]) + +use_alarm=yes + +if test "$mysql_cv_socket_timeout" = yes; then + case $SYSTEM_TYPE in + dnl We trust the result from the following systems + *solaris*) use_alarm=no ;; + *freebsd*) use_alarm=no ;; + *darwin*) use_alarm=no ;; + *) + dnl We trust the result from Linux also + if test "$TARGET_LINUX" = "true"; then + use_alarm=no + fi + dnl We trust no one else for the moment + dnl (Windows is hardcoded to not use alarms) + ;; + esac +fi +AC_ARG_WITH(alarm, + AS_HELP_STRING([--with-alarm], [Use alarm to implement socket timeout.]), + [use_alarm=$withval], []) +AC_MSG_CHECKING(whether to use alarms to implement socket timeout) +if test "$use_alarm" = no ; then + AC_DEFINE([NO_ALARM], [1], [No need to use alarm for socket timeout]) fi +AC_MSG_RESULT($use_alarm) #-------------------------------------------------------------------- # Check for TCP wrapper support diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 5cf3597c638..d54ff1d2779 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -71,8 +71,10 @@ #if defined(__WIN__) || !defined(MYSQL_SERVER) /* The following is because alarms doesn't work on windows. */ +#ifndef NO_ALARM #define NO_ALARM #endif +#endif #ifndef NO_ALARM #include "my_pthread.h" -- cgit v1.2.1 From 62c39a339b0b5d57595e98dded3c82cc5fc394ac Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Thu, 26 Nov 2009 13:48:21 +0100 Subject: Fixed kill_alarm test and got it working --- configure.in | 1 + mysql-test/r/kill_alarm.result | 10 ++++++++++ mysql-test/t/kill_alarm.test | 13 +++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 mysql-test/r/kill_alarm.result create mode 100644 mysql-test/t/kill_alarm.test diff --git a/configure.in b/configure.in index 783b4444a28..890fc333cee 100644 --- a/configure.in +++ b/configure.in @@ -923,6 +923,7 @@ AC_ARG_WITH(alarm, AC_MSG_CHECKING(whether to use alarms to implement socket timeout) if test "$use_alarm" = no ; then AC_DEFINE([NO_ALARM], [1], [No need to use alarm for socket timeout]) + AC_DEFINE([SIGNAL_WITH_VIO_CLOSE], [1], [Need to use vio close for kill connection]) fi AC_MSG_RESULT($use_alarm) diff --git a/mysql-test/r/kill_alarm.result b/mysql-test/r/kill_alarm.result new file mode 100644 index 00000000000..27636f55c97 --- /dev/null +++ b/mysql-test/r/kill_alarm.result @@ -0,0 +1,10 @@ +show processlist; +Id User Host db Command Time State Info +2 root localhost test Sleep 0 NULL +3 root localhost test Sleep 0 NULL +4 root localhost test Query 0 NULL show processlist +kill connection 3; +show processlist; +Id User Host db Command Time State Info +2 root localhost test Sleep 4 NULL +4 root localhost test Query 0 NULL show processlist diff --git a/mysql-test/t/kill_alarm.test b/mysql-test/t/kill_alarm.test new file mode 100644 index 00000000000..c08eb3dcf83 --- /dev/null +++ b/mysql-test/t/kill_alarm.test @@ -0,0 +1,13 @@ +-- source include/not_embedded.inc + +connect (con1, localhost, root,,); +connect (con2, localhost, root,,); + +connection con1; +let $ID=`select connection_id()`; + +connection con2; +show processlist; +eval kill connection $ID; +--sleep 4 +show processlist; -- cgit v1.2.1 From 8df0c15b36964eac2dfc259ad59fa692fbb63184 Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Thu, 26 Nov 2009 13:58:59 +0100 Subject: Removed extra test case after review comment --- mysql-test/r/kill_alarm.result | 10 ---------- mysql-test/t/kill_alarm.test | 13 ------------- 2 files changed, 23 deletions(-) delete mode 100644 mysql-test/r/kill_alarm.result delete mode 100644 mysql-test/t/kill_alarm.test diff --git a/mysql-test/r/kill_alarm.result b/mysql-test/r/kill_alarm.result deleted file mode 100644 index 27636f55c97..00000000000 --- a/mysql-test/r/kill_alarm.result +++ /dev/null @@ -1,10 +0,0 @@ -show processlist; -Id User Host db Command Time State Info -2 root localhost test Sleep 0 NULL -3 root localhost test Sleep 0 NULL -4 root localhost test Query 0 NULL show processlist -kill connection 3; -show processlist; -Id User Host db Command Time State Info -2 root localhost test Sleep 4 NULL -4 root localhost test Query 0 NULL show processlist diff --git a/mysql-test/t/kill_alarm.test b/mysql-test/t/kill_alarm.test deleted file mode 100644 index c08eb3dcf83..00000000000 --- a/mysql-test/t/kill_alarm.test +++ /dev/null @@ -1,13 +0,0 @@ --- source include/not_embedded.inc - -connect (con1, localhost, root,,); -connect (con2, localhost, root,,); - -connection con1; -let $ID=`select connection_id()`; - -connection con2; -show processlist; -eval kill connection $ID; ---sleep 4 -show processlist; -- cgit v1.2.1