1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
# This test uses chmod, can't be run with root permissions
-- source include/not_as_root.inc
-- source include/have_log_bin.inc
#
# Test is run with max_binlog_size=2048 to force automatic rotation of the
# binary log
# Tests done:
# - Check that slaves reports correct failures if master.info has strange
# modes/information
# - Automatic binary log rotation
# - Ensure that temporary tables works over flush logs and binary log
# changes
# - Test creating a duplicate key error and recover from it
# Requires statement logging
-- source include/have_binlog_format_mixed_or_statement.inc
connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
connect (slave,localhost,root,,test,$SLAVE_MYPORT,$SLAVE_MYSOCK);
# Reset the GTID position explicitly (since we're not using rpl_init.inc).
SET GLOBAL gtid_slave_pos= "";
# Create empty file
let $MYSQLD_SLAVE_DATADIR= `select @@datadir`;
write_file $MYSQLD_SLAVE_DATADIR/master.info;
EOF
chmod 0000 $MYSQLD_SLAVE_DATADIR/master.info;
connection slave;
CALL mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.");
# START SLAVE will fail because it can't read the file (mode 000)
# (system error 13)
--replace_result $MYSQL_TEST_DIR TESTDIR
--error 1105,1105,29
start slave;
chmod 0600 $MYSQLD_SLAVE_DATADIR/master.info;
# It will fail again because the file is empty so the slave cannot get valuable
# info about how to connect to the master from it (failure in
# init_strvar_from_file() in init_master_info()).
--error 1201
start slave;
--replace_result $MASTER_MYPORT MASTER_PORT
# CHANGE MASTER will fail because it first parses master.info before changing
# it (so when master.info is bad, people have to use RESET SLAVE first).
--error 1201
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
reset slave;
--replace_result $MASTER_MYPORT MASTER_PORT
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_ssl_verify_server_cert=0;
connection master;
reset master;
connection slave;
start slave;
--source include/wait_for_slave_to_start.inc
connection master;
#
# Test FLUSH LOGS
#
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables");
create table t1 (s text);
insert into t1 values('Could not break slave'),('Tried hard');
sync_slave_with_master;
let $status_items= Master_Log_File, Relay_Master_Log_File;
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
select * from t1;
connection master;
flush logs;
create table t2(m int not null auto_increment primary key);
insert into t2 values (34),(67),(123);
flush logs;
source include/show_binary_logs.inc;
create table t3 select * from temp_table;
sync_slave_with_master;
select * from t3;
connection master;
drop table temp_table, t3;
#
# Now lets make some duplicate key mess and see if we can recover from it
#
# First insert a value on the slave
connection slave;
insert into t2 values(1234);
#same value on the master
connection master;
set insert_id=1234;
insert into t2 values(NULL);
connection slave;
# 1062 = ER_DUP_ENTRY
call mtr.add_suppression("Slave SQL.*Error .Duplicate entry .1234. for key .PRIMARY.. on query.* error.* 1062");
--let $slave_sql_errno= 1062
--source include/wait_for_slave_sql_error_and_skip.inc
connection master;
#let slave catch up
sync_slave_with_master;
connection master;
purge master logs to 'master-bin.000002';
source include/show_master_logs.inc;
# we just tests if synonyms are accepted
purge binary logs to 'master-bin.000002';
source include/show_binary_logs.inc;
--source include/wait_for_binlog_checkpoint.inc
# Set the purge time 1 second after the last modify time of master-bin.000002.
perl;
open F, ">>".$ENV{'MYSQLTEST_VARDIR'}.'/tmp/rpl_rotate_logs.tmp' or die "Tmp file rpl_rotate_logs.tmp not found";
my $binlogpath = $ENV{'MYSQLTEST_VARDIR'}.'/mysqld.1/data/master-bin.000002';
my @array = stat($binlogpath);
my $filemodifytime = $array[9];
my @t = localtime $filemodifytime;
my $modifytime = sprintf "%04u-%02u-%02u %02u:%02u:%02u",$t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$t[0];
printf F ("let \$tmpval = %s;",$modifytime);
close F;
EOF
--source $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp
remove_file $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp;
--disable_result_log
--replace_result $tmpval tmpval
--eval SELECT @time_for_purge:=DATE_ADD('$tmpval', INTERVAL 1 SECOND)
--enable_result_log
# Disable the warning "is not purged because it is the current active binlog".
# This warning will appear or not, depending on whether the timestamp of
# master-bin.000003 ends up earlier than @time_for_purge or not in the test run.
--disable_warnings
purge master logs before (@time_for_purge);
--enable_warnings
source include/show_binary_logs.inc;
insert into t2 values (65);
sync_slave_with_master;
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
select * from t2;
#
# Test forcing the replication log to rotate
#
connection master;
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables part 2");
# the nummber of produced logs is sensitive to whether checksum is NONE or CRC32
# the value of 103 makes it even
let $1=103;
create table t3 (n int);
disable_query_log;
while ($1)
{
#eval means expand $ expressions
eval insert HIGH_PRIORITY into t3 values($1 + 4);
dec $1;
}
enable_query_log;
select count(*) from t3 where n >= 4;
create table t4 select * from temp_table;
source include/show_binary_logs.inc;
source include/show_master_status.inc;
sync_slave_with_master;
select * from t4;
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
# because of concurrent insert, the table may not be up to date
# if we do not lock
lock tables t3 read;
select count(*) from t3 where n >= 4;
unlock tables;
#clean up
connection master;
drop table if exists t1,t2,t3,t4;
drop temporary table temp_table;
sync_slave_with_master;
--echo End of 4.1 tests
#
# Bug #29420: crash with show and purge binlogs
#
--error 1220
show binlog events in 'non existing_binlog_file';
--disable_warnings
purge master logs before now();
--error 1220
show binlog events in '';
purge master logs before now();
--enable_warnings
--echo End of 5.0 tests
--echo #cleanup
--remove_file $MYSQLD_SLAVE_DATADIR/master.info
--source include/stop_slave.inc
reset slave all;
|