Commit af82bc24 authored by sasha@mysql.sashanet.com's avatar sasha@mysql.sashanet.com

merged

parents e05b8392 d7c47dcf
......@@ -124,7 +124,7 @@ MASTER_RUNNING=0
MASTER_MYPORT=9306
SLAVE_RUNNING=0
SLAVE_MYPORT=9307
MYSQL_MANAGER_PORT=9308
MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves
MYSQL_MANAGER_PW_FILE=$MYSQL_TEST_DIR/var/tmp/manager.pwd
MYSQL_MANAGER_LOG=$MYSQL_TEST_DIR/var/log/manager.log
MYSQL_MANAGER_USER=root
......@@ -473,6 +473,13 @@ mysql_install_db () {
error "Could not install slave test DBs"
exit 1
fi
for slave_num in 1 2 ;
do
mkdir -p var/slave$slave_num-data/mysql
mkdir -p var/slave$slave_num-data/test
cp var/slave-data/mysql/* var/slave$slave_num-data/mysql
done
# Give mysqld some time to die.
sleep $SLEEP_TIME
return 0
......@@ -647,10 +654,33 @@ start_master()
start_slave()
{
[ x$SKIP_SLAVE = x1 ] && return
[ x$SLAVE_RUNNING = 1 ] && return
eval "this_slave_running=\$SLAVE$1_RUNNING"
[ x$this_slave_running = 1 ] && return
#when testing fail-safe replication, we will have more than one slave
#in this case, we start secondary slaves with an argument
slave_ident="slave$1"
if [ -n "$1" ] ;
then
slave_server_id=`$EXPR 2 + $1`
slave_rpl_rank=$slave_server_id
slave_port=`expr $SLAVE_MYPORT + $1`
slave_log="$SLAVE_MYLOG.$1"
slave_err="$SLAVE_MYERR.$1"
slave_datadir="var/$slave_ident-data/"
slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
slave_sock="$SLAVE_MYSOCK-$1"
else
slave_server_id=2
slave_rpl_rank=2
slave_port=$SLAVE_MYPORT
slave_log=$SLAVE_MYLOG
slave_err=$SLAVE_MYERR
slave_datadir=$SLAVE_MYDDIR
slave_pid=$SLAVE_MYPID
slave_sock="$SLAVE_MYSOCK"
fi
# Remove stale binary logs
$RM -f $MYSQL_TEST_DIR/var/log/slave-bin.*
$RM -f $MYSQL_TEST_DIR/var/log/$slave_ident-bin.*
#run slave initialization shell script if one exists
if [ -f "$slave_init_script" ] ;
......@@ -664,22 +694,22 @@ start_slave()
--master-host=127.0.0.1 \
--master-password= \
--master-port=$MASTER_MYPORT \
--server-id=2 --rpl-recovery-rank=2"
--server-id=$slave_server_id --rpl-recovery-rank=$slave_rpl_rank"
else
master_info=$SLAVE_MASTER_INFO
fi
$RM -f $SLAVE_MYDDIR/log.*
$RM -f $slave_datadir/log.*
slave_args="--no-defaults $master_info \
--exit-info=256 \
--log-bin=$MYSQL_TEST_DIR/var/log/slave-bin \
--log-bin=$MYSQL_TEST_DIR/var/log/$slave_ident-bin \
--log-slave-updates \
--log=$SLAVE_MYLOG \
--log=$slave_log \
--basedir=$MY_BASEDIR \
--datadir=$SLAVE_MYDDIR \
--pid-file=$SLAVE_MYPID \
--port=$SLAVE_MYPORT \
--socket=$SLAVE_MYSOCK \
--datadir=$slave_datadir \
--pid-file=$slave_pid \
--port=$slave_port \
--socket=$slave_sock \
--character-sets-dir=$CHARSETSDIR \
--default-character-set=$CHARACTER_SET \
--core \
......@@ -688,27 +718,27 @@ start_slave()
--skip-innodb --skip-slave-start \
--slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
--report-host=127.0.0.1 --report-user=root \
--report-port=$SLAVE_MYPORT \
--report-port=$slave_port \
--master-retry-count=5 \
$SMALL_SERVER \
$EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
CUR_MYERR=$SLAVE_MYERR
CUR_MYSOCK=$SLAVE_MYSOCK
CUR_MYERR=$slave_err
CUR_MYSOCK=$slave_sock
if [ x$DO_DDD = x1 ]
then
$ECHO "set args $master_args" > $GDB_SLAVE_INIT
manager_launch slave ddd -display $DISPLAY --debugger \
manager_launch $slave_ident ddd -display $DISPLAY --debugger \
"gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
elif [ x$DO_GDB = x1 ]
then
$ECHO "set args $slave_args" > $GDB_SLAVE_INIT
manager_launch slave $XTERM -display $DISPLAY -title "Slave" -e gdb -x \
manager_launch $slave_ident $XTERM -display $DISPLAY -title "Slave" -e gdb -x \
$GDB_SLAVE_INIT $SLAVE_MYSQLD
else
manager_launch slave $SLAVE_MYSQLD $slave_args
manager_launch $slave_ident $SLAVE_MYSQLD $slave_args
fi
SLAVE_RUNNING=1
eval "SLAVE$1_RUNNING=1"
}
mysql_start () {
......@@ -721,23 +751,31 @@ mysql_start () {
stop_slave ()
{
if [ x$SLAVE_RUNNING = x1 ]
eval "this_slave_running=\$SLAVE$1_RUNNING"
slave_ident="slave$1"
if [ -n "$1" ] ;
then
manager_term slave
if [ $? != 0 ] && [ -f $SLAVE_MYPID ]
slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
else
slave_pid=$SLAVE_MYPID
fi
if [ x$this_slave_running = x1 ]
then
manager_term $slave_ident
if [ $? != 0 ] && [ -f $slave_pid ]
then # try harder!
$ECHO "slave not cooperating with mysqladmin, will try manual kill"
kill `$CAT $SLAVE_MYPID`
kill `$CAT $slave_pid`
sleep $SLEEP_TIME
if [ -f $SLAVE_MYPID ] ; then
$ECHO "slave refused to die. Sending SIGKILL"
kill -9 `$CAT $SLAVE_MYPID`
$RM -f $SLAVE_MYPID
kill -9 `$CAT $slave_pid`
$RM -f $slave_pid
else
$ECHO "slave responded to SIGTERM "
fi
fi
SLAVE_RUNNING=0
eval "SLAVE$1_RUNNING=0"
fi
}
......@@ -771,6 +809,8 @@ mysql_stop ()
stop_master
$ECHO "Master shutdown finished"
stop_slave
stop_slave 1
stop_slave 2
$ECHO "Slave shutdown finished"
return 1
......@@ -800,6 +840,7 @@ run_testcase ()
slave_init_script=$TESTDIR/$tname-slave.sh
slave_master_info_file=$TESTDIR/$tname-slave-master-info.opt
SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
many_slaves=`$EXPR \( $tname : rpl_failsafe \) != 0`
if [ -n "$SKIP_TEST" ] ; then
SKIP_THIS_TEST=`$EXPR \( $tname : "$SKIP_TEST" \) != 0`
if [ x$SKIP_THIS_TEST = x1 ] ;
......@@ -874,6 +915,10 @@ run_testcase ()
stop_slave
start_slave
fi
if [ x$many_slaves = x1 ]; then
start_slave 1
start_slave 2
fi
fi
cd $MYSQL_TEST_DIR
......
......@@ -9,3 +9,9 @@ rpl_recovery_rank 1
show variables like 'rpl_recovery_rank';
Variable_name Value
rpl_recovery_rank 2
show variables like 'rpl_recovery_rank';
Variable_name Value
rpl_recovery_rank 3
show variables like 'rpl_recovery_rank';
Variable_name Value
rpl_recovery_rank 4
source include/master-slave.inc;
connect (slave_sec,localhost,root,,test,0,slave.sock-1);
connect (slave_ter,localhost,root,,test,0,slave.sock-2);
connection master;
show variables like 'rpl_recovery_rank';
connection slave;
show variables like 'rpl_recovery_rank';
connection slave_sec;
show variables like 'rpl_recovery_rank';
connection slave_ter;
show variables like 'rpl_recovery_rank';
......@@ -81,7 +81,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \
slave.cc sql_repl.cc sql_union.cc \
mini_client.cc mini_client_errors.c \
stacktrace.c
stacktrace.c repl_failsafe.h repl_failsafe.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS)
......
......@@ -21,6 +21,7 @@
#include "sql_acl.h"
#include "slave.h"
#include "sql_repl.h"
#include "repl_failsafe.h"
#include "stacktrace.h"
#ifdef HAVE_BERKELEY_DB
#include "ha_berkeley.h"
......@@ -1684,6 +1685,7 @@ int main(int argc, char **argv)
(void) pthread_mutex_init(&LOCK_slave, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_server_id, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
(void) pthread_cond_init(&COND_thread_count,NULL);
(void) pthread_cond_init(&COND_refresh,NULL);
(void) pthread_cond_init(&COND_thread_cache,NULL);
......@@ -1692,6 +1694,7 @@ int main(int argc, char **argv)
(void) pthread_cond_init(&COND_binlog_update, NULL);
(void) pthread_cond_init(&COND_slave_stopped, NULL);
(void) pthread_cond_init(&COND_slave_start, NULL);
(void) pthread_cond_init(&COND_rpl_status, NULL);
init_signals();
if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
......@@ -3052,6 +3055,8 @@ struct show_var_st status_vars[]= {
{"Open_streams", (char*) &my_stream_opened, SHOW_INT_CONST},
{"Opened_tables", (char*) &opened_tables, SHOW_LONG},
{"Questions", (char*) 0, SHOW_QUESTION},
{"Rpl_status", (char*) 0,
SHOW_RPL_STATUS},
{"Select_full_join", (char*) &select_full_join_count, SHOW_LONG},
{"Select_full_range_join", (char*) &select_full_range_join_count, SHOW_LONG},
{"Select_range", (char*) &select_range_count, SHOW_LONG},
......@@ -3489,6 +3494,17 @@ static void get_options(int argc,char **argv)
opt_log_slave_updates = 1;
break;
case (int) OPT_INIT_RPL_ROLE:
{
int role;
if ((role=find_type(optarg, &rpl_role_typelib, 2)) <= 0)
{
fprintf(stderr, "Unknown replication role: %s\n", optarg);
exit(1);
}
rpl_status = (rpl_role == 1) ? RPL_AUTH_MASTER : RPL_IDLE_SLAVE;
break;
}
case (int)OPT_REPLICATE_IGNORE_DB:
{
i_string *db = new i_string(optarg);
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB & Sasha
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
// Sasha Pachev <sasha@mysql.com> is currently in charge of this file
#include "mysql_priv.h"
#include "repl_failsafe.h"
RPL_STATUS rpl_status=RPL_NULL;
pthread_mutex_t LOCK_rpl_status;
pthread_cond_t COND_rpl_status;
const char *rpl_role_type[] = {"","MASTER","SLAVE",NullS};
TYPELIB rpl_role_typelib = {array_elements(rpl_role_type)-4,"",
rpl_role_type+1};
const char* rpl_status_type[] = {"AUTH_MASTER","ACTIVE_SLAVE","IDLE_SLAVE",
"LOST_SOLDIER","TROOP_SOLDIER",
"RECOVERY_CAPTAIN","NULL",NullS};
TYPELIB rpl_status_typelib= {array_elements(rpl_status_type)-1,"",
rpl_status_type};
#ifndef REPL_FAILSAFE_H
#define REPL_FAILSAFE_H
typedef enum {RPL_AUTH_MASTER=0,RPL_ACTIVE_SLAVE,RPL_IDLE_SLAVE,
RPL_LOST_SOLDIER,RPL_TROOP_SOLDIER,
RPL_RECOVERY_CAPTAIN,RPL_NULL} RPL_STATUS;
extern RPL_STATUS rpl_status;
extern pthread_mutex_t LOCK_rpl_status;
extern pthread_cond_t COND_rpl_status;
extern TYPELIB rpl_role_typelib, rpl_status_typelib;
extern char* rpl_role_type[], *rpl_status_type;
#endif
......@@ -1164,6 +1164,9 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables)
case SHOW_QUESTION:
net_store_data(&packet2,(uint32) thd->query_id);
break;
case SHOW_RPL_STATUS:
net_store_data(&packet2, rpl_status_type[(int)rpl_status]);
break;
case SHOW_OPENTABLES:
net_store_data(&packet2,(uint32) cached_tables());
break;
......
......@@ -140,6 +140,7 @@ enum SHOW_TYPE { SHOW_LONG,SHOW_CHAR,SHOW_INT,SHOW_CHAR_PTR,SHOW_BOOL,
,SHOW_SSL_CTX_SESS_TIMEOUTS, SHOW_SSL_CTX_SESS_CACHE_FULL
,SHOW_SSL_GET_CIPHER_LIST
#endif /* HAVE_OPENSSL */
,SHOW_RPL_STATUS
};
enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
......
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