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
parent 55543081
((@id := kill_id) - kill_id)
0
4
4
@a - connection_id()
3
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;
error 1204;
set @a := foo;
set @a := connection_id() + 3;
select @a - connection_id();
......@@ -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
}
......
......@@ -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
......
......@@ -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 @@ class THD :public ilink {
#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 @@ class THD :public ilink {
// 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)
{
......
......@@ -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
......
......@@ -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 */
......
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