Commit 013fc02a authored by Vladislav Vaintroub's avatar Vladislav Vaintroub Committed by Daniel Black

MDEV-32567 Remove thr_alarm from server codebase

This allows to simplify net_real_read() and net_real_write() a bit.

Removed some superfluous #ifdef/ifndef MYSQL_SERVER from net_serv.cc
The code always runs in server, either normal or embedded.
Dead code for switching socket between blocking and non-blocking modes,
is also removed.

Removed pthread_kill() with alarm signal that woke up main thread on
server shutdown. Used shutdown(2) on polling sockets instead, to the same
effect.

Removed yet another superstitious pthread_kill(), that ran on non-Windows
in terminate_slave_thread().
parent 3424ed7d
......@@ -384,7 +384,6 @@
#cmakedefine HAVE_GCC_C11_ATOMICS 1
#cmakedefine HAVE_SOLARIS_ATOMIC 1
#cmakedefine NO_FCNTL_NONBLOCK 1
#cmakedefine NO_ALARM 1
#cmakedefine _LARGE_FILES 1
#cmakedefine _LARGEFILE_SOURCE 1
......
......@@ -836,7 +836,6 @@ CHECK_CXX_SOURCE_COMPILES("
"
HAVE_SOLARIS_STYLE_GETHOST)
SET(NO_ALARM 1 CACHE BOOL "No need to use alarm to implement timeout")
# As a consequence of ALARMs no longer being used, thread
# notification for KILL must close the socket to wake up
......
......@@ -181,7 +181,6 @@ extern int my_pthread_create_detached;
#define PTHREAD_CREATE_DETACHED &my_pthread_create_detached
#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_GLOBAL
#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_LOCAL
#define USE_ALARM_THREAD
#endif /* defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) */
#if defined(_BSDI_VERSION) && _BSDI_VERSION < 199910
......
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/* Prototypes when using thr_alarm library functions */
#ifndef _thr_alarm_h
#define _thr_alarm_h
#ifdef __cplusplus
extern "C" {
#endif
#ifndef USE_ALARM_THREAD
#define USE_ONE_SIGNAL_HAND /* One must call process_alarm */
#endif
#ifdef HAVE_rts_threads
#undef USE_ONE_SIGNAL_HAND
#define USE_ALARM_THREAD
#define THR_SERVER_ALARM SIGUSR1
#else
#define THR_SERVER_ALARM SIGALRM
#endif
typedef struct st_alarm_info
{
time_t next_alarm_time;
uint active_alarms;
uint max_used_alarms;
} ALARM_INFO;
void thr_alarm_info(ALARM_INFO *info);
extern my_bool my_disable_thr_alarm;
#ifdef _WIN32
#define DONT_USE_THR_ALARM
#endif
#if defined(DONT_USE_THR_ALARM)
#define USE_ALARM_THREAD
#undef USE_ONE_SIGNAL_HAND
typedef my_bool thr_alarm_t;
typedef my_bool ALARM;
#define thr_alarm_init(A) (*(A))=0
#define thr_alarm_in_use(A) (*(A) != 0)
#define thr_end_alarm(A)
#define thr_alarm(A,B,C) ((*(A)=1)-1)
/* The following should maybe be (*(A)) */
#define thr_got_alarm(A) 0
#define init_thr_alarm(A)
#define thr_alarm_kill(A)
#define resize_thr_alarm(N)
#define end_thr_alarm(A)
#else
#if defined(_WIN32)
typedef struct st_thr_alarm_entry
{
UINT_PTR crono;
} thr_alarm_entry;
#else /* System with posix threads */
typedef int thr_alarm_entry;
#define thr_got_alarm(thr_alarm) (**(thr_alarm))
#endif /* _WIN32 */
typedef thr_alarm_entry* thr_alarm_t;
typedef struct st_alarm {
time_t expire_time;
thr_alarm_entry alarmed; /* set when alarm is due */
pthread_t thread;
my_thread_id thread_id;
uint index_in_queue;
my_bool malloced;
} ALARM;
extern uint thr_client_alarm;
extern pthread_t alarm_thread;
#define thr_alarm_init(A) (*(A))=0
#define thr_alarm_in_use(A) (*(A)!= 0)
void init_thr_alarm(uint max_alarm);
void resize_thr_alarm(uint max_alarms);
my_bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff);
void thr_alarm_kill(my_thread_id thread_id);
void thr_end_alarm(thr_alarm_t *alarmed);
void end_thr_alarm(my_bool free_structures);
sig_handler process_alarm(int);
#ifndef thr_got_alarm
my_bool thr_got_alarm(thr_alarm_t *alrm);
#endif
#endif /* DONT_USE_THR_ALARM */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _thr_alarm_h */
select @@global.debug_no_thread_alarm;
@@global.debug_no_thread_alarm
0
select @@session.debug_no_thread_alarm;
ERROR HY000: Variable 'debug_no_thread_alarm' is a GLOBAL variable
show global variables like 'debug_no_thread_alarm';
Variable_name Value
debug_no_thread_alarm OFF
show session variables like 'debug_no_thread_alarm';
Variable_name Value
debug_no_thread_alarm OFF
select * from information_schema.global_variables where variable_name='debug_no_thread_alarm';
VARIABLE_NAME VARIABLE_VALUE
DEBUG_NO_THREAD_ALARM OFF
select * from information_schema.session_variables where variable_name='debug_no_thread_alarm';
VARIABLE_NAME VARIABLE_VALUE
DEBUG_NO_THREAD_ALARM OFF
set global debug_no_thread_alarm=1;
ERROR HY000: Variable 'debug_no_thread_alarm' is a read only variable
set session debug_no_thread_alarm=1;
ERROR HY000: Variable 'debug_no_thread_alarm' is a read only variable
......@@ -46,21 +46,6 @@ ENUM_VALUE_LIST OFF,ON
READ_ONLY YES
COMMAND_LINE_ARGUMENT OPTIONAL
GLOBAL_VALUE_PATH NULL
VARIABLE_NAME DEBUG_NO_THREAD_ALARM
SESSION_VALUE NULL
GLOBAL_VALUE OFF
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE OFF
VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE BOOLEAN
VARIABLE_COMMENT Disable system thread alarm calls. Disabling it may be useful in debugging or testing, never do it in production
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST OFF,ON
READ_ONLY YES
COMMAND_LINE_ARGUMENT OPTIONAL
GLOBAL_VALUE_PATH NULL
VARIABLE_NAME DEBUG_SYNC
SESSION_VALUE ON - current signals: ''
GLOBAL_VALUE NULL
......
# bool readonly
#
# show values;
#
select @@global.debug_no_thread_alarm;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.debug_no_thread_alarm;
show global variables like 'debug_no_thread_alarm';
show session variables like 'debug_no_thread_alarm';
select * from information_schema.global_variables where variable_name='debug_no_thread_alarm';
select * from information_schema.session_variables where variable_name='debug_no_thread_alarm';
#
# show that it's read-only
#
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
set global debug_no_thread_alarm=1;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
set session debug_no_thread_alarm=1;
......@@ -34,7 +34,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c my_default.c
my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c
my_basename.c
my_write.c ptr_cmp.c queues.c stacktrace.c
string.c thr_alarm.c thr_lock.c thr_mutex.c
string.c thr_lock.c thr_mutex.c
thr_rwlock.c thr_timer.c
tree.c typelib.c base64.c my_memmem.c
my_getpagesize.c
......
......@@ -468,7 +468,7 @@ PSI_mutex_key key_LOCK_localtime_r;
PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock,
key_LOCK_alarm, key_LOCK_timer,
key_LOCK_timer,
key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap,
key_THR_LOCK_lock, key_THR_LOCK_malloc,
key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net,
......@@ -487,7 +487,6 @@ static PSI_mutex_info all_mysys_mutexes[]=
{ &key_IO_CACHE_append_buffer_lock, "IO_CACHE::append_buffer_lock", 0},
{ &key_IO_CACHE_SHARE_mutex, "IO_CACHE::SHARE_mutex", 0},
{ &key_KEY_CACHE_cache_lock, "KEY_CACHE::cache_lock", 0},
{ &key_LOCK_alarm, "LOCK_alarm", PSI_FLAG_GLOBAL},
{ &key_LOCK_timer, "LOCK_timer", PSI_FLAG_GLOBAL},
{ &key_my_thread_var_mutex, "my_thread_var::mutex", 0},
{ &key_THR_LOCK_charset, "THR_LOCK_charset", PSI_FLAG_GLOBAL},
......@@ -504,13 +503,12 @@ static PSI_mutex_info all_mysys_mutexes[]=
{ &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL }
};
PSI_cond_key key_COND_alarm, key_COND_timer, key_IO_CACHE_SHARE_cond,
PSI_cond_key key_COND_timer, key_IO_CACHE_SHARE_cond,
key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,
key_THR_COND_threads, key_WT_RESOURCE_cond;
static PSI_cond_info all_mysys_conds[]=
{
{ &key_COND_alarm, "COND_alarm", PSI_FLAG_GLOBAL},
{ &key_COND_timer, "COND_timer", PSI_FLAG_GLOBAL},
{ &key_IO_CACHE_SHARE_cond, "IO_CACHE_SHARE::cond", 0},
{ &key_IO_CACHE_SHARE_cond_writer, "IO_CACHE_SHARE::cond_writer", 0},
......@@ -526,16 +524,10 @@ static PSI_rwlock_info all_mysys_rwlocks[]=
{ &key_SAFEHASH_mutex, "SAFE_HASH::mutex", 0}
};
#ifdef USE_ALARM_THREAD
PSI_thread_key key_thread_alarm;
#endif
PSI_thread_key key_thread_timer;
static PSI_thread_info all_mysys_threads[]=
{
#ifdef USE_ALARM_THREAD
{ &key_thread_alarm, "alarm", PSI_FLAG_GLOBAL},
#endif
{ &key_thread_timer, "statement_timer", PSI_FLAG_GLOBAL}
};
......
......@@ -20,7 +20,6 @@
#include "mysys_priv.h"
#include <signal.h>
#include <m_string.h>
#include <thr_alarm.h>
#include <my_pthread.h>
#if (defined(__BSD__) || defined(_BSDI_VERSION))
......@@ -234,11 +233,7 @@ void *sigwait_thread(void *set_arg)
sigaction(i, &sact, (struct sigaction*) 0);
}
}
/* Ensure that init_thr_alarm() is called */
DBUG_ASSERT(thr_client_alarm);
sigaddset(set, thr_client_alarm);
pthread_sigmask(SIG_UNBLOCK,(sigset_t*) set,(sigset_t*) 0);
alarm_thread=pthread_self(); /* For thr_alarm */
for (;;)
{ /* Wait for signals */
......
......@@ -43,20 +43,17 @@ extern PSI_mutex_key key_LOCK_localtime_r;
#endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */
extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock, key_LOCK_alarm,
key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock,
key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap,
key_THR_LOCK_lock, key_THR_LOCK_malloc,
key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net,
key_THR_LOCK_open, key_THR_LOCK_threads, key_LOCK_uuid_generator,
key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_timer;
extern PSI_cond_key key_COND_alarm, key_COND_timer, key_IO_CACHE_SHARE_cond,
extern PSI_cond_key key_COND_timer, key_IO_CACHE_SHARE_cond,
key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,
key_THR_COND_threads;
#ifdef USE_ALARM_THREAD
extern PSI_thread_key key_thread_alarm;
#endif /* USE_ALARM_THREAD */
extern PSI_thread_key key_thread_timer;
extern PSI_rwlock_key key_SAFEHASH_mutex;
......
This diff is collapsed.
......@@ -20,7 +20,6 @@
#error You have already included an client_settings.h and it should not be included twice
#endif /* CLIENT_SETTINGS_INCLUDED */
#include <thr_alarm.h>
#include <sql_common.h>
/*
......
......@@ -113,7 +113,6 @@
#include <sys/prctl.h>
#endif
#include <thr_alarm.h>
#include <ft_global.h>
#include <errmsg.h>
#include "sp_rcontext.h"
......@@ -1670,10 +1669,11 @@ static void break_connect_loop()
int UNINIT_VAR(error);
DBUG_PRINT("info",("Waiting for select thread"));
#ifndef DONT_USE_THR_ALARM
if (pthread_kill(select_thread, thr_client_alarm))
break; // allready dead
#endif
for(size_t i=0; i < listen_sockets.size(); i++)
{
int fd=mysql_socket_getfd(listen_sockets.at(i));
shutdown(fd, SHUT_RDWR);
}
set_timespec(abstime, 2);
for (uint tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
{
......@@ -1765,8 +1765,6 @@ static void close_connections(void)
listen_sockets.free_memory();
mysql_mutex_unlock(&LOCK_start_thread);
end_thr_alarm(0); // Abort old alarms.
while (CONNECT::count)
my_sleep(100);
......@@ -1877,10 +1875,6 @@ extern "C" sig_handler print_signal_warning(int sig)
#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
my_sigset(sig,print_signal_warning); /* int. thread system calls */
#endif
#if !defined(_WIN32)
if (sig == SIGALRM)
alarm(2); /* reschedule alarm */
#endif
}
#ifdef _WIN32
......@@ -2027,7 +2021,6 @@ static void clean_up(bool print_message)
multi_keycache_free();
sp_cache_end();
free_status_vars();
end_thr_alarm(1); /* Free allocated memory */
end_thr_timer();
my_free_open_file_info();
if (defaults_argv)
......@@ -3110,8 +3103,6 @@ void init_signals(void)
struct sigaction sa;
DBUG_ENTER("init_signals");
my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called!
if (opt_stack_trace || (test_flags & TEST_CORE_ON_SIGNAL))
{
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
......@@ -3159,7 +3150,6 @@ void init_signals(void)
sa.sa_flags = 0;
sa.sa_handler = print_signal_warning;
sigaction(SIGHUP, &sa, (struct sigaction*) 0);
sigaddset(&set,THR_SERVER_ALARM);
if (test_flags & TEST_SIGINT)
{
/* Allow SIGINT to break mysqld. This is for debugging with --gdb */
......@@ -3220,7 +3210,7 @@ pthread_handler_t kill_server_thread(void *arg __attribute__((unused)))
#endif
/** This threads handles all signals and alarms. */
/** This threads handles all signals */
/* ARGSUSED */
pthread_handler_t signal_hand(void *arg __attribute__((unused)))
{
......@@ -3230,13 +3220,6 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
DBUG_ENTER("signal_hand");
signal_thread_in_use= 1;
/*
Setup alarm handler
This should actually be '+ max_number_of_slaves' instead of +10,
but the +10 should be quite safe.
*/
init_thr_alarm(thread_scheduler->max_threads + extra_max_connections +
global_system_variables.max_insert_delayed_threads + 10);
if (test_flags & TEST_SIGINT)
{
/* Allow SIGINT to break mysqld. This is for debugging with --gdb */
......@@ -3245,9 +3228,6 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
(void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
}
(void) sigemptyset(&set); // Setup up SIGINT for debug
#ifdef USE_ONE_SIGNAL_HAND
(void) sigaddset(&set,THR_SERVER_ALARM); // For alarms
#endif
#ifndef IGNORE_SIGHUP_SIGQUIT
(void) sigaddset(&set,SIGQUIT);
(void) sigaddset(&set,SIGHUP);
......@@ -3311,7 +3291,7 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
error);
#else
my_sigset(sig, SIG_IGN);
break_connect_loop(); // MIT THREAD has a alarm thread
break_connect_loop();
#endif
}
break;
......@@ -3341,11 +3321,6 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
opt_log ? fixed_log_output_options : LOG_NONE);
}
break;
#ifdef USE_ONE_SIGNAL_HAND
case THR_SERVER_ALARM:
process_alarm(sig); // Trigger alarms.
break;
#endif
default:
#ifdef EXTRA_DEBUG
sql_print_warning("Got signal: %d error: %d",sig,error); /* purecov: tested */
......@@ -5854,7 +5829,7 @@ int mysqld_main(int argc, char **argv)
#endif
/*
init signals & alarm
init signals
After this we can't quit by a simple unireg_abort
*/
start_signal_handler(); // Creates pidfile
......
This diff is collapsed.
......@@ -36,7 +36,6 @@
#include "rpl_filter.h"
#include "repl_failsafe.h"
#include "transaction.h"
#include <thr_alarm.h>
#include <my_dir.h>
#include <sql_common.h>
#include <errmsg.h>
......@@ -1075,24 +1074,11 @@ terminate_slave_thread(THD *thd,
mysql_mutex_lock(&thd->LOCK_thd_kill);
mysql_mutex_lock(&thd->LOCK_thd_data);
#ifndef DONT_USE_THR_ALARM
/*
Error codes from pthread_kill are:
EINVAL: invalid signal number (can't happen)
ESRCH: thread already killed (can happen, should be ignored)
*/
int err __attribute__((unused))= pthread_kill(thd->real_id, thr_client_alarm);
DBUG_ASSERT(err != EINVAL);
#endif
thd->awake_no_mutex(NOT_KILLED);
mysql_mutex_unlock(&thd->LOCK_thd_kill);
mysql_mutex_unlock(&thd->LOCK_thd_data);
/*
There is a small chance that slave thread might miss the first
alarm. To protect againts it, resend the signal until it reacts
*/
struct timespec abstime;
set_timespec(abstime,2);
error= mysql_cond_timedwait(term_cond, term_lock, &abstime);
......
......@@ -48,7 +48,6 @@
#include "sql_audit.h"
#include <m_ctype.h>
#include <sys/stat.h>
#include <thr_alarm.h>
#include <mysys_err.h>
#include <limits.h>
......@@ -1903,9 +1902,6 @@ void THD::awake_no_mutex(killed_state state_to_set)
}
#endif
/* Mark the target thread's alarm request expired, and signal alarm. */
thr_alarm_kill(thread_id);
/* Send an event to the scheduler that a thread should be killed. */
if (!slave_thread)
MYSQL_CALLBACK(scheduler, post_kill_notification, (this));
......
......@@ -26,7 +26,6 @@
#include "keycaches.h"
#include "my_json_writer.h"
#include <hash.h>
#include <thr_alarm.h>
#include "sql_connect.h"
#include "thread_cache.h"
#if defined(HAVE_MALLINFO) && defined(HAVE_MALLOC_H)
......@@ -611,17 +610,6 @@ Open streams: %10lu\n",
my_file_opened,
my_stream_opened);
#ifndef DONT_USE_THR_ALARM
ALARM_INFO alarm_info;
thr_alarm_info(&alarm_info);
printf("\nAlarm status:\n\
Active alarms: %u\n\
Max used alarms: %u\n\
Next alarm time: %lu\n",
alarm_info.active_alarms,
alarm_info.max_used_alarms,
(ulong)alarm_info.next_alarm_time);
#endif
display_table_locks();
#if defined(HAVE_MALLINFO2)
struct mallinfo2 info = mallinfo2();
......
......@@ -38,7 +38,6 @@
#include "my_sys.h"
#include "events.h"
#include <thr_alarm.h>
#include "slave.h"
#include "rpl_mi.h"
#include "rpl_filter.h"
......@@ -1735,10 +1734,6 @@ Sys_max_binlog_size(
static bool fix_max_connections(sys_var *self, THD *thd, enum_var_type type)
{
#ifndef EMBEDDED_LIBRARY
resize_thr_alarm(max_connections + extra_max_connections +
global_system_variables.max_insert_delayed_threads + 10);
#endif
return false;
}
......@@ -6753,13 +6748,6 @@ static Sys_var_enum Sys_histogram_type(
SESSION_VAR(histogram_type), CMD_LINE(REQUIRED_ARG),
histogram_types, DEFAULT(2));
static Sys_var_mybool Sys_no_thread_alarm(
"debug_no_thread_alarm",
"Disable system thread alarm calls. Disabling it may be useful "
"in debugging or testing, never do it in production",
READ_ONLY GLOBAL_VAR(my_disable_thr_alarm), CMD_LINE(OPT_ARG),
DEFAULT(FALSE));
static Sys_var_mybool Sys_query_cache_strip_comments(
"query_cache_strip_comments",
"Strip all comments from a query before storing it "
......
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