mysqltest can now talk to manager and start/stop servers with

server_start/server_stop
changed rpl000018 to use the new server restart feature instead of a
hack
parent bb66c80a
......@@ -80,12 +80,23 @@
* the server - to solve the problem, we try again
* after some sleep if connection fails the first
* time */
#ifndef MYSQL_MANAGER_PORT
#define MYSQL_MANAGER_PORT 23546
#endif
enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT};
static int record = 0, verbose = 0, silent = 0, opt_sleep=0;
static char *db = 0, *pass=0;
const char* user = 0, *host = 0, *unix_sock = 0;
static int port = 0, opt_big_test=0;
static uint start_lineno, *lineno;
const char* manager_user="root",*manager_host="localhost";
char *manager_pass=0;
int manager_port=MYSQL_MANAGER_PORT;
int manager_wait_timeout=3;
MYSQL_MANAGER* manager=0;
static char **default_argv;
static const char *load_default_groups[]= { "mysqltest","client",0 };
......@@ -168,6 +179,7 @@ Q_PING, Q_EVAL,
Q_RPL_PROBE, Q_ENABLE_RPL_PARSE,
Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT,
Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
Q_SERVER_START, Q_SERVER_STOP,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
Q_COMMENT_WITH_COMMAND
......@@ -200,6 +212,7 @@ const char *command_names[] = {
"rpl_probe", "enable_rpl_parse",
"disable_rpl_parse", "eval_result",
"enable_query_log", "disable_query_log",
"server_start", "server_stop",
0
};
......@@ -243,6 +256,7 @@ static int initialize_replace_buffer(void);
static void free_replace_buffer(void);
static void do_eval(DYNAMIC_STRING* query_eval, const char* query);
void str_to_file(const char* fname, char* str, int size);
int do_server_op(struct st_query* q,const char* op);
struct st_replace *glob_replace;
static char *out_buff;
......@@ -321,6 +335,8 @@ static void free_used_memory()
{
uint i;
DBUG_ENTER("free_used_memory");
if (manager)
mysql_manager_close(manager);
close_cons();
close_files();
hash_free(&var_hash);
......@@ -580,6 +596,44 @@ int open_file(const char* name)
return 0;
}
int do_server_start(struct st_query* q)
{
return do_server_op(q,"start");
}
int do_server_stop(struct st_query* q)
{
return do_server_op(q,"stop");
}
int do_server_op(struct st_query* q,const char* op)
{
char* p=q->first_argument;
char com_buf[256],*com_p;
com_p=strmov(com_buf,op);
com_p=strmov(com_p,"_exec ");
if (!*p)
die("Missing server name in server_%s\n",op);
while (*p && !isspace(*p))
{
*com_p++=*p++;
}
*com_p++=' ';
com_p=int10_to_str(manager_wait_timeout,com_p,10);
*com_p++ = '\n';
*com_p=0;
if (mysql_manager_command(manager,com_buf,(int)(com_p-com_buf)))
die("Error in command: %s(%d)",manager->last_error,manager->last_errno);
while (!manager->eof)
{
if (mysql_manager_fetch_line(manager,com_buf,sizeof(com_buf)))
die("Error fetching result line: %s(%d)", manager->last_error,
manager->last_errno);
}
return 0;
}
int do_source(struct st_query* q)
{
char* p=q->first_argument, *name;
......@@ -1125,6 +1179,17 @@ char* safe_get_param(char* str, char** arg, const char* msg)
DBUG_RETURN(str);
}
void init_manager()
{
if (!(manager=mysql_manager_init(0)))
die("Failed in mysql_manager_init()");
if (!mysql_manager_connect(manager,manager_host,manager_user,
manager_pass,manager_port))
die("Could not connect to MySQL manager: %s(%d)",manager->last_error,
manager->last_errno);
}
int safe_connect(MYSQL* con, const char* host, const char* user,
const char* pass,
const char* db, int port, const char* sock)
......@@ -1519,7 +1584,6 @@ int read_query(struct st_query** q_ptr)
return 0;
}
struct option long_options[] =
{
{"debug", optional_argument, 0, '#'},
......@@ -1527,6 +1591,11 @@ struct option long_options[] =
{"big-test", no_argument, 0, 'B'},
{"help", no_argument, 0, '?'},
{"host", required_argument, 0, 'h'},
{"manager-user",required_argument, 0, OPT_MANAGER_USER},
{"manager-host",required_argument, 0, OPT_MANAGER_HOST},
{"manager-password",required_argument,0,OPT_MANAGER_PASSWD},
{"manager-port",required_argument,0,OPT_MANAGER_PORT},
{"manager-wait-timeout",required_argument,0,OPT_MANAGER_WAIT_TIMEOUT},
{"password", optional_argument, 0, 'p'},
{"port", required_argument, 0, 'P'},
{"quiet", no_argument, 0, 'q'},
......@@ -1604,6 +1673,23 @@ int parse_args(int argc, char **argv)
case 'r':
record = 1;
break;
case (int)OPT_MANAGER_WAIT_TIMEOUT:
manager_wait_timeout=atoi(optarg);
break;
case (int)OPT_MANAGER_PORT:
manager_port=atoi(optarg);
break;
case (int)OPT_MANAGER_HOST:
manager_host=optarg;
break;
case (int)OPT_MANAGER_USER:
manager_user=optarg;
break;
case (int)OPT_MANAGER_PASSWD:
my_free(manager_pass,MYF(MY_ALLOW_ZERO_PTR));
manager_pass=my_strdup(optarg,MYF(MY_FAE));
while (*optarg) *optarg++= 'x'; /* Destroy argument */
break;
case 'u':
user = optarg;
break;
......@@ -2010,6 +2096,7 @@ int main(int argc, char** argv)
if (!*cur_file)
*cur_file = stdin;
*lineno=1;
init_manager();
if (!( mysql_init(&cur_con->mysql)))
die("Failed in mysql_init()");
......@@ -2042,6 +2129,8 @@ int main(int argc, char** argv)
case Q_DISABLE_QUERY_LOG: disable_query_log=1; break;
case Q_SOURCE: do_source(q); break;
case Q_SLEEP: do_sleep(q); break;
case Q_SERVER_START: do_server_start(q); break;
case Q_SERVER_STOP: do_server_stop(q); break;
case Q_INC: do_inc(q); break;
case Q_DEC: do_dec(q); break;
case Q_ECHO: do_echo(q); break;
......
......@@ -336,7 +336,9 @@ then
fi
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB --user=$DBUSER --password=$DBPASSWD --silent -v --tmpdir=$MYSQL_TMP_DIR"
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
--user=$DBUSER --password=$DBPASSWD --silent -v \
--tmpdir=$MYSQL_TMP_DIR"
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
......@@ -521,6 +523,13 @@ start_manager()
$MYSQL_MANAGER --log=$MYSQL_MANAGER_LOG --port=$MYSQL_MANAGER_PORT \
--password-file=$MYSQL_MANAGER_PW_FILE
abort_if_failed "Could not start MySQL manager"
mysqltest_manager_args="--manager-user=$MYSQL_MANAGER_USER \
--manager-password=$MYSQL_MANAGER_PW \
--manager-port=$MYSQL_MANAGER_PORT \
--manager-wait-timeout=$START_WAIT_TIMEOUT"
MYSQL_TEST="$MYSQL_TEST $mysqltest_manager_args"
MYSQL_TEST_ARGS="$MYSQL_TEST_ARGS $mysqltest_manager_args"
}
stop_manager()
......@@ -552,7 +561,7 @@ manager_term()
shift
$MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
--password=$MYSQL_MANAGER_PW --port=$MYSQL_MANAGER_PORT <<EOF
stop_exec $ident $TERM_WAIT_TIMEOUT
stop_exec $ident $STOP_WAIT_TIMEOUT
EOF
abort_if_failed "Could not execute manager command"
}
......@@ -561,14 +570,16 @@ EOF
start_master()
{
[ x$MASTER_RUNNING = 1 ] && return
# Remove old berkeley db log files that can confuse the server
$RM -f $MASTER_MYDDIR/log.*
# Remove stale binary logs
$RM -f $MYSQL_TEST_DIR/var/log/master-bin.*
#run master initialization shell script if one exists
if [ -f "$master_init_script" ] ;
then
/bin/sh $master_init_script
fi
cd $BASEDIR # for gcov
# Remove old berkeley db log files that can confuse the server
$RM -f $MASTER_MYDDIR/log.*
#start master
if [ -z "$DO_BENCH" ]
then
......@@ -630,6 +641,9 @@ start_slave()
[ x$SKIP_SLAVE = x1 ] && return
[ x$SLAVE_RUNNING = 1 ] && return
# Remove stale binary logs
$RM -f $MYSQL_TEST_DIR/var/log/slave-bin.*
#run slave initialization shell script if one exists
if [ -f "$slave_init_script" ] ;
then
......
......@@ -4,7 +4,6 @@ show master logs;
Log_name
master-bin.001
master-bin.002
master-bin.003
drop table if exists t1;
create table t1(n int);
insert into t1 values (3351);
......
rm -f $MYSQL_TEST_DIR/var/master-data/master-bin.*
cp $MYSQL_TEST_DIR/std_data/master-bin.001 $MYSQL_TEST_DIR/var/master-data/
echo ./master-bin.001 > $MYSQL_TEST_DIR/var/master-data/master-bin.index
connect (master,localhost,root,,test,0,mysql-master.sock);
connect (slave,localhost,root,,test,0,mysql-slave.sock);
server_stop master;
server_start master;
connection slave;
reset slave;
slave start;
......
......@@ -1646,6 +1646,7 @@ int Stop_log_event::exec_event(struct st_master_info* mi)
if(mi->pos > 4) // stop event should be ignored after rotate event
{
close_temporary_tables(thd);
//clean_up_load_tmp_dir();
mi->inc_pos(get_event_len(), log_seq);
flush_master_info(mi);
}
......
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