From 5e90d39db91cee9dd9c43e4d4442a531277a7520 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Mar 2001 23:07:12 -0700 Subject: changed signal by fd close to signal by vio_close added support for kill expr fixed coredump in set @a := foo; added testcase for user_var added testcase for kill sql/slave.cc: fd -> vio sql/sql_class.cc: fd->vio, fixed coredump on set @a := foo; sql/sql_class.h: fd -> vio sql/sql_repl.cc: fd -> vio sql/sql_yacc.yy: added support for kill expr - needed this for a clean test case of kill --- sql/slave.cc | 8 +++---- sql/sql_class.cc | 34 +++++++++++++++++++++++++----- sql/sql_class.h | 64 +++++++++++++++++++------------------------------------- sql/sql_repl.cc | 4 ++-- sql/sql_yacc.yy | 11 +++++++--- 5 files changed, 64 insertions(+), 57 deletions(-) (limited to 'sql') diff --git a/sql/slave.cc b/sql/slave.cc index 37e11d43573..be1d919c4cd 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1381,8 +1381,8 @@ static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) { mysql_log.write(thd, COM_CONNECT_OUT, "%s@%s:%d", mi->user, mi->host, mi->port); -#ifdef STOP_IO_WITH_FD_CLOSE - thd->set_active_fd(vio_fd(mysql->net.vio)); +#ifdef SIGNAL_WITH_VIO_CLOSE + thd->set_active_vio(mysql->net.vio); #endif } @@ -1417,8 +1417,8 @@ replication resumed in log '%s' at position %s", glob_mi.user, glob_mi.host, glob_mi.port, RPL_LOG_NAME, llstr(glob_mi.pos,llbuff)); -#ifdef STOP_IO_WITH_FD_CLOSE - thd->set_active_fd(vio_fd(mysql->net.vio)); +#ifdef SIGNAL_WITH_VIO_CLOSE + thd->set_active_vio(mysql->net.vio); #endif } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1bced49be57..925061594a9 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -30,6 +30,7 @@ #include "sql_acl.h" #include #include +#include #ifdef __WIN__ #include #endif @@ -79,14 +80,15 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), global_read_lock(0),bootstrap(0) { proc_info="login"; + where="field list"; host=user=priv_user=db=query=ip=0; locked=killed=count_cuted_fields=some_tables_deleted=no_errors=password= query_start_used=0; query_length=col_access=0; query_error=0; -#ifdef STOP_IO_WITH_FD_CLOSE - active_fd = -1; - pthread_mutex_init(&active_fd_lock, NULL); +#ifdef SIGNAL_WITH_VIO_CLOSE + active_vio = 0; + pthread_mutex_init(&active_vio_lock, NULL); #endif server_id = ::server_id; server_status=SERVER_STATUS_AUTOCOMMIT; @@ -186,12 +188,34 @@ THD::~THD() safeFree(ip); free_root(&mem_root,MYF(0)); mysys_var=0; // Safety (shouldn't be needed) -#ifdef STOP_IO_WITH_FD_CLOSE - pthread_mutex_destroy(&active_fd_lock); +#ifdef SIGNAL_WITH_VIO_CLOSE + pthread_mutex_destroy(&active_vio_lock); #endif DBUG_VOID_RETURN; } +void THD::prepare_to_die() +{ + thr_alarm_kill(real_id); + killed = 1; +#ifdef SIGNAL_WITH_VIO_CLOSE + close_active_vio(); +#endif + if (mysys_var) + { + pthread_mutex_lock(&mysys_var->mutex); + if (!system_thread) // Don't abort locks + mysys_var->abort=1; + if (mysys_var->current_mutex) + { + pthread_mutex_lock(mysys_var->current_mutex); + pthread_cond_broadcast(mysys_var->current_cond); + pthread_mutex_unlock(mysys_var->current_mutex); + } + pthread_mutex_unlock(&mysys_var->mutex); + } +} + // remember the location of thread info, the structure needed for // sql_alloc() and the structure for the net buffer diff --git a/sql/sql_class.h b/sql/sql_class.h index 3fd166ebc5a..b3ab4bb947d 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -21,8 +21,6 @@ #pragma interface /* gcc class implementation */ #endif -#include - class Query_log_event; class Load_log_event; @@ -258,9 +256,9 @@ public: #ifndef __WIN__ sigset_t signals,block_signals; #endif -#ifdef STOP_IO_WITH_FD_CLOSE - int active_fd; - pthread_mutex_t active_fd_lock; +#ifdef SIGNAL_WITH_VIO_CLOSE + Vio* active_vio; + pthread_mutex_t active_vio_lock; #endif ulonglong next_insert_id,last_insert_id,current_insert_id; ha_rows select_limit,offset_limit,default_select_limit,cuted_fields, @@ -285,59 +283,39 @@ public: // each thread that is using LOG_INFO needs to adjust the pointer to it ulong slave_proxy_id; // in slave thread we need to know in behalf of which - // thread the query is being run to replicate temp tables properly + // thread the query is being run to replicate temp tables properly // thread-specific state map for lex parser uchar state_map[256]; - + THD(); ~THD(); bool store_globals(); -#ifdef STOP_IO_WITH_FD_CLOSE - inline void set_active_fd(int fd) +#ifdef SIGNAL_WITH_VIO_CLOSE + inline void set_active_vio(Vio* vio) { - pthread_mutex_lock(&active_fd_lock); - active_fd = fd; - pthread_mutex_unlock(&active_fd_lock); + pthread_mutex_lock(&active_vio_lock); + active_vio = vio; + pthread_mutex_unlock(&active_vio_lock); } - inline void clear_active_fd() + inline void clear_active_vio() { - pthread_mutex_lock(&active_fd_lock); - active_fd = -1; - pthread_mutex_unlock(&active_fd_lock); + pthread_mutex_lock(&active_vio_lock); + active_vio = 0; + pthread_mutex_unlock(&active_vio_lock); } - inline void close_active_fd() + inline void close_active_vio() { - pthread_mutex_lock(&active_fd_lock); - if(active_fd >= 0) + pthread_mutex_lock(&active_vio_lock); + if(active_vio) { - my_close(active_fd, MYF(MY_WME)); - active_fd = -1; + vio_close(active_vio); + active_vio = 0; } - pthread_mutex_unlock(&active_fd_lock); + pthread_mutex_unlock(&active_vio_lock); } #endif - inline void prepare_to_die() - { - thr_alarm_kill(real_id); - killed = 1; -#ifdef STOP_IO_WITH_FD_CLOSE - close_active_fd(); -#endif - if (mysys_var) - { - pthread_mutex_lock(&mysys_var->mutex); - if (!system_thread) // Don't abort locks - mysys_var->abort=1; - if (mysys_var->current_mutex) - { - pthread_mutex_lock(mysys_var->current_mutex); - pthread_cond_broadcast(mysys_var->current_cond); - pthread_mutex_unlock(mysys_var->current_mutex); - } - pthread_mutex_unlock(&mysys_var->mutex); - } - } + void prepare_to_die(); inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg) { diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 7922ad0eb6a..05e64670df5 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -572,8 +572,8 @@ int stop_slave(THD* thd, bool net_report ) { abort_slave = 1; thr_alarm_kill(slave_real_id); -#ifdef STOP_IO_WITH_FD_CLOSE - slave_thd->close_active_fd(); +#ifdef SIGNAL_WITH_VIO_CLOSE + slave_thd->close_active_vio(); #endif // do not abort the slave in the middle of a query, so we do not set // thd->killed for the slave thread diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9a0badda099..a533b9ff44a 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2293,10 +2293,15 @@ purge: /* kill threads */ kill: - KILL_SYM NUM + KILL_SYM expr { - Lex->sql_command=SQLCOM_KILL; - Lex->thread_id= (ulong) strtoul($2.str,NULL,10); + if ($2->fix_fields(current_thd,0)) + { + send_error(¤t_thd->net, ER_SET_CONSTANTS_ONLY); + YYABORT; + } + Lex->sql_command=SQLCOM_KILL; + Lex->thread_id= (ulong) $2->val_int(); } /* change database */ -- cgit v1.2.1