summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/kill.result4
-rw-r--r--mysql-test/r/user_var.result2
-rw-r--r--mysql-test/t/kill.test23
-rw-r--r--mysql-test/t/user_var.test5
-rw-r--r--sql/slave.cc8
-rw-r--r--sql/sql_class.cc34
-rw-r--r--sql/sql_class.h64
-rw-r--r--sql/sql_repl.cc4
-rw-r--r--sql/sql_yacc.yy11
9 files changed, 98 insertions, 57 deletions
diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result
new file mode 100644
index 00000000000..628c6d21094
--- /dev/null
+++ b/mysql-test/r/kill.result
@@ -0,0 +1,4 @@
+((@id := kill_id) - kill_id)
+0
+4
+4
diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result
new file mode 100644
index 00000000000..f1bfdf9116d
--- /dev/null
+++ b/mysql-test/r/user_var.result
@@ -0,0 +1,2 @@
+@a - connection_id()
+3
diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test
new file mode 100644
index 00000000000..19739c88673
--- /dev/null
+++ b/mysql-test/t/kill.test
@@ -0,0 +1,23 @@
+connect (con1, localhost, root,,test,0, mysql-master.sock);
+connect (con2, localhost, root,,test,0, mysql-master.sock);
+
+#remember id of con1
+connection con1;
+drop table if exists connection_kill;
+create table connection_kill (kill_id int);
+insert into connection_kill values(connection_id());
+
+#kill con1
+connection con2;
+select ((@id := kill_id) - kill_id) from connection_kill;
+kill @id;
+
+# verify that con1 is really dead
+connection con1;
+error 2013;
+select 1;
+
+#make sure the server is still alive
+connection con2;
+select 4;
+drop table connection_kill;
diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test
new file mode 100644
index 00000000000..711b23b7ac1
--- /dev/null
+++ b/mysql-test/t/user_var.test
@@ -0,0 +1,5 @@
+error 1204;
+set @a := foo;
+set @a := connection_id() + 3;
+select @a - connection_id();
+
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 <m_ctype.h>
#include <sys/stat.h>
+#include <thr_alarm.h>
#ifdef __WIN__
#include <io.h>
#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 <thr_alarm.h>
-
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(&current_thd->net, ER_SET_CONSTANTS_ONLY);
+ YYABORT;
+ }
+ Lex->sql_command=SQLCOM_KILL;
+ Lex->thread_id= (ulong) $2->val_int();
}
/* change database */