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