rpl_rotate_logs.test 5.52 KB
Newer Older
1 2 3
# This test uses chmod, can't be run with root permissions
-- source include/not_as_root.inc

4 5
-- source include/have_log_bin.inc

6
#
7
# Test is run with max_binlog_size=2048 to force automatic rotation of the
8 9 10 11 12 13 14 15
# 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
16

17
# Requires statement logging
18
-- source include/have_binlog_format_mixed_or_statement.inc
19

monty@mysql.com's avatar
monty@mysql.com committed
20
connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
21
connect (slave,localhost,root,,test,$SLAVE_MYPORT,$SLAVE_MYSOCK);
22

23
# Create empty file
msvensson@pilot.mysql.com's avatar
msvensson@pilot.mysql.com committed
24 25
let $MYSQLD_SLAVE_DATADIR= `select @@datadir`;
write_file $MYSQLD_SLAVE_DATADIR/master.info;
26
EOF
msvensson@pilot.mysql.com's avatar
msvensson@pilot.mysql.com committed
27
chmod 0000 $MYSQLD_SLAVE_DATADIR/master.info;
28
connection slave;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
29 30 31

# START SLAVE will fail because it can't read the file (mode 000)
# (system error 13)
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
32
--replace_result $MYSQL_TEST_DIR TESTDIR
33
--error 1105,1105,29
34
start slave;
msvensson@pilot.mysql.com's avatar
msvensson@pilot.mysql.com committed
35
chmod 0600  $MYSQLD_SLAVE_DATADIR/master.info;
36 37 38
# 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()).
39
--error 1201
40
start slave;
41
--replace_result $MASTER_MYPORT MASTER_PORT
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
42 43 44

# 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).
45 46
--error 1201
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
47
reset slave;
48
--replace_result $MASTER_MYPORT MASTER_PORT
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
49
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; 
50 51 52
connection master;
reset master;
connection slave;
53
start slave;
54
connection master;
55 56 57 58 59 60

#
# Test FLUSH LOGS
#
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables");
61 62
create table t1 (s text);
insert into t1 values('Could not break slave'),('Tried hard');
63
sync_slave_with_master;
64 65 66
let $status_items= Master_Log_File, Relay_Master_Log_File;
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
67
select * from t1;
68 69
connection master;
flush logs;
70
create table t2(m int not null auto_increment primary key);
71
insert into t2 values (34),(67),(123);
72
flush logs;
hezx@mail.hezx.com's avatar
hezx@mail.hezx.com committed
73
source include/show_binary_logs.inc;
74
create table t3 select * from temp_table;
75

76
sync_slave_with_master;
77 78 79 80 81 82 83 84 85 86 87

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;
88
insert into t2 values(1234);
89

90 91
#same value on the master
connection master;
92 93
set insert_id=1234;
insert into t2 values(NULL);
94
connection slave;
95
# 1062 = ER_DUP_ENTRY
96
call mtr.add_suppression("Slave SQL.*Error .Duplicate entry .1234. for key .PRIMARY.. on query.* Error_code: 1062");
97 98
--let $slave_sql_errno= 1062
--source include/wait_for_slave_sql_error_and_skip.inc
99

100
connection master;
101

sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
102
#let slave catch up
103
sync_slave_with_master;
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
104
connection master;
105
purge master logs to 'master-bin.000002';
hezx@mail.hezx.com's avatar
hezx@mail.hezx.com committed
106
source include/show_master_logs.inc;
107 108
# we just tests if synonyms are accepted
purge binary logs to 'master-bin.000002';
hezx@mail.hezx.com's avatar
hezx@mail.hezx.com committed
109
source include/show_binary_logs.inc;
110

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
# 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;

126
--disable_result_log
127 128
--replace_result $tmpval tmpval
--eval SELECT @time_for_purge:=DATE_ADD('$tmpval', INTERVAL 1 SECOND)
129 130 131
--enable_result_log

purge master logs before (@time_for_purge);
hezx@mail.hezx.com's avatar
hezx@mail.hezx.com committed
132
source include/show_binary_logs.inc;
133
insert into t2 values (65);
134
sync_slave_with_master;
135 136
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
137
select * from t2;
138 139 140 141 142

#
# Test forcing the replication log to rotate
# 

143
connection master;
144 145
create temporary table temp_table (a char(80) not null);
insert into temp_table values ("testing temporary tables part 2");
146
let $1=100;
147

148
create table t3 (n int);
149
disable_query_log;
150 151
while ($1)
{
152 153
#eval means expand $ expressions
 eval insert into t3 values($1 + 4);
154 155
 dec $1;
}
156
enable_query_log;
157
select count(*) from t3 where n >= 4;
158
create table t4 select * from temp_table;
hezx@mail.hezx.com's avatar
hezx@mail.hezx.com committed
159 160
source include/show_binary_logs.inc;
source include/show_master_status.inc;
161 162 163
save_master_pos;
connection slave;
sync_with_master;
164 165
select * from t4;

166 167
source include/show_slave_status.inc;
source include/check_slave_is_running.inc;
168 169 170
# because of concurrent insert, the table may not be up to date
# if we do not lock
lock tables t3 read;
171
select count(*) from t3 where n >= 4;
172
unlock tables;
173 174
#clean up
connection master;
175
drop table if exists t1,t2,t3,t4;
176
sync_slave_with_master;
177

178 179 180 181 182 183 184 185 186 187 188 189 190
--echo End of 4.1 tests

#
# Bug #29420: crash with show and purge binlogs
#
--error 1220
show binlog events in 'non existing_binlog_file';
purge master logs before now();
--error 1220
show binlog events in '';
purge master logs before now();

--echo End of 5.0 tests
191 192
--source include/stop_slave.inc
CHANGE MASTER TO MASTER_HOST = '';