1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

fixed improper read of log name from master.info which broke slave server restart

fixed sync bugs in three test cases
added offset argument to sync_with_master to mysqltest to be able to fix sync bugs
added a test case for slave startup with existing master.info
expanded mysql-test-run.sh to be able to run pre-start shell script initializations


client/mysqltest.c:
  added offset argument to sync_with_master
mysql-test/mysql-test-run.sh:
  added option to run master or slave initialization shell script
mysql-test/r/rpl000016.result:
  fixed bug in test case
mysql-test/t/rpl000012.test:
  fixed syncronization bug
mysql-test/t/rpl000013.test:
  fixed sync bug
mysql-test/t/rpl000016.test:
  fixed ambiguous show slave status.
sql/slave.cc:
  fixed bug that broke slave server start with existing master.info,
  Monty's optimization was not chopping off newline from logname.
This commit is contained in:
unknown
2001-01-24 12:47:09 -07:00
parent 0ee9e34a72
commit b302ee39bc
11 changed files with 83 additions and 16 deletions

View File

@ -485,14 +485,19 @@ int do_echo(struct st_query* q)
return 0;
}
int do_sync_with_master()
int do_sync_with_master(struct st_query* q)
{
MYSQL_RES* res;
MYSQL_ROW row;
MYSQL* mysql = &cur_con->mysql;
char query_buf[FN_REFLEN+128];
int offset = 0;
char* p = q->first_argument;
if(*p)
offset = atoi(p);
sprintf(query_buf, "select master_pos_wait('%s', %ld)", master_pos.file,
master_pos.pos);
master_pos.pos + offset);
if(mysql_query(mysql, query_buf))
die("At line %u: failed in %s: %d: %s", start_lineno, query_buf,
mysql_errno(mysql), mysql_error(mysql));

View File

@ -72,6 +72,7 @@ cd ..
BASEDIR=`pwd`
cd $CWD
MYSQL_TEST_DIR=$BASEDIR/mysql-test
export MYSQL_TEST_DIR
STD_DATA=$MYSQL_TEST_DIR/std_data
hostname=`hostname` # Installed in the mysql privilege table
@ -336,6 +337,11 @@ gcov_collect () {
start_master()
{
[ x$MASTER_RUNNING = 1 ] && return
#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.*
@ -375,6 +381,13 @@ start_slave()
{
[ x$SKIP_SLAVE = x1 ] && return
[ x$SLAVE_RUNNING = 1 ] && return
#run slave initialization shell script if one exists
if [ -f "$slave_init_script" ] ;
then
/bin/sh $slave_init_script
fi
if [ -z "$SLAVE_MASTER_INFO" ] ; then
master_info="--master-user=root \
--master-connect-retry=1 \
@ -502,6 +515,8 @@ run_testcase ()
tname=`$BASENAME $tf .test`
master_opt_file=$TESTDIR/$tname-master.opt
slave_opt_file=$TESTDIR/$tname-slave.opt
master_init_script=$TESTDIR/$tname-master.sh
slave_init_script=$TESTDIR/$tname-slave.sh
slave_master_info_file=$TESTDIR/$tname-slave-master-info.opt
SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`

View File

@ -7,8 +7,6 @@ Log_name
master-bin.001
master-bin.002
master-bin.003
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter
127.0.0.1 root 9306 60 master-bin.003 129 Yes 1062 error 'Duplicate entry '1234' for key 1' on query 'insert into t2 values(1234)' 0
Log_name
master-bin.003
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter

View File

@ -0,0 +1,2 @@
n
24

View File

@ -10,20 +10,26 @@ connection master1;
create temporary table t1 (n int);
insert into t1 values (4),(5);
insert into t2 select * from t1;
save_master_pos;
disconnect master;
connection slave;
#add 1 to the saved position, so we will catch drop table on disconnect
#for sure
sync_with_master 1;
connection master1;
insert into t2 values(6);
disconnect master1;
connect (master2,localhost,root,,test,0,mysql-master.sock);
connection master2;
save_master_pos;
disconnect master1;
connection slave;
sync_with_master;
#same trick - make sure we catch drop of temporary table on disconnect
sync_with_master 1;
@r/rpl000012.result select * from t2;
@r/rpl000012.status.result show status like 'Slave_open_temp_tables';
#
# Clean up
#
connect (master2,localhost,root,,test,0,mysql-master.sock);
connection master2;
drop table if exists t1,t2;
save_master_pos;

View File

@ -13,20 +13,24 @@ connection master1;
create temporary table t1 (n int);
insert into t1 values (4),(5);
insert into t2 select * from t1;
save_master_pos;
disconnect master;
connection slave;
#add 1 to catch drop table
sync_with_master 1;
connection master1;
insert into t2 values(6);
disconnect master1;
connect (master2,localhost,root,,test,0,mysql-master.sock);
connection master2;
save_master_pos;
disconnect master1;
connection slave;
sync_with_master;
# same trick to go one more event
sync_with_master 1;
@r/rpl000013.result select * from t2;
@r/rpl000013.status.result show status like 'Slave_open_temp_tables';
#
# Clean up
#
connect (master2,localhost,root,,test,0,mysql-master.sock);
connection master2;
drop table if exists t1,t2;
save_master_pos;

View File

@ -31,28 +31,34 @@ insert into t2 values (34),(67),(123);
save_master_pos;
flush logs;
show master logs;
#now lets make some duplicate key mess and see if we can recover from it
#first insert a value on the slave
connection slave;
sync_with_master;
insert into t2 values(1234);
#same value on the master
connection master;
save_master_pos;
insert into t2 values(1234);
connection slave;
sync_with_master;
#the slave may have already stopped, so we ignore the error
!slave stop;
#restart slave skipping one event
set sql_slave_skip_counter=1;
slave start;
connection master;
save_master_pos;
#let slave catch up
connection slave;
sync_with_master;
show slave status;
connection master;
purge master logs to 'master-bin.003';
show master logs;
@ -74,6 +80,8 @@ while ($1)
show master logs;
save_master_pos;
connection slave;
slave stop;
slave start;
sync_with_master;
select count(*) from t3 where n = 4;
#clean up

View File

@ -0,0 +1 @@
--skip-slave-start

View File

@ -0,0 +1,9 @@
cat > $MYSQL_TEST_DIR/var/slave-data/master.info <<EOF
master-bin.001
4
127.0.0.1
root
9306
1
EOF

View File

@ -0,0 +1,19 @@
connect (master,localhost,root,,test,0,mysql-master.sock);
connect (slave,localhost,root,,test,0,mysql-slave.sock);
connection master;
reset master;
connection slave;
slave start;
connection master;
drop table if exists t1;
create table t1(n int);
insert into t1 values(24);
save_master_pos;
connection slave;
sync_with_master;
select * from t1;
connection master;
drop table t1;
save_master_pos;
connection slave;
sync_with_master;

View File

@ -509,14 +509,14 @@ int init_master_info(MASTER_INFO* mi)
return 1;
}
if (!(length=my_b_gets(&mi->file, mi->log_file_name,
sizeof(mi->log_file_name))))
if ((length=my_b_gets(&mi->file, mi->log_file_name,
sizeof(mi->log_file_name))) < 1)
{
msg="Error reading log file name from master info file ";
goto error;
}
mi->log_file_name[length]= 0; // kill \n
mi->log_file_name[length-1]= 0; // kill \n
char buf[FN_REFLEN];
if(!my_b_gets(&mi->file, buf, sizeof(buf)))
{