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