Commit f87b3ee4 authored by unknown's avatar unknown

untested changes to close socket on slave stop for OS's that do not

interrupt I/O after thr_alarm_kill()

test case for order by desc coredump


mysql-test/t/order_by.test:
  added test case for order by desc bug
sql/slave.cc:
  close socket on slave stop
sql/slave.h:
  close socket on slave stop
sql/sql_class.cc:
  close socket on slave stop
sql/sql_class.h:
  close socket on slave stop
sql/sql_parse.cc:
  changed kill_one_thread to use prepare_to_die()
sql/sql_repl.cc:
  close socket on slave stop
parent 76d77185
...@@ -165,3 +165,43 @@ insert into t3 (ID, DateOfAction) values (87, '1999-07-19'), (89, '1999-07-19 ...@@ -165,3 +165,43 @@ insert into t3 (ID, DateOfAction) values (87, '1999-07-19'), (89, '1999-07-19
select t3.DateOfAction, t1.TransactionID from t1 join t2 join t3 where t2.ID = t1.TransactionID and t3.ID = t2.GroupID order by t3.DateOfAction, t1.TransactionID; select t3.DateOfAction, t1.TransactionID from t1 join t2 join t3 where t2.ID = t1.TransactionID and t3.ID = t2.GroupID order by t3.DateOfAction, t1.TransactionID;
select t3.DateOfAction, t1.TransactionID from t1 join t2 join t3 where t2.ID = t1.TransactionID and t3.ID = t2.GroupID order by t1.TransactionID,t3.DateOfAction; select t3.DateOfAction, t1.TransactionID from t1 join t2 join t3 where t2.ID = t1.TransactionID and t3.ID = t2.GroupID order by t1.TransactionID,t3.DateOfAction;
drop table t1,t2,t3; drop table t1,t2,t3;
#bug reported by Wouter de Jong
drop table if exists members;
CREATE TABLE members (
member_id int(11) NOT NULL auto_increment,
inschrijf_datum varchar(20) NOT NULL default '',
lastchange_datum varchar(20) NOT NULL default '',
nickname varchar(20) NOT NULL default '',
password varchar(8) NOT NULL default '',
voornaam varchar(30) NOT NULL default '',
tussenvoegsels varchar(10) NOT NULL default '',
achternaam varchar(50) NOT NULL default '',
straat varchar(100) NOT NULL default '',
postcode varchar(10) NOT NULL default '',
wijk varchar(40) NOT NULL default '',
plaats varchar(50) NOT NULL default '',
telefoon varchar(10) NOT NULL default '',
geboortedatum date NOT NULL default '0000-00-00',
geslacht varchar(5) NOT NULL default '',
email varchar(80) NOT NULL default '',
uin varchar(15) NOT NULL default '',
homepage varchar(100) NOT NULL default '',
internet varchar(15) NOT NULL default '',
scherk varchar(30) NOT NULL default '',
favo_boek varchar(50) NOT NULL default '',
favo_tijdschrift varchar(50) NOT NULL default '',
favo_tv varchar(50) NOT NULL default '',
favo_eten varchar(50) NOT NULL default '',
favo_muziek varchar(30) NOT NULL default '',
info text NOT NULL,
ipnr varchar(30) NOT NULL default '',
PRIMARY KEY (member_id)
) TYPE=MyISAM PACK_KEYS=1;
insert into members (member_id) values (1),(2),(3);
select member_id, nickname, voornaam FROM members
ORDER by lastchange_datum DESC LIMIT 2;
drop table members;
...@@ -36,6 +36,7 @@ bool wild_do_table_inited = 0, wild_ignore_table_inited = 0; ...@@ -36,6 +36,7 @@ bool wild_do_table_inited = 0, wild_ignore_table_inited = 0;
bool table_rules_on = 0; bool table_rules_on = 0;
uint32 slave_skip_counter = 0; uint32 slave_skip_counter = 0;
static TABLE* save_temporary_tables = 0; static TABLE* save_temporary_tables = 0;
THD* slave_thd = 0;
// when slave thread exits, we need to remember the temporary tables so we // when slave thread exits, we need to remember the temporary tables so we
// can re-use them on slave start // can re-use them on slave start
...@@ -1157,7 +1158,7 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused))) ...@@ -1157,7 +1158,7 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused)))
// needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff // needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff
my_thread_init(); my_thread_init();
thd = new THD; // note that contructor of THD uses DBUG_ ! slave_thd = thd = new THD; // note that contructor of THD uses DBUG_ !
thd->set_time(); thd->set_time();
DBUG_ENTER("handle_slave"); DBUG_ENTER("handle_slave");
...@@ -1347,6 +1348,7 @@ position %s", ...@@ -1347,6 +1348,7 @@ position %s",
pthread_cond_broadcast(&COND_slave_stopped); // tell the world we are done pthread_cond_broadcast(&COND_slave_stopped); // tell the world we are done
pthread_mutex_unlock(&LOCK_slave); pthread_mutex_unlock(&LOCK_slave);
net_end(&thd->net); // destructor will not free it, because we are weird net_end(&thd->net); // destructor will not free it, because we are weird
slave_thd = 0;
delete thd; delete thd;
my_thread_end(); my_thread_end();
#ifndef DBUG_OFF #ifndef DBUG_OFF
...@@ -1376,8 +1378,13 @@ static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) ...@@ -1376,8 +1378,13 @@ static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
} }
if(!slave_was_killed) if(!slave_was_killed)
mysql_log.write(thd, COM_CONNECT_OUT, "%s@%s:%d", {
mysql_log.write(thd, COM_CONNECT_OUT, "%s@%s:%d",
mi->user, mi->host, mi->port); mi->user, mi->host, mi->port);
#ifdef STOP_IO_WITH_FD_CLOSE
thd->set_active_fd(vio_fd(mysql->net.vio));
#endif
}
return slave_was_killed; return slave_was_killed;
} }
...@@ -1404,11 +1411,16 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) ...@@ -1404,11 +1411,16 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
} }
if(!slave_was_killed) if(!slave_was_killed)
sql_print_error("Slave: reconnected to master '%s@%s:%d',\ {
sql_print_error("Slave: reconnected to master '%s@%s:%d',\
replication resumed in log '%s' at position %s", glob_mi.user, replication resumed in log '%s' at position %s", glob_mi.user,
glob_mi.host, glob_mi.port, glob_mi.host, glob_mi.port,
RPL_LOG_NAME, RPL_LOG_NAME,
llstr(glob_mi.pos,llbuff)); llstr(glob_mi.pos,llbuff));
#ifdef STOP_IO_WITH_FD_CLOSE
thd->set_active_fd(vio_fd(mysql->net.vio));
#endif
}
return slave_was_killed; return slave_was_killed;
} }
......
...@@ -99,6 +99,7 @@ extern uint32 slave_skip_counter; ...@@ -99,6 +99,7 @@ extern uint32 slave_skip_counter;
// have caused errors, and have been manually applied by DBA already // have caused errors, and have been manually applied by DBA already
extern pthread_t slave_real_id; extern pthread_t slave_real_id;
extern THD* slave_thd;
extern MASTER_INFO glob_mi; extern MASTER_INFO glob_mi;
extern HASH replicate_do_table, replicate_ignore_table; extern HASH replicate_do_table, replicate_ignore_table;
extern DYNAMIC_ARRAY replicate_wild_do_table, replicate_wild_ignore_table; extern DYNAMIC_ARRAY replicate_wild_do_table, replicate_wild_ignore_table;
......
...@@ -84,6 +84,10 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), ...@@ -84,6 +84,10 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
query_start_used=0; query_start_used=0;
query_length=col_access=0; query_length=col_access=0;
query_error=0; query_error=0;
#ifdef STOP_IO_WITH_FD_CLOSE
active_fd = -1;
pthread_mutex_init(&active_fd_lock, NULL);
#endif
server_id = ::server_id; server_id = ::server_id;
server_status=SERVER_STATUS_AUTOCOMMIT; server_status=SERVER_STATUS_AUTOCOMMIT;
next_insert_id=last_insert_id=0; next_insert_id=last_insert_id=0;
...@@ -182,6 +186,9 @@ THD::~THD() ...@@ -182,6 +186,9 @@ THD::~THD()
safeFree(ip); safeFree(ip);
free_root(&mem_root,MYF(0)); free_root(&mem_root,MYF(0));
mysys_var=0; // Safety (shouldn't be needed) mysys_var=0; // Safety (shouldn't be needed)
#ifdef STOP_IO_WITH_FD_CLOSE
pthread_mutex_destroy(&active_fd_lock);
#endif
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#pragma interface /* gcc class implementation */ #pragma interface /* gcc class implementation */
#endif #endif
#include <thr_alarm.h>
class Query_log_event; class Query_log_event;
class Load_log_event; class Load_log_event;
...@@ -256,6 +258,10 @@ public: ...@@ -256,6 +258,10 @@ public:
#ifndef __WIN__ #ifndef __WIN__
sigset_t signals,block_signals; sigset_t signals,block_signals;
#endif #endif
#ifdef STOP_IO_WITH_FD_CLOSE
int active_fd;
pthread_mutex_t active_fd_lock;
#endif
ulonglong next_insert_id,last_insert_id,current_insert_id; ulonglong next_insert_id,last_insert_id,current_insert_id;
ha_rows select_limit,offset_limit,default_select_limit,cuted_fields, ha_rows select_limit,offset_limit,default_select_limit,cuted_fields,
max_join_size,sent_row_count; max_join_size,sent_row_count;
...@@ -284,6 +290,51 @@ public: ...@@ -284,6 +290,51 @@ public:
THD(); THD();
~THD(); ~THD();
bool store_globals(); bool store_globals();
#ifdef STOP_IO_WITH_FD_CLOSE
inline void set_active_fd(int fd)
{
pthread_mutex_lock(&active_fd_lock);
active_fd = fd;
pthread_mutex_unlock(&active_fd_lock);
}
inline void clear_active_fd()
{
pthread_mutex_lock(&active_fd_lock);
active_fd = -1;
pthread_mutex_unlock(&active_fd_lock);
}
inline void close_active_fd()
{
pthread_mutex_lock(&active_fd_lock);
if(active_fd >= 0)
{
my_close(active_fd, MYF(MY_WME));
active_fd = -1;
}
pthread_mutex_unlock(&active_fd_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);
}
}
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
const char* msg) const char* msg)
{ {
......
...@@ -2778,22 +2778,8 @@ void kill_one_thread(THD *thd, ulong id) ...@@ -2778,22 +2778,8 @@ void kill_one_thread(THD *thd, ulong id)
if ((thd->master_access & PROCESS_ACL) || if ((thd->master_access & PROCESS_ACL) ||
!strcmp(thd->user,tmp->user)) !strcmp(thd->user,tmp->user))
{ {
thr_alarm_kill(tmp->real_id); tmp->prepare_to_die();
tmp->killed=1;
error=0; error=0;
if (tmp->mysys_var)
{
pthread_mutex_lock(&tmp->mysys_var->mutex);
if (!tmp->system_thread) // Don't abort locks
tmp->mysys_var->abort=1;
if (tmp->mysys_var->current_mutex)
{
pthread_mutex_lock(tmp->mysys_var->current_mutex);
pthread_cond_broadcast(tmp->mysys_var->current_cond);
pthread_mutex_unlock(tmp->mysys_var->current_mutex);
}
pthread_mutex_unlock(&tmp->mysys_var->mutex);
}
} }
else else
error=ER_KILL_DENIED_ERROR; error=ER_KILL_DENIED_ERROR;
......
...@@ -572,6 +572,9 @@ int stop_slave(THD* thd, bool net_report ) ...@@ -572,6 +572,9 @@ int stop_slave(THD* thd, bool net_report )
{ {
abort_slave = 1; abort_slave = 1;
thr_alarm_kill(slave_real_id); thr_alarm_kill(slave_real_id);
#ifdef STOP_IO_WITH_FD_CLOSE
slave_thd->close_active_fd();
#endif
// do not abort the slave in the middle of a query, so we do not set // do not abort the slave in the middle of a query, so we do not set
// thd->killed for the slave thread // thd->killed for the slave thread
thd->proc_info = "waiting for slave to die"; thd->proc_info = "waiting for slave to die";
......
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