Commit c95e3cd2 authored by unknown's avatar unknown

added loops and other cool stuff to mysqltest

fixed slave to preserve temp tables on slave stop; slave start
added abort-slave-event-count option to mysqld to test the above
added a test case for temp tables with a contantly aborting slave
removed warning in sql_parse.cc
fixed thimble.cc to compile


BitKeeper/etc/ignore:
  Added client/thimble support-files/mysql-3.23.29-gamma.spec to the ignore list
client/mysqltest.c:
  added while, let, and echo, added fractional sec sleep support
client/thimble.cc:
  fixes to make it compile
mysql-test/t/3.23/rpl000001.test:
  sleep less
mysql-test/t/3.23/rpl000002.test:
  sleep less
mysql-test/t/3.23/rpl000003.test:
  sleep less
mysql-test/t/3.23/rpl000005.test:
  sleep less
sql/mysqld.cc:
  --abort-slave-event count
sql/slave.cc:
  remember temp tables when slave thread termintates and restore them on
  slave start
sql/slave.h:
  --abort-slave-event-count
sql/sql_parse.cc:
  remove warning
parent a5f309d4
......@@ -371,3 +371,5 @@ libmysql_r/thr_mutex.c
libmysql_r/typelib.c
libmysql_r/violite.c
linked_libmysql_r_sources
client/thimble
support-files/mysql-3.23.29-gamma.spec
This diff is collapsed.
......@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "my_global.h"
static void spawn_stern_thread(pthread_t *t);
static int act_goofy(void);
......@@ -13,6 +14,7 @@ static struct {
int msg;
} comm = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 };
int
main(void)
{
......@@ -65,7 +67,7 @@ static int act_goofy(void)
return ret;
}
static void *be_stern(void *v __attribute((unused)))
static void *be_stern(void *v __attribute__((unused)))
{
int msg;
for (;;) {
......@@ -87,3 +89,5 @@ static void *be_stern(void *v __attribute((unused)))
fputs("You are NOTHING!\n", stderr);
return NULL;
}
Variable_name Value
Slave_open_temp_tables 0
......@@ -8,7 +8,7 @@ drop table if exists foo;
create table foo(n int);
insert into foo values(1),(2);
connection slave;
sleep 3;
sleep 2;
use test;
@r/3.23/rpl000001.a.result select * from foo;
@r/3.23/rpl000001.b.result select sum(length(word)) from words;
......
......@@ -7,5 +7,5 @@ set insert_id = 2000;
insert into x values (NULL),(NULL),(NULL);
connection slave;
use test;
sleep 1;
sleep 0.5;
@r/3.23/rpl000002.result select * from x;
......@@ -5,5 +5,5 @@ create table x(n int primary key);
!insert into x values (1),(2),(2);
insert into x values (3);
connection slave;
sleep 1;
sleep 0.5;
@r/3.23/rpl000003.result select * from x;
......@@ -8,5 +8,5 @@ INSERT into test SET name='Caleb', age=1;
ALTER TABLE test ADD id int(8) ZEROFILL AUTO_INCREMENT PRIMARY KEY;
@r/3.23/rpl000005.result select * from test;
connection slave;
sleep 1;
sleep 0.5;
@r/3.23/rpl000005.result select * from test;
--abort-slave-event-count=1
source t/include/master-slave.inc;
connection master;
drop table if exists x;
create table x(n int);
create temporary table t(n int);
insert into t values(1),(2),(3);
insert into x select * from t;
connection master1;
create temporary table t (n int);
insert into t values (4),(5);
insert into x select * from t;
disconnect master;
connection master1;
insert into x values(6);
disconnect master1;
connection slave;
let $1=12;
while ($1)
{
!slave start;
sleep 0.2;
dec $1;
}
@r/3.23/rpl000013.result select * from x;
@r/3.23/rpl000013.status.result show status like 'Slave_open_temp_tables';
......@@ -2217,7 +2217,7 @@ enum options {
OPT_SKIP_INNOBASE,OPT_SAFEMALLOC_MEM_LIMIT,
OPT_REPLICATE_DO_TABLE, OPT_REPLICATE_IGNORE_TABLE,
OPT_REPLICATE_WILD_DO_TABLE, OPT_REPLICATE_WILD_IGNORE_TABLE,
OPT_DISCONNECT_SLAVE_EVENT_COUNT
OPT_DISCONNECT_SLAVE_EVENT_COUNT, OPT_ABORT_SLAVE_EVENT_COUNT
};
static struct option long_options[] = {
......@@ -2277,6 +2277,8 @@ static struct option long_options[] = {
// is a no-op
{"disconnect-slave-event-count", required_argument, 0,
(int) OPT_DISCONNECT_SLAVE_EVENT_COUNT},
{"abort-slave-event-count", required_argument, 0,
(int) OPT_ABORT_SLAVE_EVENT_COUNT},
#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
{"safemalloc-mem-limit", required_argument, 0, (int)
OPT_SAFEMALLOC_MEM_LIMIT},
......@@ -2883,6 +2885,11 @@ static void get_options(int argc,char **argv)
case (int)OPT_DISCONNECT_SLAVE_EVENT_COUNT:
#ifndef DBUG_OFF
disconnect_slave_event_count = atoi(optarg);
#endif
break;
case (int)OPT_ABORT_SLAVE_EVENT_COUNT:
#ifndef DBUG_OFF
abort_slave_event_count = atoi(optarg);
#endif
break;
case (int) OPT_LOG_SLAVE_UPDATES:
......
......@@ -33,9 +33,13 @@ DYNAMIC_ARRAY replicate_wild_do_table, replicate_wild_ignore_table;
bool do_table_inited = 0, ignore_table_inited = 0;
bool wild_do_table_inited = 0, wild_ignore_table_inited = 0;
bool table_rules_on = 0;
// when slave thread exits, we need to remember the temporary tables so we
// can re-use them on slave start
static TABLE* save_temporary_tables = 0;
#ifndef DBUG_OFF
int disconnect_slave_event_count = 0;
static int events_till_disconnect = -1;
int disconnect_slave_event_count = 0, abort_slave_event_count = 0;
static int events_till_disconnect = -1, events_till_abort = -1;
static int stuck_count = 0;
#endif
......@@ -43,8 +47,8 @@ static int stuck_count = 0;
static inline void skip_load_data_infile(NET* net);
static inline bool slave_killed(THD* thd);
static int init_slave_thread(THD* thd);
static void safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi);
static void safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi);
static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi);
static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi);
static int safe_sleep(THD* thd, int sec);
static int request_table_dump(MYSQL* mysql, char* db, char* table);
static int create_table_from_dump(THD* thd, NET* net, const char* db,
......@@ -968,7 +972,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
pthread_handler_decl(handle_slave,arg __attribute__((unused)))
{
THD *thd;; // needs to be first for thread_stack
THD *thd; // needs to be first for thread_stack
MYSQL *mysql = NULL ;
if(!server_id)
......@@ -985,6 +989,9 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused)))
}
slave_running = 1;
abort_slave = 0;
#ifndef DBUG_OFF
events_till_abort = abort_slave_event_count;
#endif
pthread_mutex_unlock(&LOCK_slave);
int error = 1;
......@@ -1001,7 +1008,7 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused)))
if(init_slave_thread(thd) || init_master_info(&glob_mi))
goto err;
thd->thread_stack = (char*)&thd; // remember where our stack is
thd->temporary_tables = save_temporary_tables; // restore temp tables
threads.append(thd);
DBUG_PRINT("info",("master info: log_file_name=%s, position=%d",
......@@ -1017,14 +1024,16 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused)))
thd->proc_info = "connecting to master";
#ifndef DBUG_OFF
sql_print_error("Slave thread initialized");
#endif
safe_connect(thd, mysql, &glob_mi);
// always report status on startup, even if we are not in debug
sql_print_error("Slave: connected to master '%s@%s:%d',\
replication started in log '%s' at position %ld", glob_mi.user,
#endif
// we can get killed during safe_connect
if(!safe_connect(thd, mysql, &glob_mi))
sql_print_error("Slave: connected to master '%s@%s:%d',\
replication started in log '%s' at position %ld", glob_mi.user,
glob_mi.host, glob_mi.port,
RPL_LOG_NAME,
glob_mi.pos);
else
goto err;
while(!slave_killed(thd))
{
......@@ -1053,8 +1062,7 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused)))
sql_print_error("Slave: failed dump request, reconnecting to \
try again, log '%s' at postion %ld", RPL_LOG_NAME,
last_failed_pos = glob_mi.pos );
safe_reconnect(thd, mysql, &glob_mi);
if(slave_killed(thd))
if(safe_reconnect(thd, mysql, &glob_mi) || slave_killed(thd))
goto err;
continue;
......@@ -1084,8 +1092,7 @@ try again, log '%s' at postion %ld", RPL_LOG_NAME,
sql_print_error("Slave: Failed reading log event, \
reconnecting to retry, log '%s' position %ld", RPL_LOG_NAME,
last_failed_pos = glob_mi.pos);
safe_reconnect(thd, mysql, &glob_mi);
if(slave_killed(thd))
if(safe_reconnect(thd, mysql, &glob_mi) || slave_killed(thd))
goto err;
break;
}
......@@ -1101,6 +1108,13 @@ reconnecting to retry, log '%s' position %ld", RPL_LOG_NAME,
// abort the slave thread, when the problem is fixed, the user
// should restart the slave with mysqladmin start-slave
}
#ifndef DBUG_OFF
if(abort_slave_event_count && !--events_till_abort)
{
sql_print_error("Slave: debugging abort");
goto err;
}
#endif
// successful exec with offset advance,
// the slave repents and his sins are forgiven!
......@@ -1143,6 +1157,8 @@ position %ld",
pthread_mutex_lock(&LOCK_slave);
slave_running = 0;
abort_slave = 0;
save_temporary_tables = thd->temporary_tables;
thd->temporary_tables = 0; // remove tempation from destructor to close them
pthread_cond_broadcast(&COND_slave_stopped); // tell the world we are done
pthread_mutex_unlock(&LOCK_slave);
delete thd;
......@@ -1151,13 +1167,14 @@ position %ld",
DBUG_RETURN(0); // Can't return anything here
}
static void safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
// will try to connect until successful
static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
// will try to connect until successful or slave killed
{
int slave_was_killed;
#ifndef DBUG_OFF
events_till_disconnect = disconnect_slave_event_count;
#endif
while(!slave_killed(thd) &&
while(!(slave_was_killed = slave_killed(thd)) &&
!mc_mysql_connect(mysql, mi->host, mi->user, mi->password, 0,
mi->port, 0, 0))
{
......@@ -1166,28 +1183,39 @@ static void safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
safe_sleep(thd, mi->connect_retry);
}
mysql_log.write(thd, COM_CONNECT_OUT, "%s@%s:%d",
if(!slave_was_killed)
mysql_log.write(thd, COM_CONNECT_OUT, "%s@%s:%d",
mi->user, mi->host, mi->port);
return slave_was_killed;
}
// will try to connect until successful
// will try to connect until successful or slave killed
static void safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
{
int slave_was_killed;
mi->pending = 0; // if we lost connection after reading a state set event
// we will be re-reading it, so pending needs to be cleared
#ifndef DBUG_OFF
events_till_disconnect = disconnect_slave_event_count;
#endif
while(!slave_killed(thd) && mc_mysql_reconnect(mysql))
while(!(slave_was_killed = slave_killed(thd)) && mc_mysql_reconnect(mysql))
{
sql_print_error("Slave thread: error connecting to master:\
%s, retry in %d sec",
mc_mysql_error(mysql), mi->connect_retry);
sql_print_error("Slave thread: error re-connecting to master:\
%s, last_errno=%d, retry in %d sec",
mc_mysql_error(mysql), errno, mi->connect_retry);
safe_sleep(thd, mi->connect_retry);
}
if(!slave_was_killed)
sql_print_error("Slave: reconnected to master '%s@%s:%d',\
replication resumed in log '%s' at position %ld", glob_mi.user,
glob_mi.host, glob_mi.port,
RPL_LOG_NAME,
glob_mi.pos);
return slave_was_killed;
}
#ifdef __GNUC__
......
......@@ -95,7 +95,7 @@ extern bool do_table_inited, ignore_table_inited,
extern bool table_rules_on;
#ifndef DBUG_OFF
extern int disconnect_slave_event_count ;
extern int disconnect_slave_event_count, abort_slave_event_count ;
#endif
// the master variables are defaults read from my.cnf or command line
......
......@@ -462,7 +462,7 @@ pthread_handler_decl(handle_bootstrap,arg)
thd->proc_info=0;
thd->version=refresh_version;
thd->priv_user=thd->user="boot";
thd->priv_user=thd->user=(char*)"boot";
buff= (char*) thd->net.buff;
init_sql_alloc(&thd->mem_root,8192,8192);
......
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